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); | |
Lei Zhang
2014/08/12 20:00:46
nit: no need for extensions:: in namespace extensi
ericzeng
2014/08/12 22:07:17
Done.
| |
122 ExtensionApiTest::SetUpCommandLine(command_line); | |
123 } | |
124 | |
125 scoped_ptr<FeatureSwitch::ScopedOverride> enable_options_; | |
111 }; | 126 }; |
112 | 127 |
113 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIs) { | 128 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckAvailableAPIs) { |
114 ASSERT_TRUE(RunTestOnExtensions("sanity_check_available_apis.js")); | 129 ASSERT_TRUE(RunTestOnExtensions("sanity_check_available_apis.js")); |
115 } | 130 } |
116 | 131 |
117 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) { | 132 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) { |
118 ASSERT_TRUE(RunTestOnAbout("sanity_check_available_apis.js")); | 133 ASSERT_TRUE(RunTestOnAbout("sanity_check_available_apis.js")); |
119 } | 134 } |
120 | 135 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 ASSERT_TRUE(RunTestOnExtensions("runtime_last_error.js")); | 175 ASSERT_TRUE(RunTestOnExtensions("runtime_last_error.js")); |
161 | 176 |
162 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 177 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
163 listener->ReplyWithError("unknown host"); | 178 listener->ReplyWithError("unknown host"); |
164 | 179 |
165 listener.reset(new ExtensionTestMessageListener(false)); | 180 listener.reset(new ExtensionTestMessageListener(false)); |
166 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 181 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
167 EXPECT_EQ("true", listener->message()); | 182 EXPECT_EQ("true", listener->message()); |
168 } | 183 } |
169 | 184 |
185 IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) { | |
186 scoped_ptr<ExtensionTestMessageListener> listener( | |
187 new ExtensionTestMessageListener("ready", true)); | |
188 | |
189 const Extension* extension = InstallExtension( | |
190 test_data_dir_.AppendASCII("extension_options").AppendASCII("embed_self"), | |
191 1); | |
192 ASSERT_TRUE(extension); | |
193 | |
194 ASSERT_TRUE(RunTestOnExtensions("can_embed_extension_options.js")); | |
195 | |
196 ASSERT_TRUE(listener->WaitUntilSatisfied()); | |
197 listener->Reply(extension->id()); | |
198 listener.reset(new ExtensionTestMessageListener("guest loaded", false)); | |
199 ASSERT_TRUE(listener->WaitUntilSatisfied()); | |
200 } | |
201 | |
170 } // namespace | 202 } // namespace |
171 | 203 |
172 } // namespace extensions | 204 } // namespace extensions |
OLD | NEW |