diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 21:50:23 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 21:50:23 +0000 |
commit | d012ee4b9d8b6e976127008dda31716a6d15e6e2 (patch) | |
tree | 2f0e1b67c9c1ec9cfee23d3b24eb6350c220bef6 | |
parent | 0e8d7a39fb625fc03e31f43d2c778fede9cff841 (diff) | |
download | chromium_src-d012ee4b9d8b6e976127008dda31716a6d15e6e2.zip chromium_src-d012ee4b9d8b6e976127008dda31716a6d15e6e2.tar.gz chromium_src-d012ee4b9d8b6e976127008dda31716a6d15e6e2.tar.bz2 |
Include more extension browser tests on mac and linux. Some minor changes and reorganization.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/504064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35737 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_browsertests_misc.cc | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_devtools_browsertests.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_startup_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_tabs_apitest.cc | 7 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 14 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/basics/manifest.json | 6 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/basics/test.js | 103 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/connect/echo.js (renamed from chrome/test/data/extensions/api_test/tabs/basics/echo.js) | 0 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/connect/manifest.json | 13 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/connect/tabs_util.js | 77 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/connect/test.html | 102 |
11 files changed, 225 insertions, 106 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 6b9822b..51d58dd 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -20,7 +20,6 @@ #include "chrome/browser/views/extensions/extension_shelf.h" #include "chrome/browser/views/frame/browser_view.h" #endif - #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/notification_service.h" @@ -223,12 +222,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { // keep these from working #define MAYBE_PageAction DISABLED_PageAction #define MAYBE_UnloadPageAction DISABLED_UnloadPageAction -#define MAYBE_TitleLocalizationBrowserAction DISABLED_TitleLocalizationBrowserAction #define MAYBE_TitleLocalizationPageAction DISABLED_TitleLocalizationPageAction #else #define MAYBE_PageAction PageAction #define MAYBE_UnloadPageAction UnloadPageAction -#define MAYBE_TitleLocalizationBrowserAction TitleLocalizationBrowserAction #define MAYBE_TitleLocalizationPageAction TitleLocalizationPageAction #endif @@ -280,7 +277,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_UnloadPageAction) { // Tests that tooltips of a browser action icon can be specified using UTF8. // See http://crbug.com/25349. -IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_TitleLocalizationBrowserAction) { +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationBrowserAction) { FilePath extension_path(test_data_dir_.AppendASCII("browsertest") .AppendASCII("title_localized")); ASSERT_TRUE(LoadExtension(extension_path)); diff --git a/chrome/browser/extensions/extension_devtools_browsertests.cc b/chrome/browser/extensions/extension_devtools_browsertests.cc index d030fd1..28e9211 100644 --- a/chrome/browser/extensions/extension_devtools_browsertests.cc +++ b/chrome/browser/extensions/extension_devtools_browsertests.cc @@ -16,8 +16,6 @@ #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/views/extensions/extension_shelf.h" -#include "chrome/browser/views/frame/browser_view.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/devtools_messages.h" #include "chrome/common/extensions/extension_error_reporter.h" diff --git a/chrome/browser/extensions/extension_startup_unittest.cc b/chrome/browser/extensions/extension_startup_unittest.cc index 2ec4701..19be2c7 100644 --- a/chrome/browser/extensions/extension_startup_unittest.cc +++ b/chrome/browser/extensions/extension_startup_unittest.cc @@ -159,12 +159,10 @@ class ExtensionsStartupTest : public ExtensionStartupTestBase { } }; -#if defined(OS_WIN) IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, Test) { WaitForServicesToStart(3, true); TestInjection(true, true); } -#endif // defined(OS_WIN) // ExtensionsLoadTest // Ensures that we can startup the browser with --load-extension and see them diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc index 427f6cf..b5ad2ab 100644 --- a/chrome/browser/extensions/extension_tabs_apitest.cc +++ b/chrome/browser/extensions/extension_tabs_apitest.cc @@ -4,7 +4,12 @@ #include "chrome/browser/extensions/extension_apitest.h" -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs) { +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsBasics) { StartHTTPServer(); ASSERT_TRUE(RunExtensionTest("tabs/basics")) << message_; } + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsConnect) { + StartHTTPServer(); + ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_; +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7eb8acbd..0f053b4 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -9,14 +9,7 @@ 'browser/views/find_bar_host_browsertest.cc', ], 'browser_tests_sources_win_specific': [ - 'browser/extensions/extension_devtools_browsertest.cc', - 'browser/extensions/extension_devtools_browsertest.h', - 'browser/extensions/extension_devtools_browsertests.cc', 'browser/extensions/extension_shelf_model_unittest.cc', - 'browser/extensions/extension_startup_unittest.cc', - 'browser/extensions/extension_storage_apitest.cc', - 'browser/extensions/extension_tabs_apitest.cc', - 'browser/extensions/extension_i18n_apitest.cc', 'browser/extensions/extension_popup_apitest.cc', # TODO(jam): http://crbug.com/15101 These tests fail on Linux and Mac. 'browser/child_process_security_policy_browser_test.cc', @@ -1107,10 +1100,17 @@ 'browser/extensions/extension_browsertest.cc', 'browser/extensions/extension_browsertest.h', 'browser/extensions/extension_browsertests_misc.cc', + 'browser/extensions/extension_devtools_browsertest.cc', + 'browser/extensions/extension_devtools_browsertest.h', + 'browser/extensions/extension_devtools_browsertests.cc', 'browser/extensions/extension_history_apitest.cc', + 'browser/extensions/extension_i18n_apitest.cc', 'browser/extensions/extension_javascript_url_apitest.cc', 'browser/extensions/extension_messages_apitest.cc', 'browser/extensions/extension_override_apitest.cc', + 'browser/extensions/extension_startup_unittest.cc', + 'browser/extensions/extension_storage_apitest.cc', + 'browser/extensions/extension_tabs_apitest.cc', 'browser/extensions/extension_toolstrip_apitest.cc', 'browser/extensions/incognito_noscript_apitest.cc', 'browser/extensions/isolated_world_apitest.cc', 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 a516ddc..7f43fcc 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics/test.js +++ b/chrome/test/data/extensions/api_test/tabs/basics/test.js @@ -15,6 +15,14 @@ var pass = chrome.test.callbackPass; var assertEq = chrome.test.assertEq; var assertTrue = chrome.test.assertTrue; +// The browser tests on windows run with the homepage set to the ntp. +// On mac and linux, the homepage is google. +var kDefaultUrl; +if (navigator.userAgent.indexOf("Win") != -1) // if running on windows + kDefaultUrl = "chrome://newtab/" +else + kDefaultUrl = "http://www.google.com/" + function pageUrl(letter) { return chrome.extension.getURL(letter + ".html"); } @@ -35,7 +43,7 @@ chrome.test.runTests([ assertTrue(tab.index > firstTabIndex); assertEq(firstWindowId, tab.windowId); assertEq(false, tab.selected); - assertEq("chrome://newtab/", tab.url); + assertEq(kDefaultUrl, tab.url); })); }, @@ -487,91 +495,18 @@ chrome.test.runTests([ 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); + // Regression test for crbug.com/28325. Does not perfectly reproduce the issue + // unfortunately. + function moveWindowsAndCreate() { + setupWindow(["", ""], pass(function(win1, win1Tabs) { + createWindow([""], pass(function(win2, win2Tabs) { + chrome.tabs.move(win1Tabs[1], {"windowId": win2, "index": 2}, + pass(function(tab) { + chrome.tabs.create({"windowId": win1, "url": "chrome://newtab/"}); + })); })); })); - }, */ - - function sendRequest() { - var request = "test"; - chrome.tabs.sendRequest(testTabId, request, pass(function(response) { - assertEq(request, response); - })); - }, + } // TODO(asargent) // It would be an improvement to check the captureVisibleTab results 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..413a1d4 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics/echo.js +++ b/chrome/test/data/extensions/api_test/tabs/connect/echo.js 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..dfc45f3 --- /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.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/connect/tabs_util.js b/chrome/test/data/extensions/api_test/tabs/connect/tabs_util.js new file mode 100644 index 0000000..f087948 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/tabs_util.js @@ -0,0 +1,77 @@ +// 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, callback) { + chrome.windows.create({"url": tabUrls[0]}, 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() {...}. +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..d6279ed --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/connect/test.html @@ -0,0 +1,102 @@ +<script src="tabs_util.js" /> +<script> +var firstWindowId = null; +var secondWindowId = null; +var firstTabIndex = null; +var testTabId = null; + +var windowEventsWindow = null; +var moveTabIds = {}; + +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); + })); + } +]); +</script> |