| 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() : saw_install_(false), browser_open_count_(0) {} |
| 243 virtual ~CommandLineWebstoreInstall() {} | 247 virtual ~CommandLineWebstoreInstall() {} |
| 244 | 248 |
| 245 virtual void SetUpOnMainThread() OVERRIDE { | 249 virtual void SetUpOnMainThread() OVERRIDE { |
| 246 WebstoreStartupInstallerTest::SetUpOnMainThread(); | 250 WebstoreStartupInstallerTest::SetUpOnMainThread(); |
| 247 registrar_.Add( | 251 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, | 252 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 252 content::NotificationService::AllSources()); | 253 content::NotificationService::AllSources()); |
| 253 } | 254 } |
| 254 | 255 |
| 256 virtual void TearDownOnMainThread() OVERRIDE { |
| 257 extensions::ExtensionRegistry::Get(browser()->profile()) |
| 258 ->RemoveObserver(this); |
| 259 WebstoreStartupInstallerTest::TearDownOnMainThread(); |
| 260 } |
| 261 |
| 255 bool saw_install() { return saw_install_; } | 262 bool saw_install() { return saw_install_; } |
| 256 | 263 |
| 257 int browser_open_count() { return browser_open_count_; } | 264 int browser_open_count() { return browser_open_count_; } |
| 258 | 265 |
| 259 // NotificationObserver interface. | 266 // NotificationObserver interface. |
| 260 virtual void Observe(int type, | 267 virtual void Observe(int type, |
| 261 const content::NotificationSource& source, | 268 const content::NotificationSource& source, |
| 262 const content::NotificationDetails& details) OVERRIDE { | 269 const content::NotificationDetails& details) OVERRIDE { |
| 263 if (type == | 270 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED); |
| 264 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED) { | 271 ++browser_open_count_; |
| 265 const Extension* extension = | 272 } |
| 266 content::Details<const extensions::InstalledExtensionInfo>(details)-> | 273 |
| 267 extension; | 274 virtual void OnExtensionWillBeInstalled( |
| 268 ASSERT_TRUE(extension != NULL); | 275 content::BrowserContext* browser_context, |
| 269 EXPECT_EQ(extension->id(), kTestExtensionId); | 276 const extensions::Extension* extension, |
| 270 saw_install_ = true; | 277 bool is_update, |
| 271 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 278 bool from_ephemeral, |
| 272 browser_open_count_++; | 279 const std::string& old_name) OVERRIDE { |
| 273 } else { | 280 EXPECT_EQ(extension->id(), kTestExtensionId); |
| 274 ASSERT_TRUE(false) << "Unexpected notification type : " << type; | 281 saw_install_ = true; |
| 275 } | |
| 276 } | 282 } |
| 277 | 283 |
| 278 content::NotificationRegistrar registrar_; | 284 content::NotificationRegistrar registrar_; |
| 279 | 285 |
| 280 // Have we seen an installation notification for kTestExtensionId ? | 286 // Have we seen an installation notification for kTestExtensionId ? |
| 281 bool saw_install_; | 287 bool saw_install_; |
| 282 | 288 |
| 283 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? | 289 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? |
| 284 int browser_open_count_; | 290 int browser_open_count_; |
| 285 }; | 291 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 335 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 330 command_line->AppendSwitchASCII( | 336 command_line->AppendSwitchASCII( |
| 331 switches::kLimitedInstallFromWebstore, "2"); | 337 switches::kLimitedInstallFromWebstore, "2"); |
| 332 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), | 338 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), |
| 333 base::MessageLoop::QuitWhenIdleClosure()); | 339 base::MessageLoop::QuitWhenIdleClosure()); |
| 334 base::MessageLoop::current()->Run(); | 340 base::MessageLoop::current()->Run(); |
| 335 | 341 |
| 336 EXPECT_TRUE(saw_install()); | 342 EXPECT_TRUE(saw_install()); |
| 337 EXPECT_EQ(0, browser_open_count()); | 343 EXPECT_EQ(0, browser_open_count()); |
| 338 } | 344 } |
| OLD | NEW |