Commit 14b052fb authored by kevers@chromium.org's avatar kevers@chromium.org

Fix test failure in list_selection_model_test.html and port to automated browser test.

BUG=249104
TEST=WebUIResourceBrowserTest

Review URL: https://chromiumcodereview.appspot.com/17450012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207855 0039d316-1c4b-4281-b951-d872f2087c98
parent a19bde39
...@@ -3,30 +3,54 @@ ...@@ -3,30 +3,54 @@
<head> <head>
<title></title> <title></title>
<style> <style>
</style> </style>
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> <script src="webui_resource_test.js"></script>
<script src="../../cr.js"></script>
<script src="../event_target.js"></script>
<script src="list_selection_model.js"></script>
<script src="list_selection_model_test_util.js"></script>
<script>
goog.require('goog.testing.jsunit');
</script>
</head> </head>
<body> <body>
<script> <script>
function createSelectionModel(len, opt_dependentLeadItem) { function createSelectionModel(len, opt_dependentLeadItem) {
var sm = new cr.ui.ListSelectionModel(len); var sm = new cr.ui.ListSelectionModel(len);
sm.independentLeadItem_ = !opt_dependentLeadItem; sm.independentLeadItem_ = !opt_dependentLeadItem;
return sm; return sm;
} }
/**
* Creates an array spanning a range of integer values.
* @param{number} start The first number in the range.
* @param{number} end The last number in the range inclusive.
* @return {!Array.<number>}
*/
function range(start, end) {
var a = [];
for (var i = start; i <= end; i++) {
a.push(i);
}
return a;
}
/**
* Modifies a selection model.
* @param {!ListSelectionModel} model The selection model to adjust.
* @param {number} index Starting index of the edit.
* @param {number} removed Number of entries to remove from the list.
* @param {number} added Number of entries to add to the list.
*/
function adjust(model, index, removed, added) {
var permutation = [];
for (var i = 0; i < index; i++) {
permutation.push(i);
}
for (var i = 0; i < removed; i++) {
permutation.push(-1);
}
for (var i = index + removed; i < model.length; i++) {
permutation.push(i - removed + added);
}
model.adjustLength(model.length - removed + added);
model.adjustToReordering(permutation);
}
function testAdjust1() { function testAdjust1() {
var sm = createSelectionModel(200); var sm = createSelectionModel(200);
...@@ -80,9 +104,9 @@ function testAdjust5() { ...@@ -80,9 +104,9 @@ function testAdjust5() {
adjust(sm, 99, 1, 0); adjust(sm, 99, 1, 0);
assertEquals('lead', -1, sm.leadIndex); assertEquals(98, sm.leadIndex, 'lead');
assertEquals('anchor', -1, sm.anchorIndex); assertEquals(98, sm.anchorIndex, 'anchor');
assertArrayEquals([], sm.selectedIndexes); assertArrayEquals([98], sm.selectedIndexes);
} }
function testAdjust6() { function testAdjust6() {
...@@ -94,8 +118,8 @@ function testAdjust6() { ...@@ -94,8 +118,8 @@ function testAdjust6() {
// Remove 100 - 105 // Remove 100 - 105
adjust(sm, 100, 5, 0); adjust(sm, 100, 5, 0);
assertEquals('lead', 100, sm.leadIndex); assertEquals(100, sm.leadIndex, 'lead');
assertEquals('anchor', 100, sm.anchorIndex); assertEquals(100, sm.anchorIndex, 'anchor');
assertArrayEquals(range(100, 105), sm.selectedIndexes); assertArrayEquals(range(100, 105), sm.selectedIndexes);
} }
...@@ -106,8 +130,8 @@ function testAdjust7() { ...@@ -106,8 +130,8 @@ function testAdjust7() {
adjust(sm, 0, 0, 10); adjust(sm, 0, 0, 10);
assertEquals('lead', 10, sm.leadIndex); assertEquals(10, sm.leadIndex, 'lead');
assertEquals('anchor', 10, sm.anchorIndex); assertEquals(10, sm.anchorIndex, 'anchor');
assertArrayEquals([10], sm.selectedIndexes); assertArrayEquals([10], sm.selectedIndexes);
} }
...@@ -119,8 +143,8 @@ function testAdjust8() { ...@@ -119,8 +143,8 @@ function testAdjust8() {
adjust(sm, 10, 80, 0); adjust(sm, 10, 80, 0);
assertEquals('lead', -1, sm.leadIndex); assertEquals(-1, sm.leadIndex, 'lead');
assertEquals('anchor', -1, sm.anchorIndex); assertEquals(-1, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 19), sm.selectedIndexes); assertArrayEquals(range(0, 19), sm.selectedIndexes);
} }
...@@ -133,8 +157,8 @@ function testAdjust9() { ...@@ -133,8 +157,8 @@ function testAdjust9() {
// Remove all // Remove all
adjust(sm, 0, 10, 0); adjust(sm, 0, 10, 0);
assertEquals('lead', -1, sm.leadIndex); assertEquals(-1, sm.leadIndex, 'lead');
assertEquals('anchor', -1, sm.anchorIndex); assertEquals(-1, sm.anchorIndex, 'anchor');
assertArrayEquals([], sm.selectedIndexes); assertArrayEquals([], sm.selectedIndexes);
} }
...@@ -146,9 +170,9 @@ function testAdjust10() { ...@@ -146,9 +170,9 @@ function testAdjust10() {
adjust(sm, 0, 10, 20); adjust(sm, 0, 10, 20);
assertEquals('lead', -1, sm.leadIndex); assertEquals(5, sm.leadIndex, 'lead');
assertEquals('anchor', -1, sm.anchorIndex); assertEquals(5, sm.anchorIndex, 'anchor');
assertArrayEquals([], sm.selectedIndexes); assertArrayEquals([5], sm.selectedIndexes);
} }
function testAdjust11() { function testAdjust11() {
...@@ -159,8 +183,8 @@ function testAdjust11() { ...@@ -159,8 +183,8 @@ function testAdjust11() {
adjust(sm, 5, 20, 10); adjust(sm, 5, 20, 10);
assertEquals('lead', -1, sm.leadIndex); assertEquals(-1, sm.leadIndex, 'lead');
assertEquals('anchor', -1, sm.anchorIndex); assertEquals(-1, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 4), sm.selectedIndexes); assertArrayEquals(range(0, 4), sm.selectedIndexes);
} }
...@@ -172,8 +196,8 @@ function testAdjust12() { ...@@ -172,8 +196,8 @@ function testAdjust12() {
adjust(sm, 5, 20, 10); adjust(sm, 5, 20, 10);
assertEquals('lead', 4, sm.leadIndex); assertEquals(4, sm.leadIndex, 'lead');
assertEquals('anchor', 4, sm.anchorIndex); assertEquals(4, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 4), sm.selectedIndexes); assertArrayEquals(range(0, 4), sm.selectedIndexes);
} }
...@@ -185,8 +209,8 @@ function testAdjust13() { ...@@ -185,8 +209,8 @@ function testAdjust13() {
adjust(sm, 5, 5, 0); adjust(sm, 5, 5, 0);
assertEquals('lead', 10, sm.leadIndex); assertEquals(10, sm.leadIndex, 'lead');
assertEquals('anchor', 10, sm.anchorIndex); assertEquals(10, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 14), sm.selectedIndexes); assertArrayEquals(range(0, 14), sm.selectedIndexes);
} }
...@@ -196,8 +220,8 @@ function testLeadAndAnchor1() { ...@@ -196,8 +220,8 @@ function testLeadAndAnchor1() {
sm.selectAll(); sm.selectAll();
sm.leadIndex = sm.anchorIndex = 10; sm.leadIndex = sm.anchorIndex = 10;
assertEquals('lead', 10, sm.leadIndex); assertEquals(10, sm.leadIndex, 'lead');
assertEquals('anchor', 10, sm.anchorIndex); assertEquals(10, sm.anchorIndex, 'anchor');
} }
function testLeadAndAnchor2() { function testLeadAndAnchor2() {
...@@ -206,8 +230,8 @@ function testLeadAndAnchor2() { ...@@ -206,8 +230,8 @@ function testLeadAndAnchor2() {
sm.leadIndex = sm.anchorIndex = 10; sm.leadIndex = sm.anchorIndex = 10;
sm.selectAll(); sm.selectAll();
assertEquals('lead', 19, sm.leadIndex); assertEquals(19, sm.leadIndex, 'lead');
assertEquals('anchor', 19, sm.anchorIndex); assertEquals(19, sm.anchorIndex, 'anchor');
} }
</script> </script>
......
...@@ -100,6 +100,13 @@ IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, GridTest) { ...@@ -100,6 +100,13 @@ IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, GridTest) {
RunTest(base::FilePath(FILE_PATH_LITERAL("grid_test.html"))); RunTest(base::FilePath(FILE_PATH_LITERAL("grid_test.html")));
} }
IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ListSelectionModelTest) {
AddLibrary(IDR_WEBUI_JS_CR);
AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL);
RunTest(base::FilePath(FILE_PATH_LITERAL("list_selection_model_test.html")));
}
IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, LocalStringsTest) { IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, LocalStringsTest) {
AddLibrary(IDR_WEBUI_JS_LOCAL_STRINGS); AddLibrary(IDR_WEBUI_JS_LOCAL_STRINGS);
RunTest(base::FilePath(FILE_PATH_LITERAL("local_strings_test.html"))); RunTest(base::FilePath(FILE_PATH_LITERAL("local_strings_test.html")));
......
...@@ -73,8 +73,8 @@ function assertThrows(f) { ...@@ -73,8 +73,8 @@ function assertThrows(f) {
/** /**
* Verifies that the contents of the expected and observed arrays match. * Verifies that the contents of the expected and observed arrays match.
* @param {Array} expected The expected result. * @param {!Array} expected The expected result.
* @param {Array} observed The actual result. * @param {!Array} observed The actual result.
*/ */
function assertArrayEquals(expected, observed) { function assertArrayEquals(expected, observed) {
var v1 = Array.prototype.slice.call(expected); var v1 = Array.prototype.slice.call(expected);
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function range(start, end) {
var a = [];
for (var i = start; i <= end; i++) {
a.push(i);
}
return a;
}
function adjust(sm, index, removed, added) {
var permutation = [];
for (var i = 0; i < index; i++) {
permutation.push(i);
}
for (var i = 0; i < removed; i++) {
permutation.push(-1);
}
for (var i = index + removed; i < sm.length; i++) {
permutation.push(i - removed + added);
}
sm.adjustLength(sm.length - removed + added);
sm.adjustToReordering(permutation);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment