summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-22 17:12:15 +0000
committerskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-22 17:12:15 +0000
commit2a9662e31f18f77b856487b7266c70ccede557e0 (patch)
tree06d2f0438ae92b113061c26584276de4b4f22ab1
parent4d84f3ac1f433b2afc0a4de13f69e36e6bc2d429 (diff)
downloadchromium_src-2a9662e31f18f77b856487b7266c70ccede557e0.zip
chromium_src-2a9662e31f18f77b856487b7266c70ccede557e0.tar.gz
chromium_src-2a9662e31f18f77b856487b7266c70ccede557e0.tar.bz2
Fix more extension api tests to not hard-code port 1337.
BUG=53632 TEST=ExtensionApiTest.(ExecuteScript|ContentScriptFragmentNavigation|ExecuteScriptFragmentNavigation|ContentScriptExtensionIframe|ContentScriptAllFrames|ContentScriptExtensionProcess) Review URL: http://codereview.chromium.org/4066001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63525 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/content_script_all_frames_apitest.cc4
-rw-r--r--chrome/browser/extensions/content_script_extension_process_apitest.cc5
-rw-r--r--chrome/test/data/extensions/api_test/content_scripts/all_frames/test.html12
-rw-r--r--chrome/test/data/extensions/api_test/content_scripts/extension_iframe/test.html11
-rw-r--r--chrome/test/data/extensions/api_test/content_scripts/extension_process/background.html17
-rw-r--r--chrome/test/data/extensions/api_test/content_scripts/fragment/background.html70
-rw-r--r--chrome/test/data/extensions/api_test/executescript/file_after_close/test.html11
-rw-r--r--chrome/test/data/extensions/api_test/executescript/in_frame/test.html7
-rw-r--r--chrome/test/data/extensions/api_test/executescript/permissions/frames.html21
-rw-r--r--chrome/test/data/extensions/api_test/executescript/permissions/test.html83
10 files changed, 153 insertions, 88 deletions
diff --git a/chrome/browser/extensions/content_script_all_frames_apitest.cc b/chrome/browser/extensions/content_script_all_frames_apitest.cc
index fac6362..b465c42 100644
--- a/chrome/browser/extensions/content_script_all_frames_apitest.cc
+++ b/chrome/browser/extensions/content_script_all_frames_apitest.cc
@@ -5,11 +5,11 @@
#include "chrome/browser/extensions/extension_apitest.h"
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) {
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) {
- ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_;
}
diff --git a/chrome/browser/extensions/content_script_extension_process_apitest.cc b/chrome/browser/extensions/content_script_extension_process_apitest.cc
index 46729d2..64574a0 100644
--- a/chrome/browser/extensions/content_script_extension_process_apitest.cc
+++ b/chrome/browser/extensions/content_script_extension_process_apitest.cc
@@ -10,6 +10,7 @@
#include "chrome/test/ui_test_utils.h"
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) {
- ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(RunExtensionTest("content_scripts/extension_process")) << message_;
+ ASSERT_TRUE(StartTestServer());
+ ASSERT_TRUE(
+ RunExtensionTest("content_scripts/extension_process")) << message_;
}
diff --git a/chrome/test/data/extensions/api_test/content_scripts/all_frames/test.html b/chrome/test/data/extensions/api_test/content_scripts/all_frames/test.html
index e8f8088..ad02a1c 100644
--- a/chrome/test/data/extensions/api_test/content_scripts/all_frames/test.html
+++ b/chrome/test/data/extensions/api_test/content_scripts/all_frames/test.html
@@ -27,8 +27,14 @@ chrome.test.runTests([
}
]);
-chrome.test.log("Creating tab...");
-chrome.tabs.create({
- url: "http://localhost:1337/files/extensions/test_file_with_iframe.html"
+chrome.test.getConfig(function(config) {
+ chrome.test.log("Creating tab...");
+
+ var test_url =
+ "http://localhost:PORT/files/extensions/test_file_with_iframe.html"
+ .replace(/PORT/, config.testServer.port);
+
+ chrome.tabs.create({ url: test_url });
});
+
</script>
diff --git a/chrome/test/data/extensions/api_test/content_scripts/extension_iframe/test.html b/chrome/test/data/extensions/api_test/content_scripts/extension_iframe/test.html
index 72240e7..905f967 100644
--- a/chrome/test/data/extensions/api_test/content_scripts/extension_iframe/test.html
+++ b/chrome/test/data/extensions/api_test/content_scripts/extension_iframe/test.html
@@ -11,8 +11,13 @@ chrome.test.runTests([
}
]);
-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...");
+
+ var test_url = "http://localhost:PORT/files/extensions/test_file.html"
+ .replace(/PORT/, config.testServer.port);
+
+ chrome.tabs.create({ url: test_url });
});
+
</script>
diff --git a/chrome/test/data/extensions/api_test/content_scripts/extension_process/background.html b/chrome/test/data/extensions/api_test/content_scripts/extension_process/background.html
index a33b1b1..4ae18ce 100644
--- a/chrome/test/data/extensions/api_test/content_scripts/extension_process/background.html
+++ b/chrome/test/data/extensions/api_test/content_scripts/extension_process/background.html
@@ -18,6 +18,19 @@ chrome.extension.onRequest.addListener(function(data) {
chrome.test.notifyPass();
});
-var w = window.open("http://localhost:1337/files/extensions/test_file.html");
+chrome.test.getConfig(function(config) {
+ var test_file_url = "http://localhost:PORT/files/extensions/test_file.html"
+ .replace(/PORT/, config.testServer.port);
+
+ // Add a window.
+ var w = window.open(test_file_url);
+
+ // Add an iframe.
+ var iframe = document.createElement("iframe");
+ iframe.src = test_file_url;
+ document.getElementById("iframeContainer").appendChild(iframe);
+});
+
</script>
-<iframe src="http://localhost:1337/files/extensions/test_file.html"></iframe>
+
+<div id="iframeContainer"> </div>
diff --git a/chrome/test/data/extensions/api_test/content_scripts/fragment/background.html b/chrome/test/data/extensions/api_test/content_scripts/fragment/background.html
index 065cf24..e42c7bd 100644
--- a/chrome/test/data/extensions/api_test/content_scripts/fragment/background.html
+++ b/chrome/test/data/extensions/api_test/content_scripts/fragment/background.html
@@ -16,10 +16,10 @@ function fail() {
}
}
-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";
@@ -33,35 +33,45 @@ if (debug) {
chrome.test.fail = function(){ console.log("fail"); };
}
-chrome.test.runTests([
- function test1() {
- chrome.extension.onRequest.addListener(function(req, sender) {
- chrome.test.log("got request: " + JSON.stringify(req));
- if (req == "fail") {
- fail();
- } else if (req == "content_script_start") {
- var tab = sender.tab;
- if (tab.url.indexOf("#") != -1) {
+function runTests() {
+ chrome.test.runTests([
+ function test1() {
+ chrome.extension.onRequest.addListener(function(req, sender) {
+ chrome.test.log("got request: " + JSON.stringify(req));
+ if (req == "fail") {
fail();
- } else {
- chrome.tabs.update(tab.id, {"url": tab.url + "#foo"});
- }
- }
- });
- chrome.tabs.onUpdated.addListener(function(tabid, info, tab) {
- chrome.test.log("onUpdated status: " + info.status + " url:" + tab.url);
- if (info.status == "complete" && tab.url.indexOf("#foo") != -1) {
- setTimeout(function() {
- if (!did_fail()) {
- chrome.test.succeed();
+ } else if (req == "content_script_start") {
+ var tab = sender.tab;
+ if (tab.url.indexOf("#") != -1) {
+ fail();
+ } else {
+ chrome.tabs.update(tab.id, {"url": tab.url + "#foo"});
}
- }, 750);
- }
- });
- chrome.test.log("creating tab");
- chrome.tabs.create({"url": test_url});
- }
-]);
+ }
+ });
+ chrome.tabs.onUpdated.addListener(function(tabid, info, tab) {
+ chrome.test.log("onUpdated status: " + info.status + " url:" + tab.url);
+ if (info.status == "complete" && tab.url.indexOf("#foo") != -1) {
+ setTimeout(function() {
+ if (!did_fail()) {
+ chrome.test.succeed();
+ }
+ }, 750);
+ }
+ });
+ chrome.test.log("creating tab");
+ chrome.tabs.create({"url": test_url});
+ }
+ ]);
+}
+if (debug) {
+ 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/executescript/file_after_close/test.html b/chrome/test/data/extensions/api_test/executescript/file_after_close/test.html
index c9e97fc..a18e66f 100644
--- a/chrome/test/data/extensions/api_test/executescript/file_after_close/test.html
+++ b/chrome/test/data/extensions/api_test/executescript/file_after_close/test.html
@@ -1,5 +1,5 @@
<script>
-var server = 'http://b.com:1337';
+var server = 'http://b.com:PORT';
var relativePath = '/files/extensions/api_test/executescript/file_after_close/';
var extensionPage = chrome.extension.getURL('extension_page.html');
var webPage1 = server + relativePath + 'web_page1.html';
@@ -14,7 +14,7 @@ var listener = function(tabId, changeInfo, tab) {
if (!extensionPageOpened && tab.url == webPage1) {
chrome.tabs.create({ url: extensionPage });
extensionPageOpened = true;
- return;
+ return;
}
if (tab.url == webPage2) {
@@ -25,5 +25,10 @@ var listener = function(tabId, changeInfo, tab) {
};
chrome.tabs.onUpdated.addListener(listener);
-chrome.tabs.create({ url: webPage1 });
+chrome.test.getConfig(function(config) {
+ webPage1 = webPage1.replace(/PORT/, config.testServer.port);
+ webPage2 = webPage2.replace(/PORT/, config.testServer.port);
+ chrome.tabs.create({ url: webPage1 });
+});
+
</script>
diff --git a/chrome/test/data/extensions/api_test/executescript/in_frame/test.html b/chrome/test/data/extensions/api_test/executescript/in_frame/test.html
index 4dd18d1..9cd61e6 100644
--- a/chrome/test/data/extensions/api_test/executescript/in_frame/test.html
+++ b/chrome/test/data/extensions/api_test/executescript/in_frame/test.html
@@ -6,7 +6,7 @@ var assertEq = chrome.test.assertEq;
var assertTrue = chrome.test.assertTrue;
var relativePath =
'/files/extensions/api_test/executescript/in_frame/test_executescript.html';
-var testUrl = 'http://a.com:1337' + relativePath;
+var testUrl = 'http://a.com:PORT' + relativePath;
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status != 'complete')
@@ -63,6 +63,9 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
]);
});
-chrome.tabs.create({ url: testUrl });
+chrome.test.getConfig(function(config) {
+ testUrl = testUrl.replace(/PORT/, config.testServer.port);
+ chrome.tabs.create({ url: testUrl });
+});
</script>
diff --git a/chrome/test/data/extensions/api_test/executescript/permissions/frames.html b/chrome/test/data/extensions/api_test/executescript/permissions/frames.html
index 85ba47b..45a471b 100644
--- a/chrome/test/data/extensions/api_test/executescript/permissions/frames.html
+++ b/chrome/test/data/extensions/api_test/executescript/permissions/frames.html
@@ -1,10 +1,19 @@
<html>
-<iframe src="http://a.com:1337/files/extensions/api_test/executescript/permissions/empty.html">
-</iframe>
+<body>
+<script>
-<iframe src="http://b.com:1337/files/extensions/api_test/executescript/permissions/empty.html">
-</iframe>
+// document.write is not pretty, but it saves us from having to wait for the
+// DOM to load before adding iframes. This means one less callback to wait on.
+function addIFrame(host) {
+ document.write(['<iframe src="http://', host, ':', location.port,
+ '/files/extensions/api_test/executescript',
+ '/permissions/empty.html"> </iframe>'].join(''));
+}
+addIFrame("a.com");
+addIFrame("b.com");
+addIFrame("c.com");
-<iframe src="http://c.com:1337/files/extensions/api_test/executescript/permissions/empty.html">
-</iframe>
+</script>
+
+</body>
</html>
diff --git a/chrome/test/data/extensions/api_test/executescript/permissions/test.html b/chrome/test/data/extensions/api_test/executescript/permissions/test.html
index 74c6e32..b831912 100644
--- a/chrome/test/data/extensions/api_test/executescript/permissions/test.html
+++ b/chrome/test/data/extensions/api_test/executescript/permissions/test.html
@@ -16,40 +16,53 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
onTabLoaded(tab);
});
-chrome.test.runTests([
- // Test a race that used to occur here (see bug 30937).
- // Open a tab that we're not allowed to execute in (c.com), then navigate it
- // to a tab we *are* allowed to execute in (a.com), then quickly run script in
- // the tab before it navigates. It should appear to work (no error -- it could
- // have been a developer mistake), but not actually do anything.
- function() {
- chrome.tabs.create({url: 'http://c.com:1337/' + testFile});
- onTabLoaded = function(tab) {
- onTabLoaded = null;
- numReceivedRequests = 0;
- chrome.tabs.update(tab.id, {url: 'http://a.com:1337/' + testFile});
- chrome.tabs.executeScript(tab.id, {file: 'script.js'});
- window.setTimeout(function() {
- assertEq(0, numReceivedRequests);
- chrome.test.runNextTest();
- }, 4000);
- };
- },
-
- // Inject into all frames. This should only affect frames we have access to.
- // This page has three subframes, one each from a.com, b.com, and c.com. We
- // have access to two of those, plus the root frame, so we should get three
- // responses.
- function() {
- chrome.tabs.create({url: 'http://a.com:1337/' + testFileFrames});
- onTabLoaded = function(tab) {
- numReceivedRequests = 0;
- chrome.tabs.executeScript(tab.id, {file: 'script.js', allFrames: true});
- window.setTimeout(function() {
- chrome.test.assertEq(3, numReceivedRequests);
- chrome.test.runNextTest();
- }, 4000);
- };
+chrome.test.getConfig(function(config) {
+
+ function fixPort(url) {
+ return url.replace(/PORT/, config.testServer.port);
}
-]);
+
+ chrome.test.runTests([
+ // Test a race that used to occur here (see bug 30937).
+ // Open a tab that we're not allowed to execute in (c.com), then
+ // navigate it to a tab we *are* allowed to execute in (a.com),
+ // then quickly run script in the tab before it navigates. It
+ // should appear to work (no error -- it could have been a developer
+ // mistake), but not actually do anything.
+ function() {
+ chrome.tabs.create({url: fixPort('http://c.com:PORT/') + testFile});
+ onTabLoaded = function(tab) {
+ onTabLoaded = null;
+ numReceivedRequests = 0;
+ chrome.tabs.update(
+ tab.id, {url: fixPort('http://a.com:PORT/') + testFile});
+ chrome.tabs.executeScript(tab.id, {file: 'script.js'});
+ window.setTimeout(function() {
+ assertEq(0, numReceivedRequests);
+ chrome.test.runNextTest();
+ }, 4000);
+ };
+ },
+
+ // Inject into all frames. This should only affect frames we have
+ // access to. This page has three subframes, one each from a.com,
+ // b.com, and c.com. We have access to two of those, plus the root
+ // frame, so we should get three responses.
+ function() {
+ chrome.tabs.create(
+ {url: fixPort('http://a.com:PORT/') + testFileFrames});
+ onTabLoaded = function(tab) {
+ numReceivedRequests = 0;
+ chrome.tabs.executeScript(tab.id,
+ {file: 'script.js', allFrames: true});
+ window.setTimeout(function() {
+ chrome.test.assertEq(3, numReceivedRequests);
+ chrome.test.runNextTest();
+ }, 4000);
+ };
+ }
+ ]);
+
+});
+
</script>