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

Side by Side Diff: chrome/test/live_sync/live_themes_sync_test.cc

Issue 6873061: [Sync] Revamp and re-enable themes/extensions sync integration tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
8
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "chrome/browser/extensions/extension_service.h" 8 #include "base/string_number_conversions.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h" 9 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/themes/theme_service_factory.h" 10 #include "chrome/browser/themes/theme_service_factory.h"
14 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
15 12
13 namespace {
14
15 // Make a name to pass to an extension helper.
16 std::string MakeName(int index) {
17 return "faketheme" + base::IntToString(index);
18 }
19
20 ThemeService* GetThemeService(Profile* profile) {
21 return ThemeServiceFactory::GetForProfile(profile);
22 }
23
24 } // namespace
25
16 LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type) 26 LiveThemesSyncTest::LiveThemesSyncTest(TestType test_type)
17 : LiveExtensionsSyncTestBase(test_type) {} 27 : LiveSyncTest(test_type) {}
18 28
19 LiveThemesSyncTest::~LiveThemesSyncTest() {} 29 LiveThemesSyncTest::~LiveThemesSyncTest() {}
20 30
21 void LiveThemesSyncTest::SetTheme( 31 bool LiveThemesSyncTest::SetupClients() {
22 Profile* profile, scoped_refptr<Extension> theme) { 32 if (!LiveSyncTest::SetupClients())
23 CHECK(theme->is_theme()); 33 return false;
24 InstallExtension(profile, theme); 34
35 extension_helper_.Setup(this);
36 return true;
25 } 37 }
26 38
27 void LiveThemesSyncTest::SetNativeTheme(Profile* profile) { 39 std::string LiveThemesSyncTest::GetCustomTheme(int index) const {
28 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); 40 return extension_helper_.NameToId(MakeName(index));
29 } 41 }
30 42
31 void LiveThemesSyncTest::UseDefaultTheme(Profile* profile) { 43 std::string LiveThemesSyncTest::GetThemeID(Profile* profile) const {
32 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); 44 return GetThemeService(profile)->GetThemeID();
33 } 45 }
34 46
35 const Extension* LiveThemesSyncTest::GetCustomTheme( 47 bool LiveThemesSyncTest::UsingCustomTheme(Profile* profile) const {
36 Profile* profile) { 48 return GetThemeID(profile) != ThemeService::kDefaultThemeID;
37 return ThemeServiceFactory::GetThemeForProfile(profile);
38 } 49 }
39 50
40 bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) { 51 bool LiveThemesSyncTest::UsingDefaultTheme(Profile* profile) const {
41 return !ThemeServiceFactory::GetThemeForProfile(profile) && 52 return GetThemeService(profile)->UsingDefaultTheme();
42 ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme();
43 } 53 }
44 54
45 bool LiveThemesSyncTest::UsingNativeTheme(Profile* profile) { 55 // TODO(akalin): Move this logic into ThemeService.
56 bool LiveThemesSyncTest::UsingNativeTheme(Profile* profile) const {
46 #if defined(TOOLKIT_USES_GTK) 57 #if defined(TOOLKIT_USES_GTK)
47 const bool kHasDistinctNativeTheme = true; 58 const bool kHasDistinctNativeTheme = true;
48 #else 59 #else
49 const bool kHasDistinctNativeTheme = false; 60 const bool kHasDistinctNativeTheme = false;
50 #endif 61 #endif
51 62
52 // Return true if we're not using a custom theme and we don't make a 63 if (!kHasDistinctNativeTheme) {
53 // distinction between the default and the system theme, or we do 64 return UsingDefaultTheme(profile);
54 // and we're not using the default theme. 65 }
55 return !ThemeServiceFactory::GetThemeForProfile(profile) && 66
56 (!kHasDistinctNativeTheme || 67 return !UsingCustomTheme(profile) && !UsingDefaultTheme(profile);
57 !ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme());
58 } 68 }
59 69
60 bool LiveThemesSyncTest::ExtensionIsPendingInstall( 70 bool LiveThemesSyncTest::ThemeIsPendingInstall(
61 Profile* profile, const Extension* extension) { 71 Profile* profile, const std::string& id) const {
62 const PendingExtensionManager* pending_extension_manager = 72 return extension_helper_.IsExtensionPendingInstallForSync(profile, id);
63 profile->GetExtensionService()->pending_extension_manager();
64 return pending_extension_manager->IsIdPending(extension->id());
65 } 73 }
66 74
67 bool LiveThemesSyncTest::HasOrWillHaveCustomTheme( 75 bool LiveThemesSyncTest::HasOrWillHaveCustomTheme(
68 Profile* profile, const Extension* theme) { 76 Profile* profile, const std::string& id) const {
69 return 77 return (GetThemeID(profile) == id) || ThemeIsPendingInstall(profile, id);
70 (GetCustomTheme(profile) == theme) ||
71 ExtensionIsPendingInstall(profile, theme);
72 } 78 }
79
80 void LiveThemesSyncTest::UseCustomTheme(Profile* profile, int index) {
81 extension_helper_.InstallExtension(
82 profile, MakeName(index), Extension::TYPE_THEME);
83 }
84
85 void LiveThemesSyncTest::UseDefaultTheme(Profile* profile) {
86 GetThemeService(profile)->UseDefaultTheme();
87 }
88
89 void LiveThemesSyncTest::UseNativeTheme(Profile* profile) {
90 // TODO(akalin): Fix this inconsistent naming in the theme service.
91 GetThemeService(profile)->SetNativeTheme();
92 }
OLDNEW
« no previous file with comments | « chrome/test/live_sync/live_themes_sync_test.h ('k') | chrome/test/live_sync/single_client_live_extensions_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698