4 <script src=
"list_selection_model_test_util.js"></script>
10 function createSelectionModel(len
, opt_dependentLeadItem
) {
11 var sm
= new cr
.ui
.ListSingleSelectionModel(len
);
12 sm
.independentLeadItem_
= !opt_dependentLeadItem
;
16 function testAdjust1() {
17 var sm
= createSelectionModel(200);
19 sm
.leadIndex
= sm
.anchorIndex
= sm
.selectedIndex
= 100;
22 assertEquals(90, sm
.leadIndex
);
23 assertEquals(90, sm
.anchorIndex
);
24 assertEquals(90, sm
.selectedIndex
);
27 function testAdjust2() {
28 var sm
= createSelectionModel(200);
30 sm
.leadIndex
= sm
.anchorIndex
= sm
.selectedIndex
= 50;
31 adjust(sm
, 60, 10, 0);
33 assertEquals(50, sm
.leadIndex
);
34 assertEquals(50, sm
.anchorIndex
);
35 assertEquals(50, sm
.selectedIndex
);
38 function testAdjust3() {
39 var sm
= createSelectionModel(200);
41 sm
.leadIndex
= sm
.anchorIndex
= sm
.selectedIndex
= 100;
44 assertEquals(110, sm
.leadIndex
);
45 assertEquals(110, sm
.anchorIndex
);
46 assertEquals(110, sm
.selectedIndex
);
49 function testAdjust4() {
50 var sm
= createSelectionModel(100);
52 sm
.leadIndex
= sm
.anchorIndex
= sm
.selectedIndex
= 99;
56 assertEquals(-1, sm
.leadIndex
, 'lead');
57 assertEquals(-1, sm
.anchorIndex
, 'anchor');
58 assertArrayEquals([], sm
.selectedIndexes
);
61 function testAdjust5() {
62 var sm
= createSelectionModel(1);
64 sm
.leadIndex
= sm
.anchorIndex
= sm
.selectedIndex
= 0;
68 assertEquals(10, sm
.leadIndex
,'lead');
69 assertEquals(10, sm
.anchorIndex
, 'anchor');
70 assertArrayEquals([10], sm
.selectedIndexes
);
73 function testSelectedIndex1() {
74 var sm
= createSelectionModel(100, true);
76 sm
.selectedIndex
= 99;
78 assertEquals(99, sm
.leadIndex
, 'lead');
79 assertEquals(99, sm
.anchorIndex
, 'anchor');
80 assertArrayEquals([99], sm
.selectedIndexes
);
83 function testLeadIndex1() {
84 var sm
= createSelectionModel(100);
88 assertEquals(99, sm
.leadIndex
, 'lead');
89 assertEquals(99, sm
.anchorIndex
, 'anchor');
90 assertArrayEquals([], sm
.selectedIndexes
);
93 function testLeadIndex2() {
94 var sm
= createSelectionModel(100, true);
98 assertEquals(-1, sm
.leadIndex
, 'lead');
99 assertEquals(-1, sm
.anchorIndex
, 'anchor');
100 assertArrayEquals([], sm
.selectedIndexes
);