Index: chrome/test/data/extensions/api_test/sessions/sessions.js |
diff --git a/chrome/test/data/extensions/api_test/sessions/sessions.js b/chrome/test/data/extensions/api_test/sessions/sessions.js |
index 431edbec72fb11ed0a052bebb3a721a68cc1e13f..f7e475ec7d419546076a06552115fa404d28d135 100644 |
--- a/chrome/test/data/extensions/api_test/sessions/sessions.js |
+++ b/chrome/test/data/extensions/api_test/sessions/sessions.js |
@@ -59,6 +59,33 @@ function checkEntries(expectedEntries, actualEntries) { |
}); |
} |
+function checkOnChangedEvent(expectedCallbackCount) { |
+ var callbackCount = 0; |
+ var done = chrome.test.listenForever(chrome.sessions.onChanged, function() { |
+ callbackCount++; |
+ } |
+ ); |
+ |
+ return function() { |
+ var maxRetry = 10, retry = 1; |
+ var checkEvent = function() { |
+ if (callbackCount < expectedCallbackCount) { |
+ console.log("Waiting for " + |
+ (expectedCallbackCount - callbackCount) + |
+ " more onChanged events"); |
+ retry++; |
+ if (retry < maxRetry) { |
+ window.setTimeout(checkEvent, 100); |
+ return; |
+ } |
+ } |
+ assertEq(callbackCount, expectedCallbackCount); |
+ done(); |
+ }; |
+ window.setTimeout(checkEvent, 100); |
not at google - send to devlin
2014/03/28 15:51:10
100*10ms is too small, this only gives the test 1
|
+ }; |
+} |
+ |
chrome.test.runTests([ |
// After setupWindows |
// |
@@ -108,6 +135,8 @@ chrome.test.runTests([ |
function retrieveClosedTabs() { |
// Check that the recently closed list contains what we expect |
// after removing tabs. |
+ var checkEvent = checkOnChangedEvent(2); |
+ |
callForEach( |
chrome.tabs.remove, |
firstWindowTabIds.slice(0, 2).reverse(), |
@@ -125,6 +154,7 @@ chrome.test.runTests([ |
entries.forEach(function(entry) { |
recentlyClosedTabIds.push(entry.tab.sessionId); |
}); |
+ checkEvent(); |
}) |
); |
} |
@@ -134,6 +164,8 @@ chrome.test.runTests([ |
function retrieveClosedWindows() { |
// Check that the recently closed list contains what we expect |
// after removing windows. |
+ var checkEvent = checkOnChangedEvent(2); |
+ |
callForEach( |
chrome.windows.remove, |
windowIds.slice(1, 3).reverse(), |
@@ -154,6 +186,7 @@ chrome.test.runTests([ |
entries.forEach(function(entry) { |
recentlyClosedWindowIds.push(entry.window.sessionId); |
}); |
+ checkEvent(); |
}) |
); |
} |
@@ -197,6 +230,8 @@ chrome.test.runTests([ |
}, |
function restoreClosedTabs() { |
+ var checkEvent = checkOnChangedEvent(2); |
+ |
chrome.windows.get(windowIds[0], {"populate": true}, |
callbackPass(function(win) { |
var tabCountBeforeRestore = win.tabs.length; |
@@ -212,6 +247,7 @@ chrome.test.runTests([ |
win.tabs.forEach(function(tab, i) { |
assertEq(pages[i++], tab.url); |
}); |
+ checkEvent(); |
}) |
); |
}) |
@@ -219,6 +255,8 @@ chrome.test.runTests([ |
}, |
function restoreTabInClosedWindow() { |
+ var checkEvent = checkOnChangedEvent(1); |
+ |
chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
var windowCountBeforeRestore = win.length; |
chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], |
@@ -229,6 +267,7 @@ chrome.test.runTests([ |
assertEq(windowCountBeforeRestore + 1, win.length); |
assertEq(1, win[win.length - 1].tabs.length); |
assertEq(pages[0], win[win.length - 1].tabs[0].url); |
+ checkEvent(); |
}) |
); |
}) |
@@ -237,11 +276,14 @@ chrome.test.runTests([ |
}, |
function restoreClosedWindows() { |
+ var checkEvent = checkOnChangedEvent(1); |
+ |
chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
var windowCountBeforeRestore = win.length; |
chrome.sessions.restore(recentlyClosedWindowIds[0], |
function(win_session) { |
assertEq(1, win_session.window.tabs.length); |
+ checkEvent(); |
}); |
function done() { |
chrome.windows.getAll({"populate": true}, |
@@ -285,6 +327,8 @@ chrome.test.runTests([ |
}, |
function restoreMostRecentEntry() { |
+ var checkEvent = checkOnChangedEvent(1); |
+ |
chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
var windowCountBeforeRestore = win.length; |
chrome.sessions.restore(callbackPass(function(win_session) { |
@@ -292,6 +336,7 @@ chrome.test.runTests([ |
chrome.windows.getAll({"populate": true}, |
callbackPass(function(win) { |
assertEq(windowCountBeforeRestore + 1, win.length); |
+ checkEvent(); |
}) |
); |
})); |