4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
9 <script src=
"../base.js"></script>
11 base
.require('base.unittest');
12 base
.require('ui.list_view');
19 var ListView
= ui
.ListView
;
21 function testInstantiate() {
22 var view
= new ListView();
23 var i1
= view
.addItem('item 1');
24 var i2
= view
.addItem('item 2');
25 var i3
= view
.addItem('item 3');
26 this.addHTMLOutput('basic-list-view', view
);
30 function testProgrammaticSelection() {
31 var view
= new ListView();
32 var i1
= view
.addItem('item 1');
33 var i2
= view
.addItem('item 2');
34 var i3
= view
.addItem('item 3');
35 this.addHTMLOutput('programmatic selection', view
);
37 assertTrue(i2
.hasAttribute('selected'));
39 assertFalse(i2
.hasAttribute('selected'));
40 assertTrue(i3
.hasAttribute('selected'));
43 function testSelectionEvents() {
44 var view
= new ListView();
45 var didSelectionChange
= 0;
46 view
.addEventListener('selection-changed', function() {
47 didSelectionChange
= true;
49 var i1
= view
.addItem('item 1');
50 var i2
= view
.addItem('item 2');
51 var i3
= view
.addItem('item 3');
53 didSelectionChange
= false;
55 assertTrue(didSelectionChange
);
57 didSelectionChange
= false;
59 assertTrue(didSelectionChange
);