Chromium Code Reviews| Index: chrome/browser/extensions/extension_disabled_ui_browsertest.cc |
| diff --git a/chrome/browser/extensions/extension_disabled_ui_browsertest.cc b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e0c611254438bb588e988a5cfbf95933becd273 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/extensions/extension_browsertest.h" |
| +#include "chrome/browser/extensions/extension_disabled_ui.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/global_error_service.h" |
| +#include "chrome/browser/ui/global_error_service_factory.h" |
| +#include "chrome/common/extensions/extension.h" |
| + |
| +// Test structure: |
| +// Load test extension |
| + |
| +class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest { |
| + protected: |
| + void SetUpOnMainThread() { |
| + service_ = browser()->profile()->GetExtensionService(); |
| + } |
| + |
| + // Returns the ExtensionDisabledGlobalError, if present. |
| + // Caution: currently only supports one error at a time. |
| + GlobalError* GetExtensionDisabledGlobalError() { |
| + return GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> |
| + GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST); |
| + } |
| + |
| + // Helper function to install an extension and upgrade it to a version |
| + // requiring additional permissions. Returns the new disabled Extension. |
| + const Extension* InstallAndUpdateIncreasingPermissionsExtension() { |
| + 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.
|
| + size_t size_before = service->extensions()->size(); |
| + |
| + // Install the initial version, which should happen just fine. |
| + const Extension* extension = InstallExtension( |
| + test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1); |
| + if (!extension) |
| + return NULL; |
| + if (service->extensions()->size() != size_before + 1) |
| + return NULL; |
| + |
| + // Upgrade to a version that wants more permissions. We should disable the |
| + // extension and prompt the user to reenable. |
| + if (UpdateExtension( |
| + extension->id(), |
| + test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1)) |
| + return NULL; |
| + EXPECT_EQ(size_before, service->extensions()->size()); |
| + if (service->disabled_extensions()->size() != 1u) |
| + return NULL; |
| + |
| + return *service->disabled_extensions()->begin(); |
| + } |
| + |
| + ExtensionService* service_; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) { |
| + const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); |
| + ASSERT_TRUE(extension); |
| + ASSERT_TRUE(GetExtensionDisabledGlobalError()); |
| + service_->GrantPermissionsAndEnableExtension(extension); |
| + ASSERT_FALSE(GetExtensionDisabledGlobalError()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) { |
| + const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension(); |
| + ASSERT_TRUE(extension); |
| + ASSERT_TRUE(GetExtensionDisabledGlobalError()); |
| + UninstallExtension(extension->id()); |
| + ASSERT_FALSE(GetExtensionDisabledGlobalError()); |
| +} |