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

Side by Side Diff: chrome/browser/extensions/extension_disabled_ui_browsertest.cc

Issue 10014005: Add a preference for why an extension is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "chrome/app/chrome_command_ids.h" 5 #include "chrome/app/chrome_command_ids.h"
6 #include "chrome/browser/extensions/extension_browsertest.h" 6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/extensions/extension_prefs.h"
7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/global_error.h"
10 #include "chrome/browser/ui/global_error_service.h" 12 #include "chrome/browser/ui/global_error_service.h"
11 #include "chrome/browser/ui/global_error_service_factory.h" 13 #include "chrome/browser/ui/global_error_service_factory.h"
12 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
13 15
14 class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest { 16 class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest {
15 protected: 17 protected:
16 void SetUpOnMainThread() { 18 void SetUpOnMainThread() {
17 service_ = browser()->profile()->GetExtensionService(); 19 service_ = browser()->profile()->GetExtensionService();
18 } 20 }
19 21
20 // Returns the ExtensionDisabledGlobalError, if present. 22 // Returns the ExtensionDisabledGlobalError, if present.
21 // Caution: currently only supports one error at a time. 23 // Caution: currently only supports one error at a time.
22 GlobalError* GetExtensionDisabledGlobalError() { 24 GlobalError* GetExtensionDisabledGlobalError() {
23 return GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> 25 return GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
24 GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST); 26 GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST);
25 } 27 }
26 28
27 // Helper function to install an extension and upgrade it to a version 29 // Install the initial version, which should happen just fine.
28 // requiring additional permissions. Returns the new disabled Extension. 30 const Extension* InstallIncreasingPermissionExtensionV1() {
29 const Extension* InstallAndUpdateIncreasingPermissionsExtension() {
30 size_t size_before = service_->extensions()->size(); 31 size_t size_before = service_->extensions()->size();
31
32 // Install the initial version, which should happen just fine.
33 const Extension* extension = InstallExtension( 32 const Extension* extension = InstallExtension(
34 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); 33 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1);
35 if (!extension) 34 if (!extension)
36 return NULL; 35 return NULL;
37 if (service_->extensions()->size() != size_before + 1) 36 if (service_->extensions()->size() != size_before + 1)
38 return NULL; 37 return NULL;
38 return extension;
39 }
39 40
40 // Upgrade to a version that wants more permissions. We should disable the 41 // Upgrade to a version that wants more permissions. We should disable the
41 // extension and prompt the user to reenable. 42 // extension and prompt the user to reenable.
43 const Extension* UpdateIncreasingPermissionExtension(
44 const Extension* extension,
45 const std::string& crx_file,
46 int expected_change) {
47 size_t size_before = service_->extensions()->size();
42 if (UpdateExtension( 48 if (UpdateExtension(
43 extension->id(), 49 extension->id(),
44 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) 50 test_data_dir_.AppendASCII(crx_file),
51 expected_change))
45 return NULL; 52 return NULL;
46 EXPECT_EQ(size_before, service_->extensions()->size()); 53 EXPECT_EQ(size_before + expected_change, service_->extensions()->size());
47 if (service_->disabled_extensions()->size() != 1u) 54 if (service_->disabled_extensions()->size() != 1u)
48 return NULL; 55 return NULL;
49 56
50 return *service_->disabled_extensions()->begin(); 57 return *service_->disabled_extensions()->begin();
51 } 58 }
52 59
60 // Helper function to install an extension and upgrade it to a version
61 // requiring additional permissions. Returns the new disabled Extension.
62 const Extension* InstallAndUpdateIncreasingPermissionsExtension() {
63 const Extension* extension = InstallIncreasingPermissionExtensionV1();
64 extension = UpdateIncreasingPermissionExtension(
65 extension, "permissions-high-v2.crx", -1);
66 return extension;
67 }
68
53 ExtensionService* service_; 69 ExtensionService* service_;
54 }; 70 };
55 71
56 // Tests the process of updating an extension to one that requires higher 72 // Tests the process of updating an extension to one that requires higher
57 // permissions, and accepting the permissions. 73 // permissions, and accepting the permissions.
58 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) { 74 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) {
59 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); 75 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
60 ASSERT_TRUE(extension); 76 ASSERT_TRUE(extension);
61 ASSERT_TRUE(GetExtensionDisabledGlobalError()); 77 ASSERT_TRUE(GetExtensionDisabledGlobalError());
62 const size_t size_before = service_->extensions()->size(); 78 const size_t size_before = service_->extensions()->size();
63 79
64 service_->GrantPermissionsAndEnableExtension(extension); 80 service_->GrantPermissionsAndEnableExtension(extension);
65 EXPECT_EQ(size_before + 1, service_->extensions()->size()); 81 EXPECT_EQ(size_before + 1, service_->extensions()->size());
66 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 82 EXPECT_EQ(0u, service_->disabled_extensions()->size());
67 ASSERT_FALSE(GetExtensionDisabledGlobalError()); 83 ASSERT_FALSE(GetExtensionDisabledGlobalError());
68 } 84 }
69 85
70 // Tests uninstalling an extension that was disabled due to higher permissions. 86 // Tests uninstalling an extension that was disabled due to higher permissions.
71 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) { 87 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) {
72 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); 88 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
73 ASSERT_TRUE(extension); 89 ASSERT_TRUE(extension);
74 ASSERT_TRUE(GetExtensionDisabledGlobalError()); 90 ASSERT_TRUE(GetExtensionDisabledGlobalError());
75 const size_t size_before = service_->extensions()->size(); 91 const size_t size_before = service_->extensions()->size();
76 92
77 UninstallExtension(extension->id()); 93 UninstallExtension(extension->id());
78 EXPECT_EQ(size_before, service_->extensions()->size()); 94 EXPECT_EQ(size_before, service_->extensions()->size());
79 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 95 EXPECT_EQ(0u, service_->disabled_extensions()->size());
80 ASSERT_FALSE(GetExtensionDisabledGlobalError()); 96 ASSERT_FALSE(GetExtensionDisabledGlobalError());
81 } 97 }
98
99 // Tests that no error appears if the user disabled the extension.
100 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, UserDisabled) {
101 const Extension* extension = InstallIncreasingPermissionExtensionV1();
102 DisableExtension(extension->id());
103 extension = UpdateIncreasingPermissionExtension(
104 extension, "permissions-high-v2.crx", 0);
105 ASSERT_FALSE(GetExtensionDisabledGlobalError());
106 }
107
108 // Test that no error appears if the disable reason is unknown
109 // (but probably was by the user).
110 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
111 UnknownReasonSamePermissions) {
112 const Extension* extension = InstallIncreasingPermissionExtensionV1();
113 DisableExtension(extension->id());
114 // Override disable reason to UNKNOWN to simulate legacy disables.
115 service_->extension_prefs()->SetDisableReason(
116 extension->id(), ExtensionPrefs::DISABLE_UNKNOWN);
117 // Upgrade to version 2. Infer from version 1 having the same permissions
118 // granted by the user that it was disabled by the user.
119 extension = UpdateIncreasingPermissionExtension(
120 extension, "permissions-high-v2.crx", 0);
121 ASSERT_TRUE(extension);
122 ASSERT_FALSE(GetExtensionDisabledGlobalError());
123 }
124
125 // Test that an error appears if the disable reason is unknown
126 // (but probably was for increased permissions).
127 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
128 UnknownReasonHigherPermissions) {
129 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
130 // Override disable reason to UNKNOWN to simulate legacy disables.
131 // We now have version 2 but only accepted permissions for version 1.
132 service_->extension_prefs()->SetDisableReason(
133 extension->id(), ExtensionPrefs::DISABLE_UNKNOWN);
134 GlobalError* error = GetExtensionDisabledGlobalError();
135 ASSERT_TRUE(error);
136 // Also, remove the upgrade error for version 2.
137 GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
138 RemoveGlobalError(error);
139 delete error;
140 // Upgrade to version 3, with even higher permissions. Infer from
141 // version 2 having higher-than-granted permissions that it was disabled
142 // for permissions increase.
143 extension = UpdateIncreasingPermissionExtension(
144 extension, "permissions-higher-v3.crx", 0);
Aaron Boodman 2012/04/09 20:30:48 These crx files are a maintenance problem. Just ch
Yoyo Zhou 2012/04/10 01:57:36 Done.
145 ASSERT_TRUE(extension);
146 ASSERT_TRUE(GetExtensionDisabledGlobalError());
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698