OLD | NEW |
1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_test_api.h" | 10 #include "chrome/browser/extensions/extension_test_api.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 | 196 |
197 if (!catcher.GetNextResult()) { | 197 if (!catcher.GetNextResult()) { |
198 message_ = catcher.message(); | 198 message_ = catcher.message(); |
199 return false; | 199 return false; |
200 } else { | 200 } else { |
201 return true; | 201 return true; |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 // Test that exactly one extension is loaded, and return it. | 205 // Test that exactly one extension loaded. |
206 const Extension* ExtensionApiTest::GetSingleLoadedExtension() { | 206 const Extension* ExtensionApiTest::GetSingleLoadedExtension() { |
207 ExtensionService* service = browser()->profile()->GetExtensionService(); | 207 ExtensionService* service = browser()->profile()->GetExtensionService(); |
208 | 208 |
209 const Extension* extension = NULL; | 209 int found_extension_index = -1; |
210 for (ExtensionSet::const_iterator it = service->extensions()->begin(); | 210 for (size_t i = 0; i < service->extensions()->size(); ++i) { |
211 it != service->extensions()->end(); ++it) { | |
212 // Ignore any component extensions. They are automatically loaded into all | 211 // Ignore any component extensions. They are automatically loaded into all |
213 // profiles and aren't the extension we're looking for here. | 212 // profiles and aren't the extension we're looking for here. |
214 if ((*it)->location() == Extension::COMPONENT) | 213 if (service->extensions()->at(i)->location() == Extension::COMPONENT) |
215 continue; | 214 continue; |
216 | 215 |
217 if (extension != NULL) { | 216 if (found_extension_index != -1) { |
218 // TODO(yoz): this is misleading; it counts component extensions. | |
219 message_ = base::StringPrintf( | 217 message_ = base::StringPrintf( |
220 "Expected only one extension to be present. Found %u.", | 218 "Expected only one extension to be present. Found %u.", |
221 static_cast<unsigned>(service->extensions()->size())); | 219 static_cast<unsigned>(service->extensions()->size())); |
222 return NULL; | 220 return NULL; |
223 } | 221 } |
224 | 222 |
225 extension = *it; | 223 found_extension_index = static_cast<int>(i); |
226 } | 224 } |
227 | 225 |
| 226 const Extension* extension = service->extensions()->at(found_extension_index); |
228 if (!extension) { | 227 if (!extension) { |
229 message_ = "extension pointer is NULL."; | 228 message_ = "extension pointer is NULL."; |
230 return NULL; | 229 return NULL; |
231 } | 230 } |
232 return extension; | 231 return extension; |
233 } | 232 } |
234 | 233 |
235 bool ExtensionApiTest::StartTestServer() { | 234 bool ExtensionApiTest::StartTestServer() { |
236 if (!test_server()->Start()) | 235 if (!test_server()->Start()) |
237 return false; | 236 return false; |
238 | 237 |
239 // Build a dictionary of values that tests can use to build URLs that | 238 // Build a dictionary of values that tests can use to build URLs that |
240 // access the test server and local file system. Tests can see these values | 239 // access the test server and local file system. Tests can see these values |
241 // using the extension API function chrome.test.getConfig(). | 240 // using the extension API function chrome.test.getConfig(). |
242 test_config_->SetInteger(kTestServerPort, | 241 test_config_->SetInteger(kTestServerPort, |
243 test_server()->host_port_pair().port()); | 242 test_server()->host_port_pair().port()); |
244 | 243 |
245 return true; | 244 return true; |
246 } | 245 } |
247 | 246 |
248 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 247 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { |
249 ExtensionBrowserTest::SetUpCommandLine(command_line); | 248 ExtensionBrowserTest::SetUpCommandLine(command_line); |
250 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 249 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); |
251 } | 250 } |
OLD | NEW |