diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 06:26:33 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 06:26:33 +0000 |
commit | 247b37e561b328f90e2939d75c911037aa1f82fb (patch) | |
tree | 92d2221dab6308af49705f44094bcb304524cba7 /chrome/test | |
parent | aef3f32aab8843aea4f4e1d01b82a795b44b6780 (diff) | |
download | chromium_src-247b37e561b328f90e2939d75c911037aa1f82fb.zip chromium_src-247b37e561b328f90e2939d75c911037aa1f82fb.tar.gz chromium_src-247b37e561b328f90e2939d75c911037aa1f82fb.tar.bz2 |
[Sync] Added some basic extension sync integration tests.
Refactored theme integration tests to share code with extension integration tests.
Fixed a crasher in ExtensionUpdater when run under integration tests.
BUG=53531
TEST=New integration tests
Review URL: http://codereview.chromium.org/4732005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
10 files changed, 532 insertions, 126 deletions
diff --git a/chrome/test/live_sync/live_extensions_sync_test.cc b/chrome/test/live_sync/live_extensions_sync_test.cc new file mode 100644 index 0000000..b4f287a --- /dev/null +++ b/chrome/test/live_sync/live_extensions_sync_test.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_extensions_sync_test.h" + +#include <map> +#include <string> + +#include "base/logging.h" +#include "base/ref_counted.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/themes/browser_theme_provider.h" +#include "chrome/common/extensions/extension.h" + +LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type) + : LiveExtensionsSyncTestBase(test_type) {} + +LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {} + +bool LiveExtensionsSyncTest::HasSameExtensionsAsVerifier(int profile) { + return HasSameExtensionsHelper(GetProfile(profile), + verifier()); +} + +bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { + for (int i = 0; i < num_clients(); ++i) { + if (!HasSameExtensionsAsVerifier(i)) + return false; + } + return true; +} + +namespace { + +enum ExtensionState { DISABLED, PENDING, ENABLED }; + +typedef std::map<std::string, ExtensionState> ExtensionStateMap; + +ExtensionStateMap GetExtensionStates(ExtensionsService* extensions_service) { + ExtensionStateMap extension_states; + + const ExtensionList* extensions = extensions_service->extensions(); + for (ExtensionList::const_iterator it = extensions->begin(); + it != extensions->end(); ++it) { + extension_states[(*it)->id()] = 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; + } + + const PendingExtensionMap& pending_extensions = + extensions_service->pending_extensions(); + for (PendingExtensionMap::const_iterator it = pending_extensions.begin(); + it != pending_extensions.end(); ++it) { + extension_states[it->first] = PENDING; + } + + return extension_states; +} + +} // namespace + +bool LiveExtensionsSyncTest::HasSameExtensionsHelper( + Profile* profile1, Profile* profile2) { + ExtensionStateMap extension_states1( + GetExtensionStates(profile1->GetExtensionsService())); + ExtensionStateMap extension_states2( + GetExtensionStates(profile2->GetExtensionsService())); + return extension_states1 == extension_states2; +} diff --git a/chrome/test/live_sync/live_extensions_sync_test.h b/chrome/test/live_sync/live_extensions_sync_test.h new file mode 100644 index 0000000..3d188cd --- /dev/null +++ b/chrome/test/live_sync/live_extensions_sync_test.h @@ -0,0 +1,43 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_H_ +#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/scoped_temp_dir.h" +#include "base/ref_counted.h" +#include "chrome/test/live_sync/live_extensions_sync_test_base.h" + +class Extension; +class Profile; + +class LiveExtensionsSyncTest : public LiveExtensionsSyncTestBase { + 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; + + // Returns true iff all existing profiles have the same extensions + // as the verifier. + bool AllProfilesHaveSameExtensionsAsVerifier() WARN_UNUSED_RESULT; + + 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; + + DISALLOW_COPY_AND_ASSIGN(LiveExtensionsSyncTest); +}; + +#endif // CHROME_TEST_LIVE_SYNC_LIVE_EXTENSIONS_SYNC_TEST_H_ diff --git a/chrome/test/live_sync/live_extensions_sync_test_base.cc b/chrome/test/live_sync/live_extensions_sync_test_base.cc new file mode 100644 index 0000000..154ef18 --- /dev/null +++ b/chrome/test/live_sync/live_extensions_sync_test_base.cc @@ -0,0 +1,122 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_extensions_sync_test_base.h" + +#include <string> + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/ref_counted.h" +#include "base/string_number_conversions.h" +#include "base/values.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/profile.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_constants.h" + +LiveExtensionsSyncTestBase::LiveExtensionsSyncTestBase(TestType test_type) + : LiveSyncTest(test_type) {} + +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, false, &error); + if (!error.empty()) { + LOG(WARNING) << error; + return NULL; + } + return extension; +} + +} // namespace + +bool LiveExtensionsSyncTestBase::SetupClients() { + if (!LiveSyncTest::SetupClients()) + return false; + + for (int i = 0; i < num_clients(); ++i) { + GetProfile(i)->InitExtensions(); + } + verifier()->InitExtensions(); + + if (!extension_base_dir_.CreateUniqueTempDir()) + return false; + + return true; +} + +scoped_refptr<Extension> LiveExtensionsSyncTestBase::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->GetExtensionsService()->OnExtensionInstalled(extension, true); +} + +void LiveExtensionsSyncTestBase::InstallAllPendingExtensions( + Profile* profile) { + // TODO(akalin): Mock out the servers that the extensions + // auto-update mechanism talk to so as to more closely match what + // actually happens. + const PendingExtensionMap& pending_extensions = + profile->GetExtensionsService()->pending_extensions(); + for (PendingExtensionMap::const_iterator it = pending_extensions.begin(); + it != pending_extensions.end(); ++it) { + 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 new file mode 100644 index 0000000..787ac0d --- /dev/null +++ b/chrome/test/live_sync/live_extensions_sync_test_base.h @@ -0,0 +1,69 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#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/scoped_temp_dir.h" +#include "base/ref_counted.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_themes_sync_test.cc b/chrome/test/live_sync/live_themes_sync_test.cc index c9a5258..a92d898 100644 --- a/chrome/test/live_sync/live_themes_sync_test.cc +++ b/chrome/test/live_sync/live_themes_sync_test.cc @@ -6,86 +6,21 @@ #include <string> -#include "base/file_path.h" -#include "base/file_util.h" #include "base/logging.h" -#include "base/ref_counted.h" -#include "base/string_number_conversions.h" -#include "base/values.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/themes/browser_theme_provider.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_constants.h" LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type) - : LiveSyncTest(test_type) {} + : LiveExtensionsSyncTestBase(test_type) {} LiveThemesSyncTest::~LiveThemesSyncTest() {} -namespace { - -scoped_refptr<Extension> MakeTheme(const ScopedTempDir& scoped_temp_dir, - int index) { - DictionaryValue source; - source.SetString( - extension_manifest_keys::kName, - std::string("ThemeExtension") + base::IntToString(index)); - source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); - source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); - FilePath theme_dir; - if (!file_util::CreateTemporaryDirInDir(scoped_temp_dir.path(), - FILE_PATH_LITERAL("faketheme"), - &theme_dir)) { - return NULL; - } - std::string error; - scoped_refptr<Extension> extension = - Extension::Create(theme_dir, - Extension::INTERNAL, source, false, &error); - if (!error.empty()) { - LOG(WARNING) << error; - return NULL; - } - return extension; -} - -} // namespace - -bool LiveThemesSyncTest::SetupClients() { - if (!LiveSyncTest::SetupClients()) - return false; - - for (int i = 0; i < num_clients(); ++i) { - GetProfile(i)->InitExtensions(); - } - verifier()->InitExtensions(); - - if (!theme_dir_.CreateUniqueTempDir()) - return false; - - for (int i = 0; i < num_clients(); ++i) { - scoped_refptr<Extension> theme = MakeTheme(theme_dir_, i); - if (!theme.get()) - return false; - themes_.push_back(theme); - } - - return true; -} - -scoped_refptr<Extension> LiveThemesSyncTest::GetTheme(int index) { - CHECK_GE(index, 0); - CHECK_LT(index, static_cast<int>(themes_.size())); - return themes_[index]; -} - void LiveThemesSyncTest::SetTheme( Profile* profile, scoped_refptr<Extension> theme) { - CHECK(profile); - CHECK(theme.get()); CHECK(theme->is_theme()); - profile->GetExtensionsService()->OnExtensionInstalled(theme, true); + InstallExtension(profile, theme); } const Extension* LiveThemesSyncTest::GetCustomTheme( diff --git a/chrome/test/live_sync/live_themes_sync_test.h b/chrome/test/live_sync/live_themes_sync_test.h index e4f9071..c98e3e4 100644 --- a/chrome/test/live_sync/live_themes_sync_test.h +++ b/chrome/test/live_sync/live_themes_sync_test.h @@ -12,25 +12,17 @@ #include "base/compiler_specific.h" #include "base/scoped_temp_dir.h" #include "base/ref_counted.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 LiveThemesSyncTest : public LiveSyncTest { +class LiveThemesSyncTest : public LiveExtensionsSyncTestBase { public: explicit LiveThemesSyncTest(TestType test_type); virtual ~LiveThemesSyncTest(); - // Like LiveSyncTest::SetupClients(), but also initializes - // extensions for each profile and also creates n themes (n = - // num_clients()). - virtual bool SetupClients() WARN_UNUSED_RESULT; - protected: - // Get the index'th theme created by SetupClients(). - scoped_refptr<Extension> GetTheme(int index) WARN_UNUSED_RESULT; - // 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); @@ -58,9 +50,6 @@ class LiveThemesSyncTest : public LiveSyncTest { const Extension* theme) WARN_UNUSED_RESULT; private: - ScopedTempDir theme_dir_; - std::vector<scoped_refptr<Extension> > themes_; - 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 new file mode 100644 index 0000000..3bdd624 --- /dev/null +++ b/chrome/test/live_sync/single_client_live_extensions_sync_test.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_extensions_sync_test.h" + +#include "base/basictypes.h" +#include "chrome/common/extensions/extension.h" + +class SingleClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { + public: + SingleClientLiveExtensionsSyncTest() + : LiveExtensionsSyncTest(SINGLE_CLIENT) {} + + virtual ~SingleClientLiveExtensionsSyncTest() {} + + private: + DISALLOW_COPY_AND_ASSIGN(SingleClientLiveExtensionsSyncTest); +}; + +IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, + StartWithNoExtensions) { + ASSERT_TRUE(SetupSync()); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} + +IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, + StartWithSomeExtensions) { + ASSERT_TRUE(SetupClients()); + + const int kNumExtensions = 5; + for (int i = 0; i < kNumExtensions; ++i) { + InstallExtension(GetProfile(0), GetExtension(i)); + InstallExtension(verifier(), GetExtension(i)); + } + + ASSERT_TRUE(SetupSync()); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} + +IN_PROC_BROWSER_TEST_F(SingleClientLiveExtensionsSyncTest, + InstallSomeExtensions) { + ASSERT_TRUE(SetupSync()); + + const int kNumExtensions = 5; + for (int i = 0; i < kNumExtensions; ++i) { + InstallExtension(GetProfile(0), GetExtension(i)); + InstallExtension(verifier(), GetExtension(i)); + } + + ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( + "Waiting for extension changes.")); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} 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 f8cef03..a8f92e4 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 @@ -23,33 +23,31 @@ class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, CustomTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); ASSERT_EQ(NULL, GetCustomTheme(verifier())); - SetTheme(GetProfile(0), theme); - SetTheme(verifier(), theme); - ASSERT_EQ(theme, GetCustomTheme(GetProfile(0))); - ASSERT_EQ(theme, GetCustomTheme(verifier())); + SetTheme(GetProfile(0), GetTheme(0)); + SetTheme(verifier(), GetTheme(0)); + ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); + ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( - "Waiting for themes change.")); + "Waiting for custom themes change.")); - ASSERT_EQ(theme, GetCustomTheme(GetProfile(0))); - ASSERT_EQ(theme, GetCustomTheme(verifier())); + ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); + ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); } IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); - SetTheme(GetProfile(0), theme); - SetTheme(verifier(), theme); + SetTheme(GetProfile(0), GetTheme(0)); + SetTheme(verifier(), GetTheme(0)); ASSERT_FALSE(UsingNativeTheme(GetProfile(0))); ASSERT_FALSE(UsingNativeTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( - "Waiting for themes change.")); + "Waiting for custom themes change.")); GetProfile(0)->SetNativeTheme(); verifier()->SetNativeTheme(); @@ -57,7 +55,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { ASSERT_TRUE(UsingNativeTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( - "Waiting for native theme change.")); + "Waiting for native themes change.")); ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(verifier())); @@ -66,14 +64,13 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, NativeTheme) { IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, DefaultTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); - SetTheme(GetProfile(0), theme); - SetTheme(verifier(), theme); + SetTheme(GetProfile(0), GetTheme(0)); + SetTheme(verifier(), GetTheme(0)); ASSERT_FALSE(UsingDefaultTheme(GetProfile(0))); ASSERT_FALSE(UsingDefaultTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( - "Waiting for themes change.")); + "Waiting for custom themes change.")); GetProfile(0)->ClearTheme(); verifier()->ClearTheme(); @@ -81,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientLiveThemesSyncTest, DefaultTheme) { ASSERT_TRUE(UsingDefaultTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( - "Waiting for cleared theme change.")); + "Waiting for native themes change.")); ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); ASSERT_TRUE(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 new file mode 100644 index 0000000..064eba6 --- /dev/null +++ b/chrome/test/live_sync/two_client_live_extensions_sync_test.cc @@ -0,0 +1,121 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_extensions_sync_test.h" + +#include "base/basictypes.h" +#include "chrome/common/extensions/extension.h" + +class TwoClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { + public: + TwoClientLiveExtensionsSyncTest() + : LiveExtensionsSyncTest(TWO_CLIENT) {} + + virtual ~TwoClientLiveExtensionsSyncTest() {} + + private: + DISALLOW_COPY_AND_ASSIGN(TwoClientLiveExtensionsSyncTest); +}; + +IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, + StartWithNoExtensions) { + ASSERT_TRUE(SetupSync()); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} + +IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, + 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)); + } + + ASSERT_TRUE(SetupSync()); + + ASSERT_TRUE(AwaitQuiescence()); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} + +IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, + 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)); + } + + const int kNumProfile0Extensions = 10; + for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) { + InstallExtension(GetProfile(0), GetExtension(i)); + InstallExtension(verifier(), GetExtension(i)); + } + + const int kNumProfile1Extensions = 10; + for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) { + InstallExtension(GetProfile(1), GetExtension(i)); + InstallExtension(verifier(), GetExtension(i)); + } + + ASSERT_TRUE(SetupSync()); + + ASSERT_TRUE(AwaitQuiescence()); + + InstallAllPendingExtensions(GetProfile(0)); + InstallAllPendingExtensions(GetProfile(1)); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} + +IN_PROC_BROWSER_TEST_F(TwoClientLiveExtensionsSyncTest, + 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)); + } + + ASSERT_TRUE(SetupSync()); + + ASSERT_TRUE(AwaitQuiescence()); + + const int kNumProfile0Extensions = 10; + for (int j = 0; j < kNumProfile0Extensions; ++i, ++j) { + InstallExtension(GetProfile(0), GetExtension(i)); + InstallExtension(verifier(), GetExtension(i)); + } + + const int kNumProfile1Extensions = 10; + for (int j = 0; j < kNumProfile1Extensions; ++i, ++j) { + InstallExtension(GetProfile(1), GetExtension(i)); + InstallExtension(verifier(), GetExtension(i)); + } + + ASSERT_TRUE(AwaitQuiescence()); + + InstallAllPendingExtensions(GetProfile(0)); + InstallAllPendingExtensions(GetProfile(1)); + + ASSERT_TRUE(AllProfilesHaveSameExtensionsAsVerifier()); +} + +// TODO(akalin): Add tests exercising: +// - Extensions enabled/disabled state sync behavior +// - Extension uninstallation +// - Offline installation/uninstallation behavior 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 c9db7b9..40ac412 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 @@ -23,36 +23,34 @@ class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); ASSERT_EQ(NULL, GetCustomTheme(verifier())); - SetTheme(GetProfile(0), theme); - SetTheme(verifier(), theme); - ASSERT_EQ(theme, GetCustomTheme(GetProfile(0))); + SetTheme(GetProfile(0), GetTheme(0)); + SetTheme(verifier(), GetTheme(0)); + ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); - ASSERT_EQ(theme, GetCustomTheme(verifier())); + ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_EQ(theme, GetCustomTheme(GetProfile(0))); + ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); // 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), theme)); - ASSERT_EQ(theme, GetCustomTheme(verifier())); + ASSERT_TRUE(ExtensionIsPendingInstall(GetProfile(1), GetTheme(0))); + ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); } IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); - SetTheme(GetProfile(0), theme); - SetTheme(GetProfile(1), theme); - SetTheme(verifier(), theme); + SetTheme(GetProfile(0), GetTheme(0)); + SetTheme(GetProfile(1), GetTheme(0)); + SetTheme(verifier(), GetTheme(0)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AwaitQuiescence()); GetProfile(0)->SetNativeTheme(); verifier()->SetNativeTheme(); @@ -70,12 +68,11 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); - SetTheme(GetProfile(0), theme); - SetTheme(GetProfile(1), theme); - SetTheme(verifier(), theme); + SetTheme(GetProfile(0), GetTheme(0)); + SetTheme(GetProfile(1), GetTheme(0)); + SetTheme(verifier(), GetTheme(0)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AwaitQuiescence()); GetProfile(0)->ClearTheme(); verifier()->ClearTheme(); @@ -112,10 +109,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); - SetTheme(GetProfile(0), theme); + SetTheme(GetProfile(0), GetTheme(0)); GetProfile(1)->SetNativeTheme(); - ASSERT_EQ(theme, GetCustomTheme(GetProfile(0))); + ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); ASSERT_TRUE(AwaitQuiescence()); @@ -123,28 +119,29 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { // TODO(akalin): Add function to wait for pending extensions to be // installed. - ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), theme), - HasOrWillHaveCustomTheme(GetProfile(1), theme)); + ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), + HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); } IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomDefaultRace) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - scoped_refptr<Extension> theme = GetTheme(0); - SetTheme(GetProfile(0), theme); + SetTheme(GetProfile(0), GetTheme(0)); GetProfile(1)->ClearTheme(); - ASSERT_EQ(theme, GetCustomTheme(GetProfile(0))); + ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); ASSERT_TRUE(AwaitQuiescence()); - ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), theme), - HasOrWillHaveCustomTheme(GetProfile(1), theme)); + ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), + HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); } IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + // TODO(akalin): Generalize this to n clients. + SetTheme(GetProfile(0), GetTheme(0)); SetTheme(GetProfile(1), GetTheme(1)); ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); |