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

Side by Side Diff: chrome/browser/sync/test/integration/sync_extension_helper.cc

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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) 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 "chrome/browser/sync/test/integration/sync_extension_helper.h" 5 #include "chrome/browser/sync/test/integration/sync_extension_helper.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 12 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/extensions/pending_extension_info.h" 13 #include "chrome/browser/extensions/pending_extension_info.h"
14 #include "chrome/browser/extensions/pending_extension_manager.h" 14 #include "chrome/browser/extensions/pending_extension_manager.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
17 #include "chrome/browser/sync/test/integration/sync_test.h" 17 #include "chrome/browser/sync/test/integration/sync_test.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_manifest_constants.h" 19 #include "chrome/common/extensions/extension_manifest_constants.h"
20 #include "sync/api/string_ordinal.h" 20 #include "sync/api/string_ordinal.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 using extensions::Extension; 23 using extensions::Extension;
24 using extensions::Manifest;
24 25
25 SyncExtensionHelper::ExtensionState::ExtensionState() 26 SyncExtensionHelper::ExtensionState::ExtensionState()
26 : enabled_state(ENABLED), incognito_enabled(false) {} 27 : enabled_state(ENABLED), incognito_enabled(false) {}
27 28
28 SyncExtensionHelper::ExtensionState::~ExtensionState() {} 29 SyncExtensionHelper::ExtensionState::~ExtensionState() {}
29 30
30 bool SyncExtensionHelper::ExtensionState::Equals( 31 bool SyncExtensionHelper::ExtensionState::Equals(
31 const SyncExtensionHelper::ExtensionState &other) const { 32 const SyncExtensionHelper::ExtensionState &other) const {
32 return ((enabled_state == other.enabled_state) && 33 return ((enabled_state == other.enabled_state) &&
33 (incognito_enabled == other.incognito_enabled)); 34 (incognito_enabled == other.incognito_enabled));
(...skipping 23 matching lines...) Expand all
57 58
58 for (int i = 0; i < test->num_clients(); ++i) { 59 for (int i = 0; i < test->num_clients(); ++i) {
59 SetupProfile(test->GetProfile(i)); 60 SetupProfile(test->GetProfile(i));
60 } 61 }
61 SetupProfile(test->verifier()); 62 SetupProfile(test->verifier());
62 63
63 setup_completed_ = true; 64 setup_completed_ = true;
64 } 65 }
65 66
66 std::string SyncExtensionHelper::InstallExtension( 67 std::string SyncExtensionHelper::InstallExtension(
67 Profile* profile, const std::string& name, Extension::Type type) { 68 Profile* profile, const std::string& name, Manifest::Type type) {
68 scoped_refptr<Extension> extension = GetExtension(profile, name, type); 69 scoped_refptr<Extension> extension = GetExtension(profile, name, type);
69 if (!extension.get()) { 70 if (!extension.get()) {
70 NOTREACHED() << "Could not install extension " << name; 71 NOTREACHED() << "Could not install extension " << name;
71 return ""; 72 return "";
72 } 73 }
73 profile->GetExtensionService()->OnExtensionInstalled( 74 profile->GetExtensionService()->OnExtensionInstalled(
74 extension, syncer::StringOrdinal(), false /* no requirement errors */, 75 extension, syncer::StringOrdinal(), false /* no requirement errors */,
75 false /* don't wait for idle to install */); 76 false /* don't wait for idle to install */);
76 return extension->id(); 77 return extension->id();
77 } 78 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 std::string pem; 260 std::string pem;
260 EXPECT_TRUE(Extension::ProducePEM(name, &pem) && 261 EXPECT_TRUE(Extension::ProducePEM(name, &pem) &&
261 Extension::FormatPEMForFileOutput(pem, &public_key, 262 Extension::FormatPEMForFileOutput(pem, &public_key,
262 true /* is_public */)); 263 true /* is_public */));
263 return public_key; 264 return public_key;
264 } 265 }
265 266
266 // TODO(akalin): Somehow unify this with MakeExtension() in 267 // TODO(akalin): Somehow unify this with MakeExtension() in
267 // extension_util_unittest.cc. 268 // extension_util_unittest.cc.
268 scoped_refptr<Extension> CreateExtension( 269 scoped_refptr<Extension> CreateExtension(
269 const FilePath& base_dir, const std::string& name, 270 const FilePath& base_dir, const std::string& name, Manifest::Type type) {
270 Extension::Type type) {
271 DictionaryValue source; 271 DictionaryValue source;
272 source.SetString(extension_manifest_keys::kName, name); 272 source.SetString(extension_manifest_keys::kName, name);
273 const std::string& public_key = NameToPublicKey(name); 273 const std::string& public_key = NameToPublicKey(name);
274 source.SetString(extension_manifest_keys::kPublicKey, public_key); 274 source.SetString(extension_manifest_keys::kPublicKey, public_key);
275 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); 275 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
276 switch (type) { 276 switch (type) {
277 case Extension::TYPE_EXTENSION: 277 case Manifest::TYPE_EXTENSION:
278 // Do nothing. 278 // Do nothing.
279 break; 279 break;
280 case Extension::TYPE_THEME: 280 case Manifest::TYPE_THEME:
281 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); 281 source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
282 break; 282 break;
283 case Extension::TYPE_HOSTED_APP: 283 case Manifest::TYPE_HOSTED_APP:
284 case Extension::TYPE_LEGACY_PACKAGED_APP: 284 case Manifest::TYPE_LEGACY_PACKAGED_APP:
285 source.Set(extension_manifest_keys::kApp, new DictionaryValue()); 285 source.Set(extension_manifest_keys::kApp, new DictionaryValue());
286 source.SetString(extension_manifest_keys::kLaunchWebURL, 286 source.SetString(extension_manifest_keys::kLaunchWebURL,
287 "http://www.example.com"); 287 "http://www.example.com");
288 break; 288 break;
289 case Extension::TYPE_PLATFORM_APP: { 289 case Manifest::TYPE_PLATFORM_APP: {
290 source.Set(extension_manifest_keys::kApp, new DictionaryValue()); 290 source.Set(extension_manifest_keys::kApp, new DictionaryValue());
291 source.Set(extension_manifest_keys::kPlatformAppBackground, 291 source.Set(extension_manifest_keys::kPlatformAppBackground,
292 new DictionaryValue()); 292 new DictionaryValue());
293 ListValue* scripts = new ListValue(); 293 ListValue* scripts = new ListValue();
294 scripts->AppendString("main.js"); 294 scripts->AppendString("main.js");
295 source.Set(extension_manifest_keys::kPlatformAppBackgroundScripts, 295 source.Set(extension_manifest_keys::kPlatformAppBackgroundScripts,
296 scripts); 296 scripts);
297 break; 297 break;
298 } 298 }
299 default: 299 default:
300 ADD_FAILURE(); 300 ADD_FAILURE();
301 return NULL; 301 return NULL;
302 } 302 }
303 const FilePath sub_dir = FilePath().AppendASCII(name); 303 const FilePath sub_dir = FilePath().AppendASCII(name);
304 FilePath extension_dir; 304 FilePath extension_dir;
305 if (!file_util::PathExists(base_dir) && 305 if (!file_util::PathExists(base_dir) &&
306 !file_util::CreateDirectory(base_dir)) { 306 !file_util::CreateDirectory(base_dir)) {
307 ADD_FAILURE(); 307 ADD_FAILURE();
308 return NULL; 308 return NULL;
309 } 309 }
310 if (!file_util::CreateTemporaryDirInDir( 310 if (!file_util::CreateTemporaryDirInDir(
311 base_dir, sub_dir.value(), &extension_dir)) { 311 base_dir, sub_dir.value(), &extension_dir)) {
312 ADD_FAILURE(); 312 ADD_FAILURE();
313 return NULL; 313 return NULL;
314 } 314 }
315 std::string error; 315 std::string error;
316 scoped_refptr<Extension> extension = 316 scoped_refptr<Extension> extension =
317 Extension::Create(extension_dir, Extension::INTERNAL, source, 317 Extension::Create(extension_dir, Manifest::INTERNAL, source,
318 Extension::NO_FLAGS, &error); 318 Extension::NO_FLAGS, &error);
319 if (!error.empty()) { 319 if (!error.empty()) {
320 ADD_FAILURE() << error; 320 ADD_FAILURE() << error;
321 return NULL; 321 return NULL;
322 } 322 }
323 if (!extension.get()) { 323 if (!extension.get()) {
324 ADD_FAILURE(); 324 ADD_FAILURE();
325 return NULL; 325 return NULL;
326 } 326 }
327 if (extension->name() != name) { 327 if (extension->name() != name) {
328 EXPECT_EQ(name, extension->name()); 328 EXPECT_EQ(name, extension->name());
329 return NULL; 329 return NULL;
330 } 330 }
331 if (extension->GetType() != type) { 331 if (extension->GetType() != type) {
332 EXPECT_EQ(type, extension->GetType()); 332 EXPECT_EQ(type, extension->GetType());
333 return NULL; 333 return NULL;
334 } 334 }
335 return extension; 335 return extension;
336 } 336 }
337 337
338 } // namespace 338 } // namespace
339 339
340 scoped_refptr<Extension> SyncExtensionHelper::GetExtension( 340 scoped_refptr<Extension> SyncExtensionHelper::GetExtension(
341 Profile* profile, const std::string& name, 341 Profile* profile, const std::string& name, Manifest::Type type) {
342 Extension::Type type) {
343 if (name.empty()) { 342 if (name.empty()) {
344 ADD_FAILURE(); 343 ADD_FAILURE();
345 return NULL; 344 return NULL;
346 } 345 }
347 ProfileExtensionNameMap::iterator it = profile_extensions_.find(profile); 346 ProfileExtensionNameMap::iterator it = profile_extensions_.find(profile);
348 if (it == profile_extensions_.end()) { 347 if (it == profile_extensions_.end()) {
349 ADD_FAILURE(); 348 ADD_FAILURE();
350 return NULL; 349 return NULL;
351 } 350 }
352 ExtensionNameMap::const_iterator it2 = it->second.find(name); 351 ExtensionNameMap::const_iterator it2 = it->second.find(name);
(...skipping 13 matching lines...) Expand all
366 EXPECT_EQ(expected_id, extension->id()); 365 EXPECT_EQ(expected_id, extension->id());
367 return NULL; 366 return NULL;
368 } 367 }
369 DVLOG(2) << "created extension with name = " 368 DVLOG(2) << "created extension with name = "
370 << name << ", id = " << expected_id; 369 << name << ", id = " << expected_id;
371 (it->second)[name] = extension; 370 (it->second)[name] = extension;
372 id_to_name_[expected_id] = name; 371 id_to_name_[expected_id] = name;
373 id_to_type_[expected_id] = type; 372 id_to_type_[expected_id] = type;
374 return extension; 373 return extension;
375 } 374 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_extension_helper.h ('k') | chrome/browser/sync/test/integration/themes_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698