diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 09:45:58 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 09:45:58 +0000 |
commit | 1d3f16684e93ab5bbfd51d5fcb53ad2321157ba0 (patch) | |
tree | db685caeb5d24fc61c9394c592d404aeb71d03f9 | |
parent | 7a3622dbbbec6bb16288ff21c2f7f0112da87213 (diff) | |
download | chromium_src-1d3f16684e93ab5bbfd51d5fcb53ad2321157ba0.zip chromium_src-1d3f16684e93ab5bbfd51d5fcb53ad2321157ba0.tar.gz chromium_src-1d3f16684e93ab5bbfd51d5fcb53ad2321157ba0.tar.bz2 |
[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
-rw-r--r-- | chrome/chrome_tests.gypi | 4 | ||||
-rw-r--r-- | chrome/test/live_sync/live_extensions_sync_test.cc | 67 | ||||
-rw-r--r-- | chrome/test/live_sync/live_extensions_sync_test.h | 27 | ||||
-rw-r--r-- | chrome/test/live_sync/live_extensions_sync_test_base.cc | 126 | ||||
-rw-r--r-- | chrome/test/live_sync/live_extensions_sync_test_base.h | 69 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_extension_helper.cc | 196 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_extension_helper.h | 68 | ||||
-rw-r--r-- | chrome/test/live_sync/live_themes_sync_test.cc | 90 | ||||
-rw-r--r-- | chrome/test/live_sync/live_themes_sync_test.h | 64 | ||||
-rw-r--r-- | chrome/test/live_sync/single_client_live_extensions_sync_test.cc | 13 | ||||
-rw-r--r-- | chrome/test/live_sync/single_client_live_themes_sync_test.cc | 30 | ||||
-rw-r--r-- | chrome/test/live_sync/two_client_live_extensions_sync_test.cc | 58 | ||||
-rw-r--r-- | chrome/test/live_sync/two_client_live_themes_sync_test.cc | 78 |
13 files changed, 494 insertions, 396 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 6646ccb..1e502fe 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3097,8 +3097,6 @@ 'test/live_sync/live_autofill_sync_test.h', 'test/live_sync/live_bookmarks_sync_test.cc', '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.h', 'test/live_sync/live_passwords_sync_test.cc', @@ -3108,6 +3106,8 @@ 'test/live_sync/live_sessions_sync_test.h', 'test/live_sync/live_themes_sync_test.cc', '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.h', 'test/live_sync/many_client_live_bookmarks_sync_test.cc', diff --git a/chrome/test/live_sync/live_extensions_sync_test.cc b/chrome/test/live_sync/live_extensions_sync_test.cc index 65e5d3d..9711519 100644 --- a/chrome/test/live_sync/live_extensions_sync_test.cc +++ b/chrome/test/live_sync/live_extensions_sync_test.cc @@ -8,27 +8,21 @@ #include <string> #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/profiles/profile.h" -#include "chrome/browser/themes/theme_service.h" #include "chrome/common/extensions/extension.h" LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type) - : LiveExtensionsSyncTestBase(test_type) {} + : LiveSyncTest(test_type) {} LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {} -bool LiveExtensionsSyncTest::HasSameExtensionsAsVerifier(int profile) { - return HasSameExtensionsHelper(GetProfile(profile), - verifier()); -} +bool LiveExtensionsSyncTest::SetupClients() { + if (!LiveSyncTest::SetupClients()) + return false; -bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { - for (int i = 0; i < num_clients(); ++i) { - if (!HasSameExtensionsAsVerifier(i)) - return false; - } + extension_helper_.Setup(this); return true; } @@ -39,19 +33,26 @@ enum ExtensionState { DISABLED, PENDING, ENABLED }; typedef std::map<std::string, ExtensionState> ExtensionStateMap; 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(); for (ExtensionList::const_iterator it = extensions->begin(); 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 = extensions_service->disabled_extensions(); for (ExtensionList::const_iterator it = disabled_extensions->begin(); 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 = @@ -59,19 +60,37 @@ ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) { PendingExtensionManager::const_iterator it; for (it = pending_extension_manager->begin(); 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 -bool LiveExtensionsSyncTest::HasSameExtensionsHelper( - Profile* profile1, Profile* profile2) { - ExtensionStateMap extension_states1( - GetExtensionStates(profile1->GetExtensionService())); - ExtensionStateMap extension_states2( - GetExtensionStates(profile2->GetExtensionService())); - return extension_states1 == extension_states2; +bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { + ExtensionStateMap verifier_extension_state_map( + GetExtensionStates(verifier()->GetExtensionService())); + for (int i = 0; i < num_clients(); ++i) { + ExtensionStateMap extension_state_map( + GetExtensionStates(GetProfile(i)->GetExtensionService())); + 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); } diff --git a/chrome/test/live_sync/live_extensions_sync_test.h b/chrome/test/live_sync/live_extensions_sync_test.h index 624ca3a..c5b2fed 100644 --- a/chrome/test/live_sync/live_extensions_sync_test.h +++ b/chrome/test/live_sync/live_extensions_sync_test.h @@ -6,36 +6,35 @@ #define CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_H_ #pragma once -#include <vector> - #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_extensions_sync_test_base.h" +#include "chrome/test/live_sync/live_sync_extension_helper.h" +#include "chrome/test/live_sync/live_sync_test.h" -class Extension; class Profile; -class LiveExtensionsSyncTest : public LiveExtensionsSyncTestBase { +class LiveExtensionsSyncTest : public LiveSyncTest { public: explicit LiveExtensionsSyncTest(TestType test_type); virtual ~LiveExtensionsSyncTest(); protected: - // Returns true iff the given profile has the same extensions as the - // verifier. - bool HasSameExtensionsAsVerifier(int profile) WARN_UNUSED_RESULT; + // Like LiveSyncTest::SetupClients(), but also sets up + // |extension_helper_|. + virtual bool SetupClients() OVERRIDE WARN_UNUSED_RESULT; // Returns true iff all existing profiles have the same extensions // as the verifier. 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: - // Returns true iff the given two profiles have the same set of - // enabled, disabled, and pending extensions. - static bool HasSameExtensionsHelper( - Profile* profile1, Profile* profile2) WARN_UNUSED_RESULT; + LiveSyncExtensionHelper extension_helper_; DISALLOW_COPY_AND_ASSIGN(LiveExtensionsSyncTest); }; diff --git a/chrome/test/live_sync/live_extensions_sync_test_base.cc b/chrome/test/live_sync/live_extensions_sync_test_base.cc deleted file mode 100644 index c97da04..0000000 --- a/chrome/test/live_sync/live_extensions_sync_test_base.cc +++ /dev/null @@ -1,126 +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_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); - } -} diff --git a/chrome/test/live_sync/live_extensions_sync_test_base.h b/chrome/test/live_sync/live_extensions_sync_test_base.h deleted file mode 100644 index 16b5aa7..0000000 --- a/chrome/test/live_sync/live_extensions_sync_test_base.h +++ /dev/null @@ -1,69 +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. - -#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_ diff --git a/chrome/test/live_sync/live_sync_extension_helper.cc b/chrome/test/live_sync/live_sync_extension_helper.cc new file mode 100644 index 0000000..05a41a6 --- /dev/null +++ b/chrome/test/live_sync/live_sync_extension_helper.cc @@ -0,0 +1,196 @@ +// 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; +} diff --git a/chrome/test/live_sync/live_sync_extension_helper.h b/chrome/test/live_sync/live_sync_extension_helper.h new file mode 100644 index 0000000..3751c2c --- /dev/null +++ b/chrome/test/live_sync/live_sync_extension_helper.h @@ -0,0 +1,68 @@ +// 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_ diff --git a/chrome/test/live_sync/live_themes_sync_test.cc b/chrome/test/live_sync/live_themes_sync_test.cc index 14994a3..4e7a4eb 100644 --- a/chrome/test/live_sync/live_themes_sync_test.cc +++ b/chrome/test/live_sync/live_themes_sync_test.cc @@ -4,69 +4,89 @@ #include "chrome/test/live_sync/live_themes_sync_test.h" -#include <string> - #include "base/logging.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile.h" +#include "base/string_number_conversions.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.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) - : LiveExtensionsSyncTestBase(test_type) {} + : LiveSyncTest(test_type) {} LiveThemesSyncTest::~LiveThemesSyncTest() {} -void LiveThemesSyncTest::SetTheme( - Profile* profile, scoped_refptr<Extension> theme) { - CHECK(theme->is_theme()); - InstallExtension(profile, theme); +bool LiveThemesSyncTest::SetupClients() { + if (!LiveSyncTest::SetupClients()) + return false; + + extension_helper_.Setup(this); + return true; } -void LiveThemesSyncTest::SetNativeTheme(Profile* profile) { - ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); +std::string LiveThemesSyncTest::GetCustomTheme(int index) const { + return extension_helper_.NameToId(MakeName(index)); } -void LiveThemesSyncTest::UseDefaultTheme(Profile* profile) { - ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); +std::string LiveThemesSyncTest::GetThemeID(Profile* profile) const { + return GetThemeService(profile)->GetThemeID(); } -const Extension* LiveThemesSyncTest::GetCustomTheme( - Profile* profile) { - return ThemeServiceFactory::GetThemeForProfile(profile); +bool LiveThemesSyncTest::UsingCustomTheme(Profile* profile) const { + return GetThemeID(profile) != ThemeService::kDefaultThemeID; } -bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) { - return !ThemeServiceFactory::GetThemeForProfile(profile) && - ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme(); +bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) const { + return GetThemeService(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) const bool kHasDistinctNativeTheme = true; #else const bool kHasDistinctNativeTheme = false; #endif - // Return true if we're not using a custom theme and we don't make a - // distinction between the default and the system theme, or we do - // and we're not using the default theme. - return !ThemeServiceFactory::GetThemeForProfile(profile) && - (!kHasDistinctNativeTheme || - !ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme()); + if (!kHasDistinctNativeTheme) { + return UsingDefaultTheme(profile); + } + + return !UsingCustomTheme(profile) && !UsingDefaultTheme(profile); } -bool LiveThemesSyncTest::ExtensionIsPendingInstall( - Profile* profile, const Extension* extension) { - const PendingExtensionManager* pending_extension_manager = - profile->GetExtensionService()->pending_extension_manager(); - return pending_extension_manager->IsIdPending(extension->id()); +bool LiveThemesSyncTest::ThemeIsPendingInstall( + Profile* profile, const std::string& id) const { + return extension_helper_.IsExtensionPendingInstallForSync(profile, id); } bool LiveThemesSyncTest::HasOrWillHaveCustomTheme( - Profile* profile, const Extension* theme) { - return - (GetCustomTheme(profile) == theme) || - ExtensionIsPendingInstall(profile, theme); + Profile* profile, const std::string& id) const { + return (GetThemeID(profile) == id) || ThemeIsPendingInstall(profile, id); +} + +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(); } diff --git a/chrome/test/live_sync/live_themes_sync_test.h b/chrome/test/live_sync/live_themes_sync_test.h index 69d64fd..130b9a8 100644 --- a/chrome/test/live_sync/live_themes_sync_test.h +++ b/chrome/test/live_sync/live_themes_sync_test.h @@ -6,56 +6,62 @@ #define CHROME_TEST_LIVE_SYNC_LIVE_THEMES_SYNC_TEST_H_ #pragma once -#include <vector> +#include <string> #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_extensions_sync_test_base.h" +#include "chrome/test/live_sync/live_sync_extension_helper.h" +#include "chrome/test/live_sync/live_sync_test.h" -class Extension; class Profile; -class LiveThemesSyncTest : public LiveExtensionsSyncTestBase { +class LiveThemesSyncTest : public LiveSyncTest { public: explicit LiveThemesSyncTest(TestType test_type); virtual ~LiveThemesSyncTest(); protected: - // Set the theme of the given profile to a custom theme from the - // given theme extension. - static void SetTheme(Profile* profile, scoped_refptr<Extension> theme); + // Like LiveSyncTest::SetupClients(), but also sets up + // |extension_helper_|. + virtual bool SetupClients() OVERRIDE WARN_UNUSED_RESULT; - // Sets |profile| so that it uses the native theme. - void SetNativeTheme(Profile* profile); + // Gets the unique ID of the custom theme with the given index. + std::string GetCustomTheme(int index) const WARN_UNUSED_RESULT; - // Sets |profile| to the default theme. - void UseDefaultTheme(Profile* profile); + // Gets the ID of |profile|'s theme. + std::string GetThemeID(Profile* profile) const WARN_UNUSED_RESULT; - // Gets the custom theme of the given profile, or NULL if the given - // profile doesn't have one. - const Extension* GetCustomTheme(Profile* profile) WARN_UNUSED_RESULT; + // Returns true iff |profile| is using a custom theme. + bool UsingCustomTheme(Profile* profile) const WARN_UNUSED_RESULT; - // Returns true iff the given profile is using the default theme. - bool UsingDefaultTheme(Profile* profile) WARN_UNUSED_RESULT; + // Returns true iff |profile| is using the default theme. + bool UsingDefaultTheme(Profile* profile) const WARN_UNUSED_RESULT; - // Returns true iff the given profile is using the native theme. On - // platforms where the native theme is just the default theme, this - // is equivalent to UsingDefaultTheme(). - bool UsingNativeTheme(Profile* profile) WARN_UNUSED_RESULT; + // Returns true iff |profile| is using the native theme. + bool UsingNativeTheme(Profile* profile) const WARN_UNUSED_RESULT; - // Returns true iff the given extension is pending install for the - // given profile. - bool ExtensionIsPendingInstall( - Profile* profile, const Extension* extension) WARN_UNUSED_RESULT; + // Returns true iff a theme with the given ID is pending install in + // |profile|. + bool ThemeIsPendingInstall( + 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. - bool HasOrWillHaveCustomTheme(Profile* profile, - const Extension* theme) WARN_UNUSED_RESULT; + bool HasOrWillHaveCustomTheme( + 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: + LiveSyncExtensionHelper extension_helper_; + DISALLOW_COPY_AND_ASSIGN(LiveThemesSyncTest); }; diff --git a/chrome/test/live_sync/single_client_live_extensions_sync_test.cc b/chrome/test/live_sync/single_client_live_extensions_sync_test.cc index 801ea6a..3192692 100644 --- a/chrome/test/live_sync/single_client_live_extensions_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_extensions_sync_test.cc @@ -3,9 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" -#include "chrome/browser/profiles/profile.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" class SingleClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { @@ -26,15 +24,14 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); } -// TODO(rsimha): Enable after http://crbug.com/70028 is fixed. IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, - DISABLED_StartWithSomeExtensions) { + StartWithSomeExtensions) { ASSERT_TRUE(SetupClients()); const int kNumExtensions = 5; for (int i = 0; i < kNumExtensions; ++i) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(verifier(), i); } ASSERT_TRUE(SetupSync()); @@ -48,8 +45,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, const int kNumExtensions = 5; for (int i = 0; i < kNumExtensions; ++i) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(verifier(), i); } ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( diff --git a/chrome/test/live_sync/single_client_live_themes_sync_test.cc b/chrome/test/live_sync/single_client_live_themes_sync_test.cc index 8ae2c3b..70b4fb9 100644 --- a/chrome/test/live_sync/single_client_live_themes_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_themes_sync_test.cc @@ -3,9 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" -#include "chrome/browser/profiles/profile.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" class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest { @@ -24,34 +22,34 @@ class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, CustomTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); - ASSERT_EQ(NULL, GetCustomTheme(verifier())); + ASSERT_FALSE(UsingCustomTheme(GetProfile(0))); + ASSERT_FALSE(UsingCustomTheme(verifier())); - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(verifier(), GetTheme(0)); - ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); - ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(verifier(), 0); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( "Waiting for custom themes change.")); - ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); - ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier())); } IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(verifier(), GetTheme(0)); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(verifier(), 0); ASSERT_FALSE(UsingNativeTheme(GetProfile(0))); ASSERT_FALSE(UsingNativeTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( "Waiting for custom themes change.")); - SetNativeTheme(GetProfile(0)); - SetNativeTheme(verifier()); + UseNativeTheme(GetProfile(0)); + UseNativeTheme(verifier()); ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(verifier())); @@ -65,8 +63,8 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, DefaultTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(verifier(), GetTheme(0)); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(verifier(), 0); ASSERT_FALSE(UsingDefaultTheme(GetProfile(0))); ASSERT_FALSE(UsingDefaultTheme(verifier())); diff --git a/chrome/test/live_sync/two_client_live_extensions_sync_test.cc b/chrome/test/live_sync/two_client_live_extensions_sync_test.cc index d726f01..f4448a1 100644 --- a/chrome/test/live_sync/two_client_live_extensions_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_extensions_sync_test.cc @@ -1,12 +1,9 @@ -// 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 // found in the LICENSE file. -#include "chrome/test/live_sync/live_extensions_sync_test.h" - #include "base/basictypes.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/extensions/extension.h" +#include "chrome/test/live_sync/live_extensions_sync_test.h" class TwoClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { public: @@ -26,16 +23,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); } -// TODO(rsimha): Enable after http://crbug.com/70028 is fixed. IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, - DISABLED_StartWithSameExtensions) { + StartWithSameExtensions) { ASSERT_TRUE(SetupClients()); const int kNumExtensions = 5; for (int i = 0; i < kNumExtensions; ++i) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(GetProfile(1), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(GetProfile(1), i); + InstallExtension(verifier(), i); } ASSERT_TRUE(SetupSync()); @@ -45,54 +41,52 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); } -// TODO(rsimha): Remove DISABLED_ prefix after http://crbug.com/66925 is fixed. IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, - DISABLED_StartWithDifferentExtensions) { + StartWithDifferentExtensions) { ASSERT_TRUE(SetupClients()); int i = 0; const int kNumCommonExtensions = 5; for (int j = 0; j < kNumCommonExtensions; ++i, ++j) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(GetProfile(1), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(GetProfile(1), i); + InstallExtension(verifier(), i); } const int kNumProfile0Extensions = 10; for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(verifier(), i); } const int kNumProfile1Extensions = 10; for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) { - InstallExtension(GetProfile(1), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(1), i); + InstallExtension(verifier(), i); } ASSERT_TRUE(SetupSync()); ASSERT_TRUE(AwaitQuiescence()); - InstallAllPendingExtensions(GetProfile(0)); - InstallAllPendingExtensions(GetProfile(1)); + InstallExtensionsPendingForSync(GetProfile(0)); + InstallExtensionsPendingForSync(GetProfile(1)); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); } -// TODO(rsimha): Remove DISABLED_ prefix after http://crbug.com/66925 is fixed. IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, - DISABLED_InstallDifferentExtensions) { + InstallDifferentExtensions) { ASSERT_TRUE(SetupClients()); int i = 0; const int kNumCommonExtensions = 5; for (int j = 0; j < kNumCommonExtensions; ++i, ++j) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(GetProfile(1), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(GetProfile(1), i); + InstallExtension(verifier(), i); } ASSERT_TRUE(SetupSync()); @@ -101,20 +95,20 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, const int kNumProfile0Extensions = 10; for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) { - InstallExtension(GetProfile(0), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(0), i); + InstallExtension(verifier(), i); } const int kNumProfile1Extensions = 10; for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) { - InstallExtension(GetProfile(1), GetExtension(i)); - InstallExtension(verifier(), GetExtension(i)); + InstallExtension(GetProfile(1), i); + InstallExtension(verifier(), i); } ASSERT_TRUE(AwaitQuiescence()); - InstallAllPendingExtensions(GetProfile(0)); - InstallAllPendingExtensions(GetProfile(1)); + InstallExtensionsPendingForSync(GetProfile(0)); + InstallExtensionsPendingForSync(GetProfile(1)); ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); } diff --git a/chrome/test/live_sync/two_client_live_themes_sync_test.cc b/chrome/test/live_sync/two_client_live_themes_sync_test.cc index da5545d..a8197a7 100644 --- a/chrome/test/live_sync/two_client_live_themes_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_themes_sync_test.cc @@ -3,9 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" -#include "chrome/browser/profiles/profile.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" class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { @@ -24,39 +22,38 @@ class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); - ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); - ASSERT_EQ(NULL, GetCustomTheme(verifier())); + ASSERT_FALSE(UsingCustomTheme(GetProfile(0))); + ASSERT_FALSE(UsingCustomTheme(GetProfile(1))); + ASSERT_FALSE(UsingCustomTheme(verifier())); - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(verifier(), GetTheme(0)); - ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); - ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); - ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(verifier(), 0); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier())); 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 // is installed as well as when a pending extension fails to // install. - ASSERT_TRUE(ExtensionIsPendingInstall(GetProfile(1), GetTheme(0))); - ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); + ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0))); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier())); } IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(GetProfile(1), GetTheme(0)); - SetTheme(verifier(), GetTheme(0)); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(GetProfile(1), 0); + UseCustomTheme(verifier(), 0); ASSERT_TRUE(AwaitQuiescence()); - SetNativeTheme(GetProfile(0)); - SetNativeTheme(verifier()); + UseNativeTheme(GetProfile(0)); + UseNativeTheme(verifier()); ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); - ASSERT_FALSE(UsingNativeTheme(GetProfile(1))); ASSERT_TRUE(UsingNativeTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -69,16 +66,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(GetProfile(1), GetTheme(0)); - SetTheme(verifier(), GetTheme(0)); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(GetProfile(1), 0); + UseCustomTheme(verifier(), 0); ASSERT_TRUE(AwaitQuiescence()); UseDefaultTheme(GetProfile(0)); UseDefaultTheme(verifier()); ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); - ASSERT_FALSE(UsingDefaultTheme(GetProfile(1))); ASSERT_TRUE(UsingDefaultTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); @@ -91,7 +87,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetNativeTheme(GetProfile(0)); + UseNativeTheme(GetProfile(0)); UseDefaultTheme(GetProfile(1)); ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); @@ -110,9 +106,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetTheme(GetProfile(0), GetTheme(0)); - SetNativeTheme(GetProfile(1)); - ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); + UseCustomTheme(GetProfile(0), 0); + UseNativeTheme(GetProfile(1)); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); ASSERT_TRUE(AwaitQuiescence()); @@ -120,22 +116,22 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { // TODO(akalin): Add function to wait for pending extensions to be // installed. - ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), - HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); + ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)), + HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0))); } IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomDefaultRace) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - SetTheme(GetProfile(0), GetTheme(0)); + UseCustomTheme(GetProfile(0), 0); UseDefaultTheme(GetProfile(1)); - ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); ASSERT_TRUE(AwaitQuiescence()); - ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), - HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); + ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)), + HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0))); } 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. - SetTheme(GetProfile(0), GetTheme(0)); - SetTheme(GetProfile(1), GetTheme(1)); - ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); - ASSERT_EQ(GetTheme(1), GetCustomTheme(GetProfile(1))); + UseCustomTheme(GetProfile(0), 0); + UseCustomTheme(GetProfile(1), 1); + ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); + ASSERT_EQ(GetCustomTheme(1), GetThemeID(GetProfile(1))); ASSERT_TRUE(AwaitQuiescence()); bool using_theme_0 = - (GetCustomTheme(GetProfile(0)) == GetTheme(0)) && - HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0)); + (GetThemeID(GetProfile(0)) == GetCustomTheme(0)) && + HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)); bool using_theme_1 = - HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(1)) && - (GetCustomTheme(GetProfile(1)) == GetTheme(1)); + HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(1)) && + (GetThemeID(GetProfile(1)) == GetCustomTheme(1)); // Equivalent to using_theme_0 xor using_theme_1. ASSERT_NE(using_theme_0, using_theme_1); |