OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/scoped_observer.h" | |
6 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
7 #include "chrome/browser/extensions/extension_install_prompt.h" | 8 #include "chrome/browser/extensions/extension_install_prompt.h" |
8 #include "chrome/browser/extensions/extension_install_ui.h" | 9 #include "chrome/browser/extensions/extension_install_ui.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/startup_helper.h" | 11 #include "chrome/browser/extensions/startup_helper.h" |
11 #include "chrome/browser/extensions/webstore_installer_test.h" | 12 #include "chrome/browser/extensions/webstore_installer_test.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/test_switches.h" | 20 #include "chrome/test/base/test_switches.h" |
20 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
26 #include "extensions/browser/extension_host.h" | 27 #include "extensions/browser/extension_host.h" |
27 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
29 #include "extensions/browser/extension_registry_observer.h" | |
28 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
29 #include "extensions/common/extension_builder.h" | 31 #include "extensions/common/extension_builder.h" |
30 #include "extensions/common/value_builder.h" | 32 #include "extensions/common/value_builder.h" |
31 #include "net/dns/mock_host_resolver.h" | 33 #include "net/dns/mock_host_resolver.h" |
32 #include "url/gurl.h" | 34 #include "url/gurl.h" |
33 | 35 |
34 using content::WebContents; | 36 using content::WebContents; |
35 using extensions::DictionaryBuilder; | 37 using extensions::DictionaryBuilder; |
36 using extensions::Extension; | 38 using extensions::Extension; |
37 using extensions::ExtensionBuilder; | 39 using extensions::ExtensionBuilder; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 WebstoreStartupInstallUnpackFailureTest) { | 231 WebstoreStartupInstallUnpackFailureTest) { |
230 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 232 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
231 ExtensionInstallPrompt::ACCEPT; | 233 ExtensionInstallPrompt::ACCEPT; |
232 | 234 |
233 ui_test_utils::NavigateToURL(browser(), | 235 ui_test_utils::NavigateToURL(browser(), |
234 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); | 236 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); |
235 | 237 |
236 RunTest("runTest"); | 238 RunTest("runTest"); |
237 } | 239 } |
238 | 240 |
239 class CommandLineWebstoreInstall : public WebstoreStartupInstallerTest, | 241 class CommandLineWebstoreInstall |
240 public content::NotificationObserver { | 242 : public WebstoreStartupInstallerTest, |
243 public content::NotificationObserver, | |
244 public extensions::ExtensionRegistryObserver { | |
241 public: | 245 public: |
242 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} | 246 CommandLineWebstoreInstall() |
247 : saw_install_(false), | |
248 browser_open_count_(0) {} | |
243 virtual ~CommandLineWebstoreInstall() {} | 249 virtual ~CommandLineWebstoreInstall() {} |
244 | 250 |
245 virtual void SetUpOnMainThread() OVERRIDE { | 251 virtual void SetUpOnMainThread() OVERRIDE { |
246 WebstoreStartupInstallerTest::SetUpOnMainThread(); | 252 WebstoreStartupInstallerTest::SetUpOnMainThread(); |
247 registrar_.Add( | 253 extensions::ExtensionRegistry::Get(browser()->profile())->AddObserver(this); |
248 this, | |
249 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | |
250 content::NotificationService::AllSources()); | |
251 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 254 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
252 content::NotificationService::AllSources()); | 255 content::NotificationService::AllSources()); |
253 } | 256 } |
254 | 257 |
258 virtual void TearDownOnMainThread() OVERRIDE { | |
259 extensions::ExtensionRegistry::Get(browser()->profile()) | |
260 ->RemoveObserver(this); | |
not at google - send to devlin
2014/08/04 15:46:05
also run WebstoreStartupInstallerTest::TearDownOnM
limasdf
2014/08/04 16:38:09
Done.
| |
261 } | |
262 | |
255 bool saw_install() { return saw_install_; } | 263 bool saw_install() { return saw_install_; } |
256 | 264 |
257 int browser_open_count() { return browser_open_count_; } | 265 int browser_open_count() { return browser_open_count_; } |
258 | 266 |
259 // NotificationObserver interface. | 267 // NotificationObserver interface. |
260 virtual void Observe(int type, | 268 virtual void Observe(int type, |
261 const content::NotificationSource& source, | 269 const content::NotificationSource& source, |
262 const content::NotificationDetails& details) OVERRIDE { | 270 const content::NotificationDetails& details) OVERRIDE { |
263 if (type == | 271 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED); |
264 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED) { | 272 ++browser_open_count_; |
265 const Extension* extension = | 273 } |
266 content::Details<const extensions::InstalledExtensionInfo>(details)-> | 274 |
267 extension; | 275 virtual void OnExtensionWillBeInstalled( |
268 ASSERT_TRUE(extension != NULL); | 276 content::BrowserContext* browser_context, |
269 EXPECT_EQ(extension->id(), kTestExtensionId); | 277 const extensions::Extension* extension, |
270 saw_install_ = true; | 278 bool is_update, |
271 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 279 bool from_ephemeral, |
272 browser_open_count_++; | 280 const std::string& old_name) OVERRIDE { |
273 } else { | 281 EXPECT_EQ(extension->id(), kTestExtensionId); |
274 ASSERT_TRUE(false) << "Unexpected notification type : " << type; | 282 saw_install_ = true; |
275 } | |
276 } | 283 } |
277 | 284 |
278 content::NotificationRegistrar registrar_; | 285 content::NotificationRegistrar registrar_; |
279 | 286 |
280 // Have we seen an installation notification for kTestExtensionId ? | 287 // Have we seen an installation notification for kTestExtensionId ? |
281 bool saw_install_; | 288 bool saw_install_; |
282 | 289 |
283 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? | 290 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? |
284 int browser_open_count_; | 291 int browser_open_count_; |
285 }; | 292 }; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 336 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
330 command_line->AppendSwitchASCII( | 337 command_line->AppendSwitchASCII( |
331 switches::kLimitedInstallFromWebstore, "2"); | 338 switches::kLimitedInstallFromWebstore, "2"); |
332 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), | 339 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), |
333 base::MessageLoop::QuitWhenIdleClosure()); | 340 base::MessageLoop::QuitWhenIdleClosure()); |
334 base::MessageLoop::current()->Run(); | 341 base::MessageLoop::current()->Run(); |
335 | 342 |
336 EXPECT_TRUE(saw_install()); | 343 EXPECT_TRUE(saw_install()); |
337 EXPECT_EQ(0, browser_open_count()); | 344 EXPECT_EQ(0, browser_open_count()); |
338 } | 345 } |
OLD | NEW |