Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: chrome/browser/extensions/extension_apitest.cc

Issue 8733004: Make ExtensionService use ExtensionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: + Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 loaded. 205 // Test that exactly one extension is loaded, and return it.
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 int found_extension_index = -1; 209 const Extension* extension = NULL;
210 for (size_t i = 0; i < service->extensions()->size(); ++i) { 210 for (ExtensionSet::const_iterator it = service->extensions()->begin();
211 it != service->extensions()->end(); ++it) {
211 // Ignore any component extensions. They are automatically loaded into all 212 // Ignore any component extensions. They are automatically loaded into all
212 // profiles and aren't the extension we're looking for here. 213 // profiles and aren't the extension we're looking for here.
213 if (service->extensions()->at(i)->location() == Extension::COMPONENT) 214 if ((*it)->location() == Extension::COMPONENT)
214 continue; 215 continue;
215 216
216 if (found_extension_index != -1) { 217 if (extension != NULL) {
218 // TODO(yoz): this is misleading; it counts component extensions.
217 message_ = base::StringPrintf( 219 message_ = base::StringPrintf(
218 "Expected only one extension to be present. Found %u.", 220 "Expected only one extension to be present. Found %u.",
219 static_cast<unsigned>(service->extensions()->size())); 221 static_cast<unsigned>(service->extensions()->size()));
220 return NULL; 222 return NULL;
221 } 223 }
222 224
223 found_extension_index = static_cast<int>(i); 225 extension = *it;
224 } 226 }
225 227
226 const Extension* extension = service->extensions()->at(found_extension_index);
227 if (!extension) { 228 if (!extension) {
228 message_ = "extension pointer is NULL."; 229 message_ = "extension pointer is NULL.";
229 return NULL; 230 return NULL;
230 } 231 }
231 return extension; 232 return extension;
232 } 233 }
233 234
234 bool ExtensionApiTest::StartTestServer() { 235 bool ExtensionApiTest::StartTestServer() {
235 if (!test_server()->Start()) 236 if (!test_server()->Start())
236 return false; 237 return false;
237 238
238 // Build a dictionary of values that tests can use to build URLs that 239 // Build a dictionary of values that tests can use to build URLs that
239 // access the test server and local file system. Tests can see these values 240 // access the test server and local file system. Tests can see these values
240 // using the extension API function chrome.test.getConfig(). 241 // using the extension API function chrome.test.getConfig().
241 test_config_->SetInteger(kTestServerPort, 242 test_config_->SetInteger(kTestServerPort,
242 test_server()->host_port_pair().port()); 243 test_server()->host_port_pair().port());
243 244
244 return true; 245 return true;
245 } 246 }
246 247
247 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { 248 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
248 ExtensionBrowserTest::SetUpCommandLine(command_line); 249 ExtensionBrowserTest::SetUpCommandLine(command_line);
249 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); 250 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
250 } 251 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/component_loader_unittest.cc ('k') | chrome/browser/extensions/extension_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698