| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/live_sync/live_themes_sync_test.h" | 5 #include "chrome/test/live_sync/live_themes_sync_test.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/logging.h" | 9 #include "base/logging.h" |
| 12 #include "base/ref_counted.h" | |
| 13 #include "base/string_number_conversions.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/extensions/extensions_service.h" | 10 #include "chrome/browser/extensions/extensions_service.h" |
| 16 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/themes/browser_theme_provider.h" | 12 #include "chrome/browser/themes/browser_theme_provider.h" |
| 18 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | |
| 20 | 14 |
| 21 LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type) | 15 LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type) |
| 22 : LiveSyncTest(test_type) {} | 16 : LiveExtensionsSyncTestBase(test_type) {} |
| 23 | 17 |
| 24 LiveThemesSyncTest::~LiveThemesSyncTest() {} | 18 LiveThemesSyncTest::~LiveThemesSyncTest() {} |
| 25 | 19 |
| 26 namespace { | |
| 27 | |
| 28 scoped_refptr<Extension> MakeTheme(const ScopedTempDir& scoped_temp_dir, | |
| 29 int index) { | |
| 30 DictionaryValue source; | |
| 31 source.SetString( | |
| 32 extension_manifest_keys::kName, | |
| 33 std::string("ThemeExtension") + base::IntToString(index)); | |
| 34 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | |
| 35 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | |
| 36 FilePath theme_dir; | |
| 37 if (!file_util::CreateTemporaryDirInDir(scoped_temp_dir.path(), | |
| 38 FILE_PATH_LITERAL("faketheme"), | |
| 39 &theme_dir)) { | |
| 40 return NULL; | |
| 41 } | |
| 42 std::string error; | |
| 43 scoped_refptr<Extension> extension = | |
| 44 Extension::Create(theme_dir, | |
| 45 Extension::INTERNAL, source, false, &error); | |
| 46 if (!error.empty()) { | |
| 47 LOG(WARNING) << error; | |
| 48 return NULL; | |
| 49 } | |
| 50 return extension; | |
| 51 } | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 55 bool LiveThemesSyncTest::SetupClients() { | |
| 56 if (!LiveSyncTest::SetupClients()) | |
| 57 return false; | |
| 58 | |
| 59 for (int i = 0; i < num_clients(); ++i) { | |
| 60 GetProfile(i)->InitExtensions(); | |
| 61 } | |
| 62 verifier()->InitExtensions(); | |
| 63 | |
| 64 if (!theme_dir_.CreateUniqueTempDir()) | |
| 65 return false; | |
| 66 | |
| 67 for (int i = 0; i < num_clients(); ++i) { | |
| 68 scoped_refptr<Extension> theme = MakeTheme(theme_dir_, i); | |
| 69 if (!theme.get()) | |
| 70 return false; | |
| 71 themes_.push_back(theme); | |
| 72 } | |
| 73 | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 scoped_refptr<Extension> LiveThemesSyncTest::GetTheme(int index) { | |
| 78 CHECK_GE(index, 0); | |
| 79 CHECK_LT(index, static_cast<int>(themes_.size())); | |
| 80 return themes_[index]; | |
| 81 } | |
| 82 | |
| 83 void LiveThemesSyncTest::SetTheme( | 20 void LiveThemesSyncTest::SetTheme( |
| 84 Profile* profile, scoped_refptr<Extension> theme) { | 21 Profile* profile, scoped_refptr<Extension> theme) { |
| 85 CHECK(profile); | |
| 86 CHECK(theme.get()); | |
| 87 CHECK(theme->is_theme()); | 22 CHECK(theme->is_theme()); |
| 88 profile->GetExtensionsService()->OnExtensionInstalled(theme, true); | 23 InstallExtension(profile, theme); |
| 89 } | 24 } |
| 90 | 25 |
| 91 const Extension* LiveThemesSyncTest::GetCustomTheme( | 26 const Extension* LiveThemesSyncTest::GetCustomTheme( |
| 92 Profile* profile) { | 27 Profile* profile) { |
| 93 return profile->GetTheme(); | 28 return profile->GetTheme(); |
| 94 } | 29 } |
| 95 | 30 |
| 96 bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) { | 31 bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) { |
| 97 return | 32 return |
| 98 !profile->GetTheme() && | 33 !profile->GetTheme() && |
| (...skipping 22 matching lines...) Expand all Loading... |
| 121 profile->GetExtensionsService()->pending_extensions(); | 56 profile->GetExtensionsService()->pending_extensions(); |
| 122 return pending_extensions.find(extension->id()) != pending_extensions.end(); | 57 return pending_extensions.find(extension->id()) != pending_extensions.end(); |
| 123 } | 58 } |
| 124 | 59 |
| 125 bool LiveThemesSyncTest::HasOrWillHaveCustomTheme( | 60 bool LiveThemesSyncTest::HasOrWillHaveCustomTheme( |
| 126 Profile* profile, const Extension* theme) { | 61 Profile* profile, const Extension* theme) { |
| 127 return | 62 return |
| 128 (GetCustomTheme(profile) == theme) || | 63 (GetCustomTheme(profile) == theme) || |
| 129 ExtensionIsPendingInstall(profile, theme); | 64 ExtensionIsPendingInstall(profile, theme); |
| 130 } | 65 } |
| OLD | NEW |