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

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

Issue 8488012: Fix for management API related to escalated permissions disabled extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased again Created 9 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/stringprintf.h"
5 #include "chrome/browser/extensions/extension_browsertest.h" 6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/extensions/extension_install_dialog.h"
9 #include "chrome/browser/extensions/extension_management_api.h"
10 #include "chrome/browser/extensions/extension_management_api_constants.h"
11 #include "chrome/browser/extensions/extension_service.h"
6 #include "chrome/browser/extensions/extension_test_message_listener.h" 12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_notification_types.h"
16
17 namespace keys = extension_management_api_constants;
18 namespace util = extension_function_test_utils;
7 19
8 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {}; 20 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {};
9 21
10 // We test this here instead of in an ExtensionApiTest because normal extensions 22 // We test this here instead of in an ExtensionApiTest because normal extensions
11 // are not allowed to call the install function. 23 // are not allowed to call the install function.
12 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { 24 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) {
13 ExtensionTestMessageListener listener1("ready", false); 25 ExtensionTestMessageListener listener1("ready", false);
14 ASSERT_TRUE(LoadExtension( 26 ASSERT_TRUE(LoadExtension(
15 test_data_dir_.AppendASCII("management/install_event"))); 27 test_data_dir_.AppendASCII("management/install_event")));
16 ASSERT_TRUE(listener1.WaitUntilSatisfied()); 28 ASSERT_TRUE(listener1.WaitUntilSatisfied());
(...skipping 19 matching lines...) Expand all
36 48
37 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, 49 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest,
38 LaunchAppFromBackground) { 50 LaunchAppFromBackground) {
39 ExtensionTestMessageListener listener1("success", false); 51 ExtensionTestMessageListener listener1("success", false);
40 ASSERT_TRUE(LoadExtension( 52 ASSERT_TRUE(LoadExtension(
41 test_data_dir_.AppendASCII("management/packaged_app"))); 53 test_data_dir_.AppendASCII("management/packaged_app")));
42 ASSERT_TRUE(LoadExtension( 54 ASSERT_TRUE(LoadExtension(
43 test_data_dir_.AppendASCII("management/launch_app_from_background"))); 55 test_data_dir_.AppendASCII("management/launch_app_from_background")));
44 ASSERT_TRUE(listener1.WaitUntilSatisfied()); 56 ASSERT_TRUE(listener1.WaitUntilSatisfied());
45 } 57 }
58
59 class ExtensionManagementApiEscalationTest : public ExtensionBrowserTest {
60 protected:
61 // The id of the permissions escalation test extension we use.
62 static const char kId[];
63
64 virtual void SetUpOnMainThread() OVERRIDE {
65 ExtensionService* service = browser()->profile()->GetExtensionService();
66
67 // Install low-permission version of the extension.
68 ASSERT_TRUE(InstallExtension(
69 test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1));
70 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL);
71
72 // Update to a high-permission version - it should get disabled.
73 EXPECT_TRUE(UpdateExtension(
74 kId, test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1));
75 EXPECT_TRUE(service->GetExtensionById(kId, false) == NULL);
76 EXPECT_TRUE(service->GetExtensionById(kId, true) != NULL);
77 EXPECT_TRUE(
78 service->extension_prefs()->DidExtensionEscalatePermissions(kId));
79 }
80
81 void ReEnable(bool user_gesture, const std::string& expected_error) {
82 scoped_refptr<SetEnabledFunction> function(new SetEnabledFunction);
83 if (user_gesture)
84 function->set_user_gesture(true);
85 bool response = util::RunAsyncFunction(
86 function.get(),
87 base::StringPrintf("[\"%s\", true]", kId),
88 browser(),
89 util::NONE);
90 if (expected_error.empty()) {
91 EXPECT_EQ(true, response);
92 } else {
93 EXPECT_TRUE(response == false);
94 EXPECT_EQ(expected_error, function->GetError());
95 }
96 }
97
98 };
99
100 const char ExtensionManagementApiEscalationTest::kId[] =
101 "pgdpcfcocojkjfbgpiianjngphoopgmo";
102
103 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest,
104 DisabledReason) {
105 scoped_ptr<base::Value> result(
106 util::RunFunctionAndReturnResult(new GetExtensionByIdFunction(),
107 base::StringPrintf("[\"%s\"]", kId),
108 browser()));
109 ASSERT_TRUE(result.get() != NULL);
110 ASSERT_TRUE(result->IsType(base::Value::TYPE_DICTIONARY));
111 base::DictionaryValue* dict =
112 static_cast<base::DictionaryValue*>(result.get());
113 std::string reason;
114 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason));
115 EXPECT_EQ(reason, std::string(keys::kDisabledReasonPermissionsIncrease));
116 }
117
118 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest,
119 ReEnable) {
120 // Expect an error about no gesture.
121 ReEnable(false, keys::kGestureNeededForEscalationError);
122
123 // Expect an error that user cancelled the dialog.
124 SetExtensionInstallDialogAutoConfirmForTests(false);
125 ReEnable(true, keys::kUserDidNotReEnableError);
126
127 // This should succeed when user accepts dialog.
128 SetExtensionInstallDialogAutoConfirmForTests(true);
129 ReEnable(true, "");
130 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_api.cc ('k') | chrome/browser/extensions/extension_webstore_private_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698