From 2a9662e31f18f77b856487b7266c70ccede557e0 Mon Sep 17 00:00:00 2001 From: "skerner@chromium.org" Date: Fri, 22 Oct 2010 17:12:15 +0000 Subject: 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 --- .../content_script_all_frames_apitest.cc | 4 +- .../content_script_extension_process_apitest.cc | 5 +- .../api_test/content_scripts/all_frames/test.html | 12 +++- .../content_scripts/extension_iframe/test.html | 11 ++- .../extension_process/background.html | 17 ++++- .../content_scripts/fragment/background.html | 70 ++++++++++-------- .../executescript/file_after_close/test.html | 11 ++- .../api_test/executescript/in_frame/test.html | 7 +- .../api_test/executescript/permissions/frames.html | 21 ++++-- .../api_test/executescript/permissions/test.html | 83 +++++++++++++--------- 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 }); }); + 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 }); }); + 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); +}); + - + +
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(); + }); +} 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 @@ 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 }); +}); 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 @@ - + + + + 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); + }; + } + ]); + +}); + -- cgit v1.1