| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 17 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
| 18 #include "extensions/common/api/test.h" | 18 #include "extensions/common/api/test.h" |
| 19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 20 #include "extensions/test/extension_test_message_listener.h" | 20 #include "extensions/test/extension_test_message_listener.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 namespace OnMessage = core_api::test::OnMessage; | 25 namespace OnMessage = core_api::test::OnMessage; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void FindFrame(const GURL& url, | |
| 30 content::RenderFrameHost** out, | |
| 31 content::RenderFrameHost* frame) { | |
| 32 if (frame->GetLastCommittedURL() == url) { | |
| 33 if (*out != NULL) { | |
| 34 ADD_FAILURE() << "Found multiple frames at " << url; | |
| 35 } | |
| 36 *out = frame; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 // Tests running extension APIs on WebUI. | 29 // Tests running extension APIs on WebUI. |
| 41 class ExtensionWebUITest : public ExtensionApiTest { | 30 class ExtensionWebUITest : public ExtensionApiTest { |
| 42 protected: | 31 protected: |
| 43 testing::AssertionResult RunTest(const char* name, | 32 testing::AssertionResult RunTest(const char* name, |
| 44 const GURL& page_url, | 33 const GURL& page_url, |
| 45 const GURL& frame_url, | 34 const GURL& frame_url, |
| 46 bool expected_result) { | 35 bool expected_result) { |
| 47 // Tests are located in chrome/test/data/extensions/webui/$(name). | 36 // Tests are located in chrome/test/data/extensions/webui/$(name). |
| 48 base::FilePath path; | 37 base::FilePath path; |
| 49 PathService::Get(chrome::DIR_TEST_DATA, &path); | 38 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 content::RenderFrameHost* NavigateToWebUI(const GURL& page_url, | 101 content::RenderFrameHost* NavigateToWebUI(const GURL& page_url, |
| 113 const GURL& frame_url) { | 102 const GURL& frame_url) { |
| 114 ui_test_utils::NavigateToURL(browser(), page_url); | 103 ui_test_utils::NavigateToURL(browser(), page_url); |
| 115 | 104 |
| 116 content::WebContents* active_web_contents = | 105 content::WebContents* active_web_contents = |
| 117 browser()->tab_strip_model()->GetActiveWebContents(); | 106 browser()->tab_strip_model()->GetActiveWebContents(); |
| 118 | 107 |
| 119 if (active_web_contents->GetLastCommittedURL() == frame_url) | 108 if (active_web_contents->GetLastCommittedURL() == frame_url) |
| 120 return active_web_contents->GetMainFrame(); | 109 return active_web_contents->GetMainFrame(); |
| 121 | 110 |
| 122 content::RenderFrameHost* frame_host = NULL; | 111 return FrameMatchingPredicate( |
| 123 active_web_contents->ForEachFrame( | 112 active_web_contents, |
| 124 base::Bind(&FindFrame, frame_url, &frame_host)); | 113 base::Bind(&content::FrameHasSourceUrl, frame_url)); |
| 125 return frame_host; | |
| 126 } | 114 } |
| 127 }; | 115 }; |
| 128 | 116 |
| 129 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIsInFrame) { | 117 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIsInFrame) { |
| 130 ASSERT_TRUE(RunTestOnExtensionsFrame("sanity_check_available_apis.js")); | 118 ASSERT_TRUE(RunTestOnExtensionsFrame("sanity_check_available_apis.js")); |
| 131 } | 119 } |
| 132 | 120 |
| 133 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, | 121 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, |
| 134 SanityCheckAvailableAPIsInChromeFrame) { | 122 SanityCheckAvailableAPIsInChromeFrame) { |
| 135 ASSERT_TRUE(RunTestOnChromeExtensionsFrame("sanity_check_available_apis.js")); | 123 ASSERT_TRUE(RunTestOnChromeExtensionsFrame("sanity_check_available_apis.js")); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 237 |
| 250 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 238 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| 251 listener->Reply(extension_id); | 239 listener->Reply(extension_id); |
| 252 listener.reset(new ExtensionTestMessageListener("createfailed", false)); | 240 listener.reset(new ExtensionTestMessageListener("createfailed", false)); |
| 253 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 241 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| 254 } | 242 } |
| 255 | 243 |
| 256 } // namespace | 244 } // namespace |
| 257 | 245 |
| 258 } // namespace extensions | 246 } // namespace extensions |
| OLD | NEW |