summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-19 20:32:30 +0000
committerskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-19 20:32:30 +0000
commite18a19b149d4a88701a45873307e03d866a01565 (patch)
tree6f27ee6bc23374784afcd1ab92f5d6c06cd07bb8 /chrome
parent2b9a9f16465b34ee13e09e9b93086f75c925d3ac (diff)
downloadchromium_src-e18a19b149d4a88701a45873307e03d866a01565.zip
chromium_src-e18a19b149d4a88701a45873307e03d866a01565.tar.gz
chromium_src-e18a19b149d4a88701a45873307e03d866a01565.tar.bz2
Fix a bunch of extensions api tests to not hard-code port 1337.
Fixed about 2/3 of the problem tests. These are the simple cases, where chrome.test.getConfig() can easily solve the problem. BUG=53632 TEST=ExtensionApiTest.* Review URL: http://codereview.chromium.org/3820010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/app_background_page_apitest.cc4
-rw-r--r--chrome/browser/extensions/cross_origin_xhr_apitest.cc2
-rw-r--r--chrome/browser/extensions/execute_script_apitest.cc4
-rw-r--r--chrome/browser/extensions/extension_incognito_apitest.cc28
-rw-r--r--chrome/browser/extensions/extension_javascript_url_apitest.cc2
-rw-r--r--chrome/browser/extensions/extension_messages_apitest.cc2
-rw-r--r--chrome/browser/extensions/fragment_navigation_apitest.cc4
-rw-r--r--chrome/browser/extensions/isolated_world_apitest.cc2
-rw-r--r--chrome/browser/extensions/window_open_apitest.cc2
-rw-r--r--chrome/test/automation/dom_automation_browsertest.cc6
-rw-r--r--chrome/test/data/extensions/api_test/app_background_page/basic/test.html23
-rw-r--r--chrome/test/data/extensions/api_test/content_scripts/isolated_world1/background.html10
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/test.html97
-rw-r--r--chrome/test/data/extensions/api_test/executescript/basic/test.html143
-rw-r--r--chrome/test/data/extensions/api_test/executescript/fragment/background.html56
-rw-r--r--chrome/test/data/extensions/api_test/incognito/apis/background.html186
-rw-r--r--chrome/test/data/extensions/api_test/incognito/split/background.html163
-rw-r--r--chrome/test/data/extensions/api_test/messaging/connect/test.html201
-rw-r--r--chrome/test/data/extensions/api_test/tabs/javascript_url_permissions/test.html47
-rw-r--r--chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/background.html31
-rw-r--r--chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/pop.js9
21 files changed, 540 insertions, 482 deletions
diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc
index a75fc50..d1e78d1 100644
--- a/chrome/browser/extensions/app_background_page_apitest.cc
+++ b/chrome/browser/extensions/app_background_page_apitest.cc
@@ -18,7 +18,7 @@ class AppBackgroundPageApiTest : public ExtensionApiTest {
IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, Basic) {
host_resolver()->AddRule("a.com", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
LoadExtension(test_data_dir_.AppendASCII(
"app_background_page/app_has_permission"));
@@ -27,7 +27,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, Basic) {
IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, LacksPermission) {
host_resolver()->AddRule("a.com", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
LoadExtension(test_data_dir_.AppendASCII(
"app_background_page/app_lacks_permission"));
diff --git a/chrome/browser/extensions/cross_origin_xhr_apitest.cc b/chrome/browser/extensions/cross_origin_xhr_apitest.cc
index 41474bc..a7f7abb 100644
--- a/chrome/browser/extensions/cross_origin_xhr_apitest.cc
+++ b/chrome/browser/extensions/cross_origin_xhr_apitest.cc
@@ -7,6 +7,6 @@
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHR) {
host_resolver()->AddRule("*.com", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("cross_origin_xhr")) << message_;
}
diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc
index f6c963b..a450fe0 100644
--- a/chrome/browser/extensions/execute_script_apitest.cc
+++ b/chrome/browser/extensions/execute_script_apitest.cc
@@ -12,7 +12,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ExecuteScript) {
host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500);
host_resolver()->AddRule("b.com", "127.0.0.1");
host_resolver()->AddRule("c.com", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("executescript/basic")) << message_;
ASSERT_TRUE(RunExtensionTest("executescript/in_frame")) << message_;
@@ -23,7 +23,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ExecuteScript) {
// (ExecuteScript) tests are de-flakified, reunite this case with it's brethern.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ExecuteScriptFileAfterClose) {
host_resolver()->AddRule("b.com", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_;
}
diff --git a/chrome/browser/extensions/extension_incognito_apitest.cc b/chrome/browser/extensions/extension_incognito_apitest.cc
index 43f8a38..372b7a6 100644
--- a/chrome/browser/extensions/extension_incognito_apitest.cc
+++ b/chrome/browser/extensions/extension_incognito_apitest.cc
@@ -17,13 +17,13 @@
#include "chrome/test/ui_test_utils.h"
#include "net/base/mock_host_resolver.h"
-IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) {
- ASSERT_TRUE(test_server()->Start());
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) {
+ ASSERT_TRUE(StartTestServer());
// Loads a simple extension which attempts to change the title of every page
// that loads to "modified".
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
- .AppendASCII("incognito").AppendASCII("content_scripts")));
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito")
+ .AppendASCII("content_scripts")));
// Open incognito window and navigate to test page.
ui_test_utils::OpenURLOffTheRecord(
@@ -44,23 +44,23 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoNoScript) {
EXPECT_TRUE(result);
}
-IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoYesScript) {
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoYesScript) {
host_resolver()->AddRule("*", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
// Load a dummy extension. This just tests that we don't regress a
// crash fix when multiple incognito- and non-incognito-enabled extensions
// are mixed.
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
- .AppendASCII("content_scripts").AppendASCII("all_frames")));
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts")
+ .AppendASCII("all_frames")));
// Loads a simple extension which attempts to change the title of every page
// that loads to "modified".
- ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test")
+ ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
.AppendASCII("incognito").AppendASCII("content_scripts")));
// Dummy extension #2.
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
+ ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("content_scripts").AppendASCII("isolated_world1")));
// Open incognito window and navigate to test page.
@@ -94,7 +94,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DontCreateIncognitoProfile) {
// Tests that the APIs in an incognito-enabled extension work properly.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) {
host_resolver()->AddRule("*", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ResultCatcher catcher;
@@ -120,7 +120,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) {
// properly.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoSplitMode) {
host_resolver()->AddRule("*", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
// We need 2 ResultCatchers because we'll be running the same test in both
// regular and incognito mode.
@@ -154,7 +154,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoSplitMode) {
// events or callbacks.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) {
host_resolver()->AddRule("*", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ResultCatcher catcher;
@@ -172,7 +172,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) {
// Test that opening a popup from an incognito browser window works properly.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoPopup) {
host_resolver()->AddRule("*", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ResultCatcher catcher;
diff --git a/chrome/browser/extensions/extension_javascript_url_apitest.cc b/chrome/browser/extensions/extension_javascript_url_apitest.cc
index 2b6cf59..7b7e06e 100644
--- a/chrome/browser/extensions/extension_javascript_url_apitest.cc
+++ b/chrome/browser/extensions/extension_javascript_url_apitest.cc
@@ -8,7 +8,7 @@
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, JavaScriptURLPermissions) {
host_resolver()->AddRule("a.com", "127.0.0.1");
host_resolver()->AddRule("b.com", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("tabs/javascript_url_permissions")) << message_;
}
diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc
index b76a944..760a627 100644
--- a/chrome/browser/extensions/extension_messages_apitest.cc
+++ b/chrome/browser/extensions/extension_messages_apitest.cc
@@ -51,7 +51,7 @@ class MessageSender : public NotificationObserver {
// Tests that message passing between extensions and content scripts works.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Messaging) {
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("messaging/connect")) << message_;
}
diff --git a/chrome/browser/extensions/fragment_navigation_apitest.cc b/chrome/browser/extensions/fragment_navigation_apitest.cc
index aa7bc46..68ca622 100644
--- a/chrome/browser/extensions/fragment_navigation_apitest.cc
+++ b/chrome/browser/extensions/fragment_navigation_apitest.cc
@@ -6,13 +6,13 @@
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) {
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
const char* extension_name = "content_scripts/fragment";
ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ExecuteScriptFragmentNavigation) {
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
const char* extension_name = "executescript/fragment";
ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
}
diff --git a/chrome/browser/extensions/isolated_world_apitest.cc b/chrome/browser/extensions/isolated_world_apitest.cc
index 4b0761d..6a71b5b 100644
--- a/chrome/browser/extensions/isolated_world_apitest.cc
+++ b/chrome/browser/extensions/isolated_world_apitest.cc
@@ -7,7 +7,7 @@
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IsolatedWorld1) {
// This extension runs various bits of script and tests that they all run in
// the same isolated world.
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_;
// Now load a different extension, inject into same page, verify worlds aren't
diff --git a/chrome/browser/extensions/window_open_apitest.cc b/chrome/browser/extensions/window_open_apitest.cc
index 8ff06d7..6853f65 100644
--- a/chrome/browser/extensions/window_open_apitest.cc
+++ b/chrome/browser/extensions/window_open_apitest.cc
@@ -51,7 +51,7 @@ void WaitForTabsAndPopups(Browser* browser, int num_tabs, int num_popups) {
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) {
host_resolver()->AddRule("*", "127.0.0.1");
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
diff --git a/chrome/test/automation/dom_automation_browsertest.cc b/chrome/test/automation/dom_automation_browsertest.cc
index 48192c4..502797d 100644
--- a/chrome/test/automation/dom_automation_browsertest.cc
+++ b/chrome/test/automation/dom_automation_browsertest.cc
@@ -23,9 +23,9 @@ class DOMAutomationTest : public InProcessBrowserTest {
}
GURL GetTestURL(const char* path) {
- std::string url("http://localhost:1337/files/dom_automation/");
- url.append(path);
- return GURL(url);
+ std::string url_path = "files/dom_automation/";
+ url_path.append(path);
+ return test_server()->GetURL(url_path);
}
};
diff --git a/chrome/test/data/extensions/api_test/app_background_page/basic/test.html b/chrome/test/data/extensions/api_test/app_background_page/basic/test.html
index 2311b31..209dd54 100644
--- a/chrome/test/data/extensions/api_test/app_background_page/basic/test.html
+++ b/chrome/test/data/extensions/api_test/app_background_page/basic/test.html
@@ -13,7 +13,7 @@ var pageB;
var backgroundPageResponded = false;
var pagePrefix =
- 'http://a.com:1337/files/extensions/api_test/app_background_page/common';
+ 'http://a.com:PORT/files/extensions/api_test/app_background_page/common';
// Dispatch "tunneled" functions from the live web pages to this testing page.
chrome.extension.onRequest.addListener(function(request) {
@@ -30,16 +30,27 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// Start the test by opening the first page in the app.
window.onload = function() {
- chrome.tabs.create({ 'url': pagePrefix + '/a.html' }, function(tab) {
- pageA = tab;
+ // We wait for window.onload before getting the test config. If the
+ // config is requested before onload, then sometimes onload has already
+ // fired by the time chrome.test.getConfig()'s callback runs.
+ chrome.test.getConfig(function(config) {
+ var a_url =
+ pagePrefix.replace(/PORT/, config.testServer.port) + '/a.html';
+ chrome.tabs.create({ 'url': a_url }, function(tab) {
+ pageA = tab;
+ });
});
}
// Background page opened by pageA.
function onBackgroundPageLoaded() {
chrome.tabs.remove(pageA.id, function() {
- chrome.tabs.create({ url: pagePrefix + '/b.html' }, function(tab) {
- pageB = tab;
+ chrome.test.getConfig(function(config) {
+ var b_url =
+ pagePrefix.replace(/PORT/, config.testServer.port) + '/b.html';
+ chrome.tabs.create({ url: b_url }, function(tab) {
+ pageB = tab;
+ });
});
});
}
@@ -64,4 +75,4 @@ function onCounterError() {
chrome.test.notifyFail("checkCounter found an unexpected value");
}
-</script> \ No newline at end of file
+</script>
diff --git a/chrome/test/data/extensions/api_test/content_scripts/isolated_world1/background.html b/chrome/test/data/extensions/api_test/content_scripts/isolated_world1/background.html
index ff563d48..6c96c25 100644
--- a/chrome/test/data/extensions/api_test/content_scripts/isolated_world1/background.html
+++ b/chrome/test/data/extensions/api_test/content_scripts/isolated_world1/background.html
@@ -16,8 +16,12 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
}
});
-chrome.test.log("Creating tab...");
-chrome.tabs.create({
- url: "http://localhost:1337/files/extensions/test_file.html"
+chrome.test.getConfig(function(config) {
+ chrome.test.log("Creating tab...");
+ chrome.tabs.create({
+ url: "http://localhost:PORT/files/extensions/test_file.html"
+ .replace(/PORT/, config.testServer.port)
+ });
});
+
</script>
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html b/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html
index 52a8a33..9efd231 100644
--- a/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html
@@ -1,54 +1,59 @@
<script>
-function doReq(domain, expectSuccess) {
- var req = new XMLHttpRequest();
- var url = domain + ":1337/files/extensions/test_file.txt";
-
- chrome.test.log("Requesting url: " + url);
- req.open("GET", url, true);
+chrome.test.getConfig(function(config) {
+ function doReq(domain, expectSuccess) {
+ var req = new XMLHttpRequest();
+ var url = domain + ":PORT/files/extensions/test_file.txt";
+ url = url.replace(/PORT/, config.testServer.port);
- if (expectSuccess) {
- req.onload = function() {
- chrome.test.assertEq(200, req.status);
- chrome.test.assertEq("Hello!", req.responseText);
- chrome.test.runNextTest();
- }
- req.onerror = function() {
- chrome.test.log("status: " + req.status);
- chrome.test.log("text: " + req.responseText);
- chrome.test.fail("Unexpected error for domain: " + domain);
- }
- } else {
- req.onload = function() {
- chrome.test.fail("Unexpected success for domain: " + domain);
- }
- req.onerror = function() {
- chrome.test.assertEq(0, req.status);
- chrome.test.runNextTest();
+ chrome.test.log("Requesting url: " + url);
+ req.open("GET", url, true);
+
+
+ if (expectSuccess) {
+ req.onload = function() {
+ chrome.test.assertEq(200, req.status);
+ chrome.test.assertEq("Hello!", req.responseText);
+ chrome.test.runNextTest();
+ }
+ req.onerror = function() {
+ chrome.test.log("status: " + req.status);
+ chrome.test.log("text: " + req.responseText);
+ chrome.test.fail("Unexpected error for domain: " + domain);
+ }
+ } else {
+ req.onload = function() {
+ chrome.test.fail("Unexpected success for domain: " + domain);
+ }
+ req.onerror = function() {
+ chrome.test.assertEq(0, req.status);
+ chrome.test.runNextTest();
+ }
}
+
+ req.send(null);
}
- req.send(null);
-}
+ chrome.test.runTests([
+ function allowedOrigin() {
+ doReq("http://a.com", true);
+ },
+ function diallowedOrigin() {
+ doReq("http://c.com", false);
+ },
+ function allowedSubdomain() {
+ doReq("http://foo.b.com", true);
+ },
+ function noSubdomain() {
+ doReq("http://b.com", true);
+ },
+ function disallowedSubdomain() {
+ doReq("http://foob.com", false);
+ },
+ function disallowedSSL() {
+ doReq("https://a.com", false);
+ }
+ ]);
+});
-chrome.test.runTests([
- function allowedOrigin() {
- doReq("http://a.com", true);
- },
- function diallowedOrigin() {
- doReq("http://c.com", false);
- },
- function allowedSubdomain() {
- doReq("http://foo.b.com", true);
- },
- function noSubdomain() {
- doReq("http://b.com", true);
- },
- function disallowedSubdomain() {
- doReq("http://foob.com", false);
- },
- function disallowedSSL() {
- doReq("https://a.com", false);
- }
-]);
</script>
diff --git a/chrome/test/data/extensions/api_test/executescript/basic/test.html b/chrome/test/data/extensions/api_test/executescript/basic/test.html
index b0e16a3..a5a2f66 100644
--- a/chrome/test/data/extensions/api_test/executescript/basic/test.html
+++ b/chrome/test/data/extensions/api_test/executescript/basic/test.html
@@ -6,96 +6,101 @@ var assertEq = chrome.test.assertEq;
var assertTrue = chrome.test.assertTrue;
var relativePath =
'/files/extensions/api_test/executescript/basic/test_executescript.html';
-var testUrl = 'http://a.com:1337' + relativePath;
-var testFailureUrl = 'http://b.com:1337' + relativePath;
+var testUrl = 'http://a.com:PORT' + relativePath;
+var testFailureUrl = 'http://b.com:PORT' + relativePath;
var firstEnter = true;
-chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
- if (changeInfo.status != 'complete')
- return;
- if (!firstEnter) {
- return;
- }
- firstEnter = false;
+chrome.test.getConfig(function(config) {
+ testUrl = testUrl.replace(/PORT/, config.testServer.port);
+ testFailureUrl = testFailureUrl.replace(/PORT/, config.testServer.port);
- chrome.test.runTests([
-
- function executeJavaScriptCodeShouldSucceed() {
- var script_file = {};
- script_file.code = "document.title = 'executeScript';";
- chrome.tabs.executeScript(tabId, script_file, function() {
- chrome.tabs.get(tabId, pass(function(tab) {
- assertEq(tab.title, 'executeScript');
- }));
- });
- },
+ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
+ if (changeInfo.status != 'complete')
+ return;
+ if (!firstEnter) {
+ return;
+ }
+ firstEnter = false;
- function executeJavaScriptFileShouldSucceed() {
- var script_file = {};
- script_file.file = 'script1.js';
- chrome.tabs.executeScript(tabId, script_file, function() {
- chrome.tabs.get(tabId, pass(function(tab) {
- assertEq(tab.title, 'executeScript1');
- }));
- });
- },
+ chrome.test.runTests([
- function insertCSSTextShouldSucceed() {
- var css_file = {};
- css_file.code = "p {display:none;}";
- chrome.tabs.insertCSS(tabId, css_file, function() {
+ function executeJavaScriptCodeShouldSucceed() {
var script_file = {};
- script_file.file = 'script3.js';
+ script_file.code = "document.title = 'executeScript';";
chrome.tabs.executeScript(tabId, script_file, function() {
chrome.tabs.get(tabId, pass(function(tab) {
- assertEq(tab.title, 'none');
+ assertEq(tab.title, 'executeScript');
}));
});
- });
- },
+ },
- function insertCSSFileShouldSucceed() {
- var css_file = {};
- css_file.file = '1.css';
- chrome.tabs.insertCSS(tabId, css_file, function() {
+ function executeJavaScriptFileShouldSucceed() {
var script_file = {};
- script_file.file = 'script2.js';
+ script_file.file = 'script1.js';
chrome.tabs.executeScript(tabId, script_file, function() {
chrome.tabs.get(tabId, pass(function(tab) {
- assertEq(tab.title, 'block');
+ assertEq(tab.title, 'executeScript1');
}));
});
- });
- },
+ },
+
+ function insertCSSTextShouldSucceed() {
+ var css_file = {};
+ css_file.code = "p {display:none;}";
+ chrome.tabs.insertCSS(tabId, css_file, function() {
+ var script_file = {};
+ script_file.file = 'script3.js';
+ chrome.tabs.executeScript(tabId, script_file, function() {
+ chrome.tabs.get(tabId, pass(function(tab) {
+ assertEq(tab.title, 'none');
+ }));
+ });
+ });
+ },
+
+ function insertCSSFileShouldSucceed() {
+ var css_file = {};
+ css_file.file = '1.css';
+ chrome.tabs.insertCSS(tabId, css_file, function() {
+ var script_file = {};
+ script_file.file = 'script2.js';
+ chrome.tabs.executeScript(tabId, script_file, function() {
+ chrome.tabs.get(tabId, pass(function(tab) {
+ assertEq(tab.title, 'block');
+ }));
+ });
+ });
+ },
- function executeJavaScriptCodeShouldFail() {
- chrome.tabs.update(tabId, { url: testFailureUrl }, function() {
+ function executeJavaScriptCodeShouldFail() {
+ chrome.tabs.update(tabId, { url: testFailureUrl }, function() {
+ var script_file = {};
+ script_file.code = "document.title = 'executeScript';";
+ chrome.tabs.executeScript(tabId, script_file, fail(
+ 'Cannot access contents of url "' + testFailureUrl +
+ '". Extension manifest must request permission to access this ' +
+ 'host.'));
+ });
+ },
+
+ function executeJavaScriptWithNoneValueShouldFail() {
var script_file = {};
- script_file.code = "document.title = 'executeScript';";
chrome.tabs.executeScript(tabId, script_file, fail(
- 'Cannot access contents of url "' + testFailureUrl +
- '". Extension manifest must request permission to access this ' +
- 'host.'));
- });
- },
+ 'No source code or file specified.'));
+ },
- function executeJavaScriptWithNoneValueShouldFail() {
- var script_file = {};
- chrome.tabs.executeScript(tabId, script_file, fail(
- 'No source code or file specified.'));
- },
+ function executeJavaScriptWithTwoValuesShouldFail() {
+ var script_file = {};
+ script_file.file = 'script1.js';
+ script_file.code = 'var test = 1;';
+ chrome.tabs.executeScript(tabId, script_file, fail(
+ 'Code and file should not be specified ' +
+ 'at the same time in the second argument.'));
+ }
+ ]);
+ });
- function executeJavaScriptWithTwoValuesShouldFail() {
- var script_file = {};
- script_file.file = 'script1.js';
- script_file.code = 'var test = 1;';
- chrome.tabs.executeScript(tabId, script_file, fail(
- 'Code and file should not be specified ' +
- 'at the same time in the second argument.'));
- }
- ]);
+ chrome.tabs.create({ url: testUrl });
});
-chrome.tabs.create({ url: testUrl });
-
</script>
diff --git a/chrome/test/data/extensions/api_test/executescript/fragment/background.html b/chrome/test/data/extensions/api_test/executescript/fragment/background.html
index 673a56f..d55686d 100644
--- a/chrome/test/data/extensions/api_test/executescript/fragment/background.html
+++ b/chrome/test/data/extensions/api_test/executescript/fragment/background.html
@@ -1,13 +1,13 @@
<script>
var got_request = false;
-var test_url = "http://localhost:1337/files/extensions/test_file.html";
+var test_url = "http://localhost:PORT/files/extensions/test_file.html";
-// For running in normal chrome (ie outside of the browser_tests environment),
-// set debug to 1 here.
+// For running in normal chrome (ie outside of the browser_tests environment),
+// set debug to 1 here.
var debug = 0;
if (debug) {
- test_url = "http://www.google.com";
+ test_url = "http://www.google.com/";
chrome.test.log = function(msg) { console.log(msg) };
chrome.test.runTests = function(tests) {
for (var i in tests) {
@@ -35,25 +35,35 @@ function do_execute(tab) {
}, 10000);
}
+function runTests() {
+ chrome.test.runTests([
+ // When the tab is created, a content script will send a request letting
+ // know the onload has fired. Then we navigate to a fragment, and try
+ // running chrome.tabs.executeScript.
+ function test1() {
+ chrome.extension.onRequest.addListener(function(req, sender) {
+ chrome.test.log("got request: " + JSON.stringify(req));
+ if (req == "content_script") {
+ navigate_to_fragment(sender.tab, do_execute);
+ } else if (req == "execute_script") {
+ suceeded = true;
+ chrome.test.succeed();
+ }
+ });
+ chrome.test.log("creating tab");
+ chrome.tabs.create({"url": test_url});
+ }
+ ]);
+}
-chrome.test.runTests([
- // When the tab is created, a content script will send a request letting
- // know the onload has fired. Then we navigate to a fragment, and try
- // running chrome.tabs.executeScript.
- function test1() {
- chrome.extension.onRequest.addListener(function(req, sender) {
- chrome.test.log("got request: " + JSON.stringify(req));
- if (req == "content_script") {
- navigate_to_fragment(sender.tab, do_execute);
- } else if (req == "execute_script") {
- suceeded = true;
- chrome.test.succeed();
- }
- });
- chrome.test.log("creating tab");
- chrome.tabs.create({"url": test_url});
- }
-]);
-
+if (debug) {
+ // No port to fix. Run tests directly.
+ runTests();
+} else {
+ chrome.test.getConfig(function(config) {
+ test_url = test_url.replace(/PORT/, config.testServer.port);
+ runTests();
+ });
+}
</script>
diff --git a/chrome/test/data/extensions/api_test/incognito/apis/background.html b/chrome/test/data/extensions/api_test/incognito/apis/background.html
index 34d2f25..f57523f 100644
--- a/chrome/test/data/extensions/api_test/incognito/apis/background.html
+++ b/chrome/test/data/extensions/api_test/incognito/apis/background.html
@@ -6,105 +6,109 @@ var pass = chrome.test.callbackPass;
var assertEq = chrome.test.assertEq;
var assertTrue = chrome.test.assertTrue;
-chrome.test.runTests([
- function setupWindows() {
- // The test harness should have set us up with 2 windows: 1 incognito
- // and 1 regular. Verify that we can see both when we ask for it.
- chrome.windows.getAll({populate: true}, pass(function(windows) {
- assertEq(2, windows.length);
+chrome.test.getConfig(function(config) {
+ chrome.test.runTests([
+ function setupWindows() {
+ // The test harness should have set us up with 2 windows: 1 incognito
+ // and 1 regular. Verify that we can see both when we ask for it.
+ chrome.windows.getAll({populate: true}, pass(function(windows) {
+ assertEq(2, windows.length);
- if (windows[0].incognito) {
- incognitoWindow = windows[0];
- normalWindow = windows[1];
- } else {
- normalWindow = windows[0];
- incognitoWindow = windows[1];
- }
- normalTab = normalWindow.tabs[0];
- incognitoTab = incognitoWindow.tabs[0];
- assertTrue(!normalWindow.incognito);
- assertTrue(incognitoWindow.incognito);
- }));
- },
+ if (windows[0].incognito) {
+ incognitoWindow = windows[0];
+ normalWindow = windows[1];
+ } else {
+ normalWindow = windows[0];
+ incognitoWindow = windows[1];
+ }
+ normalTab = normalWindow.tabs[0];
+ incognitoTab = incognitoWindow.tabs[0];
+ assertTrue(!normalWindow.incognito);
+ assertTrue(incognitoWindow.incognito);
+ }));
+ },
- // Tests that we can update an incognito tab and get the event for it.
- function tabUpdate() {
- var newUrl = "about:blank";
+ // Tests that we can update an incognito tab and get the event for it.
+ function tabUpdate() {
+ var newUrl = "about:blank";
- // Prepare the event listeners first.
- var done = chrome.test.listenForever(chrome.tabs.onUpdated,
- function(id, info, tab) {
- if (id == incognitoTab.id) {
- assertTrue(tab.incognito);
- assertEq(newUrl, tab.url);
- if (info.status == "complete")
- done();
- }
- });
+ // Prepare the event listeners first.
+ var done = chrome.test.listenForever(chrome.tabs.onUpdated,
+ function(id, info, tab) {
+ if (id == incognitoTab.id) {
+ assertTrue(tab.incognito);
+ assertEq(newUrl, tab.url);
+ if (info.status == "complete")
+ done();
+ }
+ });
- // Update our tabs.
- chrome.tabs.update(incognitoTab.id, {"url": newUrl}, pass());
- },
+ // Update our tabs.
+ chrome.tabs.update(incognitoTab.id, {"url": newUrl}, pass());
+ },
- // Tests a sequence of tab API calls.
- function tabNested() {
- // Setup our listeners. We check that the events fire in order.
- var eventCounter = 0;
- chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
- assertEq(1, ++eventCounter);
- assertEq(incognitoTab.windowId, tab.windowId);
- assertTrue(tab.incognito);
- });
- chrome.test.listenOnce(chrome.tabs.onMoved, function(tabId) {
- assertEq(2, ++eventCounter);
- });
- chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabId) {
- assertEq(3, ++eventCounter);
- });
+ // Tests a sequence of tab API calls.
+ function tabNested() {
+ // Setup our listeners. We check that the events fire in order.
+ var eventCounter = 0;
+ chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
+ assertEq(1, ++eventCounter);
+ assertEq(incognitoTab.windowId, tab.windowId);
+ assertTrue(tab.incognito);
+ });
+ chrome.test.listenOnce(chrome.tabs.onMoved, function(tabId) {
+ assertEq(2, ++eventCounter);
+ });
+ chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabId) {
+ assertEq(3, ++eventCounter);
+ });
- // Create, select, move, and close a tab in our incognito window.
- chrome.tabs.create({windowId: incognitoTab.windowId},
- pass(function(tab) {
- chrome.tabs.move(tab.id, {index: 0},
- pass(function(tab) {
- assertEq(incognitoTab.incognito, tab.incognito);
- chrome.tabs.remove(tab.id, pass());
- }));
- }));
- },
+ // Create, select, move, and close a tab in our incognito window.
+ chrome.tabs.create({windowId: incognitoTab.windowId},
+ pass(function(tab) {
+ chrome.tabs.move(tab.id, {index: 0},
+ pass(function(tab) {
+ assertEq(incognitoTab.incognito, tab.incognito);
+ chrome.tabs.remove(tab.id, pass());
+ }));
+ }));
+ },
- // Tests content script injection to verify that the script can tell its
- // in incongnito.
- function contentScriptTestIncognito() {
- assertTrue(!chrome.extension.inIncognitoContext);
+ // Tests content script injection to verify that the script can tell its
+ // in incongnito.
+ function contentScriptTestIncognito() {
+ assertTrue(!chrome.extension.inIncognitoContext);
- var testUrl = "http://localhost:1337/files/extensions/test_file.html";
+ var testUrl = "http://localhost:PORT/files/extensions/test_file.html"
+ .replace(/PORT/, config.testServer.port);
- // Test that chrome.extension.inIncognitoTab is true for incognito tabs.
- chrome.tabs.create({windowId: incognitoWindow.id, url: testUrl},
- pass(function(tab) {
- chrome.tabs.executeScript(tab.id,
- {code: 'document.title = chrome.extension.inIncognitoContext'},
- pass(function() {
- assertEq(undefined, chrome.extension.lastError);
- chrome.tabs.get(tab.id, pass(function(tab) {
- assertEq("true", tab.title);
- }));
- }));
- }));
+ // Test that chrome.extension.inIncognitoTab is true for incognito tabs.
+ chrome.tabs.create({windowId: incognitoWindow.id, url: testUrl},
+ pass(function(tab) {
+ chrome.tabs.executeScript(tab.id,
+ {code: 'document.title = chrome.extension.inIncognitoContext'},
+ pass(function() {
+ assertEq(undefined, chrome.extension.lastError);
+ chrome.tabs.get(tab.id, pass(function(tab) {
+ assertEq("true", tab.title);
+ }));
+ }));
+ }));
+
+ // ... and false for normal tabs.
+ chrome.tabs.create({windowId: normalWindow.id, url: testUrl},
+ pass(function(tab) {
+ chrome.tabs.executeScript(tab.id,
+ {code: 'document.title = chrome.extension.inIncognitoContext'},
+ pass(function() {
+ assertEq(undefined, chrome.extension.lastError);
+ chrome.tabs.get(tab.id, pass(function(tab) {
+ assertEq("false", tab.title);
+ }));
+ }));
+ }));
+ }
+ ]);
+});
- // ... and false for normal tabs.
- chrome.tabs.create({windowId: normalWindow.id, url: testUrl},
- pass(function(tab) {
- chrome.tabs.executeScript(tab.id,
- {code: 'document.title = chrome.extension.inIncognitoContext'},
- pass(function() {
- assertEq(undefined, chrome.extension.lastError);
- chrome.tabs.get(tab.id, pass(function(tab) {
- assertEq("false", tab.title);
- }));
- }));
- }));
- }
-]);
</script>
diff --git a/chrome/test/data/extensions/api_test/incognito/split/background.html b/chrome/test/data/extensions/api_test/incognito/split/background.html
index 50ebea6..cd5811c 100644
--- a/chrome/test/data/extensions/api_test/incognito/split/background.html
+++ b/chrome/test/data/extensions/api_test/incognito/split/background.html
@@ -49,92 +49,97 @@ chrome.extension.onRequest.addListener(
}
});
-chrome.test.runTests([
- function setupWindows() {
- // The test harness should have set us up with 2 windows: 1 incognito
- // and 1 regular. Since we are in split mode, we should only see the
- // window for our profile.
- chrome.windows.getAll({populate: true}, pass(function(windows) {
- assertEq(1, windows.length);
+chrome.test.getConfig(function(config) {
+ chrome.test.runTests([
+ function setupWindows() {
+ // The test harness should have set us up with 2 windows: 1 incognito
+ // and 1 regular. Since we are in split mode, we should only see the
+ // window for our profile.
+ chrome.windows.getAll({populate: true}, pass(function(windows) {
+ assertEq(1, windows.length);
- win = windows[0];
- tab = win.tabs[0];
- assertEq(inIncognitoContext, win.incognito);
- }));
- },
-
- // Tests that we can update an incognito tab and get the event for it.
- function tabUpdate() {
- var newUrl = "about:blank";
+ win = windows[0];
+ tab = win.tabs[0];
+ assertEq(inIncognitoContext, win.incognito);
+ }));
+ },
- // Prepare the event listeners first.
- var done = chrome.test.listenForever(chrome.tabs.onUpdated,
- function(id, info, tab) {
- assertEq(tab.id, id);
- assertEq(inIncognitoContext, tab.incognito);
- assertEq(newUrl, tab.url);
- if (info.status == "complete")
- done();
- });
+ // Tests that we can update an incognito tab and get the event for it.
+ function tabUpdate() {
+ var newUrl = "about:blank";
- // Update our tab.
- chrome.tabs.update(tab.id, {"url": newUrl}, pass());
- },
+ // Prepare the event listeners first.
+ var done = chrome.test.listenForever(chrome.tabs.onUpdated,
+ function(id, info, tab) {
+ assertEq(tab.id, id);
+ assertEq(inIncognitoContext, tab.incognito);
+ assertEq(newUrl, tab.url);
+ if (info.status == "complete")
+ done();
+ });
- // Tests content script injection to verify that the script can tell its
- // in incongnito.
- function contentScriptTestIncognito() {
- var testUrl = "http://localhost:1337/files/extensions/test_file.html";
+ // Update our tab.
+ chrome.tabs.update(tab.id, {"url": newUrl}, pass());
+ },
- // Test that chrome.extension.inIncognitoContext is true for incognito
- // tabs.
- chrome.tabs.create({windowId: win.id, url: testUrl},
- pass(function(tab) {
- chrome.tabs.executeScript(tab.id,
- {code: 'chrome.extension.sendRequest({' +
- ' inIncognitoContext: chrome.extension.inIncognitoContext' +
- '});'},
- pass(function() {
- assertEq(undefined, chrome.extension.lastError);
- }));
- }));
+ // Tests content script injection to verify that the script can tell its
+ // in incongnito.
+ function contentScriptTestIncognito() {
+ var testUrl = "http://localhost:PORT/files/extensions/test_file.html"
+ .replace(/PORT/, config.testServer.port);
- var done = chrome.test.listenForever(chrome.extension.onRequest,
- function(request, sender, sendResponse) {
- assertEq(inIncognitoContext, request.inIncognitoContext);
- sendResponse();
- done();
- });
- },
+ // Test that chrome.extension.inIncognitoContext is true for incognito
+ // tabs.
+ chrome.tabs.create({windowId: win.id, url: testUrl},
+ pass(function(tab) {
+ chrome.tabs.executeScript(tab.id,
+ {code: 'chrome.extension.sendRequest({' +
+ ' inIncognitoContext: chrome.extension.inIncognitoContext' +
+ '});'},
+ pass(function() {
+ assertEq(undefined, chrome.extension.lastError);
+ }));
+ }));
- // Tests that we can receive bookmarks events in both extension processes.
- function bookmarkCreate() {
- // Each process will create 1 bookmark, but expects to see updates from the
- // other process.
- var nodeNormal = {parentId:"1", title:"normal", url:"http://google.com/"};
- var nodeIncog = {parentId:"1", title:"incog", url:"http://google.com/"};
- var node = inIncognitoContext ? nodeIncog : nodeNormal;
- var count = 0;
- var done = chrome.test.listenForever(chrome.bookmarks.onCreated,
- function(id, created) {
- node = (created.title == nodeNormal.title) ? nodeNormal : nodeIncog;
- node.id = created.id;
- node.index = created.index;
- chrome.test.assertEq(id, node.id);
- chrome.test.assertTrue(compareNode(node, created));
- if (++count == 2) {
- chrome.test.log("Bookmarks created. Incognito=" + inIncognitoContext);
+ var done = chrome.test.listenForever(chrome.extension.onRequest,
+ function(request, sender, sendResponse) {
+ assertEq(inIncognitoContext, request.inIncognitoContext);
+ sendResponse();
done();
- }
- });
- chrome.test.sendMessage("waiting", pass(function() {
- chrome.bookmarks.create(node, pass(function(results) {
- node.id = results.id; // since we couldn't know this going in
- node.index = results.index;
- chrome.test.assertTrue(compareNode(node, results),
- "created node != source");
+ });
+ },
+
+ // Tests that we can receive bookmarks events in both extension processes.
+ function bookmarkCreate() {
+ // Each process will create 1 bookmark, but expects to see updates from
+ // the other process.
+ var nodeNormal = {parentId:"1", title:"normal", url:"http://google.com/"};
+ var nodeIncog = {parentId:"1", title:"incog", url:"http://google.com/"};
+ var node = inIncognitoContext ? nodeIncog : nodeNormal;
+ var count = 0;
+ var done = chrome.test.listenForever(chrome.bookmarks.onCreated,
+ function(id, created) {
+ node = (created.title == nodeNormal.title) ? nodeNormal : nodeIncog;
+ node.id = created.id;
+ node.index = created.index;
+ chrome.test.assertEq(id, node.id);
+ chrome.test.assertTrue(compareNode(node, created));
+ if (++count == 2) {
+ chrome.test.log("Bookmarks created. Incognito=" +
+ inIncognitoContext);
+ done();
+ }
+ });
+ chrome.test.sendMessage("waiting", pass(function() {
+ chrome.bookmarks.create(node, pass(function(results) {
+ node.id = results.id; // since we couldn't know this going in
+ node.index = results.index;
+ chrome.test.assertTrue(compareNode(node, results),
+ "created node != source");
+ }));
}));
- }));
- }
-]);
+ }
+ ]);
+});
+
</script>
diff --git a/chrome/test/data/extensions/api_test/messaging/connect/test.html b/chrome/test/data/extensions/api_test/messaging/connect/test.html
index 4983a75..9802697 100644
--- a/chrome/test/data/extensions/api_test/messaging/connect/test.html
+++ b/chrome/test/data/extensions/api_test/messaging/connect/test.html
@@ -17,115 +17,118 @@ Object.prototype.toJSON = function() {
// Keep track of the tab that we're running tests in, for simplicity.
var testTab = null;
-
-chrome.test.runTests([
- function setupTestTab() {
- chrome.test.log("Creating tab...");
- chrome.tabs.create({
- url: "http://localhost:1337/files/extensions/test_file.html"
- }, function(tab) {
- chrome.tabs.onUpdated.addListener(function listener(tabid, info) {
- if (tab.id == tabid && info.status == 'complete') {
- chrome.test.log("Created tab: " + tab.url);
- chrome.tabs.onUpdated.removeListener(listener);
- testTab = tab;
- chrome.test.succeed();
- }
- });
- });
- },
- // Tests that postMessage to the tab and its response works.
- function postMessage() {
- var port = chrome.tabs.connect(testTab.id);
- port.postMessage({testPostMessage: true});
- port.onMessage.addListener(function(msg) {
- port.disconnect();
- chrome.test.succeed();
- });
- },
+chrome.test.getConfig(function(config) {
+ chrome.test.runTests([
+ function setupTestTab() {
+ chrome.test.log("Creating tab...");
+ chrome.tabs.create({
+ url: "http://localhost:PORT/files/extensions/test_file.html"
+ .replace(/PORT/, config.testServer.port)
+ }, function(tab) {
+ chrome.tabs.onUpdated.addListener(function listener(tabid, info) {
+ if (tab.id == tabid && info.status == 'complete') {
+ chrome.test.log("Created tab: " + tab.url);
+ chrome.tabs.onUpdated.removeListener(listener);
+ testTab = tab;
+ chrome.test.succeed();
+ }
+ });
+ });
+ },
- // Tests that port name is sent & received correctly.
- function portName() {
- var portName = "lemonjello";
- var port = chrome.tabs.connect(testTab.id, {name: portName});
- port.postMessage({testPortName: true});
- port.onMessage.addListener(function(msg) {
- chrome.test.assertEq(msg.portName, portName);
- port.disconnect();
- chrome.test.succeed();
- });
- },
+ // Tests that postMessage to the tab and its response works.
+ function postMessage() {
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testPostMessage: true});
+ port.onMessage.addListener(function(msg) {
+ port.disconnect();
+ chrome.test.succeed();
+ });
+ },
- // Tests that postMessage from the tab and its response works.
- function postMessageFromTab() {
- chrome.extension.onConnect.addListener(function(port) {
+ // Tests that port name is sent & received correctly.
+ function portName() {
+ var portName = "lemonjello";
+ var port = chrome.tabs.connect(testTab.id, {name: portName});
+ port.postMessage({testPortName: true});
port.onMessage.addListener(function(msg) {
- chrome.test.assertTrue(msg.testPostMessageFromTab);
- port.postMessage({success: true, portName: port.name});
- chrome.test.log("postMessageFromTab: got message from tab");
+ chrome.test.assertEq(msg.portName, portName);
+ port.disconnect();
+ chrome.test.succeed();
});
- });
+ },
- var port = chrome.tabs.connect(testTab.id);
- port.postMessage({testPostMessageFromTab: true});
- chrome.test.log("postMessageFromTab: sent first message to tab");
- port.onMessage.addListener(function(msg) {
- port.disconnect();
- chrome.test.succeed();
- });
- },
+ // Tests that postMessage from the tab and its response works.
+ function postMessageFromTab() {
+ chrome.extension.onConnect.addListener(function(port) {
+ port.onMessage.addListener(function(msg) {
+ chrome.test.assertTrue(msg.testPostMessageFromTab);
+ port.postMessage({success: true, portName: port.name});
+ chrome.test.log("postMessageFromTab: got message from tab");
+ });
+ });
- // Tests receiving a request from a content script and responding.
- function sendRequestFromTab() {
- chrome.extension.onRequest.addListener(
- function(request, sender, sendResponse) {
- chrome.test.assertTrue("url" in sender.tab, "no tab available.");
- chrome.test.assertEq(sender.id, location.host);
- if (request.step == 1) {
- // Step 1: Page should send another request for step 2.
- chrome.test.log("sendRequestFromTab: got step 1");
- sendResponse({nextStep: true});
- } else {
- // Step 2.
- chrome.test.assertEq(request.step, 2);
- sendResponse();
- chrome.test.succeed();
- }
- });
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testPostMessageFromTab: true});
+ chrome.test.log("postMessageFromTab: sent first message to tab");
+ port.onMessage.addListener(function(msg) {
+ port.disconnect();
+ chrome.test.succeed();
+ });
+ },
+
+ // Tests receiving a request from a content script and responding.
+ function sendRequestFromTab() {
+ chrome.extension.onRequest.addListener(
+ function(request, sender, sendResponse) {
+ chrome.test.assertTrue("url" in sender.tab, "no tab available.");
+ chrome.test.assertEq(sender.id, location.host);
+ if (request.step == 1) {
+ // Step 1: Page should send another request for step 2.
+ chrome.test.log("sendRequestFromTab: got step 1");
+ sendResponse({nextStep: true});
+ } else {
+ // Step 2.
+ chrome.test.assertEq(request.step, 2);
+ sendResponse();
+ chrome.test.succeed();
+ }
+ });
- var port = chrome.tabs.connect(testTab.id);
- port.postMessage({testSendRequestFromTab: true});
- port.disconnect();
- chrome.test.log("sendRequestFromTab: sent first message to tab");
- },
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testSendRequestFromTab: true});
+ port.disconnect();
+ chrome.test.log("sendRequestFromTab: sent first message to tab");
+ },
- // Tests sending a request to a tab and receiving a response.
- function sendRequest() {
- chrome.tabs.sendRequest(testTab.id, {step2: 1}, function(response) {
- chrome.test.assertTrue(response.success);
- chrome.test.succeed();
- });
- },
+ // Tests sending a request to a tab and receiving a response.
+ function sendRequest() {
+ chrome.tabs.sendRequest(testTab.id, {step2: 1}, function(response) {
+ chrome.test.assertTrue(response.success);
+ chrome.test.succeed();
+ });
+ },
- // Tests that we get the disconnect event when the tab disconnect.
- function disconnect() {
- var port = chrome.tabs.connect(testTab.id);
- port.postMessage({testDisconnect: true});
- port.onDisconnect.addListener(function() {
- chrome.test.succeed();
- });
- },
+ // Tests that we get the disconnect event when the tab disconnect.
+ function disconnect() {
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testDisconnect: true});
+ port.onDisconnect.addListener(function() {
+ chrome.test.succeed();
+ });
+ },
- // Tests that we get the disconnect event when the tab context closes.
- function disconnectOnClose() {
- var port = chrome.tabs.connect(testTab.id);
- port.postMessage({testDisconnectOnClose: true});
- port.onDisconnect.addListener(function() {
- chrome.test.succeed();
- testTab = null; // the tab is about:blank now.
- });
- },
-]);
+ // Tests that we get the disconnect event when the tab context closes.
+ function disconnectOnClose() {
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testDisconnectOnClose: true});
+ port.onDisconnect.addListener(function() {
+ chrome.test.succeed();
+ testTab = null; // the tab is about:blank now.
+ });
+ },
+ ]);
+});
</script>
diff --git a/chrome/test/data/extensions/api_test/tabs/javascript_url_permissions/test.html b/chrome/test/data/extensions/api_test/tabs/javascript_url_permissions/test.html
index 2295dd2..c4a1816 100644
--- a/chrome/test/data/extensions/api_test/tabs/javascript_url_permissions/test.html
+++ b/chrome/test/data/extensions/api_test/tabs/javascript_url_permissions/test.html
@@ -1,29 +1,34 @@
<script>
-var javaScriptURL = "javascript:void(document.body.bgColor='red')";
-chrome.tabs.create({ url: "http://a.com:1337/files/extensions/test_file.html" },
- function(tab) {
- var firstTabId = tab.id;
+chrome.test.getConfig(function(config) {
+ var javaScriptURL = "javascript:void(document.body.bgColor='red')";
- chrome.tabs.create(
- { url: "http://b.com:1337/files/extensions/test_file.html" },
- function(tab) {
- var secondTabId = tab.id;
+ var fixPort = function(url) {
+ return url.replace(/PORT/, config.testServer.port);
+ };
+ var urlA = fixPort("http://a.com:PORT/files/extensions/test_file.html");
+ var urlB = fixPort("http://b.com:PORT/files/extensions/test_file.html");
- chrome.test.runTests([
- function javaScriptURLShouldFail() {
- chrome.tabs.update(firstTabId, {url: javaScriptURL},
- chrome.test.callbackFail('Cannot access contents of url ' +
- '"http://a.com:1337/files/extensions/test_file.html". ' +
- 'Extension manifest must request permission to access this ' +
- 'host.'));
- },
+ chrome.tabs.create({ url: urlA }, function(tab) {
+ var firstTabId = tab.id;
- function javaScriptURLShouldSucceed() {
- chrome.tabs.update(secondTabId, {url: javaScriptURL},
- chrome.test.callbackPass());
- }
- ]);
+ chrome.tabs.create({ url: urlB }, function(tab) {
+ var secondTabId = tab.id;
+
+ chrome.test.runTests([
+ function javaScriptURLShouldFail() {
+ chrome.tabs.update(firstTabId, {url: javaScriptURL},
+ chrome.test.callbackFail('Cannot access contents of url ' +
+ '"' + urlA + '". Extension manifest must request ' +
+ 'permission to access this host.'));
+ },
+
+ function javaScriptURLShouldSucceed() {
+ chrome.tabs.update(secondTabId, {url: javaScriptURL},
+ chrome.test.callbackPass());
+ }
+ ]);
+ });
});
});
</script>
diff --git a/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/background.html b/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/background.html
index 5b75a5d..80dd10d 100644
--- a/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/background.html
+++ b/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/background.html
@@ -6,18 +6,27 @@ found in the LICENSE file.
<script src="pop.js"></script>
<script>
-var webPageURL =
- "http://b.com:1337/files/extensions/api_test/window_open/popup_blocking/" +
- "extension/foo.html";
-// Open a popup and a tab from the background page.
-pop();
+function buildUrl(host, port) {
+ return ("http://HOST:PORT/files/extensions/api_test/window_open/" +
+ "popup_blocking/extension/foo.html")
+ .replace(/HOST/, host).replace(/PORT/, port);
+}
-// Open a popup and a tab from a tab (tabs don't use ExtensionHost, so it's
-// interesting to test them separately).
-chrome.tabs.create({url: "tab.html", index: 1});
+chrome.test.getConfig(function(config) {
+ var popupURL = buildUrl("a.com", config.testServer.port);
+ var webPageURL = buildUrl("b.com", config.testServer.port);
+
+ // Open a popup and a tab from the background page.
+ pop(popupURL);
+
+ // Open a popup and a tab from a tab (tabs don't use ExtensionHost, so it's
+ // interesting to test them separately).
+ chrome.tabs.create({url: "tab.html", index: 1});
+
+ // Open a tab to a URL that will cause our content script to run. The content
+ // script will open a popup and a tab.
+ chrome.tabs.create({url: webPageURL, index: 2});
+});
-// Open a tab to a URL that will cause our content script to run. The content
-// script will open a popup and a tab.
-chrome.tabs.create({url: webPageURL, index: 2});
</script>
diff --git a/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/pop.js b/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/pop.js
index 9244005..4f4a293 100644
--- a/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/pop.js
+++ b/chrome/test/data/extensions/api_test/window_open/popup_blocking/extension/pop.js
@@ -1,8 +1,5 @@
-var popupURL =
- "http://a.com:1337/files/extensions/api_test/window_open/popup_blocking/" +
- "extension/foo.html";
-function pop() {
- window.open(popupURL);
- window.open(popupURL, "", "width=300,height=300");
+function pop(popupUrl) {
+ window.open(popupUrl);
+ window.open(popupUrl, "", "width=300,height=300");
}