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