| 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>ListItem Programmatic 3</title> |
| 8 |
<script type="text/javascript" src="../../deviceTheme.js"></script> |
| 9 |
<script type="text/javascript" src="../../../../dojo/dojo.js" |
| 10 |
data-dojo-config="async: true, parseOnLoad: true"></script> |
| 11 |
<script language="JavaScript" type="text/javascript"> |
| 12 |
require([ |
| 13 |
"dojo/_base/declare", |
| 14 |
"dojox/mobile/parser", |
| 15 |
"dojo/ready", // dojo.ready |
| 16 |
"dijit/registry", // dijit.byId |
| 17 |
"doh/runner", // doh functions |
| 18 |
"dojox/mobile/Heading", |
| 19 |
"dojox/mobile/ListItem", |
| 20 |
"dojox/mobile/IconItem", |
| 21 |
"dojox/mobile/IconContainer", |
| 22 |
"dojox/mobile/IconMenuItem", |
| 23 |
"dojox/mobile/IconMenu", |
| 24 |
"dojox/mobile/TabBarButton", |
| 25 |
"dojox/mobile/TabBar", |
| 26 |
"dojox/mobile/ToolBarButton", |
| 27 |
"dojox/mobile", // This is a mobile app. |
| 28 |
"dojox/mobile/View", // This mobile app uses mobile view |
| 29 |
"dojox/mobile/compat" // This mobile app supports running on desktop browsers |
| 30 |
], function(declare, parser, ready, registry, runner, |
| 31 |
Heading, ListItem, IconItem, IconContainer, |
| 32 |
IconMenuItem, IconMenu, TabBarButton, TabBar, ToolBarButton){ |
| 33 |
|
| 34 |
// This test mimics a particular case which happens in dojox/mvc due to |
| 35 |
// the binding mechanism: the values of widget properties are set before |
| 36 |
// the widget is actually started, that is before this.inherited completed. |
| 37 |
// This holds for the following properties: |
| 38 |
// ListItem: icon, checked, deleteIcon, rightIcon, rightIcon2, uncheckIcon. |
| 39 |
// IconItem: icon |
| 40 |
// IconMenuItem: icon |
| 41 |
// TabBarButton: icon (icon1 and icon2 are not delayed) |
| 42 |
// ToolBarButton: icon |
| 43 |
// For these properties, the widgets use a mechanism which reapplies the setters |
| 44 |
// once the startup is completed. |
| 45 |
// The present test checks that these properties have the expected values even |
| 46 |
// if the setters are called before startup completion. |
| 47 |
|
| 48 |
function _createListItem1(){ |
| 49 |
var MyListItem1 = declare( |
| 50 |
"dojox.mobile.MyListItem1", |
| 51 |
ListItem, { |
| 52 |
startup: function(){ |
| 53 |
this.set("checked", true); |
| 54 |
this.inherited(arguments); |
| 55 |
} |
| 56 |
}); |
| 57 |
var list = registry.byId("listInSelectMode"); |
| 58 |
var item = new MyListItem1(); |
| 59 |
list.addChild(item); |
| 60 |
return item; |
| 61 |
}; |
| 62 |
function _assertCorrectListItem1(widget){ |
| 63 |
runner.assertTrue(widget.get("checked"), |
| 64 |
"'checked' property not correctly set if setter called before startup completed"); |
| 65 |
}; |
| 66 |
|
| 67 |
// 2. Test the icon-related properties for a ListItem added to a list which is in "select" mode. |
| 68 |
// In "select" mode, the values of the properties "rightIcon" and "uncheckIcon" are overridden |
| 69 |
// by the setter of "checked". |
| 70 |
function _createListItem2(){ |
| 71 |
var MyListItem2 = declare( |
| 72 |
"dojox.mobile.MyListItem2", |
| 73 |
ListItem, { |
| 74 |
startup: function(){ |
| 75 |
this.set("icon", "../images/a-icon1.png"); |
| 76 |
this.set("deleteIcon", "../images/a-icon2.png"); |
| 77 |
this.set("rightIcon", "../images/a-icon3.png"); |
| 78 |
this.set("rightIcon2", "../images/a-icon4.png"); |
| 79 |
this.set("uncheckIcon", "../images/a-icon5.png"); |
| 80 |
|
| 81 |
this.inherited(arguments); |
| 82 |
} |
| 83 |
}); |
| 84 |
var list = registry.byId("listInSelectMode"); |
| 85 |
var item = new MyListItem2(); |
| 86 |
list.addChild(item); |
| 87 |
return item; |
| 88 |
}; |
| 89 |
function _assertCorrectListItem2(widget){ |
| 90 |
runner.assertEqual("../images/a-icon1.png", widget.get("icon"), |
| 91 |
"'icon' property not correctly set if setter called before startup completed (list in select mode)"); |
| 92 |
runner.assertEqual("../images/a-icon2.png", widget.get("deleteIcon"), |
| 93 |
"'deleteIcon' property not correctly set if setter called before startup completed (list in select mode)"); |
| 94 |
runner.assertEqual("mblDomButtonCheck", widget.get("rightIcon"), |
| 95 |
"'rightIcon' property not correctly set if setter called before startup completed (list in select mode)"); |
| 96 |
runner.assertEqual("../images/a-icon4.png", widget.get("rightIcon2"), |
| 97 |
"'rightIcon2' property not correctly set if setter called before startup completed (list in select mode)"); |
| 98 |
runner.assertEqual(undefined, widget.get("uncheckIcon"), |
| 99 |
"'uncheckIcon' property not correctly set if setter called before startup completed (list in select mode)"); |
| 100 |
}; |
| 101 |
|
| 102 |
// 3. Test the icon-related properties for a ListItem added to a list which is not in "select" mode. |
| 103 |
// In this case, the values of the properties "rightIcon" and "uncheckIcon" are not overridden |
| 104 |
// by the setter of "checked" (because the setter is not called).). |
| 105 |
function _createListItem3(){ |
| 106 |
var MyListItem3 = declare( |
| 107 |
"dojox.mobile.MyListItem3", |
| 108 |
ListItem, { |
| 109 |
startup: function(){ |
| 110 |
// This mimics what happens in dojox/mvc due to the binding mechanism: |
| 111 |
// the values of properties are set before the widget is actually started, |
| 112 |
// that is before this.inherited completed its execution. |
| 113 |
// The properties below are among those for which ListItem uses a mechanism |
| 114 |
// which reapplies the setters once the startup is completed. |
| 115 |
this.set("icon", "../images/a-icon1.png"); |
| 116 |
this.set("deleteIcon", "../images/a-icon2.png"); |
| 117 |
this.set("rightIcon", "../images/a-icon3.png"); |
| 118 |
this.set("rightIcon2", "../images/a-icon4.png"); |
| 119 |
this.set("uncheckIcon", "../images/a-icon5.png"); |
| 120 |
|
| 121 |
this.inherited(arguments); |
| 122 |
} |
| 123 |
}); |
| 124 |
var list = registry.byId("listNotInSelectMode"); |
| 125 |
var item = new MyListItem3(); |
| 126 |
list.addChild(item); |
| 127 |
return item; |
| 128 |
}; |
| 129 |
function _assertCorrectListItem3(widget){ |
| 130 |
runner.assertEqual("../images/a-icon1.png", widget.get("icon"), |
| 131 |
"'icon' property not correctly set if setter called before startup completed (list not in select mode)"); |
| 132 |
runner.assertEqual("../images/a-icon2.png", widget.get("deleteIcon"), |
| 133 |
"'deleteIcon' property not correctly set if setter called before startup completed (list not in select mode)"); |
| 134 |
runner.assertEqual("../images/a-icon3.png", widget.get("rightIcon"), |
| 135 |
"'rightIcon' property not correctly set if setter called before startup completed (list not in select mode)"); |
| 136 |
runner.assertEqual("../images/a-icon4.png", widget.get("rightIcon2"), |
| 137 |
"'rightIcon2' property not correctly set if setter called before startup completed (list not in select mode)"); |
| 138 |
runner.assertEqual("../images/a-icon5.png", widget.get("uncheckIcon"), |
| 139 |
"'uncheckIcon' property not correctly set if setter called before startup completed (list not in select mode)"); |
| 140 |
}; |
| 141 |
|
| 142 |
// 4. Test the icon property for an IconItem added to an IconContainer |
| 143 |
function _createIconItem(){ |
| 144 |
var MyIconItem = declare( |
| 145 |
"dojox.mobile.MyIconItem", |
| 146 |
IconItem, { |
| 147 |
startup: function(){ |
| 148 |
this.set("icon", "../images/a-icon1.png"); |
| 149 |
this.inherited(arguments); |
| 150 |
} |
| 151 |
}); |
| 152 |
var list = registry.byId("iconContainer"); |
| 153 |
var item = new MyIconItem(); |
| 154 |
list.addChild(item); |
| 155 |
return item; |
| 156 |
}; |
| 157 |
function _assertCorrectIconItem(widget){ |
| 158 |
runner.assertEqual("../images/a-icon1.png", widget.get("icon"), |
| 159 |
"'icon' property not correctly set if setter called before startup completed (IconItem)"); |
| 160 |
}; |
| 161 |
|
| 162 |
// 5. Test the icon property for an IconMenuItem added to an IconMenu |
| 163 |
function _createIconMenuItem(){ |
| 164 |
var MyIconMenuItem = declare( |
| 165 |
"dojox.mobile.MyIconMenuItem", |
| 166 |
IconMenuItem, { |
| 167 |
startup: function(){ |
| 168 |
this.set("icon", "../images/a-icon1.png"); |
| 169 |
this.inherited(arguments); |
| 170 |
} |
| 171 |
}); |
| 172 |
var list = registry.byId("iconMenu"); |
| 173 |
var item = new MyIconMenuItem(); |
| 174 |
list.addChild(item); |
| 175 |
return item; |
| 176 |
}; |
| 177 |
function _assertCorrectIconMenuItem(widget){ |
| 178 |
runner.assertEqual("../images/a-icon1.png", widget.get("icon"), |
| 179 |
"'icon' property not correctly set if setter called before startup completed (IconMenuItem)"); |
| 180 |
}; |
| 181 |
|
| 182 |
// 6. Test the icon1 and icon2 properties for a TabBarButton added to a TabBar |
| 183 |
function _createTabBarButton(){ |
| 184 |
var MyTabBarButton = declare( |
| 185 |
"dojox.mobile.MyTabBarButton", |
| 186 |
TabBarButton, { |
| 187 |
startup: function(){ |
| 188 |
this.set("icon", "../images/a-icon1.png"); |
| 189 |
this.set("icon1", "../images/a-icon2.png"); |
| 190 |
this.set("icon2", "../images/a-icon3.png"); |
| 191 |
this.inherited(arguments); |
| 192 |
} |
| 193 |
}); |
| 194 |
var list = registry.byId("tabBar"); |
| 195 |
var item = new MyTabBarButton(); |
| 196 |
list.addChild(item); |
| 197 |
return item; |
| 198 |
}; |
| 199 |
function _assertCorrectIconTabBarButton(widget){ |
| 200 |
runner.assertEqual("../images/a-icon1.png", widget.get("icon"), |
| 201 |
"'icon' property not correctly set if setter called before startup completed (TabBarButton)"); |
| 202 |
runner.assertEqual("../images/a-icon2.png", widget.get("icon1"), |
| 203 |
"'icon1' property not correctly set if setter called before startup completed (TabBarButton)"); |
| 204 |
runner.assertEqual("../images/a-icon3.png", widget.get("icon2"), |
| 205 |
"'icon2' property not correctly set if setter called before startup completed (TabBarButton)"); |
| 206 |
}; |
| 207 |
|
| 208 |
// 7. Test the icon property for a ToolBarButton added to a parent |
| 209 |
function _createToolBarButton(){ |
| 210 |
var MyToolBarButton = declare( |
| 211 |
"dojox.mobile.MyToolBarButton", |
| 212 |
ToolBarButton, { |
| 213 |
startup: function(){ |
| 214 |
this.set("icon", "../images/a-icon1.png"); |
| 215 |
this.inherited(arguments); |
| 216 |
} |
| 217 |
}); |
| 218 |
var list = registry.byId("toolBar"); |
| 219 |
var item = new MyToolBarButton(); |
| 220 |
list.addChild(item); |
| 221 |
return item; |
| 222 |
}; |
| 223 |
function _assertCorrectIconToolBarButton(widget){ |
| 224 |
runner.assertEqual("../images/a-icon1.png", widget.get("icon"), |
| 225 |
"'icon' property not correctly set if setter called before startup completed (ToolBarButton)"); |
| 226 |
}; |
| 227 |
|
| 228 |
ready(function(){ |
| 229 |
runner.register("dojox.mobile.test.doh.ItemBase_subclasses_Programmatic", [ |
| 230 |
{ |
| 231 |
name: "ItemBase_subclasses_Programmatic ListItem.checked", |
| 232 |
timeout: 2000, |
| 233 |
runTest: function(){ |
| 234 |
var widget = _createListItem1(); |
| 235 |
_assertCorrectListItem1(widget); |
| 236 |
} |
| 237 |
}, |
| 238 |
{ |
| 239 |
name: "ItemBase_subclasses_Programmatic ListItem.icon (select mode)", |
| 240 |
timeout: 2000, |
| 241 |
runTest: function(){ |
| 242 |
var widget = _createListItem2(); |
| 243 |
_assertCorrectListItem2(widget); |
| 244 |
} |
| 245 |
}, |
| 246 |
{ |
| 247 |
name: "ItemBase_subclasses_Programmatic ListItem.icon (not select mode)", |
| 248 |
timeout: 2000, |
| 249 |
runTest: function(){ |
| 250 |
var widget = _createListItem3(); |
| 251 |
_assertCorrectListItem3(widget); |
| 252 |
} |
| 253 |
}, |
| 254 |
{ |
| 255 |
name: "ItemBase_subclasses_Programmatic IconItem.icon", |
| 256 |
timeout: 2000, |
| 257 |
runTest: function(){ |
| 258 |
var widget = _createIconItem(); |
| 259 |
_assertCorrectIconItem(widget); |
| 260 |
} |
| 261 |
}, |
| 262 |
{ |
| 263 |
name: "ItemBase_subclasses_Programmatic IconMenuItem.icon", |
| 264 |
timeout: 2000, |
| 265 |
runTest: function(){ |
| 266 |
var widget = _createIconMenuItem(); |
| 267 |
_assertCorrectIconMenuItem(widget); |
| 268 |
} |
| 269 |
}, |
| 270 |
{ |
| 271 |
name: "ItemBase_subclasses_Programmatic TabBarButton.icon/icon1/icon2", |
| 272 |
timeout: 2000, |
| 273 |
runTest: function(){ |
| 274 |
var widget = _createTabBarButton(); |
| 275 |
_assertCorrectIconTabBarButton(widget); |
| 276 |
} |
| 277 |
}, |
| 278 |
{ |
| 279 |
name: "ItemBase_subclasses_Programmatic ToolBarButton.icon", |
| 280 |
timeout: 2000, |
| 281 |
runTest: function(){ |
| 282 |
var widget = _createToolBarButton(); |
| 283 |
_assertCorrectIconToolBarButton(widget); |
| 284 |
} |
| 285 |
} |
| 286 |
]); |
| 287 |
runner.run(); |
| 288 |
}); |
| 289 |
}); |
| 290 |
</script> |
| 291 |
</head> |
| 292 |
<body style="visibility:hidden;"> |
| 293 |
<div id="view" data-dojo-type="dojox/mobile/View" selected="true"> |
| 294 |
<h1 data-dojo-type="dojox/mobile/Heading">RoundRectList</h1> |
| 295 |
|
| 296 |
<ul id="listInSelectMode" data-dojo-type="dojox/mobile/RoundRectList" |
| 297 |
data-dojo-props="select:'single'"> |
| 298 |
</ul> |
| 299 |
|
| 300 |
<ul id="listNotInSelectMode" data-dojo-type="dojox/mobile/RoundRectList"> |
| 301 |
</ul> |
| 302 |
<ul id="iconContainer" data-dojo-type="dojox/mobile/IconContainer"> |
| 303 |
</ul> |
| 304 |
<ul id="iconMenu" data-dojo-type="dojox/mobile/IconMenu"> |
| 305 |
</ul> |
| 306 |
<ul id="tabBar" data-dojo-type="dojox/mobile/TabBar"> |
| 307 |
</ul> |
| 308 |
<div id="toolBar" data-dojo-type="dojox/mobile/Heading"> |
| 309 |
</div> |
| 310 |
</div> |
| 311 |
</body> |
| 312 |
</html> |