diff options
author | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 20:16:41 +0000 |
---|---|---|
committer | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 20:16:41 +0000 |
commit | d328413b739ed1150369743a64cacfb167086a32 (patch) | |
tree | 3c4c18ff0d0256bc3372420bf3c7a18ab0d64088 | |
parent | ad6d2c4304320a300009682901199278fabd3148 (diff) | |
download | chromium_src-d328413b739ed1150369743a64cacfb167086a32.zip chromium_src-d328413b739ed1150369743a64cacfb167086a32.tar.gz chromium_src-d328413b739ed1150369743a64cacfb167086a32.tar.bz2 |
Address ExtensionApiTest.Tabs flakiness
This addresses two problems. (1) relativeUrlTabsUpdate could fail because it was depending on testTabId getting set from relativeUrlTabsCreate, which may have happened out of order. I have refactored the callback blocking so additional blocks can be created with chrome.test.callbackAdded().
(2) tabs.update({url:}) is still failing intermitantly. This changes addeds valid html files in the extension which can be navitation targets (previously, non-existent urls had been used), in the hopes that the random failures had to do with load errors.
BUG=20828
Review URL: http://codereview.chromium.org/195090
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26258 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_tabs_apitest.cc | 3 | ||||
-rw-r--r-- | chrome/renderer/renderer_resources.grd | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/extension_apitest.js | 25 | ||||
-rwxr-xr-x | chrome/test/data/extensions/api_test/tabs/a.html | 5 | ||||
-rwxr-xr-x | chrome/test/data/extensions/api_test/tabs/b.html | 5 | ||||
-rwxr-xr-x | chrome/test/data/extensions/api_test/tabs/c.html | 5 | ||||
-rwxr-xr-x | chrome/test/data/extensions/api_test/tabs/d.html | 5 | ||||
-rwxr-xr-x | chrome/test/data/extensions/api_test/tabs/e.html | 5 | ||||
-rwxr-xr-x | chrome/test/data/extensions/api_test/tabs/f.html | 5 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/test.js | 74 |
10 files changed, 85 insertions, 49 deletions
diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc index ecb3671..ca22703 100644 --- a/chrome/browser/extensions/extension_tabs_apitest.cc +++ b/chrome/browser/extensions/extension_tabs_apitest.cc @@ -4,7 +4,6 @@ #include "chrome/browser/extensions/extension_apitest.h" -// TODO(asargent): http://crbug.com/20828 -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Tabs) { +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs) { ASSERT_TRUE(RunExtensionTest("tabs")) << message_; } diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index 80657868..50230d5 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. rw --> +without changes to the corresponding grd file. rw2 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> diff --git a/chrome/renderer/resources/extension_apitest.js b/chrome/renderer/resources/extension_apitest.js index 90cc055..e9d92b5 100644 --- a/chrome/renderer/resources/extension_apitest.js +++ b/chrome/renderer/resources/extension_apitest.js @@ -48,17 +48,17 @@ var chrome = chrome || {}; chrome.test.notifyPass(); complete(); } - + var pendingCallbacks = 0; - function callbackAdded() { + chrome.test.callbackAdded = function () { pendingCallbacks++; - }; - function callbackCompleted() { - pendingCallbacks--; - if (pendingCallbacks == 0) { - chrome.test.succeed(); + return function() { + pendingCallbacks--; + if (pendingCallbacks == 0) { + chrome.test.succeed(); + } } }; @@ -148,7 +148,7 @@ var chrome = chrome || {}; if (func) { chrome.test.assertEq(typeof(func), 'function'); } - callbackAdded(); + var callbackCompleted = chrome.test.callbackAdded(); return function() { if (expectedError == null) { @@ -167,7 +167,7 @@ var chrome = chrome || {}; }; chrome.test.listenOnce = function(event, func) { - callbackAdded(); + var callbackCompleted = chrome.test.callbackAdded(); var listener = function() { event.removeListener(listener); safeFunctionApply(func, arguments); @@ -177,14 +177,13 @@ var chrome = chrome || {}; }; chrome.test.listenForever = function(event, func) { - callbackAdded(); - + var callbackCompleted = chrome.test.callbackAdded(); + var listener = function() { safeFunctionApply(func, arguments); }; - var done = {}; - done.doneListening = function() { + var done = function() { event.removeListener(listener); callbackCompleted(); }; diff --git a/chrome/test/data/extensions/api_test/tabs/a.html b/chrome/test/data/extensions/api_test/tabs/a.html new file mode 100755 index 0000000..dcd442e --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/a.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>A</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/b.html b/chrome/test/data/extensions/api_test/tabs/b.html new file mode 100755 index 0000000..7bff50a --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/b.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>B</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/c.html b/chrome/test/data/extensions/api_test/tabs/c.html new file mode 100755 index 0000000..ccaad19 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/c.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>C</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/d.html b/chrome/test/data/extensions/api_test/tabs/d.html new file mode 100755 index 0000000..6d5df4a --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/d.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>D</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/e.html b/chrome/test/data/extensions/api_test/tabs/e.html new file mode 100755 index 0000000..8f6e3c1 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/e.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>E</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/f.html b/chrome/test/data/extensions/api_test/tabs/f.html new file mode 100755 index 0000000..0b00692 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/f.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>F</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/test.js b/chrome/test/data/extensions/api_test/tabs/test.js index 0f6cc5b..867a34c 100644 --- a/chrome/test/data/extensions/api_test/tabs/test.js +++ b/chrome/test/data/extensions/api_test/tabs/test.js @@ -16,9 +16,8 @@ var pass = chrome.test.callbackPass; var assertEq = chrome.test.assertEq; var assertTrue = chrome.test.assertTrue; -// Called by relative.html during onload. -function relativePageLoaded() { - chrome.test.succeed(); +function pageUrl(letter) { + return chrome.extension.getURL(letter + ".html"); } chrome.test.runTests([ @@ -56,10 +55,10 @@ chrome.test.runTests([ assertTrue(win.id > 0); secondWindowId = win.id; // Create first window. - chrome.tabs.create({"windowId" : firstWindowId, "url" : "chrome://a"}, + chrome.tabs.create({"windowId" : firstWindowId, "url" : pageUrl("a")}, pass(function() { // Create second window. - chrome.tabs.create({"windowId" : secondWindowId, "url" : "chrome://b"}, + chrome.tabs.create({"windowId" : secondWindowId, "url" :pageUrl("b")}, pass()); })); })); @@ -80,7 +79,7 @@ chrome.test.runTests([ } assertEq("about:blank", tabs[0].url); assertEq("chrome://newtab/", tabs[1].url); - assertEq("chrome://a/", tabs[2].url); + assertEq(pageUrl("a"), tabs[2].url); testTabId = tabs[2].id; })); }, @@ -94,20 +93,20 @@ chrome.test.runTests([ assertEq(i, tabs[i].index); } assertEq("chrome://newtab/", tabs[0].url); - assertEq("chrome://b/", tabs[1].url); + assertEq(pageUrl("b"), tabs[1].url); })); }, function updateUrl() { chrome.tabs.get(testTabId, pass(function(tab) { - assertEq("chrome://a/", tab.url); + assertEq(pageUrl("a"), tab.url); // Update url. - chrome.tabs.update(testTabId, {"url": "chrome://c/"}, + chrome.tabs.update(testTabId, {"url": pageUrl("c")}, pass(function(tab){ - chrome.test.assertEq("chrome://c/", tab.url); + chrome.test.assertEq(pageUrl("c"), tab.url); // Check url. chrome.tabs.get(testTabId, pass(function(tab) { - assertEq("chrome://c/", tab.url); + assertEq(pageUrl("c"), tab.url); })); })); })); @@ -158,9 +157,9 @@ chrome.test.runTests([ var letters = ['a', 'b', 'c', 'd', 'e']; for (var i in letters) { chrome.tabs.create({"windowId": moveWindow1, - "url": "chrome://" + letters[i]}, + "url": pageUrl(letters[i])}, pass(function(tab) { - var letter = tab.url[tab.url.length-2]; + var letter = tab.url[tab.url.length-6]; moveTabIds[letter] = tab.id; // Assert on last callback that tabs were added in the order we created @@ -169,11 +168,11 @@ chrome.test.runTests([ chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) { assertEq(6, tabs.length); assertEq("chrome://newtab/", tabs[0].url); - assertEq("chrome://a/", tabs[1].url); - assertEq("chrome://b/", tabs[2].url); - assertEq("chrome://c/", tabs[3].url); - assertEq("chrome://d/", tabs[4].url); - assertEq("chrome://e/", tabs[5].url); + assertEq(pageUrl("a"), tabs[1].url); + assertEq(pageUrl("b"), tabs[2].url); + assertEq(pageUrl("c"), tabs[3].url); + assertEq(pageUrl("d"), tabs[4].url); + assertEq(pageUrl("e"), tabs[5].url); })); } })); @@ -209,15 +208,15 @@ chrome.test.runTests([ chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) { assertEq(4, tabs.length); assertEq("chrome://newtab/", tabs[0].url); - assertEq("chrome://a/", tabs[1].url); - assertEq("chrome://e/", tabs[2].url); - assertEq("chrome://c/", tabs[3].url); + assertEq(pageUrl("a"), tabs[1].url); + assertEq(pageUrl("e"), tabs[2].url); + assertEq(pageUrl("c"), tabs[3].url); chrome.tabs.getAllInWindow(moveWindow2, pass(function(tabs) { assertEq(3, tabs.length); - assertEq("chrome://b/", tabs[0].url); + assertEq(pageUrl("b"), tabs[0].url); assertEq("chrome://newtab/", tabs[1].url); - assertEq("chrome://d/", tabs[2].url); + assertEq(pageUrl("d"), tabs[2].url); })); })); }, @@ -227,7 +226,7 @@ chrome.test.runTests([ chrome.tabs.getAllInWindow(moveWindow2, pass(function(tabs) { assertEq(2, tabs.length); - assertEq("chrome://b/", tabs[0].url); + assertEq(pageUrl("b"), tabs[0].url); assertEq("chrome://newtab/", tabs[1].url); })); })); @@ -276,23 +275,23 @@ chrome.test.runTests([ function onCreated() { chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) { - assertEq("chrome://f/", tab.url); + assertEq(pageUrl("f"), tab.url); }); - chrome.tabs.create({"windowId": moveWindow1, "url": "chrome://f", + chrome.tabs.create({"windowId": moveWindow1, "url": pageUrl("f"), "selected": true}, pass(function(tab) {})); }, function onUpdated() { - var listener = chrome.test.listenForever(chrome.tabs.onUpdated, + var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated, function(tabid, info) { if (tabid == moveTabIds['a'] && info.status == "complete") { - listener.doneListening(); + onUpdatedCompleted(); } } ); - chrome.tabs.update(moveTabIds['a'], {"url": "chrome://aa"}, + chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass()); }, @@ -338,25 +337,34 @@ chrome.test.runTests([ })); }, - // The subsequent three tests all load relative.html, which calls - // this page's relativePageLoad(), which ends the test. function relativeUrlTabsCreate() { + // Will be called from relative.html + window.relativePageLoaded = chrome.test.callbackAdded(); + var createCompleted = chrome.test.callbackAdded(); + chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'}, function(tab){ testTabId = tab.id; + createCompleted(); } ); }, function relativeUrlTabsUpdate() { - chrome.tabs.update(testTabId, {url: "chrome://a/"}, function(tab) { - chrome.test.assertEq("chrome://a/", tab.url); + // Will be called from relative.html + window.relativePageLoaded = chrome.test.callbackAdded(); + + chrome.tabs.update(testTabId, {url: pageUrl("a")}, function(tab) { + chrome.test.assertEq(pageUrl("a"), tab.url); chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) { }); }); }, function relativeUrlWindowsCreate() { + // Will be called from relative.html + window.relativePageLoaded = chrome.test.callbackAdded(); + chrome.windows.create({url: "relative.html"}); } |