OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 equals(base.trimExtension("x.y.z"), "x.y"); | 51 equals(base.trimExtension("x.y.z"), "x.y"); |
52 equals(base.trimExtension(".xyz"), ""); | 52 equals(base.trimExtension(".xyz"), ""); |
53 equals(base.trimExtension(""), ""); | 53 equals(base.trimExtension(""), ""); |
54 }); | 54 }); |
55 | 55 |
56 test("joinPath with empty parent", 1, function() { | 56 test("joinPath with empty parent", 1, function() { |
57 var value = base.joinPath("", "test.html"); | 57 var value = base.joinPath("", "test.html"); |
58 equals(value, "test.html"); | 58 equals(value, "test.html"); |
59 }); | 59 }); |
60 | 60 |
61 test("dirName", 3, function() { | |
62 equals(base.dirName("foo.html"), "foo.html"); | |
63 equals(base.dirName("foo/bar.html"), "foo"); | |
64 equals(base.dirName("foo/bar/baz.html"), "foo/bar"); | |
65 }); | |
66 | |
67 test("uniquifyArray", 5, function() { | 61 test("uniquifyArray", 5, function() { |
68 deepEqual(base.uniquifyArray([]), []); | 62 deepEqual(base.uniquifyArray([]), []); |
69 deepEqual(base.uniquifyArray(["a"]), ["a"]); | 63 deepEqual(base.uniquifyArray(["a"]), ["a"]); |
70 deepEqual(base.uniquifyArray(["a", "b"]), ["a", "b"]); | 64 deepEqual(base.uniquifyArray(["a", "b"]), ["a", "b"]); |
71 deepEqual(base.uniquifyArray(["a", "b", "b"]), ["a", "b"]); | 65 deepEqual(base.uniquifyArray(["a", "b", "b"]), ["a", "b"]); |
72 deepEqual(base.uniquifyArray(["a", "b", "b", "a"]), ["a", "b"]); | 66 deepEqual(base.uniquifyArray(["a", "b", "b", "a"]), ["a", "b"]); |
73 }); | 67 }); |
74 | 68 |
75 test("flattenArray", 5, function() { | |
76 deepEqual(base.flattenArray([]), []); | |
77 deepEqual(base.flattenArray([["a"]]), ["a"]); | |
78 deepEqual(base.flattenArray([["a"], ["b"]]), ["a", "b"]); | |
79 deepEqual(base.flattenArray([["a"], ["b", "c"]]), ["a", "b", "c"]); | |
80 deepEqual(base.flattenArray([["a"], [], ["b"]]), ["a", "b"]); | |
81 }); | |
82 | |
83 test("filterDictionary", 3, function() { | |
84 var dictionary = { | |
85 'foo': 43, | |
86 'bar': 11 | |
87 }; | |
88 deepEqual(base.filterDictionary(dictionary, function() { return true; }), { | |
89 "foo": 43, | |
90 "bar": 11 | |
91 }); | |
92 deepEqual(base.filterDictionary(dictionary, function() { return false; }), {
}); | |
93 deepEqual(base.filterDictionary(dictionary, function(key) { return key == 'f
oo'; }), { | |
94 "foo": 43 | |
95 }); | |
96 }); | |
97 | |
98 test("filterTree", 2, function() { | 69 test("filterTree", 2, function() { |
99 var tree = { | 70 var tree = { |
100 'path': { | 71 'path': { |
101 'to': { | 72 'to': { |
102 'test.html': { | 73 'test.html': { |
103 'actual': 'PASS', | 74 'actual': 'PASS', |
104 'expected': 'FAIL' | 75 'expected': 'FAIL' |
105 } | 76 } |
106 }, | 77 }, |
107 'another.html': { | 78 'another.html': { |
(...skipping 27 matching lines...) Expand all Loading... |
135 | 106 |
136 var text = base.filterTree(tree, isLeaf, actualIsText); | 107 var text = base.filterTree(tree, isLeaf, actualIsText); |
137 deepEqual(text, { | 108 deepEqual(text, { |
138 'path/another.html': { | 109 'path/another.html': { |
139 'actual': 'TEXT', | 110 'actual': 'TEXT', |
140 'expected': 'PASS' | 111 'expected': 'PASS' |
141 } | 112 } |
142 }); | 113 }); |
143 }); | 114 }); |
144 | 115 |
145 test("UpdateTracker", 20, function() { | |
146 var dict; | |
147 | |
148 function dumpKeys() | |
149 { | |
150 var updates = [] | |
151 dict.forEach(function(item, key, updated) { | |
152 updates.push(key); | |
153 }); | |
154 return updates; | |
155 } | |
156 | |
157 function dumpUpdatedKeys() | |
158 { | |
159 var updates = [] | |
160 dict.forEach(function(item, key, updated) { | |
161 updated && updates.push(key); | |
162 }); | |
163 return updates; | |
164 } | |
165 | |
166 | |
167 dict = new base.UpdateTracker(); | |
168 dict.update("5", {}); | |
169 deepEqual(dumpUpdatedKeys(), ["5"]); | |
170 dict.update("6", {}); | |
171 dict.update("7", {}); | |
172 deepEqual(dumpUpdatedKeys(), ["5", "6", "7"]); | |
173 deepEqual(dict.get("6"), {}); | |
174 ok(dict.exists("7")); | |
175 dict.purge(); | |
176 deepEqual(dumpUpdatedKeys(), []); | |
177 deepEqual(dumpKeys(), ["5", "6", "7"]); | |
178 dict.update("5", {}); | |
179 deepEqual(dumpUpdatedKeys(), ["5"]); | |
180 dict.update("4", {}); | |
181 deepEqual(dumpUpdatedKeys(), ["4", "5"]); | |
182 deepEqual(dumpKeys(), ["4", "5", "6", "7"]); | |
183 dict.purge(); | |
184 deepEqual(dumpKeys(), ["4", "5"]); | |
185 deepEqual(dumpUpdatedKeys(), []); | |
186 dict.purge(); | |
187 deepEqual(dumpKeys(), []); | |
188 | |
189 var removeCount = 0; | |
190 dict.update("one"); | |
191 deepEqual(dumpUpdatedKeys(), ["one"]); | |
192 dict.update("two"); | |
193 deepEqual(dumpUpdatedKeys(), ["one", "two"]); | |
194 dict.update("three"); | |
195 dict.purge(); | |
196 deepEqual(dumpKeys(), ["one", "three", "two"]); | |
197 dict.update("two"); | |
198 dict.purge(function() { | |
199 removeCount++; | |
200 }); | |
201 deepEqual(dumpKeys(), ["two"]); | |
202 equal(removeCount, 2); | |
203 dict.update("four"); | |
204 var removeCounter = { count: 0 }; | |
205 dict.purge(function() { | |
206 this.count++; | |
207 }, removeCounter); | |
208 equal(removeCounter.count, 1); | |
209 dict.purge(function() { | |
210 equal(String(this), "four"); | |
211 }); | |
212 | |
213 dict = new base.UpdateTracker(); | |
214 dict.update("one"); | |
215 var thisObject = {} | |
216 dict.forEach(function(item) { | |
217 equal(this, thisObject); | |
218 }, thisObject); | |
219 | |
220 }); | |
221 | |
222 test("extends", 14, function() { | 116 test("extends", 14, function() { |
223 | 117 |
224 var LikeDiv = base.extends("div", { | 118 var LikeDiv = base.extends("div", { |
225 init: function() { | 119 init: function() { |
226 this.textContent = "awesome"; | 120 this.textContent = "awesome"; |
227 }, | 121 }, |
228 method: function(msg) { | 122 method: function(msg) { |
229 return 42; | 123 return 42; |
230 } | 124 } |
231 }); | 125 }); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 document.body.appendChild(new LikeLikeProgress()); | 183 document.body.appendChild(new LikeLikeProgress()); |
290 equals(document.body.lastChild.tagName, "PROGRESS"); | 184 equals(document.body.lastChild.tagName, "PROGRESS"); |
291 // Safari 5.1 lacks the <progress> element. | 185 // Safari 5.1 lacks the <progress> element. |
292 // equals(document.body.lastChild.position, 0.1); | 186 // equals(document.body.lastChild.position, 0.1); |
293 document.body.lastChild.completed(); | 187 document.body.lastChild.completed(); |
294 // Safari 5.1 lacks the <progress> element. | 188 // Safari 5.1 lacks the <progress> element. |
295 // equals(document.body.lastChild.position, 1); | 189 // equals(document.body.lastChild.position, 1); |
296 document.body.removeChild(document.body.lastChild); | 190 document.body.removeChild(document.body.lastChild); |
297 }); | 191 }); |
298 | 192 |
299 test("getURLParameter", 1, function() { | |
300 ok(!base.getURLParameter('non-existant')); | |
301 }); | |
302 | |
303 test("parseJSONP", 6, function() { | 193 test("parseJSONP", 6, function() { |
304 deepEqual(base.parseJSONP(""), {}); | 194 deepEqual(base.parseJSONP(""), {}); |
305 deepEqual(base.parseJSONP('p({"key": "value"})'), {"key": "value"}); | 195 deepEqual(base.parseJSONP('p({"key": "value"})'), {"key": "value"}); |
306 deepEqual(base.parseJSONP('ADD_RESULTS({"dummy":"data"});'), {"dummy":"data"
}); | 196 deepEqual(base.parseJSONP('ADD_RESULTS({"dummy":"data"});'), {"dummy":"data"
}); |
307 deepEqual(base.parseJSONP('{"dummy":"data"}'), {"dummy":"data"}); | 197 deepEqual(base.parseJSONP('{"dummy":"data"}'), {"dummy":"data"}); |
308 deepEqual(base.parseJSONP('ADD_RESULTS({"builder(1)":"data"});'), {"builder(
1)":"data"}); | 198 deepEqual(base.parseJSONP('ADD_RESULTS({"builder(1)":"data"});'), {"builder(
1)":"data"}); |
309 deepEqual(base.parseJSONP('{"builder(1)":"data"}'), {"builder(1)":"data"}); | 199 deepEqual(base.parseJSONP('{"builder(1)":"data"}'), {"builder(1)":"data"}); |
310 }); | 200 }); |
311 | 201 |
312 test("base.queryParam", 2, function() { | 202 test("base.queryParam", 2, function() { |
313 equal(base.queryParam({}), ''); | 203 equal(base.queryParam({}), ''); |
314 equal(base.queryParam({ | 204 equal(base.queryParam({ |
315 'foo bar': 'bar baz', | 205 'foo bar': 'bar baz', |
316 '1 2': '3 4', | 206 '1 2': '3 4', |
317 }), 'foo+bar=bar+baz&1+2=3+4'); | 207 }), 'foo+bar=bar+baz&1+2=3+4'); |
318 }); | 208 }); |
319 | 209 |
320 })(); | 210 })(); |
OLD | NEW |