OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" | |
6 #include "chrome/browser/extensions/extension_browsertest.h" | 5 #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" | |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 6 #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; | |
19 | 7 |
20 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {}; | 8 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {}; |
21 | 9 |
22 // We test this here instead of in an ExtensionApiTest because normal extensions | 10 // We test this here instead of in an ExtensionApiTest because normal extensions |
23 // are not allowed to call the install function. | 11 // are not allowed to call the install function. |
24 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { | 12 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { |
25 ExtensionTestMessageListener listener1("ready", false); | 13 ExtensionTestMessageListener listener1("ready", false); |
26 ASSERT_TRUE(LoadExtension( | 14 ASSERT_TRUE(LoadExtension( |
27 test_data_dir_.AppendASCII("management/install_event"))); | 15 test_data_dir_.AppendASCII("management/install_event"))); |
28 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | 16 ASSERT_TRUE(listener1.WaitUntilSatisfied()); |
(...skipping 19 matching lines...) Expand all Loading... |
48 | 36 |
49 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, | 37 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, |
50 LaunchAppFromBackground) { | 38 LaunchAppFromBackground) { |
51 ExtensionTestMessageListener listener1("success", false); | 39 ExtensionTestMessageListener listener1("success", false); |
52 ASSERT_TRUE(LoadExtension( | 40 ASSERT_TRUE(LoadExtension( |
53 test_data_dir_.AppendASCII("management/packaged_app"))); | 41 test_data_dir_.AppendASCII("management/packaged_app"))); |
54 ASSERT_TRUE(LoadExtension( | 42 ASSERT_TRUE(LoadExtension( |
55 test_data_dir_.AppendASCII("management/launch_app_from_background"))); | 43 test_data_dir_.AppendASCII("management/launch_app_from_background"))); |
56 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | 44 ASSERT_TRUE(listener1.WaitUntilSatisfied()); |
57 } | 45 } |
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_EQ(false, response); | |
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 } | |
OLD | NEW |