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

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

Issue 9718008: Replace extension disabled infobar with a global error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar Created 8 years, 9 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
(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_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/global_error_service.h"
11 #include "chrome/browser/ui/global_error_service_factory.h"
12 #include "chrome/common/extensions/extension.h"
13
14 class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest {
15 protected:
16 void SetUpOnMainThread() {
17 service_ = browser()->profile()->GetExtensionService();
18 }
19
20 // Returns the ExtensionDisabledGlobalError, if present.
21 // Caution: currently only supports one error at a time.
22 GlobalError* GetExtensionDisabledGlobalError() {
23 return GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
24 GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST);
25 }
26
27 // Helper function to install an extension and upgrade it to a version
28 // requiring additional permissions. Returns the new disabled Extension.
29 const Extension* InstallAndUpdateIncreasingPermissionsExtension() {
30 size_t size_before = service_->extensions()->size();
31
32 // Install the initial version, which should happen just fine.
33 const Extension* extension = InstallExtension(
34 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1);
35 if (!extension)
36 return NULL;
37 if (service_->extensions()->size() != size_before + 1)
38 return NULL;
39
40 // Upgrade to a version that wants more permissions. We should disable the
41 // extension and prompt the user to reenable.
42 if (UpdateExtension(
43 extension->id(),
44 test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1))
45 return NULL;
46 EXPECT_EQ(size_before, service_->extensions()->size());
47 if (service_->disabled_extensions()->size() != 1u)
48 return NULL;
49
50 return *service_->disabled_extensions()->begin();
51 }
52
53 ExtensionService* service_;
54 };
55
56 // Tests the process of updating an extension to one that requires higher
57 // permissions, and accepting the permissions.
58 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, AcceptPermissions) {
59 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
60 ASSERT_TRUE(extension);
61 ASSERT_TRUE(GetExtensionDisabledGlobalError());
62 const size_t size_before = service_->extensions()->size();
63
64 service_->GrantPermissionsAndEnableExtension(extension);
65 EXPECT_EQ(size_before + 1, service_->extensions()->size());
66 EXPECT_EQ(0u, service_->disabled_extensions()->size());
67 ASSERT_FALSE(GetExtensionDisabledGlobalError());
68 }
69
70 // Tests uninstalling an extension that was disabled due to higher permissions.
71 IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) {
72 const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
73 ASSERT_TRUE(extension);
74 ASSERT_TRUE(GetExtensionDisabledGlobalError());
75 const size_t size_before = service_->extensions()->size();
76
77 UninstallExtension(extension->id());
78 EXPECT_EQ(size_before, service_->extensions()->size());
79 EXPECT_EQ(0u, service_->disabled_extensions()->size());
80 ASSERT_FALSE(GetExtensionDisabledGlobalError());
81 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_disabled_ui.cc ('k') | chrome/browser/extensions/extension_management_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698