Commit 1d3f1668 authored by akalin@chromium.org's avatar akalin@chromium.org

[Sync] Revamp and re-enable themes/extensions sync integration tests

Remove LiveExtensionsSyncTestBase and replace it with
LiveExtensionSyncHelper.

Distinguish extensions with the same ID but installed on different profiles.

Reenable all disabled tests.

BUG=70028,66925
TEST=

Review URL: http://codereview.chromium.org/6873061

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82089 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a3622db
...@@ -3097,8 +3097,6 @@ ...@@ -3097,8 +3097,6 @@
'test/live_sync/live_autofill_sync_test.h', 'test/live_sync/live_autofill_sync_test.h',
'test/live_sync/live_bookmarks_sync_test.cc', 'test/live_sync/live_bookmarks_sync_test.cc',
'test/live_sync/live_bookmarks_sync_test.h', 'test/live_sync/live_bookmarks_sync_test.h',
'test/live_sync/live_extensions_sync_test_base.cc',
'test/live_sync/live_extensions_sync_test_base.h',
'test/live_sync/live_extensions_sync_test.cc', 'test/live_sync/live_extensions_sync_test.cc',
'test/live_sync/live_extensions_sync_test.h', 'test/live_sync/live_extensions_sync_test.h',
'test/live_sync/live_passwords_sync_test.cc', 'test/live_sync/live_passwords_sync_test.cc',
...@@ -3108,6 +3106,8 @@ ...@@ -3108,6 +3106,8 @@
'test/live_sync/live_sessions_sync_test.h', 'test/live_sync/live_sessions_sync_test.h',
'test/live_sync/live_themes_sync_test.cc', 'test/live_sync/live_themes_sync_test.cc',
'test/live_sync/live_themes_sync_test.h', 'test/live_sync/live_themes_sync_test.h',
'test/live_sync/live_sync_extension_helper.cc',
'test/live_sync/live_sync_extension_helper.h',
'test/live_sync/live_sync_test.cc', 'test/live_sync/live_sync_test.cc',
'test/live_sync/live_sync_test.h', 'test/live_sync/live_sync_test.h',
'test/live_sync/many_client_live_bookmarks_sync_test.cc', 'test/live_sync/many_client_live_bookmarks_sync_test.cc',
......
...@@ -8,27 +8,21 @@ ...@@ -8,27 +8,21 @@
#include <string> #include <string>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted.h" #include "base/string_number_conversions.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension.h"
LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type) LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type)
: LiveExtensionsSyncTestBase(test_type) {} : LiveSyncTest(test_type) {}
LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {} LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {}
bool LiveExtensionsSyncTest::HasSameExtensionsAsVerifier(int profile) { bool LiveExtensionsSyncTest::SetupClients() {
return HasSameExtensionsHelper(GetProfile(profile), if (!LiveSyncTest::SetupClients())
verifier()); return false;
}
bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { extension_helper_.Setup(this);
for (int i = 0; i < num_clients(); ++i) {
if (!HasSameExtensionsAsVerifier(i))
return false;
}
return true; return true;
} }
...@@ -39,19 +33,26 @@ enum ExtensionState { DISABLED, PENDING, ENABLED }; ...@@ -39,19 +33,26 @@ enum ExtensionState { DISABLED, PENDING, ENABLED };
typedef std::map<std::string, ExtensionState> ExtensionStateMap; typedef std::map<std::string, ExtensionState> ExtensionStateMap;
ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) { ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) {
ExtensionStateMap extension_states; const std::string& profile_name =
extensions_service->profile()->GetPath().BaseName().MaybeAsASCII();
ExtensionStateMap extension_state_map;
const ExtensionList* extensions = extensions_service->extensions(); const ExtensionList* extensions = extensions_service->extensions();
for (ExtensionList::const_iterator it = extensions->begin(); for (ExtensionList::const_iterator it = extensions->begin();
it != extensions->end(); ++it) { it != extensions->end(); ++it) {
extension_states[(*it)->id()] = ENABLED; extension_state_map[(*it)->id()] = ENABLED;
VLOG(2) << "Extension " << (*it)->id() << " in profile "
<< profile_name << " is enabled";
} }
const ExtensionList* disabled_extensions = const ExtensionList* disabled_extensions =
extensions_service->disabled_extensions(); extensions_service->disabled_extensions();
for (ExtensionList::const_iterator it = disabled_extensions->begin(); for (ExtensionList::const_iterator it = disabled_extensions->begin();
it != disabled_extensions->end(); ++it) { it != disabled_extensions->end(); ++it) {
extension_states[(*it)->id()] = DISABLED; extension_state_map[(*it)->id()] = DISABLED;
VLOG(2) << "Extension " << (*it)->id() << " in profile "
<< profile_name << " is disabled";
} }
const PendingExtensionManager* pending_extension_manager = const PendingExtensionManager* pending_extension_manager =
...@@ -59,19 +60,37 @@ ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) { ...@@ -59,19 +60,37 @@ ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) {
PendingExtensionManager::const_iterator it; PendingExtensionManager::const_iterator it;
for (it = pending_extension_manager->begin(); for (it = pending_extension_manager->begin();
it != pending_extension_manager->end(); ++it) { it != pending_extension_manager->end(); ++it) {
extension_states[it->first] = PENDING; extension_state_map[it->first] = PENDING;
VLOG(2) << "Extension " << it->first << " in profile "
<< profile_name << " is pending";
} }
return extension_states; return extension_state_map;
} }
} // namespace } // namespace
bool LiveExtensionsSyncTest::HasSameExtensionsHelper( bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() {
Profile* profile1, Profile* profile2) { ExtensionStateMap verifier_extension_state_map(
ExtensionStateMap extension_states1( GetExtensionStates(verifier()->GetExtensionService()));
GetExtensionStates(profile1->GetExtensionService())); for (int i = 0; i < num_clients(); ++i) {
ExtensionStateMap extension_states2( ExtensionStateMap extension_state_map(
GetExtensionStates(profile2->GetExtensionService())); GetExtensionStates(GetProfile(i)->GetExtensionService()));
return extension_states1 == extension_states2; if (extension_state_map != verifier_extension_state_map) {
return false;
}
}
return true;
}
void LiveExtensionsSyncTest::InstallExtension(Profile* profile, int index) {
std::string name = "fakeextension" + base::IntToString(index);
return extension_helper_.InstallExtension(
profile, name, Extension::TYPE_EXTENSION);
}
void LiveExtensionsSyncTest::InstallExtensionsPendingForSync(
Profile* profile) {
extension_helper_.InstallExtensionsPendingForSync(
profile, Extension::TYPE_EXTENSION);
} }
...@@ -6,36 +6,35 @@ ...@@ -6,36 +6,35 @@
#define CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_H_ #define CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_H_
#pragma once #pragma once
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "chrome/test/live_sync/live_sync_extension_helper.h"
#include "base/memory/scoped_temp_dir.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/live_extensions_sync_test_base.h"
class Extension;
class Profile; class Profile;
class LiveExtensionsSyncTest : public LiveExtensionsSyncTestBase { class LiveExtensionsSyncTest : public LiveSyncTest {
public: public:
explicit LiveExtensionsSyncTest(TestType test_type); explicit LiveExtensionsSyncTest(TestType test_type);
virtual ~LiveExtensionsSyncTest(); virtual ~LiveExtensionsSyncTest();
protected: protected:
// Returns true iff the given profile has the same extensions as the // Like LiveSyncTest::SetupClients(), but also sets up
// verifier. // |extension_helper_|.
bool HasSameExtensionsAsVerifier(int profile) WARN_UNUSED_RESULT; virtual bool SetupClients() OVERRIDE WARN_UNUSED_RESULT;
// Returns true iff all existing profiles have the same extensions // Returns true iff all existing profiles have the same extensions
// as the verifier. // as the verifier.
bool AllProfilesHaveSameExtensionsAsVerifier() WARN_UNUSED_RESULT; bool AllProfilesHaveSameExtensionsAsVerifier() WARN_UNUSED_RESULT;
// Installs the extension for the given index to |profile|.
void InstallExtension(Profile* profile, int index);
// Installs all pending synced extensions for |profile|.
void InstallExtensionsPendingForSync(Profile* profile);
private: private:
// Returns true iff the given two profiles have the same set of LiveSyncExtensionHelper extension_helper_;
// enabled, disabled, and pending extensions.
static bool HasSameExtensionsHelper(
Profile* profile1, Profile* profile2) WARN_UNUSED_RESULT;
DISALLOW_COPY_AND_ASSIGN(LiveExtensionsSyncTest); DISALLOW_COPY_AND_ASSIGN(LiveExtensionsSyncTest);
}; };
......
// 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_extensions_sync_test_base.h"
#include <string>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
LiveExtensionsSyncTestBase::LiveExtensionsSyncTestBase(TestType test_type)
: LiveSyncTest(test_type) {}
LiveExtensionsSyncTestBase::~LiveExtensionsSyncTestBase() {}
namespace {
// TODO(akalin): Somehow unify this with MakeExtension() in
// extension_util_unittest.cc.
scoped_refptr<Extension> CreateExtension(
const ScopedTempDir& scoped_temp_dir,
bool is_theme,
int index) {
DictionaryValue source;
std::string name_prefix = is_theme ? "faketheme" : "fakeextension";
source.SetString(
extension_manifest_keys::kName,
name_prefix + 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, Extension::STRICT_ERROR_CHECKS, &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(true);
}
verifier()->InitExtensions(true);
if (!extension_base_dir_.CreateUniqueTempDir())
return false;
return true;
}
scoped_refptr<Extension> LiveExtensionsSyncTestBase::GetExtensionHelper(
bool is_theme, int index) {
std::pair<bool, int> type_index = std::make_pair(is_theme, index);
ExtensionTypeIndexMap::const_iterator it =
extensions_by_type_index_.find(type_index);
if (it != extensions_by_type_index_.end()) {
return it->second;
}
scoped_refptr<Extension> extension =
CreateExtension(extension_base_dir_, is_theme, index);
if (!extension.get())
return NULL;
extensions_by_type_index_[type_index] = extension;
extensions_by_id_[extension->id()] = extension;
return extension;
}
scoped_refptr<Extension> LiveExtensionsSyncTestBase::GetTheme(int index) {
return GetExtensionHelper(true, index);
}
scoped_refptr<Extension> LiveExtensionsSyncTestBase::GetExtension(
int index) {
return GetExtensionHelper(false, index);
}
void LiveExtensionsSyncTestBase::InstallExtension(
Profile* profile, scoped_refptr<Extension> extension) {
CHECK(profile);
CHECK(extension.get());
profile->GetExtensionService()->OnExtensionInstalled(extension);
}
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.
// 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::const_iterator it;
for (it = pending_extension_manager->begin();
it != pending_extension_manager->end(); ++it) {
ExtensionIdMap::const_iterator it2 = extensions_by_id_.find(it->first);
CHECK(it2 != extensions_by_id_.end());
InstallExtension(profile, it2->second);
}
}
// 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.
#ifndef CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_BASE_H_
#define CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_BASE_H_
#pragma once
#include <map>
#include <string>
#include <utility>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_temp_dir.h"
#include "chrome/test/live_sync/live_sync_test.h"
class Extension;
class LiveExtensionsSyncTestBase : public LiveSyncTest {
public:
virtual ~LiveExtensionsSyncTestBase();
// Like LiveSyncTest::SetupClients(), but also initializes
// extensions for each profile.
virtual bool SetupClients() WARN_UNUSED_RESULT;
protected:
// Gets a theme based on the given index. Will always return the
// same theme given the same index.
scoped_refptr<Extension> GetTheme(int index) WARN_UNUSED_RESULT;
// Gets a extension based on the given index. Will always return the
// same extension given the same index.
scoped_refptr<Extension> GetExtension(int index) WARN_UNUSED_RESULT;
// Installs the given extension to the given profile.
static void InstallExtension(
Profile* profile, scoped_refptr<Extension> extension);
// Installs all pending extensions for the given profile.
void InstallAllPendingExtensions(Profile* profile);
private:
friend class LiveThemesSyncTest;
friend class LiveExtensionsSyncTest;
// Private to avoid inadvertent instantiation except through
// approved subclasses (above).
explicit LiveExtensionsSyncTestBase(TestType test_type);
// Returns an extension of the given type and index. Will always
// return the same extension given the same type and index.
scoped_refptr<Extension> GetExtensionHelper(
bool is_theme, int index) WARN_UNUSED_RESULT;
typedef std::map<std::pair<bool, int>, scoped_refptr<Extension> >
ExtensionTypeIndexMap;
typedef std::map<std::string, scoped_refptr<Extension> > ExtensionIdMap;
ScopedTempDir extension_base_dir_;
ExtensionTypeIndexMap extensions_by_type_index_;
ExtensionIdMap extensions_by_id_;
DISALLOW_COPY_AND_ASSIGN(LiveExtensionsSyncTestBase);
};
#endif // CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_BASE_H_
// 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"
namespace {
std::string GetProfileName(Profile* profile) {
const std::string& name = profile->GetPath().BaseName().MaybeAsASCII();
EXPECT_FALSE(name.empty());
return name;
}
} // namespace
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);
}
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 = " << GetProfileName(profile) << ")";
continue;
}
InstallExtension(profile, it2->second, type);
}
}
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");
if (type == Extension::TYPE_THEME) {
source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
} else if (type != Extension::TYPE_EXTENSION) {
// TODO(akalin): Handle other types.
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;
}
// 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.
#ifndef CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_
#define CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_
#pragma once
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "chrome/common/extensions/extension.h"
class Extension;
class LiveSyncTest;
class Profile;
class LiveSyncExtensionHelper {
public:
LiveSyncExtensionHelper();
~LiveSyncExtensionHelper();
// Returns a generated extension ID for the given name.
static std::string NameToId(const std::string& name);
// Initializes the profiles in |test| and registers them with
// internal data structures.
void Setup(LiveSyncTest* test);
// Installs the extension with the given name to |profile|.
void InstallExtension(
Profile* profile, const std::string& name, Extension::Type type);
// Returns true iff the extension with the given id is pending
// install in |profile|.
bool IsExtensionPendingInstallForSync(
Profile* profile, const std::string& id) const;
// Installs all extensions pending sync in |profile| of the given
// type.
void InstallExtensionsPendingForSync(Profile* profile, Extension::Type type);
private:
typedef std::map<std::string, scoped_refptr<Extension> > ExtensionNameMap;
typedef std::map<Profile*, ExtensionNameMap> ProfileExtensionNameMap;
typedef std::map<std::string, std::string> StringMap;
// Initializes extensions for |profile| and creates an entry in
// |profile_extensions_| for it.
void SetupProfile(Profile* profile);
// Returns an extension for the given name in |profile|. type and
// index. Two extensions with the name but different profiles will
// have the same id.
scoped_refptr<Extension> GetExtension(
Profile* profile, const std::string& name,
Extension::Type type) WARN_UNUSED_RESULT;
ProfileExtensionNameMap profile_extensions_;
StringMap id_to_name_;
DISALLOW_COPY_AND_ASSIGN(LiveSyncExtensionHelper);
};
#endif // CHROME_TEST_LIVE_SYNC_LIVE_SYNC_EXTENSION_HELPER_H_
...@@ -4,69 +4,89 @@ ...@@ -4,69 +4,89 @@
#include "chrome/test/live_sync/live_themes_sync_test.h" #include "chrome/test/live_sync/live_themes_sync_test.h"
#include <string>
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/extensions/extension_service.h" #include "base/string_number_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension.h"
namespace {
// Make a name to pass to an extension helper.
std::string MakeName(int index) {
return "faketheme" + base::IntToString(index);
}
ThemeService* GetThemeService(Profile* profile) {
return ThemeServiceFactory::GetForProfile(profile);
}
} // namespace
LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type) LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type)
: LiveExtensionsSyncTestBase(test_type) {} : LiveSyncTest(test_type) {}
LiveThemesSyncTest::~LiveThemesSyncTest() {} LiveThemesSyncTest::~LiveThemesSyncTest() {}
void LiveThemesSyncTest::SetTheme( bool LiveThemesSyncTest::SetupClients() {
Profile* profile, scoped_refptr<Extension> theme) { if (!LiveSyncTest::SetupClients())
CHECK(theme->is_theme()); return false;
InstallExtension(profile, theme);
extension_helper_.Setup(this);
return true;
} }
void LiveThemesSyncTest::SetNativeTheme(Profile* profile) { std::string LiveThemesSyncTest::GetCustomTheme(int index) const {
ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); return extension_helper_.NameToId(MakeName(index));
} }
void LiveThemesSyncTest::UseDefaultTheme(Profile* profile) { std::string LiveThemesSyncTest::GetThemeID(Profile* profile) const {
ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); return GetThemeService(profile)->GetThemeID();
} }
const Extension* LiveThemesSyncTest::GetCustomTheme( bool LiveThemesSyncTest::UsingCustomTheme(Profile* profile) const {
Profile* profile) { return GetThemeID(profile) != ThemeService::kDefaultThemeID;
return ThemeServiceFactory::GetThemeForProfile(profile);
} }
bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) { bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) const {
return !ThemeServiceFactory::GetThemeForProfile(profile) && return GetThemeService(profile)->UsingDefaultTheme();
ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme();
} }
bool LiveThemesSyncTest::UsingNativeTheme(Profile* profile) { // TODO(akalin): Move this logic into ThemeService.
bool LiveThemesSyncTest::UsingNativeTheme(Profile* profile) const {
#if defined(TOOLKIT_USES_GTK) #if defined(TOOLKIT_USES_GTK)
const bool kHasDistinctNativeTheme = true; const bool kHasDistinctNativeTheme = true;
#else #else
const bool kHasDistinctNativeTheme = false; const bool kHasDistinctNativeTheme = false;
#endif #endif
// Return true if we're not using a custom theme and we don't make a if (!kHasDistinctNativeTheme) {
// distinction between the default and the system theme, or we do return UsingDefaultTheme(profile);
// and we're not using the default theme. }
return !ThemeServiceFactory::GetThemeForProfile(profile) &&
(!kHasDistinctNativeTheme || return !UsingCustomTheme(profile) && !UsingDefaultTheme(profile);
!ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme());
} }
bool LiveThemesSyncTest::ExtensionIsPendingInstall( bool LiveThemesSyncTest::ThemeIsPendingInstall(
Profile* profile, const Extension* extension) { Profile* profile, const std::string& id) const {
const PendingExtensionManager* pending_extension_manager = return extension_helper_.IsExtensionPendingInstallForSync(profile, id);
profile->GetExtensionService()->pending_extension_manager();
return pending_extension_manager->IsIdPending(extension->id());
} }
bool LiveThemesSyncTest::HasOrWillHaveCustomTheme( bool LiveThemesSyncTest::HasOrWillHaveCustomTheme(
Profile* profile, const Extension* theme) { Profile* profile, const std::string& id) const {
return return (GetThemeID(profile) == id) || ThemeIsPendingInstall(profile, id);
(GetCustomTheme(profile) == theme) || }
ExtensionIsPendingInstall(profile, theme);
void LiveThemesSyncTest::UseCustomTheme(Profile* profile, int index) {
extension_helper_.InstallExtension(
profile, MakeName(index), Extension::TYPE_THEME);
}
void LiveThemesSyncTest::UseDefaultTheme(Profile* profile) {
GetThemeService(profile)->UseDefaultTheme();
}
void LiveThemesSyncTest::UseNativeTheme(Profile* profile) {
// TODO(akalin): Fix this inconsistent naming in the theme service.
GetThemeService(profile)->SetNativeTheme();
} }
...@@ -6,56 +6,62 @@ ...@@ -6,56 +6,62 @@
#define CHROME_TEST_LIVE_SYNC_LIVE_THEMES_SYNC_TEST_H_ #define CHROME_TEST_LIVE_SYNC_LIVE_THEMES_SYNC_TEST_H_
#pragma once #pragma once
#include <vector> #include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "chrome/test/live_sync/live_sync_extension_helper.h"
#include "base/memory/scoped_temp_dir.h" #include "chrome/test/live_sync/live_sync_test.h"
#include "chrome/test/live_sync/live_extensions_sync_test_base.h"
class Extension;
class Profile; class Profile;
class LiveThemesSyncTest : public LiveExtensionsSyncTestBase { class LiveThemesSyncTest : public LiveSyncTest {
public: public:
explicit LiveThemesSyncTest(TestType test_type); explicit LiveThemesSyncTest(TestType test_type);
virtual ~LiveThemesSyncTest(); virtual ~LiveThemesSyncTest();
protected: protected:
// Set the theme of the given profile to a custom theme from the // Like LiveSyncTest::SetupClients(), but also sets up
// given theme extension. // |extension_helper_|.
static void SetTheme(Profile* profile, scoped_refptr<Extension> theme); virtual bool SetupClients() OVERRIDE WARN_UNUSED_RESULT;
// Sets |profile| so that it uses the native theme. // Gets the unique ID of the custom theme with the given index.
void SetNativeTheme(Profile* profile); std::string GetCustomTheme(int index) const WARN_UNUSED_RESULT;
// Sets |profile| to the default theme. // Gets the ID of |profile|'s theme.
void UseDefaultTheme(Profile* profile); std::string GetThemeID(Profile* profile) const WARN_UNUSED_RESULT;
// Gets the custom theme of the given profile, or NULL if the given // Returns true iff |profile| is using a custom theme.
// profile doesn't have one. bool UsingCustomTheme(Profile* profile) const WARN_UNUSED_RESULT;
const Extension* GetCustomTheme(Profile* profile) WARN_UNUSED_RESULT;
// Returns true iff the given profile is using the default theme. // Returns true iff |profile| is using the default theme.
bool UsingDefaultTheme(Profile* profile) WARN_UNUSED_RESULT; bool UsingDefaultTheme(Profile* profile) const WARN_UNUSED_RESULT;
// Returns true iff the given profile is using the native theme. On // Returns true iff |profile| is using the native theme.
// platforms where the native theme is just the default theme, this bool UsingNativeTheme(Profile* profile) const WARN_UNUSED_RESULT;
// is equivalent to UsingDefaultTheme().
bool UsingNativeTheme(Profile* profile) WARN_UNUSED_RESULT;
// Returns true iff the given extension is pending install for the // Returns true iff a theme with the given ID is pending install in
// given profile. // |profile|.
bool ExtensionIsPendingInstall( bool ThemeIsPendingInstall(
Profile* profile, const Extension* extension) WARN_UNUSED_RESULT; Profile* profile, const std::string& id) const WARN_UNUSED_RESULT;
// Returns true iff the given profile's current theme is the given // Returns true iff |profile|'s current theme is the given
// custom theme or if the given theme is pending install. // custom theme or if the given theme is pending install.
bool HasOrWillHaveCustomTheme(Profile* profile, bool HasOrWillHaveCustomTheme(
const Extension* theme) WARN_UNUSED_RESULT; Profile* profile, const std::string& id) const WARN_UNUSED_RESULT;
// Sets |profile| to use the custom theme with the given index.
void UseCustomTheme(Profile* profile, int index);
// Sets |profile| to use the default theme.
void UseDefaultTheme(Profile* profile);
// Sets |profile| to use the native theme.
void UseNativeTheme(Profile* profile);
private: private:
LiveSyncExtensionHelper extension_helper_;
DISALLOW_COPY_AND_ASSIGN(LiveThemesSyncTest); DISALLOW_COPY_AND_ASSIGN(LiveThemesSyncTest);
}; };
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/basictypes.h" #include "base/basictypes.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/test/live_sync/live_extensions_sync_test.h" #include "chrome/test/live_sync/live_extensions_sync_test.h"
class SingleClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { class SingleClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest {
...@@ -26,15 +24,14 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, ...@@ -26,15 +24,14 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest,
ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
} }
// TODO(rsimha): Enable after http://crbug.com/70028 is fixed.
IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest,
DISABLED_StartWithSomeExtensions) { StartWithSomeExtensions) {
ASSERT_TRUE(SetupClients()); ASSERT_TRUE(SetupClients());
const int kNumExtensions = 5; const int kNumExtensions = 5;
for (int i = 0; i < kNumExtensions; ++i) { for (int i = 0; i < kNumExtensions; ++i) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
...@@ -48,8 +45,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, ...@@ -48,8 +45,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest,
const int kNumExtensions = 5; const int kNumExtensions = 5;
for (int i = 0; i < kNumExtensions; ++i) { for (int i = 0; i < kNumExtensions; ++i) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/basictypes.h" #include "base/basictypes.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/test/live_sync/live_themes_sync_test.h" #include "chrome/test/live_sync/live_themes_sync_test.h"
class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest { class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest {
...@@ -24,34 +22,34 @@ class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest { ...@@ -24,34 +22,34 @@ class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest {
IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, CustomTheme) { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, CustomTheme) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
ASSERT_EQ(NULL, GetCustomTheme(verifier())); ASSERT_FALSE(UsingCustomTheme(verifier()));
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(verifier(), GetTheme(0)); UseCustomTheme(verifier(), 0);
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
"Waiting for custom themes change.")); "Waiting for custom themes change."));
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
} }
IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(verifier(), GetTheme(0)); UseCustomTheme(verifier(), 0);
ASSERT_FALSE(UsingNativeTheme(GetProfile(0))); ASSERT_FALSE(UsingNativeTheme(GetProfile(0)));
ASSERT_FALSE(UsingNativeTheme(verifier())); ASSERT_FALSE(UsingNativeTheme(verifier()));
ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion(
"Waiting for custom themes change.")); "Waiting for custom themes change."));
SetNativeTheme(GetProfile(0)); UseNativeTheme(GetProfile(0));
SetNativeTheme(verifier()); UseNativeTheme(verifier());
ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
ASSERT_TRUE(UsingNativeTheme(verifier())); ASSERT_TRUE(UsingNativeTheme(verifier()));
...@@ -65,8 +63,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { ...@@ -65,8 +63,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) {
IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, DefaultTheme) { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, DefaultTheme) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(verifier(), GetTheme(0)); UseCustomTheme(verifier(), 0);
ASSERT_FALSE(UsingDefaultTheme(GetProfile(0))); ASSERT_FALSE(UsingDefaultTheme(GetProfile(0)));
ASSERT_FALSE(UsingDefaultTheme(verifier())); ASSERT_FALSE(UsingDefaultTheme(verifier()));
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/test/live_sync/live_extensions_sync_test.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/test/live_sync/live_extensions_sync_test.h"
#include "chrome/common/extensions/extension.h"
class TwoClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { class TwoClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest {
public: public:
...@@ -26,16 +23,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, ...@@ -26,16 +23,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest,
ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
} }
// TODO(rsimha): Enable after http://crbug.com/70028 is fixed.
IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest,
DISABLED_StartWithSameExtensions) { StartWithSameExtensions) {
ASSERT_TRUE(SetupClients()); ASSERT_TRUE(SetupClients());
const int kNumExtensions = 5; const int kNumExtensions = 5;
for (int i = 0; i < kNumExtensions; ++i) { for (int i = 0; i < kNumExtensions; ++i) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(GetProfile(1), GetExtension(i)); InstallExtension(GetProfile(1), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
...@@ -45,54 +41,52 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, ...@@ -45,54 +41,52 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest,
ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
} }
// TODO(rsimha): Remove DISABLED_ prefix after http://crbug.com/66925 is fixed.
IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest,
DISABLED_StartWithDifferentExtensions) { StartWithDifferentExtensions) {
ASSERT_TRUE(SetupClients()); ASSERT_TRUE(SetupClients());
int i = 0; int i = 0;
const int kNumCommonExtensions = 5; const int kNumCommonExtensions = 5;
for (int j = 0; j < kNumCommonExtensions; ++i, ++j) { for (int j = 0; j < kNumCommonExtensions; ++i, ++j) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(GetProfile(1), GetExtension(i)); InstallExtension(GetProfile(1), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
const int kNumProfile0Extensions = 10; const int kNumProfile0Extensions = 10;
for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) { for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
const int kNumProfile1Extensions = 10; const int kNumProfile1Extensions = 10;
for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) { for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) {
InstallExtension(GetProfile(1), GetExtension(i)); InstallExtension(GetProfile(1), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
InstallAllPendingExtensions(GetProfile(0)); InstallExtensionsPendingForSync(GetProfile(0));
InstallAllPendingExtensions(GetProfile(1)); InstallExtensionsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
} }
// TODO(rsimha): Remove DISABLED_ prefix after http://crbug.com/66925 is fixed.
IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest,
DISABLED_InstallDifferentExtensions) { InstallDifferentExtensions) {
ASSERT_TRUE(SetupClients()); ASSERT_TRUE(SetupClients());
int i = 0; int i = 0;
const int kNumCommonExtensions = 5; const int kNumCommonExtensions = 5;
for (int j = 0; j < kNumCommonExtensions; ++i, ++j) { for (int j = 0; j < kNumCommonExtensions; ++i, ++j) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(GetProfile(1), GetExtension(i)); InstallExtension(GetProfile(1), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
...@@ -101,20 +95,20 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, ...@@ -101,20 +95,20 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest,
const int kNumProfile0Extensions = 10; const int kNumProfile0Extensions = 10;
for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) { for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) {
InstallExtension(GetProfile(0), GetExtension(i)); InstallExtension(GetProfile(0), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
const int kNumProfile1Extensions = 10; const int kNumProfile1Extensions = 10;
for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) { for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) {
InstallExtension(GetProfile(1), GetExtension(i)); InstallExtension(GetProfile(1), i);
InstallExtension(verifier(), GetExtension(i)); InstallExtension(verifier(), i);
} }
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
InstallAllPendingExtensions(GetProfile(0)); InstallExtensionsPendingForSync(GetProfile(0));
InstallAllPendingExtensions(GetProfile(1)); InstallExtensionsPendingForSync(GetProfile(1));
ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier());
} }
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/basictypes.h" #include "base/basictypes.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/test/live_sync/live_themes_sync_test.h" #include "chrome/test/live_sync/live_themes_sync_test.h"
class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest {
...@@ -24,39 +22,38 @@ class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { ...@@ -24,39 +22,38 @@ class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest {
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomTheme) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomTheme) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
ASSERT_EQ(NULL, GetCustomTheme(verifier())); ASSERT_FALSE(UsingCustomTheme(verifier()));
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(verifier(), GetTheme(0)); UseCustomTheme(verifier(), 0);
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier()));
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
// TODO(akalin): Add functions to simulate when a pending extension // TODO(akalin): Add functions to simulate when a pending extension
// is installed as well as when a pending extension fails to // is installed as well as when a pending extension fails to
// install. // install.
ASSERT_TRUE(ExtensionIsPendingInstall(GetProfile(1), GetTheme(0))); ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
} }
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(GetProfile(1), GetTheme(0)); UseCustomTheme(GetProfile(1), 0);
SetTheme(verifier(), GetTheme(0)); UseCustomTheme(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
SetNativeTheme(GetProfile(0)); UseNativeTheme(GetProfile(0));
SetNativeTheme(verifier()); UseNativeTheme(verifier());
ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
ASSERT_FALSE(UsingNativeTheme(GetProfile(1)));
ASSERT_TRUE(UsingNativeTheme(verifier())); ASSERT_TRUE(UsingNativeTheme(verifier()));
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
...@@ -69,16 +66,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { ...@@ -69,16 +66,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) {
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(GetProfile(1), GetTheme(0)); UseCustomTheme(GetProfile(1), 0);
SetTheme(verifier(), GetTheme(0)); UseCustomTheme(verifier(), 0);
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
UseDefaultTheme(GetProfile(0)); UseDefaultTheme(GetProfile(0));
UseDefaultTheme(verifier()); UseDefaultTheme(verifier());
ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); ASSERT_TRUE(UsingDefaultTheme(GetProfile(0)));
ASSERT_FALSE(UsingDefaultTheme(GetProfile(1)));
ASSERT_TRUE(UsingDefaultTheme(verifier())); ASSERT_TRUE(UsingDefaultTheme(verifier()));
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
...@@ -91,7 +87,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { ...@@ -91,7 +87,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) {
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetNativeTheme(GetProfile(0)); UseNativeTheme(GetProfile(0));
UseDefaultTheme(GetProfile(1)); UseDefaultTheme(GetProfile(1));
ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(GetProfile(0)));
ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
...@@ -110,9 +106,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { ...@@ -110,9 +106,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) {
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetNativeTheme(GetProfile(1)); UseNativeTheme(GetProfile(1));
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); ASSERT_TRUE(UsingNativeTheme(GetProfile(1)));
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
...@@ -120,22 +116,22 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { ...@@ -120,22 +116,22 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) {
// TODO(akalin): Add function to wait for pending extensions to be // TODO(akalin): Add function to wait for pending extensions to be
// installed. // installed.
ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
} }
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomDefaultRace) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomDefaultRace) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
UseDefaultTheme(GetProfile(1)); UseDefaultTheme(GetProfile(1));
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); ASSERT_TRUE(UsingDefaultTheme(GetProfile(1)));
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)),
HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)));
} }
IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) {
...@@ -143,19 +139,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) { ...@@ -143,19 +139,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) {
// TODO(akalin): Generalize this to n clients. // TODO(akalin): Generalize this to n clients.
SetTheme(GetProfile(0), GetTheme(0)); UseCustomTheme(GetProfile(0), 0);
SetTheme(GetProfile(1), GetTheme(1)); UseCustomTheme(GetProfile(1), 1);
ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
ASSERT_EQ(GetTheme(1), GetCustomTheme(GetProfile(1))); ASSERT_EQ(GetCustomTheme(1), GetThemeID(GetProfile(1)));
ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(AwaitQuiescence());
bool using_theme_0 = bool using_theme_0 =
(GetCustomTheme(GetProfile(0)) == GetTheme(0)) && (GetThemeID(GetProfile(0)) == GetCustomTheme(0)) &&
HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0)); HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0));
bool using_theme_1 = bool using_theme_1 =
HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(1)) && HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(1)) &&
(GetCustomTheme(GetProfile(1)) == GetTheme(1)); (GetThemeID(GetProfile(1)) == GetCustomTheme(1));
// Equivalent to using_theme_0 xor using_theme_1. // Equivalent to using_theme_0 xor using_theme_1.
ASSERT_NE(using_theme_0, using_theme_1); ASSERT_NE(using_theme_0, using_theme_1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment