Debian Codegraph @

dojox/mobile/tests/doh/fixedsplitter/FixedSplitterTests.js

raw symbols SCIP
1 var timeoutInterval = 1500;
2
3 var FIXEDSPLITER_CLASSNAME = "mblFixedSplitter";
4 var FIXEDSPLITERPANE_CLASSNAME1 = "mblContainer";
5 var FIXEDSPLITERPANE_CLASSNAME2 = "mblFixedSplitterV";
6 var FIXEDSPLITERPANE_CLASSNAME3 = "mblFixedSplitterH";
7
8 var HEIGHT_RATIO1 = 0.2;
9 var HEIGHT_RATIO2 = 1 - HEIGHT_RATIO1;
10 var WIDTH_RATIO1 = 0.2;
11 var WIDTH_RATIO2 = 1 - WIDTH_RATIO1;
12 var WIDGET_PROPS = [{style:{width:"100%", height:"100%"}, orientation:"V"},
13 {style:{backgroundColor:"yellow", height:"20%"}},
14 {style:{width:"100%", height:"100%"}, orientation:"H"},
15 {style:{backgroundColor:"pink", width:"20%"}},
16 {style:{backgroundColor:"cyan"}}];
17 var WIDGET_INNERHTML = [{},
18 {innerHTML:"pane #1"},
19 {},
20 {innerHTML:"pane #2"},
21 {innerHTML:"pane #3"}];
22 var WIDGET_IDS = [{id:"dojox_mobile_FixedSplitter_0"},
23 {id:"dojox_mobile_Container_0"},
24 {id:"dojox_mobile_FixedSplitter_1"},
25 {id:"dojox_mobile_Container_1"},
26 {id:"dojox_mobile_Container_2"}];
27
28 require([
29 "dojo/_base/connect",
30 "dojo/_base/lang", // dojo.mixin
31 "dojo/dom-construct", // dojo.place
32 "dojo/dom-class", // dojo.hasClass
33 "dojo/dom-geometry",
34 "dojo/window", // dojo.window.getBox
35 "dojo/ready", // dojo.ready
36 "dijit/registry", // dijit.byId
37 "doh/runner", //doh functions
38 "dojox/mobile/FixedSplitter",
39 "dojox/mobile/Container",
40 "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser
41 ], function(connect, lang, domConst, domClass, domGeometry, window, ready, registry, runner, FixedSplitter, Container){
42 function _createFixedSplitterDeclaratively(widgetId) {
43 return registry.byId(widgetId);
44 }
45 function _createFixedSplitterProgrammatically(placeHolderId){
46 // Create FixedSplitter
47 var widget1 = new FixedSplitter(lang.mixin(WIDGET_IDS[0], WIDGET_PROPS[0], WIDGET_INNERHTML[0]));
48 runner.assertNotEqual(null, widget1);
49 domConst.place(widget1.domNode, placeHolderId, "replace");
50 widget1.startup();
51
52 var pane1 = new Container(lang.mixin(WIDGET_IDS[1], WIDGET_PROPS[1], WIDGET_INNERHTML[1]));
53 var widget2 = new FixedSplitter(lang.mixin(WIDGET_IDS[2], WIDGET_PROPS[2], WIDGET_INNERHTML[2]));
54 var pane2 = new Container(lang.mixin(WIDGET_IDS[3], WIDGET_PROPS[3], WIDGET_INNERHTML[3]));
55 var pane3 = new Container(lang.mixin(WIDGET_IDS[4], WIDGET_PROPS[4], WIDGET_INNERHTML[4]));
56
57 widget1.addChild(pane1);
58 widget1.addChild(widget2);
59 widget2.addChild(pane2);
60 widget2.addChild(pane3);
61
62 return widget1;
63 }
64 function _createFixedSplitterProgrammaticallyWithSourceNodeReference(){
65 // Create FixedSplitter
66 var widget1 = new FixedSplitter(WIDGET_PROPS[0], WIDGET_IDS[0].id);
67 runner.assertNotEqual(null, widget1);
68
69 var pane1 = new Container(WIDGET_PROPS[1], WIDGET_IDS[1].id);
70 var widget2 = new FixedSplitter(WIDGET_PROPS[2], WIDGET_IDS[2].id);
71 var pane2 = new Container(WIDGET_PROPS[3], WIDGET_IDS[3].id);
72 var pane3 = new Container(WIDGET_PROPS[4], WIDGET_IDS[4].id);
73 widget1.startup();
74
75 return widget1;
76 }
77 function _assertCorrectFixedSplitter(widget, height, width, className){
78 _assertCorrectFixedSplitterHW(widget, height, width);
79 runner.assertTrue(domClass.contains(widget.domNode, FIXEDSPLITER_CLASSNAME), FIXEDSPLITER_CLASSNAME);
80 if(className){
81 runner.assertTrue(domClass.contains(widget.domNode, className), "expected: " + className + " but got " + widget.domNode.className);
82 }
83 }
84 function _assertCorrectContainer(widget, height, width, className){
85 _assertCorrectFixedSplitterHW(widget, height, width);
86 runner.assertTrue(domClass.contains(widget.domNode, FIXEDSPLITERPANE_CLASSNAME1), FIXEDSPLITERPANE_CLASSNAME1);
87 if(className){
88 runner.assertTrue(domClass.contains(widget.domNode, className), className);
89 }
90 }
91 function _assertCorrectFixedSplitterHW(widget, height, width){
92 runner.assertNotEqual(null, widget, "FixedSplitter: Did not instantiate.");
93 runner.assertTrue( (height - 2) < widget.domNode.offsetHeight && widget.domNode.offsetHeight < (height + 2), "expected: " +height + "+-2 but got " + widget.domNode.offsetHeight + "height: id = " + widget.domNode.id);
94 runner.assertTrue( (width - 2) < widget.domNode.offsetWidth && widget.domNode.offsetWidth < (width + 2), "expected: " +width + "+-2 but got " + widget.domNode.offsetWidth + "offsetWidth: id = " + widget.domNode.id);
95 }
96 ready(function(){
97 if(WIDGET_PROGRAMMATICALLY === 1){
98 _createFixedSplitterProgrammatically("FixedSplitterPlace");
99 }else if(WIDGET_PROGRAMMATICALLY === 2){
100 _createFixedSplitterProgrammaticallyWithSourceNodeReference();
101 }
102
103 runner.register("dojox.mobile.test.doh.FixedSplitter", [
104 {
105 name: "FixedSplitter Verification",
106 timeout: 4000,
107 runTest: function(){
108 var d = new runner.Deferred();
109 setTimeout(d.getTestCallback(function(){
110 var box = window.getBox();
111
112 var widget1 = registry.byId("dojox_mobile_FixedSplitter_0");
113 var widget2 = registry.byId("dojox_mobile_Container_0");
114 var widget3 = registry.byId("dojox_mobile_FixedSplitter_1");
115 var widget4 = registry.byId("dojox_mobile_Container_1");
116 var widget5 = registry.byId("dojox_mobile_Container_2");
117
118 var box2 = domGeometry.getMarginBox(widget1.domNode);
119
120 runner.assertEqual(box.h, widget2.domNode.offsetHeight + widget5.domNode.offsetHeight);
121 runner.assertEqual(box.w, widget4.domNode.offsetWidth + widget5.domNode.offsetWidth);
122
123 _assertCorrectFixedSplitter(widget1, 0, box2.w);
124 _assertCorrectContainer(widget2, Math.round(box.h * HEIGHT_RATIO1), box.w);
125 _assertCorrectFixedSplitter(widget3, Math.round(box.h * HEIGHT_RATIO2), box.w, FIXEDSPLITERPANE_CLASSNAME3);
126 _assertCorrectContainer(widget4, Math.round(box.h * HEIGHT_RATIO2), Math.round(box.w * WIDTH_RATIO1));
127 _assertCorrectContainer(widget5, Math.round(box.h * HEIGHT_RATIO2), Math.round(box.w * WIDTH_RATIO2));
128 }), timeoutInterval);
129 return d;
130 }
131 },
132 {
133 name: "FixedSplitter Verification 2",
134 timeout: 4000,
135 runTest: function(){
136 var widget = new FixedSplitter();
137 var d = new runner.Deferred();
138 var errorCounter = 0;
139 var errorMsg;
140 // Before the fix of #15064, there used to be an error thrown when destroying
141 // right after startup(). To test it, we cannot use a simple try-catch, because
142 // this is about an error thrown by the setTimeout function which used to be set
143 // FixedSplitter's startup(). Hence:
144 window.onerror = function(msg, url, lineNumber){
145 errorCounter++;
146 errorMsg = "After destroy: " + msg + "\nURL: " + url +
147 "\nLine number: " + lineNumber;
148 console.log(errorMsg);
149 };
150 widget.startup();
151 widget.destroyRecursive(false/*preserveDom*/);
152 // Check that no error has been thrown
153 setTimeout(d.getTestCallback(function(){
154 runner.assertEqual(0, errorCounter, errorMsg);
155 }), 2000); // smaller than the total timeout of the test case
156
157 return d;
158 }
159 }
160 ]);
161 runner.run();
162 });
163 })
164