diff options
author | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 14:09:41 +0000 |
---|---|---|
committer | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 14:09:41 +0000 |
commit | 893934384f65e8676d226396c34625880a46436a (patch) | |
tree | 43e8f7ad47475bd56df8182ef321bf50a552c1c8 /chrome | |
parent | 970e30dc8789352e51963fd205f79a317e9d3ec4 (diff) | |
download | chromium_src-893934384f65e8676d226396c34625880a46436a.zip chromium_src-893934384f65e8676d226396c34625880a46436a.tar.gz chromium_src-893934384f65e8676d226396c34625880a46436a.tar.bz2 |
Break extension tab api test into multiple parts, to reduce the odds of a timeout.
BUG=43440
TEST=ExtensionApiTest.Tab*
Review URL: http://codereview.chromium.org/2072007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
23 files changed, 414 insertions, 126 deletions
diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc index d271af0..d8ea7b9 100644 --- a/chrome/browser/extensions/extension_tabs_apitest.cc +++ b/chrome/browser/extensions/extension_tabs_apitest.cc @@ -9,8 +9,8 @@ #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" -// Disabled due to timeouts, see http://crbug.com/39843, http://crbug.com/43440. -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Tabs) { + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs) { ASSERT_TRUE(StartHTTPServer()); // The test creates a tab and checks that the URL of the new tab @@ -22,19 +22,30 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Tabs) { ASSERT_TRUE(RunExtensionTest("tabs/basics")) << message_; } -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs2) { +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabGetCurrent) { ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_; +} - // This test runs through additional tabs functionality. - browser()->profile()->GetPrefs()->SetBoolean( - prefs::kHomePageIsNewTabPage, true); +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabConnect) { + ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_; +} - ASSERT_TRUE(RunExtensionTest("tabs/basics2")) << message_; +#if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) +// The way ChromeOs deals with browser windows breaks this test. +// http://crbug.com/43440. +#define MAYBE_TabOnRemoved DISABLED_TabOnRemoved +#else +#define MAYBE_TabOnRemoved TabOnRemoved +#endif +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabOnRemoved) { + ASSERT_TRUE(StartHTTPServer()); + ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_; } IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTab) { ASSERT_TRUE(StartHTTPServer()); - ASSERT_TRUE(RunExtensionTest("tabs/capture_visible_tab")) << message_; } diff --git a/chrome/test/data/extensions/api_test/tabs/basics/manifest.json b/chrome/test/data/extensions/api_test/tabs/basics/manifest.json index dfc45f3..0ffa68f 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics/manifest.json +++ b/chrome/test/data/extensions/api_test/tabs/basics/manifest.json @@ -3,11 +3,5 @@ "version": "0.1", "description": "end-to-end browser test for chrome.tabs API", "background_page": "test.html", - "content_scripts": [ - { - "matches": ["http://*/*"], - "js": ["echo.js"] - } - ], "permissions": ["tabs"] } diff --git a/chrome/test/data/extensions/api_test/tabs/basics/test.js b/chrome/test/data/extensions/api_test/tabs/basics/test.js index 3f67eaa..a21f73e 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics/test.js +++ b/chrome/test/data/extensions/api_test/tabs/basics/test.js @@ -318,14 +318,6 @@ chrome.test.runTests([ pass()); }, - function tabsOnRemoved() { - chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) { - assertEq(moveTabIds['c'], tabid); - }); - - chrome.tabs.remove(moveTabIds['c'], pass()); - }, - function setupTabsOnAttachDetach() { setupWindow(["", ""], pass(function(winId, tabIds) { @@ -458,99 +450,5 @@ chrome.test.runTests([ }); chrome.windows.remove(window.id); })); - }, */ - - function windowsOnRemoved() { - chrome.test.listenOnce(chrome.windows.onRemoved, function(windowId) { - assertEq(windowEventsWindow.id, windowId); - }); - - chrome.windows.remove(windowEventsWindow.id, pass()); - }, - - function setupConnect() { - // The web page that our content script will be injected into. - var relativePath = '/files/extensions/api_test/tabs/basics/relative.html'; - var testUrl = 'http://localhost:1337' + relativePath; - - setupWindow([testUrl], pass(function(winId, tabIds) { - testTabId = tabIds[0]; - waitForAllTabs(pass()); - })); - }, - - function connectMultipleConnects() { - var connectCount = 0; - function connect10() { - var port = chrome.tabs.connect(testTabId); - chrome.test.listenOnce(port.onMessage, function(msg) { - assertEq(++connectCount, msg.connections); - if (connectCount < 10) - connect10(); - }); - port.postMessage("GET"); - } - connect10(); - }, - - function connectName() { - var name = "akln3901n12la"; - var port = chrome.tabs.connect(testTabId, {"name": name}); - chrome.test.listenOnce(port.onMessage, function(msg) { - assertEq(name, msg.name); - - var port = chrome.tabs.connect(testTabId); - chrome.test.listenOnce(port.onMessage, function(msg) { - assertEq('', msg.name); - }); - port.postMessage("GET"); - }); - port.postMessage("GET"); - }, - - function connectPostMessageTypes() { - var port = chrome.tabs.connect(testTabId); - // Test the content script echoes the message back. - var echoMsg = {"num": 10, "string": "hi", "array": [1,2,3,4,5], - "obj":{"dec": 1.0}}; - chrome.test.listenOnce(port.onMessage, function(msg) { - assertEq(echoMsg.num, msg.num); - assertEq(echoMsg.string, msg.string); - assertEq(echoMsg.array[4], msg.array[4]); - assertEq(echoMsg.obj.dec, msg.obj.dec); - }); - port.postMessage(echoMsg); - }, - - function connectPostManyMessages() { - var port = chrome.tabs.connect(testTabId); - var count = 0; - var done = chrome.test.listenForever(port.onMessage, function(msg) { - assertEq(count++, msg); - if (count == 999) { - done(); - } - }); - for (var i = 0; i < 1000; i++) { - port.postMessage(i); - } - }, - - /* TODO: Enable this test once we do checking on the tab id for - chrome.tabs.connect (crbug.com/27565). - function connectNoTab() { - chrome.tabs.create({}, pass(function(tab) { - chrome.tabs.remove(tab.id, pass(function() { - var port = chrome.tabs.connect(tab.id); - assertEq(null, port); - })); - })); - }, */ - - function sendRequest() { - var request = "test"; - chrome.tabs.sendRequest(testTabId, request, pass(function(response) { - assertEq(request, response); - })); - } + } */ ]); diff --git a/chrome/test/data/extensions/api_test/tabs/basics2/manifest.json b/chrome/test/data/extensions/api_test/tabs/basics2/manifest.json deleted file mode 100644 index 02db114..0000000 --- a/chrome/test/data/extensions/api_test/tabs/basics2/manifest.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "chrome.tabs2", - "version": "0.1", - "description": "the second end-to-end browser test for chrome.tabs API", - "background_page": "background.html", - "permissions": ["tabs"] -} diff --git a/chrome/test/data/extensions/api_test/tabs/basics/echo.js b/chrome/test/data/extensions/api_test/tabs/connect/echo.js index 413a1d4..1cab30c 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics/echo.js +++ b/chrome/test/data/extensions/api_test/tabs/connect/echo.js @@ -15,4 +15,4 @@ chrome.extension.onConnect.addListener(function onConnect(port) { chrome.extension.onRequest.addListener(function(request, sender, respond) { respond(request); -});
\ No newline at end of file +}); diff --git a/chrome/test/data/extensions/api_test/tabs/connect/manifest.json b/chrome/test/data/extensions/api_test/tabs/connect/manifest.json new file mode 100644 index 0000000..25b9aec --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "chrome.tabs", + "version": "0.1", + "description": "end-to-end browser test for chrome.tab.connect API", + "background_page": "test.html", + "content_scripts": [ + { + "matches": ["http://*/*"], + "js": ["echo.js"] + } + ], + "permissions": ["tabs"] +} diff --git a/chrome/test/data/extensions/api_test/tabs/connect/relative.html b/chrome/test/data/extensions/api_test/tabs/connect/relative.html new file mode 100644 index 0000000..5a9e6ee8 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/relative.html @@ -0,0 +1,9 @@ +<html> +<head> +<script> +window.onload = function() { + chrome.extension.getBackgroundPage().relativePageLoaded(); +} +</script> +</head> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/connect/tabs_util.js b/chrome/test/data/extensions/api_test/tabs/connect/tabs_util.js new file mode 100644 index 0000000..cf7cf4f --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/tabs_util.js @@ -0,0 +1,79 @@ +// Utility functions to help with tabs/windows testing. + +// Removes current windows and creates one window with tabs set to +// the urls in the array |tabUrls|. At least one url must be specified. +// The |callback| should look like function(windowId, tabIds) {...}. +function setupWindow(tabUrls, callback) { + createWindow(tabUrls, {}, function(winId, tabIds) { + // Remove all other windows. + var removedCount = 0; + chrome.windows.getAll({}, function(windows) { + for (var i in windows) { + if (windows[i].id != winId) { + chrome.windows.remove(windows[i].id, function() { + removedCount++; + if (removedCount == windows.length - 1) + callback(winId, tabIds); + }); + } + } + if (windows.length == 1) + callback(winId, tabIds); + }); + }); +} + +// Creates one window with tabs set to the urls in the array |tabUrls|. +// At least one url must be specified. +// The |callback| should look like function(windowId, tabIds) {...}. +function createWindow(tabUrls, winOptions, callback) { + winOptions["url"] = tabUrls[0]; + chrome.windows.create(winOptions, function(win) { + assertTrue(win.id > 0); + var newTabIds = []; + + // Create tabs and populate newTabIds array. + chrome.tabs.getSelected(win.id, function (tab) { + newTabIds.push(tab.id); + for (var i = 1; i < tabUrls.length; i++) { + chrome.tabs.create({"windowId": win.id, "url": tabUrls[i]}, + function(tab){ + newTabIds.push(tab.id); + if (newTabIds.length == tabUrls.length) + callback(win.id, newTabIds); + }); + } + if (tabUrls.length == 1) + callback(win.id, newTabIds); + }); + }); +} + +// Waits until all tabs (yes, in every window) have status "complete". +// This is useful to prevent test overlap when testing tab events. +// |callback| should look like function() {...}. Note that |callback| expects +// zero arguments. +function waitForAllTabs(callback) { + // Wait for all tabs to load. + function waitForTabs(){ + chrome.windows.getAll({"populate": true}, function(windows) { + var ready = true; + for (var i in windows){ + for (var j in windows[i].tabs) { + if (windows[i].tabs[j].status != "complete") { + ready = false; + break; + } + } + if (!ready) + break; + } + if (ready) + callback(); + else + window.setTimeout(waitForTabs, 30); + }); + } + waitForTabs(); +} + diff --git a/chrome/test/data/extensions/api_test/tabs/connect/test.html b/chrome/test/data/extensions/api_test/tabs/connect/test.html new file mode 100644 index 0000000..54f4ab7 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/test.html @@ -0,0 +1,2 @@ +<script src="tabs_util.js"></script> +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/tabs/connect/test.js b/chrome/test/data/extensions/api_test/tabs/connect/test.js new file mode 100644 index 0000000..16c8b0e --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/test.js @@ -0,0 +1,98 @@ +// tabs api test +// browser_tests.exe --gtest_filter=ExtensionApiTest.TabConnect + +// We have a bunch of places where we need to remember some state from one +// test (or setup code) to subsequent tests. +var testTabId = null; + +var pass = chrome.test.callbackPass; +var assertEq = chrome.test.assertEq; +var assertTrue = chrome.test.assertTrue; + +chrome.test.runTests([ + function setupConnect() { + // The web page that our content script will be injected into. + var relativePath = '/files/extensions/api_test/tabs/basics/relative.html'; + var testUrl = 'http://localhost:1337' + relativePath; + + setupWindow([testUrl], pass(function(winId, tabIds) { + testTabId = tabIds[0]; + waitForAllTabs(pass()); + })); + }, + + function connectMultipleConnects() { + var connectCount = 0; + function connect10() { + var port = chrome.tabs.connect(testTabId); + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq(++connectCount, msg.connections); + if (connectCount < 10) + connect10(); + }); + port.postMessage("GET"); + } + connect10(); + }, + + function connectName() { + var name = "akln3901n12la"; + var port = chrome.tabs.connect(testTabId, {"name": name}); + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq(name, msg.name); + + var port = chrome.tabs.connect(testTabId); + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq('', msg.name); + }); + port.postMessage("GET"); + }); + port.postMessage("GET"); + }, + + function connectPostMessageTypes() { + var port = chrome.tabs.connect(testTabId); + // Test the content script echoes the message back. + var echoMsg = {"num": 10, "string": "hi", "array": [1,2,3,4,5], + "obj":{"dec": 1.0}}; + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq(echoMsg.num, msg.num); + assertEq(echoMsg.string, msg.string); + assertEq(echoMsg.array[4], msg.array[4]); + assertEq(echoMsg.obj.dec, msg.obj.dec); + }); + port.postMessage(echoMsg); + }, + + function connectPostManyMessages() { + var port = chrome.tabs.connect(testTabId); + var count = 0; + var done = chrome.test.listenForever(port.onMessage, function(msg) { + assertEq(count++, msg); + if (count == 999) { + done(); + } + }); + for (var i = 0; i < 1000; i++) { + port.postMessage(i); + } + }, + + /* TODO: Enable this test once we do checking on the tab id for + chrome.tabs.connect (crbug.com/27565). + function connectNoTab() { + chrome.tabs.create({}, pass(function(tab) { + chrome.tabs.remove(tab.id, pass(function() { + var port = chrome.tabs.connect(tab.id); + assertEq(null, port); + })); + })); + }, */ + + function sendRequest() { + var request = "test"; + chrome.tabs.sendRequest(testTabId, request, pass(function(response) { + assertEq(request, response); + })); + } +]); diff --git a/chrome/test/data/extensions/api_test/tabs/basics2/a.html b/chrome/test/data/extensions/api_test/tabs/get_current/a.html index ce05088..ce05088 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics2/a.html +++ b/chrome/test/data/extensions/api_test/tabs/get_current/a.html diff --git a/chrome/test/data/extensions/api_test/tabs/basics2/background.html b/chrome/test/data/extensions/api_test/tabs/get_current/background.html index 46f4d74..46f4d74 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics2/background.html +++ b/chrome/test/data/extensions/api_test/tabs/get_current/background.html diff --git a/chrome/test/data/extensions/api_test/tabs/get_current/manifest.json b/chrome/test/data/extensions/api_test/tabs/get_current/manifest.json new file mode 100644 index 0000000..ee41276 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/get_current/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "chrome.tabs test", + "version": "0.1", + "description": "end-to-end browser test for chrome.tabs API getCurrent()", + "background_page": "background.html", + "permissions": ["tabs"] +} diff --git a/chrome/test/data/extensions/api_test/tabs/basics2/test.js b/chrome/test/data/extensions/api_test/tabs/get_current/test.js index eea175f..db78d99 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics2/test.js +++ b/chrome/test/data/extensions/api_test/tabs/get_current/test.js @@ -22,6 +22,7 @@ chrome.test.runTests([ function openedTabGetCurrentTab() { chrome.tabs.create({url: pageUrl("a")}); - // Completes with onCompleteGetCurrentTab. + // Completes with onCompleteGetCurrentTab, which is triggered by + // the onload of a.html . } ]); diff --git a/chrome/test/data/extensions/api_test/tabs/on_removed/a.html b/chrome/test/data/extensions/api_test/tabs/on_removed/a.html new file mode 100644 index 0000000..dcd442e --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/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/on_removed/b.html b/chrome/test/data/extensions/api_test/tabs/on_removed/b.html new file mode 100644 index 0000000..7bff50a --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/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/on_removed/c.html b/chrome/test/data/extensions/api_test/tabs/on_removed/c.html new file mode 100644 index 0000000..ccaad19 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/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/on_removed/d.html b/chrome/test/data/extensions/api_test/tabs/on_removed/d.html new file mode 100644 index 0000000..6d5df4a --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/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/on_removed/e.html b/chrome/test/data/extensions/api_test/tabs/on_removed/e.html new file mode 100644 index 0000000..8f6e3c1 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/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/on_removed/manifest.json b/chrome/test/data/extensions/api_test/tabs/on_removed/manifest.json new file mode 100644 index 0000000..e354457 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "chrome.tabs", + "version": "0.1", + "description": "end-to-end browser test for chrome.tabs.onRemoved API", + "background_page": "test.html", + "permissions": ["tabs"] +} diff --git a/chrome/test/data/extensions/api_test/tabs/on_removed/tabs_util.js b/chrome/test/data/extensions/api_test/tabs/on_removed/tabs_util.js new file mode 100644 index 0000000..cf7cf4f --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/tabs_util.js @@ -0,0 +1,79 @@ +// Utility functions to help with tabs/windows testing. + +// Removes current windows and creates one window with tabs set to +// the urls in the array |tabUrls|. At least one url must be specified. +// The |callback| should look like function(windowId, tabIds) {...}. +function setupWindow(tabUrls, callback) { + createWindow(tabUrls, {}, function(winId, tabIds) { + // Remove all other windows. + var removedCount = 0; + chrome.windows.getAll({}, function(windows) { + for (var i in windows) { + if (windows[i].id != winId) { + chrome.windows.remove(windows[i].id, function() { + removedCount++; + if (removedCount == windows.length - 1) + callback(winId, tabIds); + }); + } + } + if (windows.length == 1) + callback(winId, tabIds); + }); + }); +} + +// Creates one window with tabs set to the urls in the array |tabUrls|. +// At least one url must be specified. +// The |callback| should look like function(windowId, tabIds) {...}. +function createWindow(tabUrls, winOptions, callback) { + winOptions["url"] = tabUrls[0]; + chrome.windows.create(winOptions, function(win) { + assertTrue(win.id > 0); + var newTabIds = []; + + // Create tabs and populate newTabIds array. + chrome.tabs.getSelected(win.id, function (tab) { + newTabIds.push(tab.id); + for (var i = 1; i < tabUrls.length; i++) { + chrome.tabs.create({"windowId": win.id, "url": tabUrls[i]}, + function(tab){ + newTabIds.push(tab.id); + if (newTabIds.length == tabUrls.length) + callback(win.id, newTabIds); + }); + } + if (tabUrls.length == 1) + callback(win.id, newTabIds); + }); + }); +} + +// Waits until all tabs (yes, in every window) have status "complete". +// This is useful to prevent test overlap when testing tab events. +// |callback| should look like function() {...}. Note that |callback| expects +// zero arguments. +function waitForAllTabs(callback) { + // Wait for all tabs to load. + function waitForTabs(){ + chrome.windows.getAll({"populate": true}, function(windows) { + var ready = true; + for (var i in windows){ + for (var j in windows[i].tabs) { + if (windows[i].tabs[j].status != "complete") { + ready = false; + break; + } + } + if (!ready) + break; + } + if (ready) + callback(); + else + window.setTimeout(waitForTabs, 30); + }); + } + waitForTabs(); +} + diff --git a/chrome/test/data/extensions/api_test/tabs/on_removed/test.html b/chrome/test/data/extensions/api_test/tabs/on_removed/test.html new file mode 100644 index 0000000..54f4ab7 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/test.html @@ -0,0 +1,2 @@ +<script src="tabs_util.js"></script> +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/tabs/on_removed/test.js b/chrome/test/data/extensions/api_test/tabs/on_removed/test.js new file mode 100644 index 0000000..f44164f --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/on_removed/test.js @@ -0,0 +1,70 @@ +// tabs api test: removing windows. +// browser_tests.exe --gtest_filter=ExtensionApiTest.TabOnRemoved + +// We have a bunch of places where we need to remember some state from one +// test (or setup code) to subsequent tests. +var firstWindowId = null; +var secondWindowId = null; + +var windowEventsWindow = null; +var moveTabIds = {}; + +var pass = chrome.test.callbackPass; +var assertEq = chrome.test.assertEq; +var assertTrue = chrome.test.assertTrue; + +function pageUrl(letter) { + return chrome.extension.getURL(letter + ".html"); +} + +chrome.test.runTests([ + // Open some pages, so that we can try to close them. + function setupLetterPages() { + var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'), + pageUrl('c'), pageUrl('d'), pageUrl('e')]; + setupWindow(pages, pass(function(winId, tabIds) { + firstWindowId = winId; + moveTabIds['a'] = tabIds[1]; + moveTabIds['b'] = tabIds[2]; + moveTabIds['c'] = tabIds[3]; + moveTabIds['d'] = tabIds[4]; + moveTabIds['e'] = tabIds[5]; + createWindow(["chrome://newtab/"], {}, pass(function(winId, tabIds) { + secondWindowId = winId; + })); + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + assertEq(pages.length, tabs.length); + for (var i in tabs) { + assertEq(pages[i], tabs[i].url); + } + })); + })); + }, + + function tabsOnRemoved() { + chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) { + assertEq(moveTabIds['c'], tabid); + }); + + chrome.tabs.remove(moveTabIds['c'], pass()); + }, + + function windowsOnCreated() { + chrome.test.listenOnce(chrome.windows.onCreated, function(window) { + windowEventsWindow = window; + chrome.tabs.getAllInWindow(window.id, pass(function(tabs) { + assertEq(pageUrl("a"), tabs[0].url); + })); + }); + + chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {})); + }, + + function windowsOnRemoved() { + chrome.test.listenOnce(chrome.windows.onRemoved, function(windowId) { + assertEq(windowEventsWindow.id, windowId); + }); + + chrome.windows.remove(windowEventsWindow.id, pass()); + } +]); |