OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <!-- | |
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
7 Code distributed by Google as part of the polymer project is also | |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
9 --> | |
10 <html> | |
11 <head> | |
12 <meta charset="UTF-8"> | |
13 <title>core-selector-next-previous-wrap</title> | |
14 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> | |
15 | |
16 <script src="../../platform/platform.js"></script> | |
17 <script src="../../web-component-tester/browser.js"></script> | |
18 | |
19 <link rel="import" href="../core-selector.html"> | |
20 | |
21 <style> | |
22 .core-selected { | |
23 background: #ccc; | |
24 } | |
25 </style> | |
26 | |
27 </head> | |
28 <body unresolved> | |
29 | |
30 <core-selector id="selector" selected="0"> | |
31 <div>Item 1</div> | |
32 <div>Item 2</div> | |
33 <div>Item 3</div> | |
34 </core-selector> | |
35 | |
36 <script> | |
37 | |
38 var s = document.querySelector('#selector'); | |
39 | |
40 function assertAndSelect(method, expectedIndex, wrap) { | |
41 return function(done) { | |
42 assert.equal(s.selected, expectedIndex); | |
43 s[method](wrap); | |
44 asyncPlatformFlush(done); | |
45 } | |
46 } | |
47 | |
48 suite('next/previous', function() { | |
49 | |
50 test('selectNext(true) wraps', function(done) { | |
51 assert.equal(s.selected, 0); | |
52 | |
53 async.series([ | |
54 assertAndSelect('selectNext', 0, true), | |
55 assertAndSelect('selectNext', 1, true), | |
56 assertAndSelect('selectNext', 2, true), | |
57 function(done) { | |
58 assert.equal(s.selected, 0); | |
59 done(); | |
60 } | |
61 ], done); | |
62 }); | |
63 | |
64 test('selectPrevious(true) wraps', function(done) { | |
65 assert.equal(s.selected, 0); | |
66 | |
67 async.series([ | |
68 assertAndSelect('selectPrevious', 0, true), | |
69 assertAndSelect('selectPrevious', 2, true), | |
70 assertAndSelect('selectPrevious', 1, true), | |
71 function(done) { | |
72 assert.equal(s.selected, 0); | |
73 done(); | |
74 } | |
75 ], done); | |
76 }); | |
77 | |
78 test('selectNext() does not wrap', function(done) { | |
79 assert.equal(s.selected, 0); | |
80 | |
81 async.series([ | |
82 assertAndSelect('selectNext', 0), | |
83 assertAndSelect('selectNext', 1), | |
84 assertAndSelect('selectNext', 2), | |
85 assertAndSelect('selectNext', 2), | |
86 assertAndSelect('selectNext', 2), | |
87 function(done) { | |
88 s.selected = 0; | |
89 asyncPlatformFlush(done); | |
90 } | |
91 ], done); | |
92 }); | |
93 | |
94 test('selectPrevious() does not wrap', function(done) { | |
95 assert.equal(s.selected, 0); | |
96 s.selected = 2; | |
97 | |
98 async.series([ | |
99 asyncPlatformFlush, | |
100 assertAndSelect('selectPrevious', 2), | |
101 assertAndSelect('selectPrevious', 1), | |
102 assertAndSelect('selectPrevious', 0), | |
103 assertAndSelect('selectPrevious', 0), | |
104 assertAndSelect('selectPrevious', 0), | |
105 ], done); | |
106 }); | |
107 | |
108 }); | |
109 | |
110 </script> | |
111 | |
112 </body> | |
113 </html> | |
OLD | NEW |