Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/apps/ephemeral_app_launcher_browsertest.cc

Issue 389613006: Prevent duplicate concurrent installs of the same extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed update of webstore_result Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop/message_loop_proxy.h" 5 #include "base/message_loop/message_loop_proxy.h"
6 #include "chrome/browser/apps/ephemeral_app_launcher.h" 6 #include "chrome/browser/apps/ephemeral_app_launcher.h"
7 #include "chrome/browser/extensions/extension_install_checker.h" 7 #include "chrome/browser/extensions/extension_install_checker.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_test_message_listener.h" 9 #include "chrome/browser/extensions/extension_test_message_listener.h"
10 #include "chrome/browser/extensions/install_tracker.h"
10 #include "chrome/browser/extensions/test_blacklist.h" 11 #include "chrome/browser/extensions/test_blacklist.h"
11 #include "chrome/browser/extensions/webstore_installer_test.h" 12 #include "chrome/browser/extensions/webstore_installer_test.h"
12 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 #include "extensions/browser/extension_prefs.h" 18 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/browser/extension_registry.h" 19 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/extension_system.h" 20 #include "extensions/browser/extension_system.h"
20 #include "extensions/browser/extension_util.h" 21 #include "extensions/browser/extension_util.h"
21 #include "extensions/browser/management_policy.h" 22 #include "extensions/browser/management_policy.h"
22 23
23 using extensions::Extension; 24 using extensions::Extension;
24 using extensions::ExtensionPrefs; 25 using extensions::ExtensionPrefs;
25 using extensions::ExtensionRegistry; 26 using extensions::ExtensionRegistry;
26 using extensions::ExtensionSystem; 27 using extensions::ExtensionSystem;
28 using extensions::InstallTracker;
27 namespace webstore_install = extensions::webstore_install; 29 namespace webstore_install = extensions::webstore_install;
28 30
29 namespace { 31 namespace {
30 32
31 const char kWebstoreDomain[] = "cws.com"; 33 const char kWebstoreDomain[] = "cws.com";
32 const char kAppDomain[] = "app.com"; 34 const char kAppDomain[] = "app.com";
33 const char kNonAppDomain[] = "nonapp.com"; 35 const char kNonAppDomain[] = "nonapp.com";
34 const char kTestDataPath[] = "extensions/platform_apps/ephemeral_launcher"; 36 const char kTestDataPath[] = "extensions/platform_apps/ephemeral_launcher";
35 37
36 const char kExtensionId[] = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeid"; 38 const char kExtensionId[] = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeid";
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 EXPECT_FALSE(launched_listener.was_satisfied()); 237 EXPECT_FALSE(launched_listener.was_satisfied());
236 238
237 // Check the reference count to ensure the launcher instance will not be 239 // Check the reference count to ensure the launcher instance will not be
238 // leaked. 240 // leaked.
239 EXPECT_TRUE(launcher->HasOneRef()); 241 EXPECT_TRUE(launcher->HasOneRef());
240 } 242 }
241 243
242 void RunLaunchTest(const std::string& id, 244 void RunLaunchTest(const std::string& id,
243 webstore_install::Result expected_result, 245 webstore_install::Result expected_result,
244 bool expect_install_initiated) { 246 bool expect_install_initiated) {
247 InstallTracker* tracker = InstallTracker::Get(profile());
248 ASSERT_TRUE(tracker);
249 bool was_install_active = !!tracker->GetActiveInstall(id);
250
245 scoped_refptr<EphemeralAppLauncherForTest> launcher( 251 scoped_refptr<EphemeralAppLauncherForTest> launcher(
246 new EphemeralAppLauncherForTest(id, profile())); 252 new EphemeralAppLauncherForTest(id, profile()));
247 StartLauncherAndCheckResult( 253 StartLauncherAndCheckResult(
248 launcher.get(), expected_result, expect_install_initiated); 254 launcher.get(), expected_result, expect_install_initiated);
255
256 // Verify that the install was deregistered from the InstallTracker.
257 EXPECT_EQ(was_install_active, !!tracker->GetActiveInstall(id));
249 } 258 }
250 259
251 void ValidateAppInstalledEphemerally(const std::string& id) { 260 void ValidateAppInstalledEphemerally(const std::string& id) {
252 EXPECT_TRUE(GetInstalledExtension(id)); 261 EXPECT_TRUE(GetInstalledExtension(id));
253 EXPECT_TRUE(extensions::util::IsEphemeralApp(id, profile())); 262 EXPECT_TRUE(extensions::util::IsEphemeralApp(id, profile()));
254 } 263 }
255 264
256 const Extension* InstallAndDisableApp( 265 const Extension* InstallAndDisableApp(
257 const char* test_path, 266 const char* test_path,
258 Extension::DisableReason disable_reason) { 267 Extension::DisableReason disable_reason) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // Verifies that an installed app with unsupported requirements cannot be 521 // Verifies that an installed app with unsupported requirements cannot be
513 // launched. 522 // launched.
514 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, 523 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest,
515 LaunchAppWithUnsupportedRequirements) { 524 LaunchAppWithUnsupportedRequirements) {
516 const Extension* app = InstallAndDisableApp( 525 const Extension* app = InstallAndDisableApp(
517 kDefaultAppTestPath, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); 526 kDefaultAppTestPath, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
518 ASSERT_TRUE(app); 527 ASSERT_TRUE(app);
519 528
520 RunLaunchTest(app->id(), webstore_install::REQUIREMENT_VIOLATIONS, false); 529 RunLaunchTest(app->id(), webstore_install::REQUIREMENT_VIOLATIONS, false);
521 } 530 }
531
532 // Verifies that a launch will fail if the app is currently being installed.
533 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, InstallInProgress) {
534 extensions::ActiveInstallData install_data(kDefaultAppId);
535 InstallTracker::Get(profile())->AddActiveInstall(install_data);
536
537 RunLaunchTest(kDefaultAppId, webstore_install::INSTALL_IN_PROGRESS, false);
538 }
539
540 // Verifies that a launch will fail if a duplicate launch is in progress.
541 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, DuplicateLaunchInProgress) {
542 extensions::ActiveInstallData install_data(kDefaultAppId);
543 install_data.is_ephemeral = true;
544 InstallTracker::Get(profile())->AddActiveInstall(install_data);
545
546 RunLaunchTest(kDefaultAppId, webstore_install::LAUNCH_IN_PROGRESS, false);
547 }
OLDNEW
« no previous file with comments | « chrome/browser/apps/ephemeral_app_launcher.cc ('k') | chrome/browser/extensions/active_install_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698