Port Android relocation packer to chromium build
[chromium-blink-merge.git] / third_party / polymer / components-chromium / core-selector / test / multi.html
blobb6b12907240cc29922d6a46d433d40f4f04610c1
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.github.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/CONTRIBUTORS.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/PATENTS.txt
9 -->
10 <html>
11 <head>
12 <meta charset="UTF-8">
13 <title>core-selector-multi</title>
15 <script src="../../webcomponentsjs/webcomponents.js"></script>
16 <script src="../../web-component-tester/browser.js"></script>
18 <link rel="import" href="../core-selector.html">
20 <style>
21 .core-selected {
22 background: #ccc;
24 </style>
26 </head>
27 <body>
29 <core-selector id="selector" multi>
30 <div>Item 1</div>
31 <div>Item 2</div>
32 <div>Item 3</div>
33 <div>Item 4</div>
34 <div>Item 5</div>
35 </core-selector>
37 <script>
39 var s = document.querySelector('#selector');
41 suite('multi', function() {
43 test('honors the multi attribute', function() {
44 assert.isTrue(s.multi);
45 });
47 test('has sane defaults', function() {
48 assert.equal(s.selected, null);
49 assert.equal(s.selectedClass, 'core-selected');
50 assert.equal(s.valueattr, 'name');
51 assert.equal(s.items.length, 5);
52 });
54 test('allows multi-selection', function(done) {
55 // setup listener for core-select event
56 var selectEventCounter = 0;
57 s.addEventListener('core-select', function(e) {
58 if (e.detail.isSelected) {
59 selectEventCounter++;
60 } else {
61 selectEventCounter--;
63 });
64 // set selected
65 s.selected = [0, 2];
66 asyncPlatformFlush(function() {
67 // check core-select event
68 assert.equal(selectEventCounter, 2);
69 // check selected class
70 assert.isTrue(s.children[0].classList.contains('core-selected'));
71 assert.isTrue(s.children[2].classList.contains('core-selected'));
72 // check selectedItem
73 assert.equal(s.selectedItem.length, 2);
74 assert.equal(s.selectedItem[0], s.children[0]);
75 assert.equal(s.selectedItem[1], s.children[2]);
76 // tap on already selected element should unselect it
77 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
78 // check selected
79 assert.equal(s.selected.length, 1);
80 asyncPlatformFlush(function() {
81 assert.equal(selectEventCounter, 1);
82 assert.isFalse(s.children[0].classList.contains('core-selected'));
83 // add selected
84 s.selected.push(3);
85 s.selected.push(4);
86 // check core-select event
87 asyncPlatformFlush(function() {
88 assert.equal(selectEventCounter, 3);
89 done();
90 });
91 });
92 });
93 });
95 test('toggle multi to false', function(done) {
96 // set selected
97 s.selected = [0, 2];
98 var first = s.selected[0];
99 // set mutli to false, so to make it single-selection
100 s.multi = false;
101 asyncPlatformFlush(function() {
102 // selected should not be an array
103 assert.isNotArray(s.selected);
104 // selected should be the first value in the old array
105 assert.equal(s.selected, first);
106 done();
112 </script>
114 </body>
115 </html>