| 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 "base/scoped_observer.h" |
| 7 #include "chrome/browser/chrome_notification_types.h" | |
| 8 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/startup_helper.h" | |
| 10 #include "chrome/browser/extensions/webstore_installer_test.h" | 8 #include "chrome/browser/extensions/webstore_installer_test.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/test_switches.h" | 15 #include "chrome/test/base/test_switches.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/browser/notification_registrar.h" | |
| 20 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_types.h" | |
| 22 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 24 #include "extensions/browser/extension_host.h" | 20 #include "extensions/browser/extension_host.h" |
| 25 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/browser/extension_registry_observer.h" | |
| 27 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/install/extension_install_ui.h" | 23 #include "extensions/browser/install/extension_install_ui.h" |
| 29 #include "extensions/common/extension_builder.h" | 24 #include "extensions/common/extension_builder.h" |
| 30 #include "extensions/common/value_builder.h" | 25 #include "extensions/common/value_builder.h" |
| 31 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
| 32 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 33 | 28 |
| 34 using content::WebContents; | 29 using content::WebContents; |
| 35 using extensions::DictionaryBuilder; | 30 using extensions::DictionaryBuilder; |
| 36 using extensions::Extension; | 31 using extensions::Extension; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 218 |
| 224 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest, | 219 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest, |
| 225 WebstoreStartupInstallUnpackFailureTest) { | 220 WebstoreStartupInstallUnpackFailureTest) { |
| 226 AutoAcceptInstall(); | 221 AutoAcceptInstall(); |
| 227 | 222 |
| 228 ui_test_utils::NavigateToURL(browser(), | 223 ui_test_utils::NavigateToURL(browser(), |
| 229 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); | 224 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); |
| 230 | 225 |
| 231 RunTest("runTest"); | 226 RunTest("runTest"); |
| 232 } | 227 } |
| 233 | |
| 234 class CommandLineWebstoreInstall | |
| 235 : public WebstoreStartupInstallerTest, | |
| 236 public content::NotificationObserver, | |
| 237 public extensions::ExtensionRegistryObserver { | |
| 238 public: | |
| 239 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} | |
| 240 ~CommandLineWebstoreInstall() override {} | |
| 241 | |
| 242 void SetUpOnMainThread() override { | |
| 243 WebstoreStartupInstallerTest::SetUpOnMainThread(); | |
| 244 extensions::ExtensionRegistry::Get(browser()->profile())->AddObserver(this); | |
| 245 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | |
| 246 content::NotificationService::AllSources()); | |
| 247 } | |
| 248 | |
| 249 void TearDownOnMainThread() override { | |
| 250 extensions::ExtensionRegistry::Get(browser()->profile()) | |
| 251 ->RemoveObserver(this); | |
| 252 WebstoreStartupInstallerTest::TearDownOnMainThread(); | |
| 253 } | |
| 254 | |
| 255 bool saw_install() { return saw_install_; } | |
| 256 | |
| 257 int browser_open_count() { return browser_open_count_; } | |
| 258 | |
| 259 // NotificationObserver interface. | |
| 260 void Observe(int type, | |
| 261 const content::NotificationSource& source, | |
| 262 const content::NotificationDetails& details) override { | |
| 263 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED); | |
| 264 ++browser_open_count_; | |
| 265 } | |
| 266 | |
| 267 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | |
| 268 const extensions::Extension* extension, | |
| 269 bool is_update, | |
| 270 bool from_ephemeral, | |
| 271 const std::string& old_name) override { | |
| 272 EXPECT_EQ(extension->id(), kTestExtensionId); | |
| 273 saw_install_ = true; | |
| 274 } | |
| 275 | |
| 276 content::NotificationRegistrar registrar_; | |
| 277 | |
| 278 // Have we seen an installation notification for kTestExtensionId ? | |
| 279 bool saw_install_; | |
| 280 | |
| 281 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? | |
| 282 int browser_open_count_; | |
| 283 }; | |
| 284 | |
| 285 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) { | |
| 286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 287 command_line->AppendSwitchASCII( | |
| 288 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId); | |
| 289 AutoAcceptInstall(); | |
| 290 extensions::StartupHelper helper; | |
| 291 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile())); | |
| 292 EXPECT_FALSE(saw_install()); | |
| 293 EXPECT_EQ(0, browser_open_count()); | |
| 294 } | |
| OLD | NEW |