Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/test/live_sync/live_extensions_sync_test_base.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/ref_counted.h" | |
| 13 #include "base/string_number_conversions.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/extensions/extensions_service.h" | |
| 16 #include "chrome/browser/profile.h" | |
| 17 #include "chrome/common/extensions/extension.h" | |
| 18 #include "chrome/common/extensions/extension_constants.h" | |
| 19 | |
| 20 LiveExtensionsSyncTestBase::LiveExtensionsSyncTestBase(TestType test_type) | |
| 21 : LiveSyncTest(test_type), extension_index_(0) {} | |
| 22 | |
| 23 LiveExtensionsSyncTestBase::~LiveExtensionsSyncTestBase() {} | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 // TODO(akalin): Somehow unify this with MakeExtension() in | |
| 28 // extension_util_unittest.cc. | |
| 29 scoped_refptr<Extension> CreateExtension( | |
| 30 const ScopedTempDir& scoped_temp_dir, | |
| 31 int index, bool is_theme) { | |
|
Raghu Simha
2010/11/10 21:42:41
nit: I believe the new style guide recommendation
akalin
2010/11/12 01:20:44
Done.
| |
| 32 DictionaryValue source; | |
| 33 source.SetString( | |
| 34 extension_manifest_keys::kName, | |
| 35 std::string("fakeextension") + base::IntToString(index)); | |
| 36 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | |
| 37 if (is_theme) { | |
| 38 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | |
| 39 } | |
| 40 FilePath extension_dir; | |
| 41 if (!file_util::CreateTemporaryDirInDir( | |
| 42 scoped_temp_dir.path(), FILE_PATH_LITERAL("fakeextension"), | |
| 43 &extension_dir)) { | |
| 44 return NULL; | |
| 45 } | |
| 46 std::string error; | |
| 47 scoped_refptr<Extension> extension = | |
| 48 Extension::Create(extension_dir, | |
| 49 Extension::INTERNAL, source, false, &error); | |
| 50 if (!error.empty()) { | |
| 51 LOG(WARNING) << error; | |
| 52 return NULL; | |
| 53 } | |
| 54 return extension; | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 59 bool LiveExtensionsSyncTestBase::SetupClients() { | |
| 60 if (!LiveSyncTest::SetupClients()) | |
| 61 return false; | |
| 62 | |
| 63 for (int i = 0; i < num_clients(); ++i) { | |
| 64 GetProfile(i)->InitExtensions(); | |
| 65 } | |
| 66 verifier()->InitExtensions(); | |
| 67 | |
| 68 if (!extension_base_dir_.CreateUniqueTempDir()) | |
| 69 return false; | |
| 70 | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 scoped_refptr<Extension> LiveExtensionsSyncTestBase::MakeTheme() { | |
| 75 scoped_refptr<Extension> theme = | |
| 76 CreateExtension(extension_base_dir_, extension_index_, true); | |
| 77 ++extension_index_; | |
| 78 if (!theme.get()) | |
| 79 return false; | |
| 80 extensions_[theme->id()] = theme; | |
| 81 return theme; | |
| 82 } | |
| 83 | |
| 84 scoped_refptr<Extension> LiveExtensionsSyncTestBase::MakeExtension() { | |
| 85 scoped_refptr<Extension> extension = | |
| 86 CreateExtension(extension_base_dir_, extension_index_, false); | |
| 87 ++extension_index_; | |
| 88 if (!extension.get()) | |
| 89 return false; | |
| 90 extensions_[extension->id()] = extension; | |
| 91 return extension; | |
| 92 } | |
| 93 | |
| 94 void LiveExtensionsSyncTestBase::InstallExtension( | |
| 95 Profile* profile, scoped_refptr<Extension> extension) { | |
| 96 CHECK(profile); | |
| 97 CHECK(extension.get()); | |
| 98 profile->GetExtensionsService()->OnExtensionInstalled(extension, true); | |
| 99 } | |
| 100 | |
| 101 void LiveExtensionsSyncTestBase::InstallAllPendingExtensions( | |
| 102 Profile* profile) { | |
| 103 // TODO(akalin): Mock out the servers that the extensions | |
| 104 // auto-update mechanism talk to so as to more closely match what | |
| 105 // actually happens. | |
| 106 const PendingExtensionMap& pending_extensions = | |
| 107 profile->GetExtensionsService()->pending_extensions(); | |
| 108 for (PendingExtensionMap::const_iterator it = pending_extensions.begin(); | |
| 109 it != pending_extensions.end(); ++it) { | |
| 110 ExtensionMap::const_iterator it2 = extensions_.find(it->first); | |
| 111 CHECK(it2 != extensions_.end()); | |
| 112 InstallExtension(profile, it2->second); | |
| 113 } | |
| 114 } | |
| OLD | NEW |