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
3 // found in the LICENSE file.
5 #include "chrome/browser/themes/theme_syncable_service.h"
7 #include "base/command_line.h"
8 #include "base/compiler_specific.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/test_extension_system.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/themes/theme_service.h"
16 #include "chrome/browser/themes/theme_service_factory.h"
17 #include "chrome/common/extensions/manifest_url_handler.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/test/test_browser_thread.h"
20 #include "extensions/browser/extension_prefs.h"
21 #include "extensions/common/extension.h"
22 #include "extensions/common/extension_messages.h"
23 #include "extensions/common/manifest_constants.h"
24 #include "extensions/common/permissions/api_permission_set.h"
25 #include "extensions/common/permissions/permission_set.h"
26 #include "sync/api/attachments/attachment_id.h"
27 #include "sync/api/fake_sync_change_processor.h"
28 #include "sync/api/sync_change_processor_wrapper_for_test.h"
29 #include "sync/api/sync_error.h"
30 #include "sync/api/sync_error_factory_mock.h"
31 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
32 #include "sync/protocol/sync.pb.h"
33 #include "sync/protocol/theme_specifics.pb.h"
34 #include "testing/gtest/include/gtest/gtest.h"
36 #if defined(OS_CHROMEOS)
37 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
38 #include "chrome/browser/chromeos/settings/cros_settings.h"
39 #include "chrome/browser/chromeos/settings/device_settings_service.h"
46 static const char kCustomThemeName[] = "name";
47 static const char kCustomThemeUrl[] = "http://update.url/foo";
50 const base::FilePath::CharType kExtensionFilePath[] =
51 FILE_PATH_LITERAL("c:\\foo");
52 #elif defined(OS_POSIX)
53 const base::FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/oo");
56 class FakeThemeService : public ThemeService {
59 using_system_theme_(false),
60 using_default_theme_(false),
61 theme_extension_(NULL),
64 // ThemeService implementation
65 virtual void SetTheme(const extensions::Extension* extension) OVERRIDE {
67 theme_extension_ = extension;
68 using_system_theme_ = false;
69 using_default_theme_ = false;
72 virtual void UseDefaultTheme() OVERRIDE {
74 using_default_theme_ = true;
75 using_system_theme_ = false;
76 theme_extension_ = NULL;
79 virtual void UseSystemTheme() OVERRIDE {
81 using_system_theme_ = true;
82 using_default_theme_ = false;
83 theme_extension_ = NULL;
86 virtual bool UsingDefaultTheme() const OVERRIDE {
87 return using_default_theme_;
90 virtual bool UsingSystemTheme() const OVERRIDE {
91 return using_system_theme_;
94 virtual string GetThemeID() const OVERRIDE {
95 if (theme_extension_.get())
96 return theme_extension_->id();
101 const extensions::Extension* theme_extension() const {
102 return theme_extension_.get();
105 bool is_dirty() const {
114 bool using_system_theme_;
115 bool using_default_theme_;
116 scoped_refptr<const extensions::Extension> theme_extension_;
120 KeyedService* BuildMockThemeService(content::BrowserContext* profile) {
121 return new FakeThemeService;
124 scoped_refptr<extensions::Extension> MakeThemeExtension(
125 const base::FilePath& extension_path,
127 extensions::Manifest::Location location,
128 const string& update_url) {
129 base::DictionaryValue source;
130 source.SetString(extensions::manifest_keys::kName, name);
131 source.Set(extensions::manifest_keys::kTheme, new base::DictionaryValue());
132 source.SetString(extensions::manifest_keys::kUpdateURL, update_url);
133 source.SetString(extensions::manifest_keys::kVersion, "0.0.0.0");
135 scoped_refptr<extensions::Extension> extension =
136 extensions::Extension::Create(
137 extension_path, location, source,
138 extensions::Extension::NO_FLAGS, &error);
139 EXPECT_TRUE(extension.get());
140 EXPECT_EQ("", error);
146 class ThemeSyncableServiceTest : public testing::Test {
148 ThemeSyncableServiceTest()
149 : ui_thread_(content::BrowserThread::UI, &loop_),
150 file_thread_(content::BrowserThread::FILE, &loop_),
151 fake_theme_service_(NULL) {}
153 virtual ~ThemeSyncableServiceTest() {}
155 virtual void SetUp() {
156 profile_.reset(new TestingProfile);
157 fake_theme_service_ = BuildForProfile(profile_.get());
158 theme_sync_service_.reset(new ThemeSyncableService(profile_.get(),
159 fake_theme_service_));
160 fake_change_processor_.reset(new syncer::FakeSyncChangeProcessor);
164 virtual void TearDown() {
166 loop_.RunUntilIdle();
169 void SetUpExtension() {
170 CommandLine command_line(CommandLine::NO_PROGRAM);
171 extensions::TestExtensionSystem* test_ext_system =
172 static_cast<extensions::TestExtensionSystem*>(
173 extensions::ExtensionSystem::Get(profile_.get()));
174 ExtensionService* service = test_ext_system->CreateExtensionService(
175 &command_line, base::FilePath(kExtensionFilePath), false);
176 EXPECT_TRUE(service->extensions_enabled());
178 loop_.RunUntilIdle();
180 // Create and add custom theme extension so the ThemeSyncableService can
182 theme_extension_ = MakeThemeExtension(base::FilePath(kExtensionFilePath),
186 extensions::APIPermissionSet empty_set;
187 extensions::ManifestPermissionSet empty_manifest_permissions;
188 extensions::URLPatternSet empty_extent;
189 scoped_refptr<extensions::PermissionSet> permissions =
190 new extensions::PermissionSet(empty_set, empty_manifest_permissions,
191 empty_extent, empty_extent);
192 extensions::ExtensionPrefs::Get(profile_.get())
193 ->AddGrantedPermissions(theme_extension_->id(), permissions.get());
194 service->AddExtension(theme_extension_.get());
195 ASSERT_EQ(1u, service->extensions()->size());
198 // Overridden in PolicyInstalledThemeTest below.
199 virtual extensions::Manifest::Location GetThemeLocation() {
200 return extensions::Manifest::INTERNAL;
203 FakeThemeService* BuildForProfile(Profile* profile) {
204 return static_cast<FakeThemeService*>(
205 ThemeServiceFactory::GetInstance()->SetTestingFactoryAndUse(
206 profile, &BuildMockThemeService));
209 syncer::SyncDataList MakeThemeDataList(
210 const sync_pb::ThemeSpecifics& theme_specifics) {
211 syncer::SyncDataList list;
212 sync_pb::EntitySpecifics entity_specifics;
213 entity_specifics.mutable_theme()->CopyFrom(theme_specifics);
214 list.push_back(syncer::SyncData::CreateLocalData(
215 ThemeSyncableService::kCurrentThemeClientTag,
216 ThemeSyncableService::kCurrentThemeNodeTitle,
221 // Needed for setting up extension service.
222 base::MessageLoop loop_;
223 content::TestBrowserThread ui_thread_;
224 content::TestBrowserThread file_thread_;
226 #if defined OS_CHROMEOS
227 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
228 chromeos::ScopedTestCrosSettings test_cros_settings_;
229 chromeos::ScopedTestUserManager test_user_manager_;
232 scoped_ptr<TestingProfile> profile_;
233 FakeThemeService* fake_theme_service_;
234 scoped_refptr<extensions::Extension> theme_extension_;
235 scoped_ptr<ThemeSyncableService> theme_sync_service_;
236 scoped_ptr<syncer::FakeSyncChangeProcessor> fake_change_processor_;
239 class PolicyInstalledThemeTest : public ThemeSyncableServiceTest {
240 virtual extensions::Manifest::Location GetThemeLocation() OVERRIDE {
241 return extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD;
245 TEST_F(ThemeSyncableServiceTest, AreThemeSpecificsEqual) {
246 sync_pb::ThemeSpecifics a, b;
247 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
248 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
250 // Custom vs. non-custom.
252 a.set_use_custom_theme(true);
253 EXPECT_FALSE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
254 EXPECT_FALSE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
256 // Custom theme equality.
258 b.set_use_custom_theme(true);
259 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
260 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
262 a.set_custom_theme_id("id");
263 EXPECT_FALSE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
264 EXPECT_FALSE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
266 b.set_custom_theme_id("id");
267 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
268 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
270 a.set_custom_theme_update_url("http://update.url");
271 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
272 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
274 a.set_custom_theme_name("name");
275 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
276 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
278 // Non-custom theme equality.
280 a.set_use_custom_theme(false);
281 b.set_use_custom_theme(false);
282 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
283 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
285 a.set_use_system_theme_by_default(true);
286 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
287 EXPECT_FALSE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
289 b.set_use_system_theme_by_default(true);
290 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, false));
291 EXPECT_TRUE(ThemeSyncableService::AreThemeSpecificsEqual(a, b, true));
294 TEST_F(ThemeSyncableServiceTest, SetCurrentThemeDefaultTheme) {
295 // Set up theme service to use custom theme.
296 fake_theme_service_->SetTheme(theme_extension_.get());
298 syncer::SyncError error =
300 ->MergeDataAndStartSyncing(
302 MakeThemeDataList(sync_pb::ThemeSpecifics()),
303 scoped_ptr<syncer::SyncChangeProcessor>(
304 new syncer::SyncChangeProcessorWrapperForTest(
305 fake_change_processor_.get())),
306 scoped_ptr<syncer::SyncErrorFactory>(
307 new syncer::SyncErrorFactoryMock()))
309 EXPECT_FALSE(error.IsSet()) << error.message();
310 EXPECT_TRUE(fake_theme_service_->UsingDefaultTheme());
313 TEST_F(ThemeSyncableServiceTest, SetCurrentThemeSystemTheme) {
314 sync_pb::ThemeSpecifics theme_specifics;
315 theme_specifics.set_use_system_theme_by_default(true);
317 // Set up theme service to use custom theme.
318 fake_theme_service_->SetTheme(theme_extension_.get());
319 syncer::SyncError error =
321 ->MergeDataAndStartSyncing(
323 MakeThemeDataList(theme_specifics),
324 scoped_ptr<syncer::SyncChangeProcessor>(
325 new syncer::SyncChangeProcessorWrapperForTest(
326 fake_change_processor_.get())),
327 scoped_ptr<syncer::SyncErrorFactory>(
328 new syncer::SyncErrorFactoryMock()))
330 EXPECT_FALSE(error.IsSet()) << error.message();
331 EXPECT_TRUE(fake_theme_service_->UsingSystemTheme());
334 TEST_F(ThemeSyncableServiceTest, SetCurrentThemeCustomTheme) {
335 sync_pb::ThemeSpecifics theme_specifics;
336 theme_specifics.set_use_custom_theme(true);
337 theme_specifics.set_custom_theme_id(theme_extension_->id());
338 theme_specifics.set_custom_theme_name(kCustomThemeName);
339 theme_specifics.set_custom_theme_name(kCustomThemeUrl);
341 // Set up theme service to use default theme.
342 fake_theme_service_->UseDefaultTheme();
343 syncer::SyncError error =
345 ->MergeDataAndStartSyncing(
347 MakeThemeDataList(theme_specifics),
348 scoped_ptr<syncer::SyncChangeProcessor>(
349 new syncer::SyncChangeProcessorWrapperForTest(
350 fake_change_processor_.get())),
351 scoped_ptr<syncer::SyncErrorFactory>(
352 new syncer::SyncErrorFactoryMock()))
354 EXPECT_FALSE(error.IsSet()) << error.message();
355 EXPECT_EQ(fake_theme_service_->theme_extension(), theme_extension_.get());
358 TEST_F(ThemeSyncableServiceTest, DontResetThemeWhenSpecificsAreEqual) {
359 // Set up theme service to use default theme and expect no changes.
360 fake_theme_service_->UseDefaultTheme();
361 fake_theme_service_->MarkClean();
362 syncer::SyncError error =
364 ->MergeDataAndStartSyncing(
366 MakeThemeDataList(sync_pb::ThemeSpecifics()),
367 scoped_ptr<syncer::SyncChangeProcessor>(
368 new syncer::SyncChangeProcessorWrapperForTest(
369 fake_change_processor_.get())),
370 scoped_ptr<syncer::SyncErrorFactory>(
371 new syncer::SyncErrorFactoryMock()))
373 EXPECT_FALSE(error.IsSet()) << error.message();
374 EXPECT_FALSE(fake_theme_service_->is_dirty());
377 TEST_F(ThemeSyncableServiceTest, UpdateThemeSpecificsFromCurrentTheme) {
378 // Set up theme service to use custom theme.
379 fake_theme_service_->SetTheme(theme_extension_.get());
381 syncer::SyncError error =
383 ->MergeDataAndStartSyncing(
385 syncer::SyncDataList(),
386 scoped_ptr<syncer::SyncChangeProcessor>(
387 new syncer::SyncChangeProcessorWrapperForTest(
388 fake_change_processor_.get())),
389 scoped_ptr<syncer::SyncErrorFactory>(
390 new syncer::SyncErrorFactoryMock()))
392 EXPECT_FALSE(error.IsSet()) << error.message();
393 const syncer::SyncChangeList& changes = fake_change_processor_->changes();
394 ASSERT_EQ(1u, changes.size());
395 EXPECT_TRUE(changes[0].IsValid());
396 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[0].change_type());
397 EXPECT_EQ(syncer::THEMES, changes[0].sync_data().GetDataType());
399 const sync_pb::ThemeSpecifics& theme_specifics =
400 changes[0].sync_data().GetSpecifics().theme();
401 EXPECT_TRUE(theme_specifics.use_custom_theme());
402 EXPECT_EQ(theme_extension_->id(), theme_specifics.custom_theme_id());
403 EXPECT_EQ(theme_extension_->name(), theme_specifics.custom_theme_name());
405 extensions::ManifestURL::GetUpdateURL(theme_extension_.get()).spec(),
406 theme_specifics.custom_theme_update_url());
409 TEST_F(ThemeSyncableServiceTest, GetAllSyncData) {
410 // Set up theme service to use custom theme.
411 fake_theme_service_->SetTheme(theme_extension_.get());
413 syncer::SyncDataList data_list =
414 theme_sync_service_->GetAllSyncData(syncer::THEMES);
416 ASSERT_EQ(1u, data_list.size());
417 const sync_pb::ThemeSpecifics& theme_specifics =
418 data_list[0].GetSpecifics().theme();
419 EXPECT_TRUE(theme_specifics.use_custom_theme());
420 EXPECT_EQ(theme_extension_->id(), theme_specifics.custom_theme_id());
421 EXPECT_EQ(theme_extension_->name(), theme_specifics.custom_theme_name());
423 extensions::ManifestURL::GetUpdateURL(theme_extension_.get()).spec(),
424 theme_specifics.custom_theme_update_url());
427 TEST_F(ThemeSyncableServiceTest, ProcessSyncThemeChange) {
428 // Set up theme service to use default theme.
429 fake_theme_service_->UseDefaultTheme();
430 fake_theme_service_->MarkClean();
433 syncer::SyncError error =
435 ->MergeDataAndStartSyncing(
437 MakeThemeDataList(sync_pb::ThemeSpecifics()),
438 scoped_ptr<syncer::SyncChangeProcessor>(
439 new syncer::SyncChangeProcessorWrapperForTest(
440 fake_change_processor_.get())),
441 scoped_ptr<syncer::SyncErrorFactory>(
442 new syncer::SyncErrorFactoryMock()))
444 EXPECT_FALSE(error.IsSet()) << error.message();
445 // Don't expect theme change initially because specifics are equal.
446 EXPECT_FALSE(fake_theme_service_->is_dirty());
448 // Change specifics to use custom theme and update.
449 sync_pb::ThemeSpecifics theme_specifics;
450 theme_specifics.set_use_custom_theme(true);
451 theme_specifics.set_custom_theme_id(theme_extension_->id());
452 theme_specifics.set_custom_theme_name(kCustomThemeName);
453 theme_specifics.set_custom_theme_name(kCustomThemeUrl);
454 sync_pb::EntitySpecifics entity_specifics;
455 entity_specifics.mutable_theme()->CopyFrom(theme_specifics);
456 syncer::SyncChangeList change_list;
457 change_list.push_back(
458 syncer::SyncChange(FROM_HERE,
459 syncer::SyncChange::ACTION_UPDATE,
460 syncer::SyncData::CreateRemoteData(
464 syncer::AttachmentIdList(),
465 syncer::AttachmentServiceProxyForTest::Create())));
466 error = theme_sync_service_->ProcessSyncChanges(FROM_HERE, change_list);
467 EXPECT_FALSE(error.IsSet()) << error.message();
468 EXPECT_EQ(fake_theme_service_->theme_extension(), theme_extension_.get());
471 TEST_F(ThemeSyncableServiceTest, OnThemeChangeByUser) {
472 // Set up theme service to use default theme.
473 fake_theme_service_->UseDefaultTheme();
476 syncer::SyncError error =
478 ->MergeDataAndStartSyncing(
480 MakeThemeDataList(sync_pb::ThemeSpecifics()),
481 scoped_ptr<syncer::SyncChangeProcessor>(
482 new syncer::SyncChangeProcessorWrapperForTest(
483 fake_change_processor_.get())),
484 scoped_ptr<syncer::SyncErrorFactory>(
485 new syncer::SyncErrorFactoryMock()))
487 EXPECT_FALSE(error.IsSet()) << error.message();
488 const syncer::SyncChangeList& changes = fake_change_processor_->changes();
489 EXPECT_EQ(0u, changes.size());
491 // Change current theme to custom theme and notify theme_sync_service_.
492 fake_theme_service_->SetTheme(theme_extension_.get());
493 theme_sync_service_->OnThemeChange();
494 EXPECT_EQ(1u, changes.size());
495 const sync_pb::ThemeSpecifics& change_specifics =
496 changes[0].sync_data().GetSpecifics().theme();
497 EXPECT_TRUE(change_specifics.use_custom_theme());
498 EXPECT_EQ(theme_extension_->id(), change_specifics.custom_theme_id());
499 EXPECT_EQ(theme_extension_->name(), change_specifics.custom_theme_name());
501 extensions::ManifestURL::GetUpdateURL(theme_extension_.get()).spec(),
502 change_specifics.custom_theme_update_url());
505 TEST_F(ThemeSyncableServiceTest, StopSync) {
506 // Set up theme service to use default theme.
507 fake_theme_service_->UseDefaultTheme();
510 syncer::SyncError error =
512 ->MergeDataAndStartSyncing(
514 MakeThemeDataList(sync_pb::ThemeSpecifics()),
515 scoped_ptr<syncer::SyncChangeProcessor>(
516 new syncer::SyncChangeProcessorWrapperForTest(
517 fake_change_processor_.get())),
518 scoped_ptr<syncer::SyncErrorFactory>(
519 new syncer::SyncErrorFactoryMock()))
521 EXPECT_FALSE(error.IsSet()) << error.message();
522 const syncer::SyncChangeList& changes = fake_change_processor_->changes();
523 EXPECT_EQ(0u, changes.size());
526 theme_sync_service_->StopSyncing(syncer::THEMES);
528 // Change current theme to custom theme and notify theme_sync_service_.
529 // No change is output because sync has stopped.
530 fake_theme_service_->SetTheme(theme_extension_.get());
531 theme_sync_service_->OnThemeChange();
532 EXPECT_EQ(0u, changes.size());
534 // ProcessSyncChanges() should return error when sync has stopped.
535 error = theme_sync_service_->ProcessSyncChanges(FROM_HERE, changes);
536 EXPECT_TRUE(error.IsSet());
537 EXPECT_EQ(syncer::THEMES, error.model_type());
538 EXPECT_EQ("Theme syncable service is not started.", error.message());
541 TEST_F(ThemeSyncableServiceTest, RestoreSystemThemeBitWhenChangeToCustomTheme) {
542 // Initialize to use system theme.
543 fake_theme_service_->UseDefaultTheme();
544 sync_pb::ThemeSpecifics theme_specifics;
545 theme_specifics.set_use_system_theme_by_default(true);
546 syncer::SyncError error =
548 ->MergeDataAndStartSyncing(
550 MakeThemeDataList(theme_specifics),
551 scoped_ptr<syncer::SyncChangeProcessor>(
552 new syncer::SyncChangeProcessorWrapperForTest(
553 fake_change_processor_.get())),
554 scoped_ptr<syncer::SyncErrorFactory>(
555 new syncer::SyncErrorFactoryMock()))
558 // Change to custom theme and notify theme_sync_service_.
559 // use_system_theme_by_default bit should be preserved.
560 fake_theme_service_->SetTheme(theme_extension_.get());
561 theme_sync_service_->OnThemeChange();
562 const syncer::SyncChangeList& changes = fake_change_processor_->changes();
563 EXPECT_EQ(1u, changes.size());
564 const sync_pb::ThemeSpecifics& change_specifics =
565 changes[0].sync_data().GetSpecifics().theme();
566 EXPECT_TRUE(change_specifics.use_system_theme_by_default());
569 #if defined(TOOLKIT_GTK)
570 TEST_F(ThemeSyncableServiceTest,
571 GtkUpdateSystemThemeBitWhenChangeBetweenSystemAndDefault) {
572 // Initialize to use native theme.
573 fake_theme_service_->UseSystemTheme();
574 fake_theme_service_->MarkClean();
575 sync_pb::ThemeSpecifics theme_specifics;
576 theme_specifics.set_use_system_theme_by_default(true);
577 syncer::SyncError error =
579 ->MergeDataAndStartSyncing(
581 MakeThemeDataList(theme_specifics),
582 scoped_ptr<syncer::SyncChangeProcessor>(
583 new syncer::SyncChangeProcessorWrapperForTest(
584 fake_change_processor_.get())),
585 scoped_ptr<syncer::SyncErrorFactory>(
586 new syncer::SyncErrorFactoryMock()))
588 EXPECT_FALSE(fake_theme_service_->is_dirty());
590 // Change to default theme and notify theme_sync_service_.
591 // use_system_theme_by_default bit should be false.
592 fake_theme_service_->UseDefaultTheme();
593 theme_sync_service_->OnThemeChange();
594 syncer::SyncChangeList& changes = fake_change_processor_->changes();
595 EXPECT_EQ(1u, changes.size());
596 EXPECT_FALSE(changes[0]
600 .use_system_theme_by_default());
602 // Change to native theme and notify theme_sync_service_.
603 // use_system_theme_by_default bit should be true.
605 fake_theme_service_->UseSystemTheme();
606 theme_sync_service_->OnThemeChange();
607 EXPECT_EQ(1u, changes.size());
608 EXPECT_TRUE(changes[0]
612 .use_system_theme_by_default());
617 TEST_F(ThemeSyncableServiceTest,
618 NonGtkPreserveSystemThemeBitWhenChangeToDefaultTheme) {
619 // Set up theme service to use default theme.
620 fake_theme_service_->UseDefaultTheme();
622 // Initialize to use custom theme with use_system_theme_by_default set true.
623 sync_pb::ThemeSpecifics theme_specifics;
624 theme_specifics.set_use_custom_theme(true);
625 theme_specifics.set_custom_theme_id(theme_extension_->id());
626 theme_specifics.set_custom_theme_name(kCustomThemeName);
627 theme_specifics.set_custom_theme_name(kCustomThemeUrl);
628 theme_specifics.set_use_system_theme_by_default(true);
629 syncer::SyncError error =
631 ->MergeDataAndStartSyncing(
633 MakeThemeDataList(theme_specifics),
634 scoped_ptr<syncer::SyncChangeProcessor>(
635 new syncer::SyncChangeProcessorWrapperForTest(
636 fake_change_processor_.get())),
637 scoped_ptr<syncer::SyncErrorFactory>(
638 new syncer::SyncErrorFactoryMock()))
640 EXPECT_EQ(fake_theme_service_->theme_extension(), theme_extension_.get());
642 // Change to default theme and notify theme_sync_service_.
643 // use_system_theme_by_default bit should be preserved.
644 fake_theme_service_->UseDefaultTheme();
645 theme_sync_service_->OnThemeChange();
646 const syncer::SyncChangeList& changes = fake_change_processor_->changes();
647 EXPECT_EQ(1u, changes.size());
648 const sync_pb::ThemeSpecifics& change_specifics =
649 changes[0].sync_data().GetSpecifics().theme();
650 EXPECT_FALSE(change_specifics.use_custom_theme());
651 EXPECT_TRUE(change_specifics.use_system_theme_by_default());
655 TEST_F(PolicyInstalledThemeTest, InstallThemeByPolicy) {
656 // Set up theme service to use custom theme that was installed by policy.
657 fake_theme_service_->SetTheme(theme_extension_.get());
659 syncer::SyncDataList data_list =
660 theme_sync_service_->GetAllSyncData(syncer::THEMES);
662 ASSERT_EQ(0u, data_list.size());