| Index: chrome/browser/extensions/extension_webui_apitest.cc
|
| diff --git a/chrome/browser/extensions/extension_webui_apitest.cc b/chrome/browser/extensions/extension_webui_apitest.cc
|
| index 1eca94d9d05589bfb14624f05dcc6cf887f382f1..12fdf54c988c2feec1ec7c3bc3f1f733b5509b14 100644
|
| --- a/chrome/browser/extensions/extension_webui_apitest.cc
|
| +++ b/chrome/browser/extensions/extension_webui_apitest.cc
|
| @@ -40,7 +40,10 @@ void FindFrame(const GURL& url,
|
| // Tests running extension APIs on WebUI.
|
| class ExtensionWebUITest : public ExtensionApiTest {
|
| protected:
|
| - testing::AssertionResult RunTest(const char* name) {
|
| + testing::AssertionResult RunTest(const char* name,
|
| + const GURL& page_url,
|
| + const GURL& frame_url,
|
| + bool expected_result) {
|
| // Tests are located in chrome/test/data/extensions/webui/$(name).
|
| base::FilePath path;
|
| PathService::Get(chrome::DIR_TEST_DATA, &path);
|
| @@ -55,38 +58,63 @@ class ExtensionWebUITest : public ExtensionApiTest {
|
| script = "(function(){'use strict';" + script + "}());";
|
|
|
| // Run the test.
|
| - bool result = false;
|
| - content::RenderFrameHost* webui = NavigateToWebUI();
|
| + bool actual_result = false;
|
| + content::RenderFrameHost* webui = NavigateToWebUI(page_url, frame_url);
|
| if (!webui)
|
| return testing::AssertionFailure() << "Failed to navigate to WebUI";
|
| - CHECK(content::ExecuteScriptAndExtractBool(webui, script, &result));
|
| - return result ? testing::AssertionSuccess()
|
| - : (testing::AssertionFailure() << "Check console output");
|
| + CHECK(content::ExecuteScriptAndExtractBool(webui, script, &actual_result));
|
| + return (expected_result == actual_result)
|
| + ? testing::AssertionSuccess()
|
| + : (testing::AssertionFailure() << "Check console output");
|
| }
|
|
|
| - private:
|
| - // Navigates the browser to a WebUI page and returns the RenderFrameHost for
|
| - // that page.
|
| - content::RenderFrameHost* NavigateToWebUI() {
|
| - // Use the chrome://extensions page, cos, why not.
|
| - ui_test_utils::NavigateToURL(browser(), GURL("chrome://extensions/"));
|
| -
|
| + testing::AssertionResult RunTestOnExtensions(const char* name,
|
| + bool expected_result) {
|
| // In the current design the URL of the chrome://extensions page it's
|
| // actually chrome://extensions-frame/ -- and it's important we find it,
|
| // because the top-level frame doesn't execute any code, so a script
|
| // context is never created, so the bindings are never set up, and
|
| // apparently the call to ExecuteScriptAndExtractString doesn't adequately
|
| // set them up either.
|
| + return RunTest(name,
|
| + GURL("chrome://extensions"),
|
| + GURL("chrome://extensions-frame"),
|
| + expected_result);
|
| + }
|
| +
|
| + testing::AssertionResult RunTestOnAbout(const char* name,
|
| + bool expected_result) {
|
| + // chrome://about is an innocuous page that doesn't have any bindings.
|
| + return RunTest(
|
| + name, GURL("chrome://about"), GURL("chrome://about"), expected_result);
|
| + }
|
| +
|
| + private:
|
| + // Navigates the browser to a WebUI page and returns the RenderFrameHost for
|
| + // that page.
|
| + content::RenderFrameHost* NavigateToWebUI(const GURL& page_url,
|
| + const GURL& frame_url) {
|
| + ui_test_utils::NavigateToURL(browser(), page_url);
|
| +
|
| + content::WebContents* active_web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| +
|
| + if (active_web_contents->GetLastCommittedURL() == frame_url)
|
| + return active_web_contents->GetMainFrame();
|
| +
|
| content::RenderFrameHost* frame_host = NULL;
|
| - browser()->tab_strip_model()->GetActiveWebContents()->ForEachFrame(
|
| - base::Bind(
|
| - &FindFrame, GURL("chrome://extensions-frame/"), &frame_host));
|
| + active_web_contents->ForEachFrame(
|
| + base::Bind(&FindFrame, frame_url, &frame_host));
|
| return frame_host;
|
| }
|
| };
|
|
|
| IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIs) {
|
| - ASSERT_TRUE(RunTest("sanity_check_available_apis.js"));
|
| + ASSERT_TRUE(RunTestOnExtensions("sanity_check_available_apis.js", true));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) {
|
| + ASSERT_TRUE(RunTestOnAbout("sanity_check_available_apis.js", false));
|
| }
|
|
|
| // Tests chrome.test.sendMessage, which exercises WebUI making a
|
| @@ -95,7 +123,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SendMessage) {
|
| scoped_ptr<ExtensionTestMessageListener> listener(
|
| new ExtensionTestMessageListener("ping", true));
|
|
|
| - ASSERT_TRUE(RunTest("send_message.js"));
|
| + ASSERT_TRUE(RunTestOnExtensions("send_message.js", true));
|
|
|
| ASSERT_TRUE(listener->WaitUntilSatisfied());
|
| listener->Reply("pong");
|
| @@ -108,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SendMessage) {
|
| // Tests chrome.runtime.onMessage, which exercises WebUI registering and
|
| // receiving an event.
|
| IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, OnMessage) {
|
| - ASSERT_TRUE(RunTest("on_message.js"));
|
| + ASSERT_TRUE(RunTestOnExtensions("on_message.js", true));
|
|
|
| OnMessage::Info info;
|
| info.data = "hi";
|
| @@ -128,7 +156,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, RuntimeLastError) {
|
| scoped_ptr<ExtensionTestMessageListener> listener(
|
| new ExtensionTestMessageListener("ping", true));
|
|
|
| - ASSERT_TRUE(RunTest("runtime_last_error.js"));
|
| + ASSERT_TRUE(RunTestOnExtensions("runtime_last_error.js", true));
|
|
|
| ASSERT_TRUE(listener->WaitUntilSatisfied());
|
| listener->ReplyWithError("unknown host");
|
|
|