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

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

Issue 7599019: Allow sync integration tests to operate on multiple datatypes: Apps, Extensions, Themes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indents Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/live_sync/live_sync_extension_helper.h ('k') | chrome/test/live_sync/live_themes_sync_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/live_sync/live_sync_extension_helper.cc
diff --git a/chrome/test/live_sync/live_sync_extension_helper.cc b/chrome/test/live_sync/live_sync_extension_helper.cc
deleted file mode 100644
index c58251b3dcfd4dbea5bb095a36df630bcbc27342..0000000000000000000000000000000000000000
--- a/chrome/test/live_sync/live_sync_extension_helper.cc
+++ /dev/null
@@ -1,348 +0,0 @@
-// Copyright (c) 2011 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_sync_extension_helper.h"
-
-#include "base/file_path.h"
-#include "base/file_util.h"
-#include "base/logging.h"
-#include "base/values.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/pending_extension_info.h"
-#include "chrome/browser/extensions/pending_extension_manager.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/extensions/extension_constants.h"
-#include "chrome/test/live_sync/live_sync_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-LiveSyncExtensionHelper::ExtensionState::ExtensionState()
- : enabled_state(ENABLED), incognito_enabled(false) {}
-
-LiveSyncExtensionHelper::ExtensionState::~ExtensionState() {}
-
-bool LiveSyncExtensionHelper::ExtensionState::Equals(
- const LiveSyncExtensionHelper::ExtensionState &other) const {
- return ((enabled_state == other.enabled_state) &&
- (incognito_enabled == other.incognito_enabled));
-}
-
-LiveSyncExtensionHelper::LiveSyncExtensionHelper() {}
-
-LiveSyncExtensionHelper::~LiveSyncExtensionHelper() {}
-
-// static
-std::string LiveSyncExtensionHelper::NameToId(const std::string& name) {
- std::string id;
- EXPECT_TRUE(Extension::GenerateId(name, &id));
- return id;
-}
-
-void LiveSyncExtensionHelper::Setup(LiveSyncTest* test) {
- for (int i = 0; i < test->num_clients(); ++i) {
- SetupProfile(test->GetProfile(i));
- }
- SetupProfile(test->verifier());
-}
-
-void LiveSyncExtensionHelper::InstallExtension(
- Profile* profile, const std::string& name, Extension::Type type) {
- scoped_refptr<Extension> extension = GetExtension(profile, name, type);
- ASSERT_TRUE(extension.get()) << "Could not get extension " << name
- << " (profile = " << profile << ")";
- profile->GetExtensionService()->OnExtensionInstalled(
- extension, extension->UpdatesFromGallery());
-}
-
-void LiveSyncExtensionHelper::UninstallExtension(
- Profile* profile, const std::string& name) {
- ExtensionService::UninstallExtensionHelper(profile->GetExtensionService(),
- NameToId(name));
-}
-
-std::vector<std::string> LiveSyncExtensionHelper::GetInstalledExtensionNames(
- Profile* profile) const {
- std::vector<std::string> names;
- ExtensionService* extension_service = profile->GetExtensionService();
-
- const ExtensionList* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
- it != extensions->end(); ++it) {
- names.push_back((*it)->name());
- }
-
- const ExtensionList* disabled_extensions =
- extension_service->disabled_extensions();
- for (ExtensionList::const_iterator it = disabled_extensions->begin();
- it != disabled_extensions->end(); ++it) {
- names.push_back((*it)->name());
- }
-
- const ExtensionList* terminated_extensions =
- extension_service->terminated_extensions();
- for (ExtensionList::const_iterator it = terminated_extensions->begin();
- it != terminated_extensions->end(); ++it) {
- names.push_back((*it)->name());
- }
-
- return names;
-}
-
-void LiveSyncExtensionHelper::EnableExtension(Profile* profile,
- const std::string& name) {
- profile->GetExtensionService()->EnableExtension(NameToId(name));
-}
-
-void LiveSyncExtensionHelper::DisableExtension(Profile* profile,
- const std::string& name) {
- profile->GetExtensionService()->DisableExtension(NameToId(name));
-}
-
-bool LiveSyncExtensionHelper::IsExtensionEnabled(
- Profile* profile, const std::string& name) const {
- return profile->GetExtensionService()->IsExtensionEnabled(NameToId(name));
-}
-
-void LiveSyncExtensionHelper::IncognitoEnableExtension(
- Profile* profile, const std::string& name) {
- profile->GetExtensionService()->SetIsIncognitoEnabled(NameToId(name), true);
-}
-
-void LiveSyncExtensionHelper::IncognitoDisableExtension(
- Profile* profile, const std::string& name) {
- profile->GetExtensionService()->SetIsIncognitoEnabled(NameToId(name), false);
-}
-
-bool LiveSyncExtensionHelper::IsIncognitoEnabled(
- Profile* profile, const std::string& name) const {
- return profile->GetExtensionService()->IsIncognitoEnabled(NameToId(name));
-}
-
-
-bool LiveSyncExtensionHelper::IsExtensionPendingInstallForSync(
- Profile* profile, const std::string& id) const {
- const PendingExtensionManager* pending_extension_manager =
- profile->GetExtensionService()->pending_extension_manager();
- PendingExtensionInfo info;
- if (!pending_extension_manager->GetById(id, &info)) {
- return false;
- }
- return info.is_from_sync();
-}
-
-void LiveSyncExtensionHelper::InstallExtensionsPendingForSync(
- Profile* profile, Extension::Type type) {
- // TODO(akalin): Mock out the servers that the extensions auto-update
- // mechanism talk to so as to more closely match what actually happens.
- // Background networking will need to be re-enabled for extensions tests.
-
- // We make a copy here since InstallExtension() removes the
- // extension from the extensions service's copy.
- const PendingExtensionManager* pending_extension_manager =
- profile->GetExtensionService()->pending_extension_manager();
- PendingExtensionManager::PendingExtensionMap pending_extensions(
- pending_extension_manager->begin(),
- pending_extension_manager->end());
- for (PendingExtensionManager::const_iterator it = pending_extensions.begin();
- it != pending_extensions.end(); ++it) {
- if (!it->second.is_from_sync()) {
- continue;
- }
- const std::string& id = it->first;
- StringMap::const_iterator it2 = id_to_name_.find(id);
- if (it2 == id_to_name_.end()) {
- ADD_FAILURE() << "Could not get name for id " << id
- << " (profile = " << profile->GetDebugName() << ")";
- continue;
- }
- InstallExtension(profile, it2->second, type);
- }
-}
-
-LiveSyncExtensionHelper::ExtensionStateMap
- LiveSyncExtensionHelper::GetExtensionStates(Profile* profile) {
- const std::string& profile_debug_name = profile->GetDebugName();
-
- ExtensionStateMap extension_state_map;
-
- ExtensionService* extension_service = profile->GetExtensionService();
-
- const ExtensionList* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
- it != extensions->end(); ++it) {
- const std::string& id = (*it)->id();
- extension_state_map[id].enabled_state = ExtensionState::ENABLED;
- extension_state_map[id].incognito_enabled =
- extension_service->IsIncognitoEnabled(id);
- VLOG(2) << "Extension " << (*it)->id() << " in profile "
- << profile_debug_name << " is enabled";
- }
-
- const ExtensionList* disabled_extensions =
- extension_service->disabled_extensions();
- for (ExtensionList::const_iterator it = disabled_extensions->begin();
- it != disabled_extensions->end(); ++it) {
- const std::string& id = (*it)->id();
- extension_state_map[id].enabled_state = ExtensionState::DISABLED;
- extension_state_map[id].incognito_enabled =
- extension_service->IsIncognitoEnabled(id);
- VLOG(2) << "Extension " << (*it)->id() << " in profile "
- << profile_debug_name << " is disabled";
- }
-
- const PendingExtensionManager* pending_extension_manager =
- extension_service->pending_extension_manager();
- PendingExtensionManager::const_iterator it;
- for (it = pending_extension_manager->begin();
- it != pending_extension_manager->end(); ++it) {
- const std::string& id = it->first;
- extension_state_map[id].enabled_state = ExtensionState::PENDING;
- extension_state_map[id].incognito_enabled =
- extension_service->IsIncognitoEnabled(id);
- VLOG(2) << "Extension " << it->first << " in profile "
- << profile_debug_name << " is pending";
- }
-
- return extension_state_map;
-}
-
-bool LiveSyncExtensionHelper::ExtensionStatesMatch(
- Profile* profile1, Profile* profile2) {
- const ExtensionStateMap& state_map1 = GetExtensionStates(profile1);
- const ExtensionStateMap& state_map2 = GetExtensionStates(profile2);
- if (state_map1.size() != state_map2.size()) {
- VLOG(1) << "Number of extensions for profile " << profile1->GetDebugName()
- << " does not match profile " << profile2->GetDebugName();
- return false;
- }
-
- ExtensionStateMap::const_iterator it1 = state_map1.begin();
- ExtensionStateMap::const_iterator it2 = state_map2.begin();
- while (it1 != state_map1.end()) {
- if (it1->first != it2->first) {
- VLOG(1) << "Extensions for profile " << profile1->GetDebugName()
- << " do not match profile " << profile2->GetDebugName();
- return false;
- } else if (!it1->second.Equals(it2->second)) {
- VLOG(1) << "Extension states for profile " << profile1->GetDebugName()
- << " do not match profile " << profile2->GetDebugName();
- return false;
- }
- ++it1;
- ++it2;
- }
- return true;
-}
-
-void LiveSyncExtensionHelper::SetupProfile(Profile* profile) {
- profile->InitExtensions(true);
- profile_extensions_.insert(make_pair(profile, ExtensionNameMap()));
-}
-
-namespace {
-
-std::string NameToPublicKey(const std::string& name) {
- std::string public_key;
- std::string pem;
- EXPECT_TRUE(Extension::ProducePEM(name, &pem) &&
- Extension::FormatPEMForFileOutput(pem, &public_key,
- true /* is_public */));
- return public_key;
-}
-
-// TODO(akalin): Somehow unify this with MakeExtension() in
-// extension_util_unittest.cc.
-scoped_refptr<Extension> CreateExtension(
- const FilePath& base_dir, const std::string& name,
- Extension::Type type) {
- DictionaryValue source;
- source.SetString(extension_manifest_keys::kName, name);
- const std::string& public_key = NameToPublicKey(name);
- source.SetString(extension_manifest_keys::kPublicKey, public_key);
- source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
- switch (type) {
- case Extension::TYPE_EXTENSION:
- // Do nothing.
- break;
- case Extension::TYPE_THEME:
- source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
- break;
- case Extension::TYPE_HOSTED_APP:
- case Extension::TYPE_PACKAGED_APP:
- source.Set(extension_manifest_keys::kApp, new DictionaryValue());
- source.SetString(extension_manifest_keys::kLaunchWebURL,
- "http://www.example.com");
- break;
- default:
- ADD_FAILURE();
- return NULL;
- }
- const FilePath sub_dir = FilePath().AppendASCII(name);
- FilePath extension_dir;
- if (!file_util::PathExists(base_dir) &&
- !file_util::CreateDirectory(base_dir) &&
- !file_util::CreateTemporaryDirInDir(
- base_dir, sub_dir.value(), &extension_dir)) {
- ADD_FAILURE();
- return NULL;
- }
- std::string error;
- scoped_refptr<Extension> extension =
- Extension::Create(extension_dir, Extension::INTERNAL,
- source, Extension::STRICT_ERROR_CHECKS, &error);
- if (!error.empty()) {
- ADD_FAILURE() << error;
- return NULL;
- }
- if (!extension.get()) {
- ADD_FAILURE();
- return NULL;
- }
- if (extension->name() != name) {
- EXPECT_EQ(name, extension->name());
- return NULL;
- }
- if (extension->GetType() != type) {
- EXPECT_EQ(type, extension->GetType());
- return NULL;
- }
- return extension;
-}
-
-} // namespace
-
-scoped_refptr<Extension> LiveSyncExtensionHelper::GetExtension(
- Profile* profile, const std::string& name,
- Extension::Type type) {
- if (name.empty()) {
- ADD_FAILURE();
- return NULL;
- }
- ProfileExtensionNameMap::iterator it = profile_extensions_.find(profile);
- if (it == profile_extensions_.end()) {
- ADD_FAILURE();
- return NULL;
- }
- ExtensionNameMap::const_iterator it2 = it->second.find(name);
- if (it2 != it->second.end()) {
- return it2->second;
- }
-
- scoped_refptr<Extension> extension =
- CreateExtension(profile->GetExtensionService()->install_directory(),
- name, type);
- if (!extension.get()) {
- ADD_FAILURE();
- return NULL;
- }
- const std::string& expected_id = NameToId(name);
- if (extension->id() != expected_id) {
- EXPECT_EQ(expected_id, extension->id());
- return NULL;
- }
- VLOG(2) << "created extension with name = "
- << name << ", id = " << expected_id;
- (it->second)[name] = extension;
- id_to_name_[expected_id] = name;
- return extension;
-}
« no previous file with comments | « chrome/test/live_sync/live_sync_extension_helper.h ('k') | chrome/test/live_sync/live_themes_sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698