| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.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/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/common/api/test.h" | 19 #include "extensions/common/api/test.h" |
| 20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/feature_switch.h" |
| 22 #include "extensions/common/switches.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 24 |
| 23 namespace extensions { | 25 namespace extensions { |
| 24 | 26 |
| 25 namespace OnMessage = core_api::test::OnMessage; | 27 namespace OnMessage = core_api::test::OnMessage; |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 void FindFrame(const GURL& url, | 31 void FindFrame(const GURL& url, |
| 30 content::RenderFrameHost** out, | 32 content::RenderFrameHost** out, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 browser()->tab_strip_model()->GetActiveWebContents(); | 103 browser()->tab_strip_model()->GetActiveWebContents(); |
| 102 | 104 |
| 103 if (active_web_contents->GetLastCommittedURL() == frame_url) | 105 if (active_web_contents->GetLastCommittedURL() == frame_url) |
| 104 return active_web_contents->GetMainFrame(); | 106 return active_web_contents->GetMainFrame(); |
| 105 | 107 |
| 106 content::RenderFrameHost* frame_host = NULL; | 108 content::RenderFrameHost* frame_host = NULL; |
| 107 active_web_contents->ForEachFrame( | 109 active_web_contents->ForEachFrame( |
| 108 base::Bind(&FindFrame, frame_url, &frame_host)); | 110 base::Bind(&FindFrame, frame_url, &frame_host)); |
| 109 return frame_host; | 111 return frame_host; |
| 110 } | 112 } |
| 113 |
| 114 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 115 FeatureSwitch::ScopedOverride enable_options( |
| 116 FeatureSwitch::embedded_extension_options(), true); |
| 117 // Need to add a command line flag as well as a FeatureSwitch because the |
| 118 // FeatureSwitch is not copied over to the renderer process from the |
| 119 // browser process. |
| 120 command_line->AppendSwitch( |
| 121 extensions::switches::kEnableEmbeddedExtensionOptions); |
| 122 ExtensionApiTest::SetUpCommandLine(command_line); |
| 123 } |
| 124 |
| 125 scoped_ptr<FeatureSwitch::ScopedOverride> enable_options_; |
| 126 |
| 111 }; | 127 }; |
| 112 | 128 |
| 113 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIs) { | 129 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIs) { |
| 114 ASSERT_TRUE(RunTestOnExtensions("sanity_check_available_apis.js")); | 130 ASSERT_TRUE(RunTestOnExtensions("sanity_check_available_apis.js")); |
| 115 } | 131 } |
| 116 | 132 |
| 117 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) { | 133 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) { |
| 118 ASSERT_TRUE(RunTestOnAbout("sanity_check_available_apis.js")); | 134 ASSERT_TRUE(RunTestOnAbout("sanity_check_available_apis.js")); |
| 119 } | 135 } |
| 120 | 136 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 ASSERT_TRUE(RunTestOnExtensions("runtime_last_error.js")); | 176 ASSERT_TRUE(RunTestOnExtensions("runtime_last_error.js")); |
| 161 | 177 |
| 162 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 178 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| 163 listener->ReplyWithError("unknown host"); | 179 listener->ReplyWithError("unknown host"); |
| 164 | 180 |
| 165 listener.reset(new ExtensionTestMessageListener(false)); | 181 listener.reset(new ExtensionTestMessageListener(false)); |
| 166 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 182 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| 167 EXPECT_EQ("true", listener->message()); | 183 EXPECT_EQ("true", listener->message()); |
| 168 } | 184 } |
| 169 | 185 |
| 186 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) { |
| 187 scoped_ptr<ExtensionTestMessageListener> listener( |
| 188 new ExtensionTestMessageListener("ready", true)); |
| 189 |
| 190 const Extension* extension = InstallExtension( |
| 191 test_data_dir_.AppendASCII("extension_options").AppendASCII("embed_self"), |
| 192 1); |
| 193 ASSERT_TRUE(extension); |
| 194 |
| 195 ASSERT_TRUE(RunTestOnExtensions("can_embed_extension_options.js")); |
| 196 |
| 197 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| 198 listener->Reply(extension->id()); |
| 199 listener.reset(new ExtensionTestMessageListener("guest loaded", false)); |
| 200 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| 201 } |
| 202 |
| 170 } // namespace | 203 } // namespace |
| 171 | 204 |
| 172 } // namespace extensions | 205 } // namespace extensions |
| OLD | NEW |