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

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/array_data_model_test.html

Issue 11962043: Move webui resources from chrome\browser\resources\shared to ui\webui\resources. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j s"></script>
5 <script src="../../cr.js"></script>
6 <script src="../event_target.js"></script>
7 <script src="array_data_model.js"></script>
8 <script>
9
10 goog.require('goog.testing.jsunit');
11
12 </script>
13
14 </head>
15 <body>
16
17 <script>
18
19 function testSlice() {
20 var m = new cr.ui.ArrayDataModel([0, 1, 2]);
21 assertArrayEquals([0, 1, 2], m.slice());
22 assertArrayEquals([1, 2], m.slice(1));
23 assertArrayEquals([1], m.slice(1, 2));
24 }
25
26 function testPush() {
27 var m = new cr.ui.ArrayDataModel([0, 1, 2]);
28
29 var count = 0;
30 m.addEventListener('splice', function(e) {
31 count++;
32 assertEquals(3, e.index);
33 assertArrayEquals([], e.removed);
34 assertArrayEquals([3, 4], e.added);
35 });
36
37 assertEquals(5, m.push(3, 4));
38 var a = m.slice();
39 assertArrayEquals([0, 1, 2, 3, 4], a);
40
41 assertEquals('The splice event should only fire once', 1, count);
42 }
43
44 function testSplice() {
45 function compare(array, args) {
46 var m = new cr.ui.ArrayDataModel(array.slice());
47 var expected = array.slice();
48 var result = expected.splice.apply(expected, args);
49 assertArrayEquals(result, m.splice.apply(m, args));
50 assertArrayEquals(expected, m.slice());
51 }
52
53 compare([1, 2, 3], []);
54 compare([1, 2, 3], [0, 0]);
55 compare([1, 2, 3], [0, 1]);
56 compare([1, 2, 3], [1, 1]);
57 compare([1, 2, 3], [0, 3]);
58 compare([1, 2, 3], [0, 1, 5]);
59 compare([1, 2, 3], [0, 3, 1, 2, 3]);
60 compare([1, 2, 3], [5, 3, 1, 2, 3]);
61 }
62
63 function testPermutation() {
64 function doTest(sourceArray, spliceArgs) {
65 var m = new cr.ui.ArrayDataModel(sourceArray.slice());
66 var permutation;
67 m.addEventListener('permuted', function(event) {
68 permutation = event.permutation;
69 });
70 m.splice.apply(m, spliceArgs);
71 var deleted = 0;
72 for (var i = 0; i < sourceArray.length; i++) {
73 if (permutation[i] == -1)
74 deleted++;
75 else
76 assertEquals(sourceArray[i], m.item(permutation[i]));
77 }
78 assertEquals(deleted, spliceArgs[1]);
79 }
80
81 doTest([1, 2, 3], [0, 0]);
82 doTest([1, 2, 3], [0, 1]);
83 doTest([1, 2, 3], [1, 1]);
84 doTest([1, 2, 3], [0, 3]);
85 doTest([1, 2, 3], [0, 1, 5]);
86 doTest([1, 2, 3], [0, 3, 1, 2, 3]);
87 }
88
89 </script>
90
91 </body>
92 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698