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