Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8636)

Unified Diff: chrome/test/data/webui/list_selection_model_test.html

Issue 17450012: Fix test failure in list_selection_model_test.html and port to automated browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with trunk. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/webui_resource_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/list_selection_model_test.html
diff --git a/ui/webui/resources/js/cr/ui/list_selection_model_test.html b/chrome/test/data/webui/list_selection_model_test.html
similarity index 61%
rename from ui/webui/resources/js/cr/ui/list_selection_model_test.html
rename to chrome/test/data/webui/list_selection_model_test.html
index 66bd40fc4c32165d8a793cd2f30fb9a7eeb7ea2d..dfbacf8b0422cf376c4a53c7877460a3e8f3f56a 100644
--- a/ui/webui/resources/js/cr/ui/list_selection_model_test.html
+++ b/chrome/test/data/webui/list_selection_model_test.html
@@ -3,30 +3,54 @@
<head>
<title></title>
<style>
-
</style>
-<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.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>
-
+<script src="webui_resource_test.js"></script>
</head>
<body>
<script>
-
function createSelectionModel(len, opt_dependentLeadItem) {
var sm = new cr.ui.ListSelectionModel(len);
sm.independentLeadItem_ = !opt_dependentLeadItem;
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() {
var sm = createSelectionModel(200);
@@ -80,9 +104,9 @@ function testAdjust5() {
adjust(sm, 99, 1, 0);
- assertEquals('lead', -1, sm.leadIndex);
- assertEquals('anchor', -1, sm.anchorIndex);
- assertArrayEquals([], sm.selectedIndexes);
+ assertEquals(98, sm.leadIndex, 'lead');
+ assertEquals(98, sm.anchorIndex, 'anchor');
+ assertArrayEquals([98], sm.selectedIndexes);
}
function testAdjust6() {
@@ -94,8 +118,8 @@ function testAdjust6() {
// Remove 100 - 105
adjust(sm, 100, 5, 0);
- assertEquals('lead', 100, sm.leadIndex);
- assertEquals('anchor', 100, sm.anchorIndex);
+ assertEquals(100, sm.leadIndex, 'lead');
+ assertEquals(100, sm.anchorIndex, 'anchor');
assertArrayEquals(range(100, 105), sm.selectedIndexes);
}
@@ -106,8 +130,8 @@ function testAdjust7() {
adjust(sm, 0, 0, 10);
- assertEquals('lead', 10, sm.leadIndex);
- assertEquals('anchor', 10, sm.anchorIndex);
+ assertEquals(10, sm.leadIndex, 'lead');
+ assertEquals(10, sm.anchorIndex, 'anchor');
assertArrayEquals([10], sm.selectedIndexes);
}
@@ -119,8 +143,8 @@ function testAdjust8() {
adjust(sm, 10, 80, 0);
- assertEquals('lead', -1, sm.leadIndex);
- assertEquals('anchor', -1, sm.anchorIndex);
+ assertEquals(-1, sm.leadIndex, 'lead');
+ assertEquals(-1, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 19), sm.selectedIndexes);
}
@@ -133,8 +157,8 @@ function testAdjust9() {
// Remove all
adjust(sm, 0, 10, 0);
- assertEquals('lead', -1, sm.leadIndex);
- assertEquals('anchor', -1, sm.anchorIndex);
+ assertEquals(-1, sm.leadIndex, 'lead');
+ assertEquals(-1, sm.anchorIndex, 'anchor');
assertArrayEquals([], sm.selectedIndexes);
}
@@ -146,9 +170,9 @@ function testAdjust10() {
adjust(sm, 0, 10, 20);
- assertEquals('lead', -1, sm.leadIndex);
- assertEquals('anchor', -1, sm.anchorIndex);
- assertArrayEquals([], sm.selectedIndexes);
+ assertEquals(5, sm.leadIndex, 'lead');
+ assertEquals(5, sm.anchorIndex, 'anchor');
+ assertArrayEquals([5], sm.selectedIndexes);
}
function testAdjust11() {
@@ -159,8 +183,8 @@ function testAdjust11() {
adjust(sm, 5, 20, 10);
- assertEquals('lead', -1, sm.leadIndex);
- assertEquals('anchor', -1, sm.anchorIndex);
+ assertEquals(-1, sm.leadIndex, 'lead');
+ assertEquals(-1, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 4), sm.selectedIndexes);
}
@@ -172,8 +196,8 @@ function testAdjust12() {
adjust(sm, 5, 20, 10);
- assertEquals('lead', 4, sm.leadIndex);
- assertEquals('anchor', 4, sm.anchorIndex);
+ assertEquals(4, sm.leadIndex, 'lead');
+ assertEquals(4, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 4), sm.selectedIndexes);
}
@@ -185,8 +209,8 @@ function testAdjust13() {
adjust(sm, 5, 5, 0);
- assertEquals('lead', 10, sm.leadIndex);
- assertEquals('anchor', 10, sm.anchorIndex);
+ assertEquals(10, sm.leadIndex, 'lead');
+ assertEquals(10, sm.anchorIndex, 'anchor');
assertArrayEquals(range(0, 14), sm.selectedIndexes);
}
@@ -196,8 +220,8 @@ function testLeadAndAnchor1() {
sm.selectAll();
sm.leadIndex = sm.anchorIndex = 10;
- assertEquals('lead', 10, sm.leadIndex);
- assertEquals('anchor', 10, sm.anchorIndex);
+ assertEquals(10, sm.leadIndex, 'lead');
+ assertEquals(10, sm.anchorIndex, 'anchor');
}
function testLeadAndAnchor2() {
@@ -206,8 +230,8 @@ function testLeadAndAnchor2() {
sm.leadIndex = sm.anchorIndex = 10;
sm.selectAll();
- assertEquals('lead', 19, sm.leadIndex);
- assertEquals('anchor', 19, sm.anchorIndex);
+ assertEquals(19, sm.leadIndex, 'lead');
+ assertEquals(19, sm.anchorIndex, 'anchor');
}
</script>
« no previous file with comments | « no previous file | chrome/test/data/webui/webui_resource_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698