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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_sync_service.h" | 12 #include "chrome/browser/extensions/extension_sync_service.h" |
13 #include "chrome/browser/extensions/updater/extension_updater.h" | 13 #include "chrome/browser/extensions/updater/extension_updater.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/global_error/global_error.h" | 16 #include "chrome/browser/ui/global_error/global_error.h" |
17 #include "chrome/browser/ui/global_error/global_error_service.h" | 17 #include "chrome/browser/ui/global_error/global_error_service.h" |
18 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 18 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 #include "content/test/net/url_request_prepackaged_interceptor.h" | 22 #include "content/test/net/url_request_prepackaged_interceptor.h" |
23 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
25 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
26 | 26 |
27 using extensions::Extension; | 27 using extensions::Extension; |
28 using extensions::ExtensionPrefs; | |
28 | 29 |
29 class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest { | 30 class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest { |
30 protected: | 31 protected: |
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
32 ExtensionBrowserTest::SetUpCommandLine(command_line); | 33 ExtensionBrowserTest::SetUpCommandLine(command_line); |
33 command_line->AppendSwitchASCII(switches::kAppsGalleryUpdateURL, | 34 command_line->AppendSwitchASCII(switches::kAppsGalleryUpdateURL, |
34 "http://localhost/autoupdate/updates.xml"); | 35 "http://localhost/autoupdate/updates.xml"); |
35 } | 36 } |
36 | 37 |
37 virtual void SetUpOnMainThread() OVERRIDE { | 38 virtual void SetUpOnMainThread() OVERRIDE { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 ASSERT_FALSE(GetExtensionDisabledGlobalError()); | 143 ASSERT_FALSE(GetExtensionDisabledGlobalError()); |
143 } | 144 } |
144 | 145 |
145 // Test that no error appears if the disable reason is unknown | 146 // Test that no error appears if the disable reason is unknown |
146 // (but probably was by the user). | 147 // (but probably was by the user). |
147 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, | 148 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, |
148 UnknownReasonSamePermissions) { | 149 UnknownReasonSamePermissions) { |
149 const Extension* extension = InstallIncreasingPermissionExtensionV1(); | 150 const Extension* extension = InstallIncreasingPermissionExtensionV1(); |
150 DisableExtension(extension->id()); | 151 DisableExtension(extension->id()); |
151 // Clear disable reason to simulate legacy disables. | 152 // Clear disable reason to simulate legacy disables. |
152 service_->extension_prefs()->ClearDisableReasons(extension->id()); | 153 ExtensionPrefs::Get(service_->profile())-> |
James Cook
2014/02/07 00:53:02
nit: I would use browser()->profile() here, in the
Ken Rockot(use gerrit already)
2014/02/10 18:53:02
Done.
| |
154 ClearDisableReasons(extension->id()); | |
153 // Upgrade to version 2. Infer from version 1 having the same permissions | 155 // Upgrade to version 2. Infer from version 1 having the same permissions |
154 // granted by the user that it was disabled by the user. | 156 // granted by the user that it was disabled by the user. |
155 extension = UpdateIncreasingPermissionExtension(extension, path_v2_, 0); | 157 extension = UpdateIncreasingPermissionExtension(extension, path_v2_, 0); |
156 ASSERT_TRUE(extension); | 158 ASSERT_TRUE(extension); |
157 ASSERT_FALSE(GetExtensionDisabledGlobalError()); | 159 ASSERT_FALSE(GetExtensionDisabledGlobalError()); |
158 } | 160 } |
159 | 161 |
160 // Test that an error appears if the disable reason is unknown | 162 // Test that an error appears if the disable reason is unknown |
161 // (but probably was for increased permissions). | 163 // (but probably was for increased permissions). |
162 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, | 164 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, |
163 UnknownReasonHigherPermissions) { | 165 UnknownReasonHigherPermissions) { |
164 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); | 166 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); |
165 // Clear disable reason to simulate legacy disables. | 167 // Clear disable reason to simulate legacy disables. |
166 service_->extension_prefs()->ClearDisableReasons(extension->id()); | 168 ExtensionPrefs::Get(service_->profile())-> |
169 ClearDisableReasons(extension->id()); | |
167 // We now have version 2 but only accepted permissions for version 1. | 170 // We now have version 2 but only accepted permissions for version 1. |
168 GlobalError* error = GetExtensionDisabledGlobalError(); | 171 GlobalError* error = GetExtensionDisabledGlobalError(); |
169 ASSERT_TRUE(error); | 172 ASSERT_TRUE(error); |
170 // Also, remove the upgrade error for version 2. | 173 // Also, remove the upgrade error for version 2. |
171 GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> | 174 GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> |
172 RemoveGlobalError(error); | 175 RemoveGlobalError(error); |
173 delete error; | 176 delete error; |
174 // Upgrade to version 3, with even higher permissions. Infer from | 177 // Upgrade to version 3, with even higher permissions. Infer from |
175 // version 2 having higher-than-granted permissions that it was disabled | 178 // version 2 having higher-than-granted permissions that it was disabled |
176 // for permissions increase. | 179 // for permissions increase. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 | 218 |
216 WaitForExtensionInstall(); | 219 WaitForExtensionInstall(); |
217 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 220 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
218 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
219 | 222 |
220 extension = service_->GetExtensionById(extension_id, true); | 223 extension = service_->GetExtensionById(extension_id, true); |
221 ASSERT_TRUE(extension); | 224 ASSERT_TRUE(extension); |
222 EXPECT_EQ("2", extension->VersionString()); | 225 EXPECT_EQ("2", extension->VersionString()); |
223 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 226 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
224 EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE, | 227 EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE, |
225 service_->extension_prefs()->GetDisableReasons(extension_id)); | 228 ExtensionPrefs::Get(service_->profile())-> |
229 GetDisableReasons(extension_id)); | |
226 EXPECT_TRUE(GetExtensionDisabledGlobalError()); | 230 EXPECT_TRUE(GetExtensionDisabledGlobalError()); |
227 } | 231 } |
OLD | NEW |