OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/themes/theme_syncable_service.h" | 5 #include "chrome/browser/themes/theme_syncable_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
49 const base::FilePath::CharType kExtensionFilePath[] = | 49 const base::FilePath::CharType kExtensionFilePath[] = |
50 FILE_PATH_LITERAL("c:\\foo"); | 50 FILE_PATH_LITERAL("c:\\foo"); |
51 #elif defined(OS_POSIX) | 51 #elif defined(OS_POSIX) |
52 const base::FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/oo"); | 52 const base::FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/oo"); |
53 #endif | 53 #endif |
54 | 54 |
55 class FakeThemeService : public ThemeService { | 55 class FakeThemeService : public ThemeService { |
56 public: | 56 public: |
57 FakeThemeService() : | 57 FakeThemeService() : |
58 using_native_theme_(false), | 58 using_system_theme_(false), |
59 using_default_theme_(false), | 59 using_default_theme_(false), |
60 theme_extension_(NULL), | 60 theme_extension_(NULL), |
61 is_dirty_(false) {} | 61 is_dirty_(false) {} |
62 | 62 |
63 // ThemeService implementation | 63 // ThemeService implementation |
64 virtual void SetTheme(const extensions::Extension* extension) OVERRIDE { | 64 virtual void SetTheme(const extensions::Extension* extension) OVERRIDE { |
65 is_dirty_ = true; | 65 is_dirty_ = true; |
66 theme_extension_ = extension; | 66 theme_extension_ = extension; |
67 using_native_theme_ = false; | 67 using_system_theme_ = false; |
68 using_default_theme_ = false; | 68 using_default_theme_ = false; |
69 } | 69 } |
70 | 70 |
71 virtual void UseDefaultTheme() OVERRIDE { | 71 virtual void UseDefaultTheme() OVERRIDE { |
72 is_dirty_ = true; | 72 is_dirty_ = true; |
73 using_default_theme_ = true; | 73 using_default_theme_ = true; |
74 using_native_theme_ = false; | 74 using_system_theme_ = false; |
75 theme_extension_ = NULL; | 75 theme_extension_ = NULL; |
76 } | 76 } |
77 | 77 |
78 virtual void SetNativeTheme() OVERRIDE { | 78 virtual void UseSystemTheme() OVERRIDE { |
79 is_dirty_ = true; | 79 is_dirty_ = true; |
80 using_native_theme_ = true; | 80 using_system_theme_ = true; |
81 using_default_theme_ = false; | 81 using_default_theme_ = false; |
82 theme_extension_ = NULL; | 82 theme_extension_ = NULL; |
83 } | 83 } |
84 | 84 |
85 virtual bool UsingDefaultTheme() const OVERRIDE { | 85 virtual bool UsingDefaultTheme() const OVERRIDE { |
86 return using_default_theme_; | 86 return using_default_theme_; |
87 } | 87 } |
88 | 88 |
89 virtual bool UsingNativeTheme() const OVERRIDE { | 89 virtual bool UsingSystemTheme() const OVERRIDE { |
90 return using_native_theme_; | 90 return using_system_theme_; |
91 } | 91 } |
92 | 92 |
93 virtual string GetThemeID() const OVERRIDE { | 93 virtual string GetThemeID() const OVERRIDE { |
94 if (theme_extension_.get()) | 94 if (theme_extension_.get()) |
95 return theme_extension_->id(); | 95 return theme_extension_->id(); |
96 else | 96 else |
97 return std::string(); | 97 return std::string(); |
98 } | 98 } |
99 | 99 |
100 const extensions::Extension* theme_extension() const { | 100 const extensions::Extension* theme_extension() const { |
101 return theme_extension_.get(); | 101 return theme_extension_.get(); |
102 } | 102 } |
103 | 103 |
104 bool is_dirty() const { | 104 bool is_dirty() const { |
105 return is_dirty_; | 105 return is_dirty_; |
106 } | 106 } |
107 | 107 |
108 void MarkClean() { | 108 void MarkClean() { |
109 is_dirty_ = false; | 109 is_dirty_ = false; |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 bool using_native_theme_; | 113 bool using_system_theme_; |
114 bool using_default_theme_; | 114 bool using_default_theme_; |
115 scoped_refptr<const extensions::Extension> theme_extension_; | 115 scoped_refptr<const extensions::Extension> theme_extension_; |
116 bool is_dirty_; | 116 bool is_dirty_; |
117 }; | 117 }; |
118 | 118 |
119 KeyedService* BuildMockThemeService(content::BrowserContext* profile) { | 119 KeyedService* BuildMockThemeService(content::BrowserContext* profile) { |
120 return new FakeThemeService; | 120 return new FakeThemeService; |
121 } | 121 } |
122 | 122 |
123 scoped_refptr<extensions::Extension> MakeThemeExtension( | 123 scoped_refptr<extensions::Extension> MakeThemeExtension( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 ->MergeDataAndStartSyncing( | 320 ->MergeDataAndStartSyncing( |
321 syncer::THEMES, | 321 syncer::THEMES, |
322 MakeThemeDataList(theme_specifics), | 322 MakeThemeDataList(theme_specifics), |
323 scoped_ptr<syncer::SyncChangeProcessor>( | 323 scoped_ptr<syncer::SyncChangeProcessor>( |
324 new syncer::SyncChangeProcessorWrapperForTest( | 324 new syncer::SyncChangeProcessorWrapperForTest( |
325 fake_change_processor_.get())), | 325 fake_change_processor_.get())), |
326 scoped_ptr<syncer::SyncErrorFactory>( | 326 scoped_ptr<syncer::SyncErrorFactory>( |
327 new syncer::SyncErrorFactoryMock())) | 327 new syncer::SyncErrorFactoryMock())) |
328 .error(); | 328 .error(); |
329 EXPECT_FALSE(error.IsSet()) << error.message(); | 329 EXPECT_FALSE(error.IsSet()) << error.message(); |
330 EXPECT_TRUE(fake_theme_service_->UsingNativeTheme()); | 330 EXPECT_TRUE(fake_theme_service_->UsingSystemTheme()); |
331 } | 331 } |
332 | 332 |
333 TEST_F(ThemeSyncableServiceTest, SetCurrentThemeCustomTheme) { | 333 TEST_F(ThemeSyncableServiceTest, SetCurrentThemeCustomTheme) { |
334 sync_pb::ThemeSpecifics theme_specifics; | 334 sync_pb::ThemeSpecifics theme_specifics; |
335 theme_specifics.set_use_custom_theme(true); | 335 theme_specifics.set_use_custom_theme(true); |
336 theme_specifics.set_custom_theme_id(theme_extension_->id()); | 336 theme_specifics.set_custom_theme_id(theme_extension_->id()); |
337 theme_specifics.set_custom_theme_name(kCustomThemeName); | 337 theme_specifics.set_custom_theme_name(kCustomThemeName); |
338 theme_specifics.set_custom_theme_name(kCustomThemeUrl); | 338 theme_specifics.set_custom_theme_name(kCustomThemeUrl); |
339 | 339 |
340 // Set up theme service to use default theme. | 340 // Set up theme service to use default theme. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 EXPECT_EQ(1u, changes.size()); | 564 EXPECT_EQ(1u, changes.size()); |
565 const sync_pb::ThemeSpecifics& change_specifics = | 565 const sync_pb::ThemeSpecifics& change_specifics = |
566 changes[0].sync_data().GetSpecifics().theme(); | 566 changes[0].sync_data().GetSpecifics().theme(); |
567 EXPECT_TRUE(change_specifics.use_system_theme_by_default()); | 567 EXPECT_TRUE(change_specifics.use_system_theme_by_default()); |
568 } | 568 } |
569 | 569 |
570 #if defined(TOOLKIT_GTK) | 570 #if defined(TOOLKIT_GTK) |
571 TEST_F(ThemeSyncableServiceTest, | 571 TEST_F(ThemeSyncableServiceTest, |
572 GtkUpdateSystemThemeBitWhenChangeBetweenSystemAndDefault) { | 572 GtkUpdateSystemThemeBitWhenChangeBetweenSystemAndDefault) { |
573 // Initialize to use native theme. | 573 // Initialize to use native theme. |
574 fake_theme_service_->SetNativeTheme(); | 574 fake_theme_service_->UseSystemTheme(); |
575 fake_theme_service_->MarkClean(); | 575 fake_theme_service_->MarkClean(); |
576 sync_pb::ThemeSpecifics theme_specifics; | 576 sync_pb::ThemeSpecifics theme_specifics; |
577 theme_specifics.set_use_system_theme_by_default(true); | 577 theme_specifics.set_use_system_theme_by_default(true); |
578 syncer::SyncError error = | 578 syncer::SyncError error = |
579 theme_sync_service_ | 579 theme_sync_service_ |
580 ->MergeDataAndStartSyncing( | 580 ->MergeDataAndStartSyncing( |
581 syncer::THEMES, | 581 syncer::THEMES, |
582 MakeThemeDataList(theme_specifics), | 582 MakeThemeDataList(theme_specifics), |
583 scoped_ptr<syncer::SyncChangeProcessor>( | 583 scoped_ptr<syncer::SyncChangeProcessor>( |
584 new syncer::SyncChangeProcessorWrapperForTest( | 584 new syncer::SyncChangeProcessorWrapperForTest( |
(...skipping 11 matching lines...) Expand all Loading... |
596 EXPECT_EQ(1u, changes.size()); | 596 EXPECT_EQ(1u, changes.size()); |
597 EXPECT_FALSE(changes[0] | 597 EXPECT_FALSE(changes[0] |
598 .sync_data() | 598 .sync_data() |
599 .GetSpecifics() | 599 .GetSpecifics() |
600 .theme() | 600 .theme() |
601 .use_system_theme_by_default()); | 601 .use_system_theme_by_default()); |
602 | 602 |
603 // Change to native theme and notify theme_sync_service_. | 603 // Change to native theme and notify theme_sync_service_. |
604 // use_system_theme_by_default bit should be true. | 604 // use_system_theme_by_default bit should be true. |
605 changes.clear(); | 605 changes.clear(); |
606 fake_theme_service_->SetNativeTheme(); | 606 fake_theme_service_->UseSystemTheme(); |
607 theme_sync_service_->OnThemeChange(); | 607 theme_sync_service_->OnThemeChange(); |
608 EXPECT_EQ(1u, changes.size()); | 608 EXPECT_EQ(1u, changes.size()); |
609 EXPECT_TRUE(changes[0] | 609 EXPECT_TRUE(changes[0] |
610 .sync_data() | 610 .sync_data() |
611 .GetSpecifics() | 611 .GetSpecifics() |
612 .theme() | 612 .theme() |
613 .use_system_theme_by_default()); | 613 .use_system_theme_by_default()); |
614 } | 614 } |
615 #endif | 615 #endif |
616 | 616 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 655 |
656 TEST_F(PolicyInstalledThemeTest, InstallThemeByPolicy) { | 656 TEST_F(PolicyInstalledThemeTest, InstallThemeByPolicy) { |
657 // Set up theme service to use custom theme that was installed by policy. | 657 // Set up theme service to use custom theme that was installed by policy. |
658 fake_theme_service_->SetTheme(theme_extension_.get()); | 658 fake_theme_service_->SetTheme(theme_extension_.get()); |
659 | 659 |
660 syncer::SyncDataList data_list = | 660 syncer::SyncDataList data_list = |
661 theme_sync_service_->GetAllSyncData(syncer::THEMES); | 661 theme_sync_service_->GetAllSyncData(syncer::THEMES); |
662 | 662 |
663 ASSERT_EQ(0u, data_list.size()); | 663 ASSERT_EQ(0u, data_list.size()); |
664 } | 664 } |
OLD | NEW |