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

Unified Diff: chrome/test/live_sync/live_extensions_sync_test_base.cc

Issue 4732005: [Sync] Added some basic extension sync integration tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed whitespace Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/live_sync/live_extensions_sync_test_base.cc
diff --git a/chrome/test/live_sync/live_extensions_sync_test_base.cc b/chrome/test/live_sync/live_extensions_sync_test_base.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e8ca9dfeb4ff43e06b6fad96089282be801ba8e
--- /dev/null
+++ b/chrome/test/live_sync/live_extensions_sync_test_base.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/live_sync/live_extensions_sync_test_base.h"
+
+#include <string>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/ref_counted.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_constants.h"
+
+LiveExtensionsSyncTestBase::LiveExtensionsSyncTestBase(TestType test_type)
+ : LiveSyncTest(test_type), extension_index_(0) {}
+
+LiveExtensionsSyncTestBase::~LiveExtensionsSyncTestBase() {}
+
+namespace {
+
+// TODO(akalin): Somehow unify this with MakeExtension() in
+// extension_util_unittest.cc.
+scoped_refptr<Extension> CreateExtension(
+ const ScopedTempDir& scoped_temp_dir,
+ 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.
+ DictionaryValue source;
+ source.SetString(
+ extension_manifest_keys::kName,
+ std::string("fakeextension") + base::IntToString(index));
+ source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
+ if (is_theme) {
+ source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
+ }
+ FilePath extension_dir;
+ if (!file_util::CreateTemporaryDirInDir(
+ scoped_temp_dir.path(), FILE_PATH_LITERAL("fakeextension"),
+ &extension_dir)) {
+ return NULL;
+ }
+ std::string error;
+ scoped_refptr<Extension> extension =
+ Extension::Create(extension_dir,
+ Extension::INTERNAL, source, false, &error);
+ if (!error.empty()) {
+ LOG(WARNING) << error;
+ return NULL;
+ }
+ return extension;
+}
+
+} // namespace
+
+bool LiveExtensionsSyncTestBase::SetupClients() {
+ if (!LiveSyncTest::SetupClients())
+ return false;
+
+ for (int i = 0; i < num_clients(); ++i) {
+ GetProfile(i)->InitExtensions();
+ }
+ verifier()->InitExtensions();
+
+ if (!extension_base_dir_.CreateUniqueTempDir())
+ return false;
+
+ return true;
+}
+
+scoped_refptr<Extension> LiveExtensionsSyncTestBase::MakeTheme() {
+ scoped_refptr<Extension> theme =
+ CreateExtension(extension_base_dir_, extension_index_, true);
+ ++extension_index_;
+ if (!theme.get())
+ return false;
+ extensions_[theme->id()] = theme;
+ return theme;
+}
+
+scoped_refptr<Extension> LiveExtensionsSyncTestBase::MakeExtension() {
+ scoped_refptr<Extension> extension =
+ CreateExtension(extension_base_dir_, extension_index_, false);
+ ++extension_index_;
+ if (!extension.get())
+ return false;
+ extensions_[extension->id()] = extension;
+ return extension;
+}
+
+void LiveExtensionsSyncTestBase::InstallExtension(
+ Profile* profile, scoped_refptr<Extension> extension) {
+ CHECK(profile);
+ CHECK(extension.get());
+ profile->GetExtensionsService()->OnExtensionInstalled(extension, true);
+}
+
+void LiveExtensionsSyncTestBase::InstallAllPendingExtensions(
+ Profile* profile) {
+ // TODO(akalin): Mock out the servers that the extensions
+ // auto-update mechanism talk to so as to more closely match what
+ // actually happens.
+ const PendingExtensionMap& pending_extensions =
+ profile->GetExtensionsService()->pending_extensions();
+ for (PendingExtensionMap::const_iterator it = pending_extensions.begin();
+ it != pending_extensions.end(); ++it) {
+ ExtensionMap::const_iterator it2 = extensions_.find(it->first);
+ CHECK(it2 != extensions_.end());
+ InstallExtension(profile, it2->second);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698