| 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" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/extension_install_prompt.h" | 8 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/startup_helper.h" | 10 #include "chrome/browser/extensions/startup_helper.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId)); | 172 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId)); |
| 173 RunTest("runTest"); | 173 RunTest("runTest"); |
| 174 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); | 174 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 class WebstoreStartupInstallerSupervisedUsersTest | 177 class WebstoreStartupInstallerSupervisedUsersTest |
| 178 : public WebstoreStartupInstallerTest { | 178 : public WebstoreStartupInstallerTest { |
| 179 public: | 179 public: |
| 180 // InProcessBrowserTest overrides: | 180 // InProcessBrowserTest overrides: |
| 181 virtual void SetUpCommandLine(base::CommandLine* command_line) override { | 181 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 182 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); | 182 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); |
| 183 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); | 183 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); |
| 184 } | 184 } |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest, | 187 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest, |
| 188 InstallProhibited) { | 188 InstallProhibited) { |
| 189 #if defined(OS_WIN) && defined(USE_ASH) | 189 #if defined(OS_WIN) && defined(USE_ASH) |
| 190 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 190 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 191 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 191 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 205 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 205 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 206 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); | 206 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
| 207 EXPECT_EQ(0u, infobar_service->infobar_count()); | 207 EXPECT_EQ(0u, infobar_service->infobar_count()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // The unpack failure test needs to use a different install .crx, which is | 210 // The unpack failure test needs to use a different install .crx, which is |
| 211 // specified via a command-line flag, so it needs its own test subclass. | 211 // specified via a command-line flag, so it needs its own test subclass. |
| 212 class WebstoreStartupInstallUnpackFailureTest | 212 class WebstoreStartupInstallUnpackFailureTest |
| 213 : public WebstoreStartupInstallerTest { | 213 : public WebstoreStartupInstallerTest { |
| 214 public: | 214 public: |
| 215 virtual void SetUpCommandLine(base::CommandLine* command_line) override { | 215 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 216 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); | 216 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); |
| 217 | 217 |
| 218 GURL crx_url = GenerateTestServerUrl( | 218 GURL crx_url = GenerateTestServerUrl( |
| 219 kWebstoreDomain, "malformed_extension.crx"); | 219 kWebstoreDomain, "malformed_extension.crx"); |
| 220 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 220 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 221 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 221 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 virtual void SetUpInProcessBrowserTestFixture() override { | 224 void SetUpInProcessBrowserTestFixture() override { |
| 225 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture(); | 225 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture(); |
| 226 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); | 226 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); |
| 227 } | 227 } |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest, | 230 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest, |
| 231 WebstoreStartupInstallUnpackFailureTest) { | 231 WebstoreStartupInstallUnpackFailureTest) { |
| 232 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 232 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
| 233 ExtensionInstallPrompt::ACCEPT; | 233 ExtensionInstallPrompt::ACCEPT; |
| 234 | 234 |
| 235 ui_test_utils::NavigateToURL(browser(), | 235 ui_test_utils::NavigateToURL(browser(), |
| 236 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); | 236 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); |
| 237 | 237 |
| 238 RunTest("runTest"); | 238 RunTest("runTest"); |
| 239 } | 239 } |
| 240 | 240 |
| 241 class CommandLineWebstoreInstall | 241 class CommandLineWebstoreInstall |
| 242 : public WebstoreStartupInstallerTest, | 242 : public WebstoreStartupInstallerTest, |
| 243 public content::NotificationObserver, | 243 public content::NotificationObserver, |
| 244 public extensions::ExtensionRegistryObserver { | 244 public extensions::ExtensionRegistryObserver { |
| 245 public: | 245 public: |
| 246 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} | 246 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} |
| 247 virtual ~CommandLineWebstoreInstall() {} | 247 virtual ~CommandLineWebstoreInstall() {} |
| 248 | 248 |
| 249 virtual void SetUpOnMainThread() override { | 249 void SetUpOnMainThread() override { |
| 250 WebstoreStartupInstallerTest::SetUpOnMainThread(); | 250 WebstoreStartupInstallerTest::SetUpOnMainThread(); |
| 251 extensions::ExtensionRegistry::Get(browser()->profile())->AddObserver(this); | 251 extensions::ExtensionRegistry::Get(browser()->profile())->AddObserver(this); |
| 252 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 252 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 253 content::NotificationService::AllSources()); | 253 content::NotificationService::AllSources()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 virtual void TearDownOnMainThread() override { | 256 void TearDownOnMainThread() override { |
| 257 extensions::ExtensionRegistry::Get(browser()->profile()) | 257 extensions::ExtensionRegistry::Get(browser()->profile()) |
| 258 ->RemoveObserver(this); | 258 ->RemoveObserver(this); |
| 259 WebstoreStartupInstallerTest::TearDownOnMainThread(); | 259 WebstoreStartupInstallerTest::TearDownOnMainThread(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool saw_install() { return saw_install_; } | 262 bool saw_install() { return saw_install_; } |
| 263 | 263 |
| 264 int browser_open_count() { return browser_open_count_; } | 264 int browser_open_count() { return browser_open_count_; } |
| 265 | 265 |
| 266 // NotificationObserver interface. | 266 // NotificationObserver interface. |
| 267 virtual void Observe(int type, | 267 void Observe(int type, |
| 268 const content::NotificationSource& source, | 268 const content::NotificationSource& source, |
| 269 const content::NotificationDetails& details) override { | 269 const content::NotificationDetails& details) override { |
| 270 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED); | 270 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED); |
| 271 ++browser_open_count_; | 271 ++browser_open_count_; |
| 272 } | 272 } |
| 273 | 273 |
| 274 virtual void OnExtensionWillBeInstalled( | 274 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 275 content::BrowserContext* browser_context, | 275 const extensions::Extension* extension, |
| 276 const extensions::Extension* extension, | 276 bool is_update, |
| 277 bool is_update, | 277 bool from_ephemeral, |
| 278 bool from_ephemeral, | 278 const std::string& old_name) override { |
| 279 const std::string& old_name) override { | |
| 280 EXPECT_EQ(extension->id(), kTestExtensionId); | 279 EXPECT_EQ(extension->id(), kTestExtensionId); |
| 281 saw_install_ = true; | 280 saw_install_ = true; |
| 282 } | 281 } |
| 283 | 282 |
| 284 content::NotificationRegistrar registrar_; | 283 content::NotificationRegistrar registrar_; |
| 285 | 284 |
| 286 // Have we seen an installation notification for kTestExtensionId ? | 285 // Have we seen an installation notification for kTestExtensionId ? |
| 287 bool saw_install_; | 286 bool saw_install_; |
| 288 | 287 |
| 289 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? | 288 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? |
| 290 int browser_open_count_; | 289 int browser_open_count_; |
| 291 }; | 290 }; |
| 292 | 291 |
| 293 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) { | 292 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) { |
| 294 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 293 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 295 command_line->AppendSwitchASCII( | 294 command_line->AppendSwitchASCII( |
| 296 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId); | 295 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId); |
| 297 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 296 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
| 298 ExtensionInstallPrompt::ACCEPT; | 297 ExtensionInstallPrompt::ACCEPT; |
| 299 extensions::StartupHelper helper; | 298 extensions::StartupHelper helper; |
| 300 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile())); | 299 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile())); |
| 301 EXPECT_FALSE(saw_install()); | 300 EXPECT_FALSE(saw_install()); |
| 302 EXPECT_EQ(0, browser_open_count()); | 301 EXPECT_EQ(0, browser_open_count()); |
| 303 } | 302 } |
| OLD | NEW |