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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 virtual bool UsingDefaultTheme() const OVERRIDE { | 101 virtual bool UsingDefaultTheme() const OVERRIDE { |
102 return using_default_theme_; | 102 return using_default_theme_; |
103 } | 103 } |
104 | 104 |
105 virtual bool UsingNativeTheme() const OVERRIDE { | 105 virtual bool UsingNativeTheme() const OVERRIDE { |
106 return using_native_theme_; | 106 return using_native_theme_; |
107 } | 107 } |
108 | 108 |
109 virtual string GetThemeID() const OVERRIDE { | 109 virtual string GetThemeID() const OVERRIDE { |
110 if (theme_extension_) | 110 if (theme_extension_.get()) |
111 return theme_extension_->id(); | 111 return theme_extension_->id(); |
112 else | 112 else |
113 return std::string(); | 113 return std::string(); |
114 } | 114 } |
115 | 115 |
116 const extensions::Extension* theme_extension() const { | 116 const extensions::Extension* theme_extension() const { |
117 return theme_extension_.get(); | 117 return theme_extension_.get(); |
118 } | 118 } |
119 | 119 |
120 bool is_dirty() const { | 120 bool is_dirty() const { |
(...skipping 24 matching lines...) Expand all Loading... |
145 DictionaryValue source; | 145 DictionaryValue source; |
146 source.SetString(extension_manifest_keys::kName, name); | 146 source.SetString(extension_manifest_keys::kName, name); |
147 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | 147 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); |
148 source.SetString(extension_manifest_keys::kUpdateURL, update_url); | 148 source.SetString(extension_manifest_keys::kUpdateURL, update_url); |
149 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | 149 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); |
150 string error; | 150 string error; |
151 scoped_refptr<extensions::Extension> extension = | 151 scoped_refptr<extensions::Extension> extension = |
152 extensions::Extension::Create( | 152 extensions::Extension::Create( |
153 extension_path, location, source, | 153 extension_path, location, source, |
154 extensions::Extension::NO_FLAGS, &error); | 154 extensions::Extension::NO_FLAGS, &error); |
155 EXPECT_TRUE(extension); | 155 EXPECT_TRUE(extension.get()); |
156 EXPECT_EQ("", error); | 156 EXPECT_EQ("", error); |
157 return extension; | 157 return extension; |
158 } | 158 } |
159 | 159 |
160 } // namespace | 160 } // namespace |
161 | 161 |
162 class ThemeSyncableServiceTest : public testing::Test { | 162 class ThemeSyncableServiceTest : public testing::Test { |
163 protected: | 163 protected: |
164 ThemeSyncableServiceTest() | 164 ThemeSyncableServiceTest() |
165 : loop_(base::MessageLoop::TYPE_DEFAULT), | 165 : loop_(base::MessageLoop::TYPE_DEFAULT), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 theme_extension_ = MakeThemeExtension(base::FilePath(kExtensionFilePath), | 199 theme_extension_ = MakeThemeExtension(base::FilePath(kExtensionFilePath), |
200 kCustomThemeName, | 200 kCustomThemeName, |
201 GetThemeLocation(), | 201 GetThemeLocation(), |
202 kCustomThemeUrl); | 202 kCustomThemeUrl); |
203 extensions::APIPermissionSet empty_set; | 203 extensions::APIPermissionSet empty_set; |
204 extensions::URLPatternSet empty_extent; | 204 extensions::URLPatternSet empty_extent; |
205 scoped_refptr<extensions::PermissionSet> permissions = | 205 scoped_refptr<extensions::PermissionSet> permissions = |
206 new extensions::PermissionSet(empty_set, empty_extent, empty_extent); | 206 new extensions::PermissionSet(empty_set, empty_extent, empty_extent); |
207 service->extension_prefs()->AddGrantedPermissions( | 207 service->extension_prefs()->AddGrantedPermissions( |
208 theme_extension_->id(), permissions.get()); | 208 theme_extension_->id(), permissions.get()); |
209 service->AddExtension(theme_extension_); | 209 service->AddExtension(theme_extension_.get()); |
210 ASSERT_EQ(1u, service->extensions()->size()); | 210 ASSERT_EQ(1u, service->extensions()->size()); |
211 } | 211 } |
212 | 212 |
213 // Overridden in PolicyInstalledThemeTest below. | 213 // Overridden in PolicyInstalledThemeTest below. |
214 virtual extensions::Manifest::Location GetThemeLocation() { | 214 virtual extensions::Manifest::Location GetThemeLocation() { |
215 return extensions::Manifest::INTERNAL; | 215 return extensions::Manifest::INTERNAL; |
216 } | 216 } |
217 | 217 |
218 FakeThemeService* BuildForProfile(Profile* profile) { | 218 FakeThemeService* BuildForProfile(Profile* profile) { |
219 return static_cast<FakeThemeService*>( | 219 return static_cast<FakeThemeService*>( |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 ASSERT_EQ(1u, change_list.size()); | 382 ASSERT_EQ(1u, change_list.size()); |
383 EXPECT_TRUE(change_list[0].IsValid()); | 383 EXPECT_TRUE(change_list[0].IsValid()); |
384 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change_list[0].change_type()); | 384 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change_list[0].change_type()); |
385 EXPECT_EQ(syncer::THEMES, change_list[0].sync_data().GetDataType()); | 385 EXPECT_EQ(syncer::THEMES, change_list[0].sync_data().GetDataType()); |
386 | 386 |
387 const sync_pb::ThemeSpecifics& theme_specifics = | 387 const sync_pb::ThemeSpecifics& theme_specifics = |
388 change_list[0].sync_data().GetSpecifics().theme(); | 388 change_list[0].sync_data().GetSpecifics().theme(); |
389 EXPECT_TRUE(theme_specifics.use_custom_theme()); | 389 EXPECT_TRUE(theme_specifics.use_custom_theme()); |
390 EXPECT_EQ(theme_extension_->id(), theme_specifics.custom_theme_id()); | 390 EXPECT_EQ(theme_extension_->id(), theme_specifics.custom_theme_id()); |
391 EXPECT_EQ(theme_extension_->name(), theme_specifics.custom_theme_name()); | 391 EXPECT_EQ(theme_extension_->name(), theme_specifics.custom_theme_name()); |
392 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(theme_extension_).spec(), | 392 EXPECT_EQ( |
393 theme_specifics.custom_theme_update_url()); | 393 extensions::ManifestURL::GetUpdateURL(theme_extension_.get()).spec(), |
| 394 theme_specifics.custom_theme_update_url()); |
394 } | 395 } |
395 | 396 |
396 TEST_F(ThemeSyncableServiceTest, GetAllSyncData) { | 397 TEST_F(ThemeSyncableServiceTest, GetAllSyncData) { |
397 // Set up theme service to use custom theme. | 398 // Set up theme service to use custom theme. |
398 fake_theme_service_->SetTheme(theme_extension_.get()); | 399 fake_theme_service_->SetTheme(theme_extension_.get()); |
399 | 400 |
400 syncer::SyncDataList data_list = | 401 syncer::SyncDataList data_list = |
401 theme_sync_service_->GetAllSyncData(syncer::THEMES); | 402 theme_sync_service_->GetAllSyncData(syncer::THEMES); |
402 | 403 |
403 ASSERT_EQ(1u, data_list.size()); | 404 ASSERT_EQ(1u, data_list.size()); |
404 const sync_pb::ThemeSpecifics& theme_specifics = | 405 const sync_pb::ThemeSpecifics& theme_specifics = |
405 data_list[0].GetSpecifics().theme(); | 406 data_list[0].GetSpecifics().theme(); |
406 EXPECT_TRUE(theme_specifics.use_custom_theme()); | 407 EXPECT_TRUE(theme_specifics.use_custom_theme()); |
407 EXPECT_EQ(theme_extension_->id(), theme_specifics.custom_theme_id()); | 408 EXPECT_EQ(theme_extension_->id(), theme_specifics.custom_theme_id()); |
408 EXPECT_EQ(theme_extension_->name(), theme_specifics.custom_theme_name()); | 409 EXPECT_EQ(theme_extension_->name(), theme_specifics.custom_theme_name()); |
409 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(theme_extension_).spec(), | 410 EXPECT_EQ( |
410 theme_specifics.custom_theme_update_url()); | 411 extensions::ManifestURL::GetUpdateURL(theme_extension_.get()).spec(), |
| 412 theme_specifics.custom_theme_update_url()); |
411 } | 413 } |
412 | 414 |
413 TEST_F(ThemeSyncableServiceTest, ProcessSyncThemeChange) { | 415 TEST_F(ThemeSyncableServiceTest, ProcessSyncThemeChange) { |
414 // Set up theme service to use default theme. | 416 // Set up theme service to use default theme. |
415 fake_theme_service_->UseDefaultTheme(); | 417 fake_theme_service_->UseDefaultTheme(); |
416 fake_theme_service_->MarkClean(); | 418 fake_theme_service_->MarkClean(); |
417 | 419 |
418 // Start syncing. | 420 // Start syncing. |
419 syncer::SyncError error = theme_sync_service_->MergeDataAndStartSyncing( | 421 syncer::SyncError error = theme_sync_service_->MergeDataAndStartSyncing( |
420 syncer::THEMES, MakeThemeDataList(sync_pb::ThemeSpecifics()), | 422 syncer::THEMES, MakeThemeDataList(sync_pb::ThemeSpecifics()), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 464 |
463 // Change current theme to custom theme and notify theme_sync_service_. | 465 // Change current theme to custom theme and notify theme_sync_service_. |
464 fake_theme_service_->SetTheme(theme_extension_.get()); | 466 fake_theme_service_->SetTheme(theme_extension_.get()); |
465 theme_sync_service_->OnThemeChange(); | 467 theme_sync_service_->OnThemeChange(); |
466 EXPECT_EQ(1u, change_list.size()); | 468 EXPECT_EQ(1u, change_list.size()); |
467 const sync_pb::ThemeSpecifics& change_specifics = | 469 const sync_pb::ThemeSpecifics& change_specifics = |
468 change_list[0].sync_data().GetSpecifics().theme(); | 470 change_list[0].sync_data().GetSpecifics().theme(); |
469 EXPECT_TRUE(change_specifics.use_custom_theme()); | 471 EXPECT_TRUE(change_specifics.use_custom_theme()); |
470 EXPECT_EQ(theme_extension_->id(), change_specifics.custom_theme_id()); | 472 EXPECT_EQ(theme_extension_->id(), change_specifics.custom_theme_id()); |
471 EXPECT_EQ(theme_extension_->name(), change_specifics.custom_theme_name()); | 473 EXPECT_EQ(theme_extension_->name(), change_specifics.custom_theme_name()); |
472 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(theme_extension_).spec(), | 474 EXPECT_EQ( |
473 change_specifics.custom_theme_update_url()); | 475 extensions::ManifestURL::GetUpdateURL(theme_extension_.get()).spec(), |
| 476 change_specifics.custom_theme_update_url()); |
474 } | 477 } |
475 | 478 |
476 TEST_F(ThemeSyncableServiceTest, StopSync) { | 479 TEST_F(ThemeSyncableServiceTest, StopSync) { |
477 syncer::SyncChangeList change_list; | 480 syncer::SyncChangeList change_list; |
478 static_cast<FakeSyncChangeProcessor*>(fake_change_processor_.get())-> | 481 static_cast<FakeSyncChangeProcessor*>(fake_change_processor_.get())-> |
479 SetChangeOutput(&change_list); | 482 SetChangeOutput(&change_list); |
480 | 483 |
481 // Set up theme service to use default theme. | 484 // Set up theme service to use default theme. |
482 fake_theme_service_->UseDefaultTheme(); | 485 fake_theme_service_->UseDefaultTheme(); |
483 | 486 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 | 611 |
609 TEST_F(PolicyInstalledThemeTest, InstallThemeByPolicy) { | 612 TEST_F(PolicyInstalledThemeTest, InstallThemeByPolicy) { |
610 // Set up theme service to use custom theme that was installed by policy. | 613 // Set up theme service to use custom theme that was installed by policy. |
611 fake_theme_service_->SetTheme(theme_extension_.get()); | 614 fake_theme_service_->SetTheme(theme_extension_.get()); |
612 | 615 |
613 syncer::SyncDataList data_list = | 616 syncer::SyncDataList data_list = |
614 theme_sync_service_->GetAllSyncData(syncer::THEMES); | 617 theme_sync_service_->GetAllSyncData(syncer::THEMES); |
615 | 618 |
616 ASSERT_EQ(0u, data_list.size()); | 619 ASSERT_EQ(0u, data_list.size()); |
617 } | 620 } |
OLD | NEW |