Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/tests/synchronizer.js

Issue 6423769060999168: Issue 301 - adblockplustests: Use for (.. of ..) (Closed)
Patch Set: Created April 12, 2014, 1:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/tests/subscriptionClasses.js ('k') | chrome/content/tests/test_requestList.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 let testRunner = null; 3 let testRunner = null;
4 let requestHandlers = null; 4 let requestHandlers = null;
5 let randomResult = 0.5; 5 let randomResult = 0.5;
6 6
7 module("Synchronizer", { 7 module("Synchronizer", {
8 setup: function() 8 setup: function()
9 { 9 {
10 testRunner = this; 10 testRunner = this;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 }); 120 });
121 121
122 let tests = [ 122 let tests = [
123 {header: "[Adblock]", downloadStatus: "synchronize_ok", requiredVersion: n ull}, 123 {header: "[Adblock]", downloadStatus: "synchronize_ok", requiredVersion: n ull},
124 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersi on: null}, 124 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersi on: null},
125 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", require dVersion: null}, 125 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", require dVersion: null},
126 {header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", require dVersion: "0.0.1"}, 126 {header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", require dVersion: "0.0.1"},
127 {header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", required Version: "99.9"}, 127 {header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", required Version: "99.9"},
128 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVers ion: null} 128 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVers ion: null}
129 ]; 129 ];
130 for each (test in tests) 130 for (test of tests)
131 { 131 {
132 resetSubscription(subscription) 132 resetSubscription(subscription)
133 testRunner.runScheduledTasks(2); 133 testRunner.runScheduledTasks(2);
134 134
135 equal(subscription.downloadStatus, test.downloadStatus, "Download status f or " + test.header) 135 equal(subscription.downloadStatus, test.downloadStatus, "Download status f or " + test.header)
136 equal(subscription.requiredVersion, test.requiredVersion, "Required versio n for " + test.header) 136 equal(subscription.requiredVersion, test.requiredVersion, "Required versio n for " + test.header)
137 137
138 if (test.downloadStatus == "synchronize_ok") 138 if (test.downloadStatus == "synchronize_ok")
139 { 139 {
140 deepEqual(subscription.filters, [ 140 deepEqual(subscription.filters, [
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 }, 240 },
241 { 241 {
242 expiration: "40 hours", 242 expiration: "40 hours",
243 randomResult: 0.5, 243 randomResult: 0.5,
244 skipAfter: 5.1, 244 skipAfter: 5.1,
245 skip: 80, // Hitting hard expiration, immediate download 245 skip: 80, // Hitting hard expiration, immediate download
246 requests: [0.1, 85.1] 246 requests: [0.1, 85.1]
247 } 247 }
248 ] 248 ]
249 249
250 for each (test in tests) 250 for (test of tests)
251 { 251 {
252 requests = []; 252 requests = [];
253 randomResult = test.randomResult; 253 randomResult = test.randomResult;
254 resetSubscription(subscription); 254 resetSubscription(subscription);
255 255
256 let maxHours = Math.round(Math.max.apply(null, test.requests)) + 1; 256 let maxHours = Math.round(Math.max.apply(null, test.requests)) + 1;
257 testRunner.runScheduledTasks(maxHours, test.skipAfter, test.skip); 257 testRunner.runScheduledTasks(maxHours, test.skipAfter, test.skip);
258 258
259 let randomAddendum = (randomResult == 0.5 ? "" : " with Math.random() retu rning " + randomResult); 259 let randomAddendum = (randomResult == 0.5 ? "" : " with Math.random() retu rning " + randomResult);
260 let skipAddendum = (typeof test.skip != "number" ? "" : " skipping " + tes t.skip + " hours after " + test.skipAfter + " hours"); 260 let skipAddendum = (typeof test.skip != "number" ? "" : " skipping " + tes t.skip + " hours after " + test.skipAfter + " hours");
(...skipping 20 matching lines...) Expand all
281 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny 6Fn24b7JHsq/A===\nfoo\nbar\n", true], 281 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny 6Fn24b7JHsq/A===\nfoo\nbar\n", true],
282 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCm qXny6Fn24b7JHsq/A\nfoo\nbar\n", false], 282 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCm qXny6Fn24b7JHsq/A\nfoo\nbar\n", false],
283 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JC mqXny6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false], 283 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JC mqXny6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false],
284 ]; 284 ];
285 285
286 testRunner.registerHandler("/subscription", function(metadata) 286 testRunner.registerHandler("/subscription", function(metadata)
287 { 287 {
288 return [Cr.NS_OK, 200, subscriptionBody]; 288 return [Cr.NS_OK, 200, subscriptionBody];
289 }); 289 });
290 290
291 for each ([testName, subscriptionBody, expectedResult] in tests) 291 for ([testName, subscriptionBody, expectedResult] of tests)
292 { 292 {
293 resetSubscription(subscription); 293 resetSubscription(subscription);
294 testRunner.runScheduledTasks(2); 294 testRunner.runScheduledTasks(2);
295 equal(subscription.downloadStatus, expectedResult ? "synchronize_ok" : "sy nchronize_checksum_mismatch", testName); 295 equal(subscription.downloadStatus, expectedResult ? "synchronize_ok" : "sy nchronize_checksum_mismatch", testName);
296 } 296 }
297 }); 297 });
298 298
299 test("Special comments", function() 299 test("Special comments", function()
300 { 300 {
301 let subscription = Subscription.fromURL("http://example.com/subscription"); 301 let subscription = Subscription.fromURL("http://example.com/subscription");
302 FilterStorage.addSubscription(subscription); 302 FilterStorage.addSubscription(subscription);
303 303
304 let comment, check; 304 let comment, check;
305 let tests = [ 305 let tests = [
306 ["! Homepage: http://example.com/", function() equal(subscription.homepage , "http://example.com/", "Valid homepage comment")], 306 ["! Homepage: http://example.com/", function() equal(subscription.homepage , "http://example.com/", "Valid homepage comment")],
307 ["! Homepage: ssh://example.com/", function() equal(subscription.homepage, null, "Invalid homepage comment")], 307 ["! Homepage: ssh://example.com/", function() equal(subscription.homepage, null, "Invalid homepage comment")],
308 ["! Title: foo", function() 308 ["! Title: foo", function()
309 { 309 {
310 equal(subscription.title, "foo", "Title comment"); 310 equal(subscription.title, "foo", "Title comment");
311 equal(subscription.fixedTitle, true, "Fixed title"); 311 equal(subscription.fixedTitle, true, "Fixed title");
312 }], 312 }],
313 ["! Version: 1234", function() equal(subscription.version, 1234, "Version comment")] 313 ["! Version: 1234", function() equal(subscription.version, 1234, "Version comment")]
314 ]; 314 ];
315 315
316 testRunner.registerHandler("/subscription", function(metadata) 316 testRunner.registerHandler("/subscription", function(metadata)
317 { 317 {
318 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; 318 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"];
319 }); 319 });
320 320
321 for each([comment, check] in tests) 321 for ([comment, check] of tests)
322 { 322 {
323 resetSubscription(subscription); 323 resetSubscription(subscription);
324 testRunner.runScheduledTasks(2); 324 testRunner.runScheduledTasks(2);
325 check(); 325 check();
326 deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromText(" bar")], "Special comment not added to filters"); 326 deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromText(" bar")], "Special comment not added to filters");
327 } 327 }
328 }); 328 });
329 329
330 test("Redirects", function() 330 test("Redirects", function()
331 { 331 {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 510
511 testRunner.runScheduledTasks(24); 511 testRunner.runScheduledTasks(24);
512 512
513 equal(subscription.downloadStatus, "synchronize_connection_error", "download Status after download error"); 513 equal(subscription.downloadStatus, "synchronize_connection_error", "download Status after download error");
514 equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + 26.1 * MILLI S_IN_HOUR, "lastDownload after download error"); 514 equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + 26.1 * MILLI S_IN_HOUR, "lastDownload after download error");
515 equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + 0.1 * MILLIS_ IN_HOUR, "lastSuccess after download error"); 515 equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + 0.1 * MILLIS_ IN_HOUR, "lastSuccess after download error");
516 equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + 27.1 * MILLIS_I N_HOUR, "lastCheck after download error"); 516 equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + 27.1 * MILLIS_I N_HOUR, "lastCheck after download error");
517 equal(subscription.errors, 2, "errors after download error"); 517 equal(subscription.errors, 2, "errors after download error");
518 }); 518 });
519 })(); 519 })();
OLDNEW
« no previous file with comments | « chrome/content/tests/subscriptionClasses.js ('k') | chrome/content/tests/test_requestList.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld