OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "chrome/browser/extensions/api/management/management_api.h" | 10 #include "chrome/browser/extensions/api/management/management_api.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 browser()->profile())->extension_service(); | 97 browser()->profile())->extension_service(); |
98 | 98 |
99 // Install an extension. | 99 // Install an extension. |
100 const extensions::Extension* extension = InstallExtension( | 100 const extensions::Extension* extension = InstallExtension( |
101 test_data_dir_.AppendASCII("api_test/management/enabled_extension"), 1); | 101 test_data_dir_.AppendASCII("api_test/management/enabled_extension"), 1); |
102 ASSERT_TRUE(extension); | 102 ASSERT_TRUE(extension); |
103 | 103 |
104 const std::string id = extension->id(); | 104 const std::string id = extension->id(); |
105 | 105 |
106 // Uninstall, then cancel via the confirm dialog. | 106 // Uninstall, then cancel via the confirm dialog. |
107 scoped_refptr<UninstallFunction> uninstall_function(new UninstallFunction()); | 107 scoped_refptr<ManagementUninstallFunction> uninstall_function( |
108 UninstallFunction::SetAutoConfirmForTest(false); | 108 new ManagementUninstallFunction()); |
| 109 ManagementUninstallFunction::SetAutoConfirmForTest(false); |
109 | 110 |
110 EXPECT_TRUE(MatchPattern( | 111 EXPECT_TRUE(MatchPattern( |
111 util::RunFunctionAndReturnError( | 112 util::RunFunctionAndReturnError( |
112 uninstall_function, | 113 uninstall_function, |
113 base::StringPrintf("[\"%s\", {\"showConfirmDialog\": true}]", | 114 base::StringPrintf("[\"%s\", {\"showConfirmDialog\": true}]", |
114 id.c_str()), | 115 id.c_str()), |
115 browser()), | 116 browser()), |
116 keys::kUninstallCanceledError)); | 117 keys::kUninstallCanceledError)); |
117 | 118 |
118 // Make sure the extension wasn't uninstalled. | 119 // Make sure the extension wasn't uninstalled. |
119 EXPECT_TRUE(service->GetExtensionById(id, false) != NULL); | 120 EXPECT_TRUE(service->GetExtensionById(id, false) != NULL); |
120 | 121 |
121 // Uninstall, then accept via the confirm dialog. | 122 // Uninstall, then accept via the confirm dialog. |
122 uninstall_function = new UninstallFunction(); | 123 uninstall_function = new ManagementUninstallFunction(); |
123 UninstallFunction::SetAutoConfirmForTest(true); | 124 ManagementUninstallFunction::SetAutoConfirmForTest(true); |
124 | 125 |
125 util::RunFunctionAndReturnSingleResult( | 126 util::RunFunctionAndReturnSingleResult( |
126 uninstall_function, | 127 uninstall_function, |
127 base::StringPrintf("[\"%s\", {\"showConfirmDialog\": true}]", id.c_str()), | 128 base::StringPrintf("[\"%s\", {\"showConfirmDialog\": true}]", id.c_str()), |
128 browser()); | 129 browser()); |
129 | 130 |
130 // Make sure the extension was uninstalled. | 131 // Make sure the extension was uninstalled. |
131 EXPECT_TRUE(service->GetExtensionById(id, false) == NULL); | 132 EXPECT_TRUE(service->GetExtensionById(id, false) == NULL); |
132 } | 133 } |
133 | 134 |
134 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, | 135 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, |
135 GetAllIncludesTerminated) { | 136 GetAllIncludesTerminated) { |
136 // Load an extension with a background page, so that we know it has a process | 137 // Load an extension with a background page, so that we know it has a process |
137 // running. | 138 // running. |
138 ExtensionTestMessageListener listener("ready", false); | 139 ExtensionTestMessageListener listener("ready", false); |
139 const extensions::Extension* extension = LoadExtension( | 140 const extensions::Extension* extension = LoadExtension( |
140 test_data_dir_.AppendASCII("management/install_event")); | 141 test_data_dir_.AppendASCII("management/install_event")); |
141 ASSERT_TRUE(extension); | 142 ASSERT_TRUE(extension); |
142 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 143 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
143 | 144 |
144 // The management API should list this extension. | 145 // The management API should list this extension. |
145 scoped_refptr<GetAllExtensionsFunction> function = | 146 scoped_refptr<ManagementGetAllFunction> function = |
146 new GetAllExtensionsFunction(); | 147 new ManagementGetAllFunction(); |
147 scoped_ptr<base::Value> result(util::RunFunctionAndReturnSingleResult( | 148 scoped_ptr<base::Value> result(util::RunFunctionAndReturnSingleResult( |
148 function.get(), "[]", browser())); | 149 function.get(), "[]", browser())); |
149 base::ListValue* list; | 150 base::ListValue* list; |
150 ASSERT_TRUE(result->GetAsList(&list)); | 151 ASSERT_TRUE(result->GetAsList(&list)); |
151 EXPECT_EQ(1U, list->GetSize()); | 152 EXPECT_EQ(1U, list->GetSize()); |
152 | 153 |
153 // And it should continue to do so even after it crashes. | 154 // And it should continue to do so even after it crashes. |
154 ASSERT_TRUE(CrashEnabledExtension(extension->id())); | 155 ASSERT_TRUE(CrashEnabledExtension(extension->id())); |
155 | 156 |
156 function = new GetAllExtensionsFunction(); | 157 function = new ManagementGetAllFunction(); |
157 result.reset(util::RunFunctionAndReturnSingleResult( | 158 result.reset(util::RunFunctionAndReturnSingleResult( |
158 function.get(), "[]", browser())); | 159 function.get(), "[]", browser())); |
159 ASSERT_TRUE(result->GetAsList(&list)); | 160 ASSERT_TRUE(result->GetAsList(&list)); |
160 EXPECT_EQ(1U, list->GetSize()); | 161 EXPECT_EQ(1U, list->GetSize()); |
161 } | 162 } |
162 | 163 |
163 class ExtensionManagementApiEscalationTest : | 164 class ExtensionManagementApiEscalationTest : |
164 public ExtensionManagementApiBrowserTest { | 165 public ExtensionManagementApiBrowserTest { |
165 protected: | 166 protected: |
166 // The id of the permissions escalation test extension we use. | 167 // The id of the permissions escalation test extension we use. |
(...skipping 24 matching lines...) Expand all Loading... |
191 // Update to a high-permission version - it should get disabled. | 192 // Update to a high-permission version - it should get disabled. |
192 EXPECT_FALSE(UpdateExtension(kId, path_v2, -1)); | 193 EXPECT_FALSE(UpdateExtension(kId, path_v2, -1)); |
193 EXPECT_TRUE(service->GetExtensionById(kId, false) == NULL); | 194 EXPECT_TRUE(service->GetExtensionById(kId, false) == NULL); |
194 EXPECT_TRUE(service->GetExtensionById(kId, true) != NULL); | 195 EXPECT_TRUE(service->GetExtensionById(kId, true) != NULL); |
195 EXPECT_TRUE( | 196 EXPECT_TRUE( |
196 service->extension_prefs()->DidExtensionEscalatePermissions(kId)); | 197 service->extension_prefs()->DidExtensionEscalatePermissions(kId)); |
197 } | 198 } |
198 | 199 |
199 void SetEnabled(bool enabled, bool user_gesture, | 200 void SetEnabled(bool enabled, bool user_gesture, |
200 const std::string& expected_error) { | 201 const std::string& expected_error) { |
201 scoped_refptr<SetEnabledFunction> function(new SetEnabledFunction); | 202 scoped_refptr<ManagementSetEnabledFunction> function( |
| 203 new ManagementSetEnabledFunction); |
202 const char* enabled_string = enabled ? "true" : "false"; | 204 const char* enabled_string = enabled ? "true" : "false"; |
203 if (user_gesture) | 205 if (user_gesture) |
204 function->set_user_gesture(true); | 206 function->set_user_gesture(true); |
205 bool response = util::RunFunction( | 207 bool response = util::RunFunction( |
206 function.get(), | 208 function.get(), |
207 base::StringPrintf("[\"%s\", %s]", kId, enabled_string), | 209 base::StringPrintf("[\"%s\", %s]", kId, enabled_string), |
208 browser(), | 210 browser(), |
209 util::NONE); | 211 util::NONE); |
210 if (expected_error.empty()) { | 212 if (expected_error.empty()) { |
211 EXPECT_EQ(true, response); | 213 EXPECT_EQ(true, response); |
212 } else { | 214 } else { |
213 EXPECT_TRUE(response == false); | 215 EXPECT_TRUE(response == false); |
214 EXPECT_EQ(expected_error, function->GetError()); | 216 EXPECT_EQ(expected_error, function->GetError()); |
215 } | 217 } |
216 } | 218 } |
217 | 219 |
218 | 220 |
219 private: | 221 private: |
220 base::ScopedTempDir scoped_temp_dir_; | 222 base::ScopedTempDir scoped_temp_dir_; |
221 }; | 223 }; |
222 | 224 |
223 const char ExtensionManagementApiEscalationTest::kId[] = | 225 const char ExtensionManagementApiEscalationTest::kId[] = |
224 "pgdpcfcocojkjfbgpiianjngphoopgmo"; | 226 "pgdpcfcocojkjfbgpiianjngphoopgmo"; |
225 | 227 |
226 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, | 228 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, |
227 DisabledReason) { | 229 DisabledReason) { |
228 scoped_refptr<GetExtensionByIdFunction> function = | 230 scoped_refptr<ManagementGetFunction> function = |
229 new GetExtensionByIdFunction(); | 231 new ManagementGetFunction(); |
230 scoped_ptr<base::Value> result(util::RunFunctionAndReturnSingleResult( | 232 scoped_ptr<base::Value> result(util::RunFunctionAndReturnSingleResult( |
231 function.get(), | 233 function.get(), |
232 base::StringPrintf("[\"%s\"]", kId), | 234 base::StringPrintf("[\"%s\"]", kId), |
233 browser())); | 235 browser())); |
234 ASSERT_TRUE(result.get() != NULL); | 236 ASSERT_TRUE(result.get() != NULL); |
235 ASSERT_TRUE(result->IsType(base::Value::TYPE_DICTIONARY)); | 237 ASSERT_TRUE(result->IsType(base::Value::TYPE_DICTIONARY)); |
236 base::DictionaryValue* dict = | 238 base::DictionaryValue* dict = |
237 static_cast<base::DictionaryValue*>(result.get()); | 239 static_cast<base::DictionaryValue*>(result.get()); |
238 std::string reason; | 240 std::string reason; |
239 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason)); | 241 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason)); |
(...skipping 17 matching lines...) Expand all Loading... |
257 | 259 |
258 // Crash the extension. Mock a reload by disabling and then enabling. The | 260 // Crash the extension. Mock a reload by disabling and then enabling. The |
259 // extension should be reloaded and enabled. | 261 // extension should be reloaded and enabled. |
260 ASSERT_TRUE(CrashEnabledExtension(kId)); | 262 ASSERT_TRUE(CrashEnabledExtension(kId)); |
261 SetEnabled(false, true, ""); | 263 SetEnabled(false, true, ""); |
262 SetEnabled(true, true, ""); | 264 SetEnabled(true, true, ""); |
263 const extensions::Extension* extension = browser()->profile()-> | 265 const extensions::Extension* extension = browser()->profile()-> |
264 GetExtensionService()->GetExtensionById(kId, false); | 266 GetExtensionService()->GetExtensionById(kId, false); |
265 EXPECT_TRUE(extension); | 267 EXPECT_TRUE(extension); |
266 } | 268 } |
OLD | NEW |