Debian Codegraph @

dojox/mobile/tests/doh/button/ButtonTests.html

raw symbols SCIP
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
5 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
6 <meta name="apple-mobile-web-app-capable" content="yes" />
7 <title>Button Tests</title>
8 <script type="text/javascript" src="../../../deviceTheme.js"></script>
9 <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>
10 <script language="JavaScript" type="text/javascript">
11 var BUTTON_LABEL = "Button";
12 var BUTTON_WIDTH = 58;
13 var BUTTON_WIDTH_FF = 64;
14 var BUTTON_WIDTH_WINTHEME = 64; // IE10
15 var BUTTON_HEIGHT = 27;
16 var BUTTON_HEIGHT_WINTHEME = 28; // IE10
17 // actual width/height should differ from the expected one by at most this
18 // percentage of difference
19 var DIFF_PERCENTAGE = 15; // at most 15% of difference
20
21 require([
22 "dojo/sniff",
23 "dojo/dom-class",
24 "dojo/dom-construct", // dojo.place
25 "dojo/ready", // dojo.ready
26 "dojo/_base/window",
27 "dijit/registry", // dijit.byId
28 "doh/runner", //doh functions
29 "dojox/mobile/Button",
30 "dojox/mobile", // This is a mobile app.
31 "dojox/mobile/View", // This mobile app uses mobile view
32 "dojox/mobile/compat", // This mobile app supports running on desktop browsers
33 "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser
34 ], function(has, domClass, domConst, ready, win, registry, runner, Button){
35 function _createButtonDeclaratively(buttonId) {
36 return registry.byId(buttonId);
37 };
38 function _createButtonProgrammatically(placeHolderId){
39 var button = new Button({label:BUTTON_LABEL});
40 runner.assertNotEqual(null, button, placeHolderId);
41 domConst.place(button.domNode, placeHolderId, "replace");
42 button.startup();
43 return button;
44 };
45 function _createButtonProgrammaticallyWithSourceNodeReference(buttonId){
46 return new Button({label:BUTTON_LABEL}, buttonId);
47 };
48 function _assertCorrectButton(width, height, button){
49 if(width < 0){
50 return; // Skip for IE<9 (a negative width is the convention we use for skipping)
51 }
52 runner.assertNotEqual(null, button);
53 var widthDiffPercentage = Math.abs((width - button.domNode.clientWidth) / width) * 100;
54 var heightDiffPercentage = Math.abs((height - button.domNode.clientHeight) / width) * 100;
55 runner.assertTrue(widthDiffPercentage < DIFF_PERCENTAGE,
56 "width got " + button.domNode.clientWidth + " expected: near " + width +
57 " with less than " + DIFF_PERCENTAGE + "%" + " of difference; id=" + button.domNode.id);
58 runner.assertTrue(heightDiffPercentage < DIFF_PERCENTAGE,
59 "height got " + button.domNode.clientHeight + " expected: near " + height +
60 " with less than " + DIFF_PERCENTAGE + "%" + " of difference; id=" + button.domNode.id);
61 }
62 function _showView2(){
63 var view1 = registry.byId("view1");
64 view1.performTransition("view2", 1, "none");
65 };
66 ready(function(){
67 var buttonWidth = domClass.contains(win.doc.documentElement, "windows_theme") ?
68 BUTTON_WIDTH_WINTHEME : has("ff") ? BUTTON_WIDTH_FF : BUTTON_WIDTH;
69 var buttonHeight = domClass.contains(win.doc.documentElement, "windows_theme") ?
70 BUTTON_HEIGHT_WINTHEME : BUTTON_HEIGHT;
71 // Skip the checks for IE<9
72 if(has("ie") < 9){
73 buttonWidth = -1; // negative value as convention for skipping tests
74 }
75 runner.register("dojox.mobile.test.doh.ButtonTests", [
76 function testInView1(){
77 var button1 = _createButtonDeclaratively("view1-button1");
78 var button2 = _createButtonProgrammatically("view1-button2");
79 var button3 = _createButtonProgrammaticallyWithSourceNodeReference("view1-button3");
80
81 _assertCorrectButton(buttonWidth, buttonHeight, button1);
82 _assertCorrectButton(buttonWidth, buttonHeight, button2);
83 _assertCorrectButton(buttonWidth, buttonHeight, button3);
84 },
85 function testInView2(){
86 var button1 = _createButtonDeclaratively("view2-button1");
87 var button2 = _createButtonProgrammatically("view2-button2");
88 var button3 = _createButtonProgrammaticallyWithSourceNodeReference("view2-button3");
89
90 _showView2();
91
92 _assertCorrectButton(buttonWidth, buttonHeight, button1);
93 _assertCorrectButton(buttonWidth, buttonHeight, button2);
94 _assertCorrectButton(buttonWidth, buttonHeight, button3);
95 }
96 ]);
97 runner.run();
98 });
99 });
100 </script>
101 </head>
102 <body>
103 <div id="view1" data-dojo-type="dojox.mobile.View" selected="true">
104 <h1>View 1</h1>
105 <button id="view1-button1" data-dojo-type="dojox.mobile.Button">Button</button>
106 <div id="view1-button2"></div>
107 <button id="view1-button3"></button>
108 </div>
109 <div id="view2" data-dojo-type="dojox.mobile.View">
110 <h1>View 2</h1>
111 <button id="view2-button1" data-dojo-type="dojox.mobile.Button">Button</button>
112 <div id="view2-button2"></div>
113 <button id="view2-button3"></button>
114 </div>
115 </body>
116 </html>