| 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>Accordion Tests</title> |
| 8 | |
| 9 | <script type="text/javascript" src="../../../deviceTheme.js" data-dojo-config="'dojo-bidi': true, mblThemeFiles: ['base','Accordion','TabBar']"></script> |
| 10 | <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true, mblAlwaysHideAddressBar: true, has:{'dojo-bidi': true}"></script> |
| 11 | <style type="text/css"> |
| 12 | @import "../../../themes/common/domButtons/DomButtonBlackRightArrow16.css"; |
| 13 | @import "../../../themes/common/domButtons/DomButtonWhiteDownArrow16.css"; |
| 14 | @import "../../../themes/common/dijit/dijit.css"; |
| 15 | html,body{ |
| 16 | height: 100%; |
| 17 | } |
| 18 | .myPane { |
| 19 | background-image: -webkit-gradient(linear, left top, left bottom, from(#dcdcdc), to(#FFFFFF)); |
| 20 | font-family: Times New Roman, Helvetica; |
| 21 | color: black; |
| 22 | } |
| 23 | </style> |
| 24 | |
| 25 | <script type="text/javascript"> |
| 26 | require([ |
| 27 | "dojo/dom-construct", // dojo.place |
| 28 | "dojo/dom-class", // dojo.hasClass |
| 29 | "dojo/ready", // dojo.ready |
| 30 | "dijit/registry", // dijit.byId |
| 31 | "doh/runner", //doh functions |
| 32 | "dojox/mobile/Accordion", |
| 33 | "dojox/mobile/ContentPane", |
| 34 | "dojo/parser", |
| 35 | "dojox/mobile", |
| 36 | "dojox/mobile/compat", |
| 37 | "dojox/mobile/View" |
| 38 | ], function(domConst, domClass, ready, registry, runner, Accordion, ContentPane){ |
| 39 | function _createAccordionDeclaratively(widgetId){ |
| 40 | return registry.byId(widgetId); |
| 41 | } |
| 42 | |
| 43 | function _createAccordionProgrammatically(placeHolderId, widgetId){ |
| 44 | var r = new Accordion({id:widgetId, iconBase:"../../images/icons16.png", dir:"rtl"}); |
| 45 | runner.assertNotEqual(null, r); |
| 46 | domConst.place(r.domNode, placeHolderId, "replace"); |
| 47 | r.startup(); |
| 48 | var childWidget = ContentPane({label:"External Content 2", icon1:"mblDomButtonBlackRightArrow16", icon2:"mblDomButtonWhiteDownArrow16", href:"dojo.html"}); |
| 49 | r.addChild(childWidget); |
| 50 | return r; |
| 51 | } |
| 52 | |
| 53 | function _createAccordionProgrammaticallyWithSourceNodeReference(widgetId, childWidgetId){ |
| 54 | var r = new Accordion({iconBase:"../../images/icons16.png", dir:"rtl"}, widgetId); |
| 55 | r.startup(); |
| 56 | return r; |
| 57 | } |
| 58 | function _assertCorrectAccordion(widget){ |
| 59 | var childWidgets = widget.getChildren(); |
| 60 | runner.assertEqual(1, childWidgets.length, "id= " + widget.domNode.id + " childWidgets.length=" + childWidgets.length); |
| 61 | var child = childWidgets[0]; |
| 62 | runner.assertEqual("none", child.domNode.style.display, "id= " + widget.domNode.id); |
| 63 | runner.assertEqual('mblAccordionIconParent mblAccordionIconParent1 mblAccordionIconParentRtl', child._at.iconParentNode1.className); |
| 64 | |
| 65 | } |
| 66 | function _showView2(){ |
| 67 | var view1 = registry.byId("view1"); |
| 68 | view1.performTransition("view2", 1, "none"); |
| 69 | } |
| 70 | dojo.ready(function(){ |
| 71 | doh.register("dojox.mobile.test.doh.AccordionTests", [ |
| 72 | function testInView1(){ |
| 73 | var widget1 = _createAccordionDeclaratively("dojox_mobile_Accordion_0"); |
| 74 | var widget2 = _createAccordionProgrammatically("view1-Accordion2place", "view1-Accordion2"); |
| 75 | var widget3 = _createAccordionProgrammaticallyWithSourceNodeReference("view1-Accordion3"); |
| 76 | |
| 77 | setTimeout(function() { |
| 78 | _assertCorrectAccordion(widget1); |
| 79 | _assertCorrectAccordion(widget2); |
| 80 | _assertCorrectAccordion(widget3); |
| 81 | }, 1000); |
| 82 | }, |
| 83 | function testInView2(){ |
| 84 | var widget1 = _createAccordionDeclaratively("dojox_mobile_Accordion_1"); |
| 85 | var widget2 = _createAccordionProgrammatically("view2-Accordion2place", "view2-Accordion2"); |
| 86 | var widget3 = _createAccordionProgrammaticallyWithSourceNodeReference("view2-Accordion3"); |
| 87 | |
| 88 | _showView2(); |
| 89 | |
| 90 | setTimeout(function() { |
| 91 | _assertCorrectAccordion(widget1); |
| 92 | _assertCorrectAccordion(widget2); |
| 93 | _assertCorrectAccordion(widget3); |
| 94 | }, 1000); |
| 95 | }, |
| 96 | { |
| 97 | name: "testInView3.1", |
| 98 | timeout: 3000, |
| 99 | runTest: function(){ |
| 100 | // Test case for #15064: destroy right after startup() |
| 101 | var accordion = |
| 102 | new Accordion({iconBase:"../../images/icons16.png", fixedHeight: true}, |
| 103 | "accordion"); |
| 104 | var d = new runner.Deferred(); |
| 105 | var errorCounter = 0; |
| 106 | var errorMsg; |
| 107 | // Before the fix of #15064, there used to be an error thrown when destroying |
| 108 | // right after startup(). To test it, we cannot use a simple try-catch, because |
| 109 | // this is about an error thrown by the setTimeout function which used to be set |
| 110 | // Accordion's startup(). Hence: |
| 111 | window.onerror = function(msg, url, lineNumber){ |
| 112 | errorCounter++; |
| 113 | errorMsg = "After destroy: " + msg + "\nURL: " + url + |
| 114 | "\nLine number: " + lineNumber; |
| 115 | console.log(errorMsg); |
| 116 | }; |
| 117 | accordion.startup(); |
| 118 | accordion.destroyRecursive(false/*preserveDom*/); |
| 119 | // Check that no error has been thrown |
| 120 | setTimeout(d.getTestCallback(function(){ |
| 121 | runner.assertEqual(0, errorCounter, errorMsg); |
| 122 | }), 2000); // smaller than the total timeout of the test case |
| 123 | |
| 124 | return d; |
| 125 | } |
| 126 | }, |
| 127 | { |
| 128 | name: "testInView3.2", |
| 129 | timeout: 3000, |
| 130 | runTest: function(){ |
| 131 | // Test case for #15064: destroy right after addChild() |
| 132 | var accordion = |
| 133 | new Accordion({iconBase:"../../images/icons16.png", fixedHeight: true}, |
| 134 | "accordion"); |
| 135 | var d = new runner.Deferred(); |
| 136 | var errorCounter = 0; |
| 137 | var errorMsg; |
| 138 | // Before the fix of #15064, there used to be an error thrown when destroying |
| 139 | // right after startup(). To test it, we cannot use a simple try-catch, because |
| 140 | // this is about an error thrown by the setTimeout function which used to be set |
| 141 | // Accordion's startup(). Hence: |
| 142 | window.onerror = function(msg, url, lineNumber){ |
| 143 | errorCounter++; |
| 144 | errorMsg = "After destroy: " + msg + "\nURL: " + url + |
| 145 | "\nLine number: " + lineNumber; |
| 146 | console.log(errorMsg); |
| 147 | }; |
| 148 | accordion.startup(); |
| 149 | var childWidget = |
| 150 | ContentPane({label:"External Content 2", |
| 151 | icon1:"mblDomButtonBlackRightArrow16", |
| 152 | icon2:"mblDomButtonWhiteDownArrow16", href:"dojo.html"}); |
| 153 | accordion.addChild(childWidget); |
| 154 | accordion.destroyRecursive(false/*preserveDom*/); |
| 155 | // Check that no error has been thrown |
| 156 | setTimeout(d.getTestCallback(function(){ |
| 157 | runner.assertEqual(0, errorCounter, errorMsg); |
| 158 | }), 2000); // smaller than the total timeout of the test case |
| 159 | |
| 160 | return d; |
| 161 | } |
| 162 | } |
| 163 | ]); |
| 164 | runner.run(); |
| 165 | }); |
| 166 | }) |
| 167 | </script> |
| 168 | |
| 169 | </head> |
| 170 | <body> |
| 171 | <div dir="rtl" id="view1" data-dojo-type="dojox.mobile.View"> |
| 172 | <h1>View 1</h1> |
| 173 | <div data-dojo-type="dojox.mobile.Accordion" data-dojo-props='iconBase:"../../images/icons16.png"'> |
| 174 | <div data-dojo-type="dojox.mobile.ContentPane" data-dojo-props='label:"External Content 1", icon1:"mblDomButtonBlackRightArrow16", icon2:"mblDomButtonWhiteDownArrow16", href:"dojo.html"'> |
| 175 | </div> |
| 176 | </div> |
| 177 | <div id="view1-Accordion2place"></div> |
| 178 | <div id="view1-Accordion3"> |
| 179 | <div data-dojo-type="dojox.mobile.ContentPane" data-dojo-props='label:"External Content 3", icon1:"mblDomButtonBlackRightArrow16", icon2:"mblDomButtonWhiteDownArrow16", href:"dojo.html"'> |
| 180 | </div> |
| 181 | </div> |
| 182 | </div> |
| 183 | <div dir="rtl" id="view2" data-dojo-type="dojox.mobile.View"> |
| 184 | <h1>View 2</h1> |
| 185 | <div data-dojo-type="dojox.mobile.Accordion" data-dojo-props='iconBase:"../../images/icons16.png"'> |
| 186 | <div data-dojo-type="dojox.mobile.ContentPane" data-dojo-props='label:"External Content 1", icon1:"mblDomButtonBlackRightArrow16", icon2:"mblDomButtonWhiteDownArrow16", href:"dojo.html"'> |
| 187 | </div> |
| 188 | </div> |
| 189 | <div id="view2-Accordion2place"></div> |
| 190 | <div id="view2-Accordion3"> |
| 191 | <div data-dojo-type="dojox.mobile.ContentPane" data-dojo-props='label:"External Content 3", icon1:"mblDomButtonBlackRightArrow16", icon2:"mblDomButtonWhiteDownArrow16", href:"dojo.html"'> |
| 192 | </div> |
| 193 | </div> |
| 194 | </div> |
| 195 | |
| 196 | <div dir="rtl" id="view3" data-dojo-type="dojox.mobile.View"> |
| 197 | <h1>View ""</h1> |
| 198 | <div id="accordion"> |
| 199 | </div> |
| 200 | </div> |
| 201 | </body> |
| 202 | </html> |