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

Side by Side Diff: third_party/WebKit/LayoutTests/storage/domstorage/events/resources/eventTestHarness.js

Issue 2538773003: Deflake storage/domstorage/events tests when run in random order (Closed)
Patch Set: Rebased Created 4 years 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
OLDNEW
1 if (window.testRunner) { 1 var jsTestIsAsync = true;
2 testRunner.dumpAsText();
3 testRunner.waitUntilDone();
4 }
5 2
6 iframe = document.createElement("IFRAME"); 3 iframe = document.createElement("IFRAME");
7 iframe.src = "about:blank"; 4 iframe.src = 'about:blank';
8 document.body.appendChild(iframe); 5 document.body.appendChild(iframe);
9 iframe.contentWindow.document.body.innerText = "Nothing to see here.";
10 6
11 storageEventList = new Array(); 7 storageEventList = new Array();
12 iframe.contentWindow.onstorage = function (e) {
13 window.parent.storageEventList.push(e);
14 }
15 8
16 function runAfterNStorageEvents(callback, expectedNumEvents) 9 function runAfterNStorageEvents(callback, expectedNumEvents)
17 { 10 {
18 countStorageEvents(callback, expectedNumEvents, 0) 11 countStorageEvents(callback, expectedNumEvents, 0);
19 } 12 }
20 13
21 function countStorageEvents(callback, expectedNumEvents, times) 14 function countStorageEvents(callback, expectedNumEvents, times)
22 { 15 {
23 function onTimeout() 16 function onTimeout()
24 { 17 {
25 var currentCount = storageEventList.length; 18 var currentCount = storageEventList.length;
26 if (currentCount == expectedNumEvents) 19 if (currentCount == expectedNumEvents)
27 callback(); 20 callback();
28 else if (currentCount > expectedNumEvents) { 21 else if (currentCount > expectedNumEvents) {
29 testFailed("got at least " + currentCount + ", expected only " + exp ectedNumEvents + " events"); 22 testFailed("got at least " + currentCount + ", expected only " + exp ectedNumEvents + " events");
30 callback(); 23 callback();
31 } else if (times > 50) { 24 } else if (times > 50) {
32 testFailed("Timeout: only got " + currentCount + ", expected " + exp ectedNumEvents + " events"); 25 testFailed("Timeout: only got " + currentCount + ", expected " + exp ectedNumEvents + " events");
33 callback(); 26 callback();
34 } else 27 } else {
35 countStorageEvents(callback, expectedNumEvents, times+1) 28 countStorageEvents(callback, expectedNumEvents, times+1);
29 }
36 } 30 }
37 setTimeout(onTimeout, 20); 31 setTimeout(onTimeout, 20);
38 } 32 }
39 33
40 function testStorages(testCallback) 34 function testStorages(testCallback)
41 { 35 {
42 // When we're done testing LocalStorage, this is run.
43 function allDone()
44 {
45 debug("");
46 debug("");
47 window.successfullyParsed = true;
48 isSuccessfullyParsed();
49 debug("");
50 localStorage.clear();
51 sessionStorage.clear();
52 if (window.testRunner)
53 testRunner.notifyDone()
54 }
55
56 // When we're done testing with SessionStorage, this is run. 36 // When we're done testing with SessionStorage, this is run.
57 function runLocalStorage() 37 function runLocalStorage()
58 { 38 {
59 debug(""); 39 debug("");
60 debug(""); 40 debug("");
61 testCallback("localStorage", allDone); 41 testCallback("localStorage", finishJSTest);
62 } 42 }
63 43
64 // First run the test with SessionStorage. 44 // First run the test with SessionStorage.
65 testCallback("sessionStorage", runLocalStorage); 45 testCallback("sessionStorage", runLocalStorage);
66 } 46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698