Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/app/chrome_command_ids.h" | |
| 6 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 7 #include "chrome/browser/extensions/extension_disabled_ui.h" | |
| 8 #include "chrome/browser/extensions/extension_service.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/browser/ui/global_error_service.h" | |
| 12 #include "chrome/browser/ui/global_error_service_factory.h" | |
| 13 #include "chrome/common/extensions/extension.h" | |
| 14 | |
| 15 // Test structure: | |
| 16 // Load test extension | |
| 17 | |
| 18 class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest { | |
| 19 protected: | |
| 20 void SetUpOnMainThread() { | |
| 21 service_ = browser()->profile()->GetExtensionService(); | |
| 22 } | |
| 23 | |
| 24 // Returns the ExtensionDisabledGlobalError, if present. | |
| 25 // Caution: currently only supports one error at a time. | |
| 26 GlobalError* GetExtensionDisabledGlobalError() { | |
| 27 return GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> | |
| 28 GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST); | |
| 29 } | |
| 30 | |
| 31 // Helper function to install an extension and upgrade it to a version | |
| 32 // requiring additional permissions. Returns the new disabled Extension. | |
| 33 const Extension* InstallAndUpdateIncreasingPermissionsExtension() { | |
| 34 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
|
Matt Perry
2012/03/20 17:05:04
nit: this is just service_
Yoyo Zhou
2012/03/20 17:45:03
Done.
| |
| 35 size_t size_before = service->extensions()->size(); | |
| 36 | |
| 37 // Install the initial version, which should happen just fine. | |
| 38 const Extension* extension = InstallExtension( | |
| 39 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); | |
| 40 if (!extension) | |
| 41 return NULL; | |
| 42 if (service->extensions()->size() != size_before + 1) | |
| 43 return NULL; | |
| 44 | |
| 45 // Upgrade to a version that wants more permissions. We should disable the | |
| 46 // extension and prompt the user to reenable. | |
| 47 if (UpdateExtension( | |
| 48 extension->id(), | |
| 49 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) | |
| 50 return NULL; | |
| 51 EXPECT_EQ(size_before, service->extensions()->size()); | |
| 52 if (service->disabled_extensions()->size() != 1u) | |
| 53 return NULL; | |
| 54 | |
| 55 return *service->disabled_extensions()->begin(); | |
| 56 } | |
| 57 | |
| 58 ExtensionService* service_; | |
| 59 }; | |
| 60 | |
| 61 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) { | |
| 62 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); | |
| 63 ASSERT_TRUE(extension); | |
| 64 ASSERT_TRUE(GetExtensionDisabledGlobalError()); | |
| 65 service_->GrantPermissionsAndEnableExtension(extension); | |
| 66 ASSERT_FALSE(GetExtensionDisabledGlobalError()); | |
| 67 } | |
| 68 | |
| 69 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) { | |
| 70 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); | |
| 71 ASSERT_TRUE(extension); | |
| 72 ASSERT_TRUE(GetExtensionDisabledGlobalError()); | |
| 73 UninstallExtension(extension->id()); | |
| 74 ASSERT_FALSE(GetExtensionDisabledGlobalError()); | |
| 75 } | |
| OLD | NEW |