~ubuntu-branches/ubuntu/precise/maas/precise-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/node-focusmanager/tests/focusmanager.html

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
 
   "http://www.w3.org/TR/html4/strict.dtd">
3
 
 
4
 
<html lang="en">
5
 
<head>
6
 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7
 
        <title>YUI FocusManager Node Plugin Tests</title>
8
 
 
9
 
        <style type="text/css">
10
 
 
11
 
                ul {
12
 
                        width: 150px;
13
 
                        background-color: #ccc;
14
 
                        border: solid 1px #333;
15
 
                        padding: 10px;
16
 
                        list-style: none;
17
 
                }
18
 
                
19
 
                ul ul {
20
 
                        width: auto;
21
 
                }
22
 
 
23
 
                .focused {
24
 
 
25
 
                        border: solid 1px #ffcc00;
26
 
                        background-color: yellow;
27
 
 
28
 
                }
29
 
        
30
 
        </style>
31
 
 
32
 
</head>
33
 
<body class="yui3-skin-sam">
34
 
 
35
 
<ul id="list-1">
36
 
        <li>
37
 
                <a href="#" class="focusable"><em>One</em></a>
38
 
                <ul id="list-1-2">
39
 
                        <li><a href="#" class="focusable">One</a></li>
40
 
                        <li><a href="#" class="focusable">Two</a></li>
41
 
                        <li><a href="#" class="focusable">Three</a></li>
42
 
                        <li><a href="#" class="focusable">Four</a></li>
43
 
                </ul>
44
 
        </li>
45
 
        <li><a href="#" class="focusable" tabindex="0">Two</a></li>
46
 
        <li><a href="#" class="focusable">Three</a></li>
47
 
        <li><a href="#" class="focusable">Four</a></li>
48
 
        <li><input type="button" name="button-1" value="Five" class="focusable" disabled></li>
49
 
        <li><input type="button" name="button-2" value="Six" class="focusable"></li>
50
 
        <li><button type="button" class="focusable" disabled><em>Seven</em></button></li>       
51
 
        <li><button type="button" class="focusable"><em><em>Eight</em></em></button></li>
52
 
</ul>
53
 
 
54
 
<ul id="list-2">
55
 
        <li>
56
 
                <a href="#" class="focusable"><em>One</em></a>
57
 
                <ul id="list-2-2">
58
 
                        <li><a id="anchor-1" href="#" class="focusable">One</a></li>
59
 
                        <li><a href="#" class="focusable">Two</a></li>
60
 
                        <li><a href="#" class="focusable">Three</a></li>
61
 
                        <li><a href="#" class="focusable">Four</a></li>
62
 
                </ul>
63
 
        </li>
64
 
        <li><a href="#" class="focusable">Two</a></li>
65
 
        <li><a href="#" class="focusable">Three</a></li>
66
 
        <li><a href="#" class="focusable">Four</a></li>
67
 
        <li><input type="button" name="button-1" value="Five" class="focusable" disabled></li>
68
 
        <li><input type="button" name="button-2" value="Six" class="focusable"></li>
69
 
        <li><button type="button" class="focusable" disabled><em>Seven</em></button></li>       
70
 
        <li><button type="button" class="focusable"><em><em>Eight</em></em></button></li>
71
 
</ul>
72
 
 
73
 
<ul id="list-3"></ul>
74
 
 
75
 
 
76
 
<script src="../../../build/yui/yui.js" type="text/javascript"></script>
77
 
<script type="text/javascript">
78
 
 
79
 
        YUI({timeout: 10000, filter:'raw'}).use("node-event-simulate", "node-focusmanager", "test", "console", function(Y) {
80
 
 
81
 
                Y.on("contentready", function () {
82
 
 
83
 
                var myConsole = new Y.Console().render();
84
 
 
85
 
               var testFocusManager = new Y.Test.Case({
86
 
 
87
 
                    name: "FocusManager Tests",
88
 
 
89
 
                    testActiveDescendant: function() {
90
 
 
91
 
                                        //      TEST #1:
92
 
                                        //      If no value is specified for the "activeDescendant"
93
 
                                        //      attribute, the value is interpreted from the markup 
94
 
                                        //      by using the first descendant whose tabIndex attribute
95
 
                                        //      is set to "0"
96
 
                                        
97
 
                                        var oList1 = Y.one("#list-1");
98
 
 
99
 
                                        oList1.plug(Y.Plugin.NodeFocusManager, { 
100
 
                                                descendants: ">li>.focusable",
101
 
                                                keys: { next: "down:40", previous: "down:38" },
102
 
                                                focusClass: "focused",
103
 
                                                circular: true
104
 
                                        });
105
 
 
106
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 1));
107
 
 
108
 
 
109
 
                                        //      TEST #2:
110
 
                                        //      If no value is specified for the "activeDescendant"
111
 
                                        //      attribute, the value is interpreted from the markup 
112
 
                                        //      by using the first descendant whose tabIndex attribute
113
 
                                        //      is set to "0"
114
 
 
115
 
                                        var oList2 = Y.one("#list-2");
116
 
 
117
 
                                        oList2.plug(Y.Plugin.NodeFocusManager, { 
118
 
                                                descendants: ">li>.focusable",
119
 
                                                keys: { next: "down:40", previous: "down:38" },
120
 
                                                focusClass: "focused",
121
 
                                                circular: true
122
 
                                        });                                     
123
 
 
124
 
                        Y.Assert.isTrue((oList2.focusManager.get("activeDescendant") === 0));
125
 
 
126
 
 
127
 
                                        //      Clean up for next set of tests
128
 
                                        oList1.unplug("focusManager");
129
 
                                        oList2.unplug("focusManager");
130
 
 
131
 
 
132
 
                                        //      Test #3:
133
 
                                        //      The value specified for the activeDescendant attribute
134
 
                                        //      via the configuration object, should supercede the 
135
 
                                        //      value interpreted via the markup                                        
136
 
                                        oList1.plug(Y.Plugin.NodeFocusManager, { 
137
 
                                                descendants: ">li>.focusable",
138
 
                                                activeDescendant: 3,
139
 
                                                keys: { next: "down:40", previous: "down:38" },
140
 
                                                focusClass: "focused",
141
 
                                                circular: true
142
 
                                        });
143
 
 
144
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 3));
145
 
        
146
 
 
147
 
                                        //      TEST #4:
148
 
                                        //      Setting the "activeDescendant" attribute to -1 should
149
 
                                        //      result in none of the descendants being focusable via 
150
 
                                        //      the keyboard
151
 
                                        oList1.focusManager.set("activeDescendant", -1);
152
 
 
153
 
                                        //      Test to make sure that the "tabIndex" attribute of all
154
 
                                        //      descendants is set to "-1"
155
 
                                        oList1.focusManager.get("descendants").each(function (node) {
156
 
                                                Y.Assert.isTrue( (node.get("tabIndex") === -1) );
157
 
                                        });
158
 
 
159
 
                                        //      Calling "focus" with no arguments should result in none 
160
 
                                        //      of the descendants being focused
161
 
                                        oList1.focusManager.focus();
162
 
                        Y.Assert.isFalse(oList1.focusManager.get("focused"));
163
 
 
164
 
                                        
165
 
                                        //      TEST #5:
166
 
                                        //      With the "activeDescendant" attribute set to "-1", 
167
 
                                        //      the user can still focus a descendant by mousing 
168
 
                                        //      down on it
169
 
                                        oList1.focusManager.get("descendants").item(0).simulate("mousedown");
170
 
                        Y.Assert.isTrue(oList1.focusManager.get("focused"));
171
 
 
172
 
 
173
 
                                        //      TEST #6:
174
 
                                        //      The "activeDescendant" attribute should return the 
175
 
                                        //      index of the currently focused descendant
176
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 0));
177
 
 
178
 
 
179
 
                                        //      TEST #7:
180
 
                                        //      With the "activeDescendant" attribute set to "-1", 
181
 
                                        //      the user can focus a descendant programmically by 
182
 
                                        //      calling the "focus" method and passing in the index 
183
 
                                        //      of the descendant to be focused
184
 
                                        oList1.focusManager.set("activeDescendant", -1);
185
 
                                        oList1.focusManager.focus(1);
186
 
                        Y.Assert.isTrue(oList1.focusManager.get("focused"));
187
 
        
188
 
                                        //      The "activeDescendant" attribute should return the 
189
 
                                        //      index of the currently focused descendant       
190
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 1));
191
 
 
192
 
 
193
 
                                        //      TEST #8:
194
 
                                        //      The "activeDescendant" attribute can also be set to a 
195
 
                                        //      Node reference
196
 
                                        oList1.focusManager.focus(oList1.focusManager.get("descendants").item(2));
197
 
                        Y.Assert.isTrue(oList1.focusManager.get("focused"));
198
 
 
199
 
                                        //      The "activeDescendant" attribute should return the 
200
 
                                        //      index of the currently focused descendant
201
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 2));
202
 
 
203
 
 
204
 
                                        //      TEST #9:
205
 
                                        //      The "activeDescendant" attribute cannot be set to the 
206
 
                                        //      index of a disabled Node...
207
 
                                        oList1.focusManager.focus(4);
208
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 2));
209
 
 
210
 
                                        //      ...Or a disabled Node reference
211
 
                                        oList1.focusManager.focus(oList1.focusManager.get("descendants").item(4));
212
 
                        Y.Assert.isTrue((oList1.focusManager.get("activeDescendant") === 2));   
213
 
 
214
 
 
215
 
 
216
 
                                        //      TEST #10:
217
 
                                        //      There should be one element with the CSS class of
218
 
                                        //      "focused" applied
219
 
                                        Y.Assert.isTrue((Y.all(".focused").size() === 1));
220
 
 
221
 
                                        oList1.focusManager.blur();
222
 
 
223
 
                                        //      There should be no elements with the CSS class of 
224
 
                                        //      "focused" applied
225
 
                                        Y.Assert.isTrue((Y.all(".focused").size() === 0));
226
 
 
227
 
 
228
 
                                        //      Clean up for next set of tests
229
 
                                        oList1.unplug("focusManager");
230
 
        
231
 
                    },
232
 
        
233
 
                                testDescendants: function() {
234
 
 
235
 
                                        //      TEST #1:
236
 
                                        //      Check to make sure that the "descendants" attribute
237
 
                                        //      returns a NodeList of the correct size
238
 
 
239
 
                                        var oList1 = Y.one("#list-1");
240
 
 
241
 
                                        oList1.plug(Y.Plugin.NodeFocusManager, { 
242
 
                                                descendants: ">li>.focusable",
243
 
                                                keys: { next: "down:40", previous: "down:38" },
244
 
                                                focusClass: "focused",
245
 
                                                circular: true
246
 
                                        });
247
 
 
248
 
                                        Y.Assert.isTrue((oList1.focusManager.get("descendants").size() === 8));
249
 
 
250
 
                                        //      Test #2:
251
 
                                        //      Can update the "descendants" attribute on the fly
252
 
                                        oList1.focusManager.set("descendants", ".focusable");
253
 
                                        Y.Assert.isTrue((oList1.focusManager.get("descendants").size() === 12));
254
 
 
255
 
 
256
 
                                        //      Test #3:
257
 
                                        //      Can modify the child nodes of the current owner Node
258
 
                                        //      of the FocusManager and call "refresh" to sync the 
259
 
                                        //      number of descendants
260
 
                                        var oSublist = Y.one("#list-1-2"),
261
 
                                                oParentNode = oSublist.get("parentNode");
262
 
                                        
263
 
                                        oParentNode.removeChild(oSublist);
264
 
                                        
265
 
                                        oList1.focusManager.refresh();
266
 
                                        Y.Assert.isTrue((oList1.focusManager.get("descendants").size() === 8));
267
 
                                        
268
 
                                        //      Clean up for next set of tests
269
 
                                        oList1.unplug("focusManager");                          
270
 
 
271
 
 
272
 
                                        //      Test #3:
273
 
                    //  Start by plugging the Focus Manager into an empty
274
 
                    //  container, then update the descendants and call
275
 
                    //  the "refresh" method to update the managed descendants.
276
 
                    var oList3 = Y.one("#list-3");
277
 
 
278
 
                                        oList3.plug(Y.Plugin.NodeFocusManager, { 
279
 
                                                descendants: ">li>.focusable",
280
 
                                                keys: { next: "down:40", previous: "down:38" }
281
 
                                        });
282
 
 
283
 
                                        Y.Assert.isTrue((oList3.focusManager.get("descendants").size() === 0));
284
 
                                        
285
 
                                        oList3.append('<li><a href="#" class="focusable">One</a></li><li><a href="#" class="focusable">Two</a></li><li><a href="#" class="focusable">Three</a></li><li><a href="#" class="focusable">Four</a></li>');
286
 
                                        
287
 
                                        oList3.focusManager.refresh();
288
 
 
289
 
                                        Y.Assert.isTrue((oList3.focusManager.get("descendants").size() === 4));
290
 
                                        
291
 
                                        oList3.unplug("focusManager");
292
 
 
293
 
                                },
294
 
                                
295
 
                                testFocusedAttribute: function() {
296
 
 
297
 
                                        //      TEST #1:
298
 
                                        //      The "focused" attribute should be false by default
299
 
                                        var oList2 = Y.one("#list-2");
300
 
 
301
 
                                        oList2.plug(Y.Plugin.NodeFocusManager, { 
302
 
                                                descendants: ">li>.focusable",
303
 
                                                keys: { next: "down:40", previous: "down:38" },
304
 
                                                focusClass: "focused",
305
 
                                                circular: true
306
 
                                        });
307
 
 
308
 
                                        Y.Assert.isFalse(oList2.focusManager.get("focused"));
309
 
                                        
310
 
                                        
311
 
                                        //      TEST #2:
312
 
                                        //      Calling the "focus" method with no arguments should
313
 
                                        //      result in the "focused" attribute being set to true 
314
 
                                        //      and the "activeDescendant" attribute being 0
315
 
                                        oList2.focusManager.focus();
316
 
                        Y.Assert.isTrue(oList2.focusManager.get("focused"));
317
 
                        Y.Assert.isTrue((oList2.focusManager.get("activeDescendant") === 0));
318
 
 
319
 
 
320
 
                                        //      TEST #3:
321
 
                                        //      Calling the "blur" method should result in the 
322
 
                                        //      "focused" attribute being set to false, the 
323
 
                                        //      removal of the the "focused" CSS class,
324
 
                                        //      and the "activeDescendant" attribute being still 0                              
325
 
                                        oList2.focusManager.blur();
326
 
                                        Y.Assert.isTrue((Y.all(".focused").size() === 0));                                      
327
 
                        Y.Assert.isFalse(oList2.focusManager.get("focused"));
328
 
                        Y.Assert.isTrue((oList2.focusManager.get("activeDescendant") === 0));
329
 
 
330
 
 
331
 
                                        //      TEST #4:
332
 
                                        //      Focusing another element in the DOM will result in the 
333
 
                                        //      "focused" attribute being set to false, the 
334
 
                                        //      removal of the "focused" CSS class, 
335
 
                                        //      and the "activeDescendant" attribute being still 0
336
 
                                        oList2.focusManager.focus();
337
 
                                        Y.one("#anchor-1").focus();
338
 
                                        Y.Assert.isTrue((Y.all(".focused").size() === 0));                                      
339
 
                        Y.Assert.isFalse(oList2.focusManager.get("focused"));
340
 
                        Y.Assert.isTrue((oList2.focusManager.get("activeDescendant") === 0));
341
 
        
342
 
                                        //      Clean up for next set of tests
343
 
                                        oList2.unplug("focusManager");  
344
 
                                        
345
 
                                }, 
346
 
 
347
 
                                testFocusClassAttribute: function() {
348
 
 
349
 
                                        var oList1 = Y.one("#list-1");
350
 
 
351
 
                                        oList1.plug(Y.Plugin.NodeFocusManager, { 
352
 
                                                descendants: ">li>.focusable",
353
 
                                                keys: { next: "down:40", previous: "down:38" },
354
 
                                                focusClass: "focused",
355
 
                                                activeDescendant: 0,
356
 
                                                circular: true
357
 
                                        });
358
 
 
359
 
                                        oList1.focusManager.focus();
360
 
 
361
 
                                        //      TEST #1: Make sure that the "focused" class is 
362
 
                                        //      applied to the first descendant
363
 
 
364
 
                                        var nodes = oList1.all(".focused");
365
 
                                        
366
 
                                        Y.Assert.isTrue(nodes.size() === 1);
367
 
                                        Y.Assert.isTrue(oList1.focusManager.get("descendants").item(0).hasClass("focused"));
368
 
 
369
 
                                        oList1.focusManager.blur();
370
 
 
371
 
 
372
 
                                        //      TEST #2: Make sure that the "focused" class is not 
373
 
                                        //      not applied to any of the descendants
374
 
 
375
 
                                        nodes = oList1.all(".focused");
376
 
                                        
377
 
                                        Y.Assert.isTrue(nodes.size() === 0);
378
 
                                        Y.Assert.isFalse(oList1.focusManager.get("descendants").item(0).hasClass("focused"));
379
 
                                        
380
 
 
381
 
                                        //      TEST #3: Make sure that the "focused" class is 
382
 
                                        //      applied to the parent node of the first descendant
383
 
                                        
384
 
                                        oList1.focusManager.set("focusClass", {
385
 
                                                className: "focused",
386
 
                                                fn: function (node) {
387
 
                                                        return node.get("parentNode");
388
 
                                                }
389
 
                                        });
390
 
                                        
391
 
 
392
 
                                        oList1.focusManager.focus();                                    
393
 
 
394
 
                                        nodes = oList1.all(".focused");
395
 
                                        
396
 
                                        Y.Assert.isTrue(nodes.size() === 1);
397
 
                                        Y.Assert.isTrue(oList1.focusManager.get("descendants").item(0).get("parentNode").hasClass("focused"));
398
 
 
399
 
 
400
 
                                        //      TEST #4: Make sure that the "focused" class is not 
401
 
                                        //      not applied to any of the descendants
402
 
 
403
 
                                        oList1.focusManager.blur();
404
 
 
405
 
                                        nodes = oList1.all(".focused");
406
 
 
407
 
                                        Y.Assert.isTrue(nodes.size() === 0);
408
 
                                        Y.Assert.isFalse(oList1.focusManager.get("descendants").item(0).get("parentNode").hasClass("focused"));
409
 
                                        
410
 
                                }                               
411
 
 
412
 
                });
413
 
 
414
 
 
415
 
                Y.Test.Runner.add(testFocusManager);
416
 
                Y.Test.Runner.run();    
417
 
        
418
 
 
419
 
                }, "#list-2");
420
 
 
421
 
        });
422
 
 
423
 
</script>
424
 
 
425
 
</body>
426
 
</html>