OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/profile_resetter/profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/profile_resetter.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 fetcher->set_response_headers(download_headers); | 221 fetcher->set_response_headers(download_headers); |
222 return fetcher.Pass(); | 222 return fetcher.Pass(); |
223 } | 223 } |
224 | 224 |
225 | 225 |
226 // helper functions ----------------------------------------------------------- | 226 // helper functions ----------------------------------------------------------- |
227 | 227 |
228 scoped_refptr<Extension> CreateExtension(const std::string& name, | 228 scoped_refptr<Extension> CreateExtension(const std::string& name, |
229 const base::FilePath& path, | 229 const base::FilePath& path, |
230 Manifest::Location location, | 230 Manifest::Location location, |
231 bool theme) { | 231 extensions::Manifest::Type type) { |
232 DictionaryValue manifest; | 232 DictionaryValue manifest; |
233 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); | 233 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); |
234 manifest.SetString(extension_manifest_keys::kName, name); | 234 manifest.SetString(extension_manifest_keys::kName, name); |
235 manifest.SetString("app.launch.web_url", "http://www.google.com"); | 235 switch (type) { |
236 if (theme) | 236 case extensions::Manifest::TYPE_THEME: |
237 manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue); | 237 manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue); |
| 238 break; |
| 239 case extensions::Manifest::TYPE_HOSTED_APP: |
| 240 manifest.SetString("app.launch.web_url", "http://www.google.com"); |
| 241 break; |
| 242 case extensions::Manifest::TYPE_EXTENSION: |
| 243 // do nothing |
| 244 break; |
| 245 default: |
| 246 NOTREACHED(); |
| 247 } |
238 manifest.SetString(extension_manifest_keys::kOmniboxKeyword, name); | 248 manifest.SetString(extension_manifest_keys::kOmniboxKeyword, name); |
239 std::string error; | 249 std::string error; |
240 scoped_refptr<Extension> extension = Extension::Create( | 250 scoped_refptr<Extension> extension = Extension::Create( |
241 path, | 251 path, |
242 location, | 252 location, |
243 manifest, | 253 manifest, |
244 Extension::NO_FLAGS, | 254 Extension::NO_FLAGS, |
245 &error); | 255 &error); |
246 EXPECT_TRUE(extension.get() != NULL) << error; | 256 EXPECT_TRUE(extension.get() != NULL) << error; |
247 return extension; | 257 return extension; |
(...skipping 15 matching lines...) Expand all Loading... |
263 // Search engine's logic is tested by | 273 // Search engine's logic is tested by |
264 // TemplateURLServiceTest.ResetURLs. | 274 // TemplateURLServiceTest.ResetURLs. |
265 PrefService* prefs = profile()->GetPrefs(); | 275 PrefService* prefs = profile()->GetPrefs(); |
266 DCHECK(prefs); | 276 DCHECK(prefs); |
267 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/"); | 277 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/"); |
268 | 278 |
269 scoped_refptr<Extension> extension = CreateExtension( | 279 scoped_refptr<Extension> extension = CreateExtension( |
270 "xxx", | 280 "xxx", |
271 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 281 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
272 Manifest::COMPONENT, | 282 Manifest::COMPONENT, |
273 false); | 283 extensions::Manifest::TYPE_EXTENSION); |
274 service_->AddExtension(extension.get()); | 284 service_->AddExtension(extension.get()); |
275 | 285 |
276 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); | 286 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); |
277 | 287 |
278 // TemplateURLService should reset extension search engines. | 288 // TemplateURLService should reset extension search engines. |
279 TemplateURLService* model = | 289 TemplateURLService* model = |
280 TemplateURLServiceFactory::GetForProfile(profile()); | 290 TemplateURLServiceFactory::GetForProfile(profile()); |
281 TemplateURL* ext_url = model->GetTemplateURLForKeyword(ASCIIToUTF16("xxx")); | 291 TemplateURL* ext_url = model->GetTemplateURLForKeyword(ASCIIToUTF16("xxx")); |
282 ASSERT_TRUE(ext_url); | 292 ASSERT_TRUE(ext_url); |
283 EXPECT_TRUE(ext_url->IsExtensionKeyword()); | 293 EXPECT_TRUE(ext_url->IsExtensionKeyword()); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 content_type, std::string(), &host_settings); | 435 content_type, std::string(), &host_settings); |
426 EXPECT_EQ(1U, host_settings.size()); | 436 EXPECT_EQ(1U, host_settings.size()); |
427 } | 437 } |
428 } | 438 } |
429 } | 439 } |
430 | 440 |
431 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { | 441 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { |
432 base::ScopedTempDir temp_dir; | 442 base::ScopedTempDir temp_dir; |
433 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 443 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
434 | 444 |
435 scoped_refptr<Extension> theme = CreateExtension("example1", temp_dir.path(), | 445 scoped_refptr<Extension> theme = |
436 Manifest::INVALID_LOCATION, | 446 CreateExtension("example1", |
437 true); | 447 temp_dir.path(), |
| 448 Manifest::INVALID_LOCATION, |
| 449 extensions::Manifest::TYPE_THEME); |
438 service_->FinishInstallationForTest(theme.get()); | 450 service_->FinishInstallationForTest(theme.get()); |
439 // Let ThemeService finish creating the theme pack. | 451 // Let ThemeService finish creating the theme pack. |
440 base::MessageLoop::current()->RunUntilIdle(); | 452 base::MessageLoop::current()->RunUntilIdle(); |
441 | 453 |
442 // ThemeService isn't compiled for Android. | 454 // ThemeService isn't compiled for Android. |
443 ThemeService* theme_service = | 455 ThemeService* theme_service = |
444 ThemeServiceFactory::GetForProfile(profile()); | 456 ThemeServiceFactory::GetForProfile(profile()); |
445 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | 457 EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
446 | 458 |
447 scoped_refptr<Extension> ext2 = CreateExtension( | 459 scoped_refptr<Extension> ext2 = CreateExtension( |
448 "example2", | 460 "example2", |
449 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 461 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
450 Manifest::INVALID_LOCATION, | 462 Manifest::INVALID_LOCATION, |
451 false); | 463 extensions::Manifest::TYPE_EXTENSION); |
452 service_->AddExtension(ext2.get()); | 464 service_->AddExtension(ext2.get()); |
453 // Components and external policy extensions shouldn't be deleted. | 465 // Components and external policy extensions shouldn't be deleted. |
454 scoped_refptr<Extension> ext3 = CreateExtension( | 466 scoped_refptr<Extension> ext3 = CreateExtension( |
455 "example3", | 467 "example3", |
456 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), | 468 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), |
457 Manifest::COMPONENT, | 469 Manifest::COMPONENT, |
458 false); | 470 extensions::Manifest::TYPE_EXTENSION); |
459 service_->AddExtension(ext3.get()); | 471 service_->AddExtension(ext3.get()); |
460 scoped_refptr<Extension> ext4 = | 472 scoped_refptr<Extension> ext4 = |
461 CreateExtension("example4", | 473 CreateExtension("example4", |
462 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), | 474 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), |
463 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 475 Manifest::EXTERNAL_POLICY_DOWNLOAD, |
464 false); | 476 extensions::Manifest::TYPE_EXTENSION); |
465 service_->AddExtension(ext4.get()); | 477 service_->AddExtension(ext4.get()); |
466 EXPECT_EQ(4u, service_->extensions()->size()); | 478 EXPECT_EQ(4u, service_->extensions()->size()); |
467 | 479 |
468 ResetAndWait(ProfileResetter::EXTENSIONS); | 480 ResetAndWait(ProfileResetter::EXTENSIONS); |
469 | |
470 EXPECT_EQ(2u, service_->extensions()->size()); | 481 EXPECT_EQ(2u, service_->extensions()->size()); |
| 482 EXPECT_FALSE(service_->extensions()->Contains(theme->id())); |
| 483 EXPECT_FALSE(service_->extensions()->Contains(ext2->id())); |
471 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); | 484 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); |
472 EXPECT_TRUE(service_->extensions()->Contains(ext4->id())); | 485 EXPECT_TRUE(service_->extensions()->Contains(ext4->id())); |
473 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 486 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
474 } | 487 } |
475 | 488 |
476 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { | 489 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { |
477 scoped_refptr<Extension> ext2 = CreateExtension( | 490 scoped_refptr<Extension> ext2 = CreateExtension( |
478 "example2", | 491 "example2", |
479 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 492 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
480 Manifest::INVALID_LOCATION, | 493 Manifest::INVALID_LOCATION, |
481 false); | 494 extensions::Manifest::TYPE_EXTENSION); |
482 service_->AddExtension(ext2.get()); | 495 service_->AddExtension(ext2.get()); |
483 // Components and external policy extensions shouldn't be deleted. | 496 // Components and external policy extensions shouldn't be deleted. |
484 scoped_refptr<Extension> ext3 = CreateExtension( | 497 scoped_refptr<Extension> ext3 = CreateExtension( |
485 "example3", | 498 "example3", |
486 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), | 499 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), |
487 Manifest::INVALID_LOCATION, | 500 Manifest::INVALID_LOCATION, |
488 false); | 501 extensions::Manifest::TYPE_EXTENSION); |
489 service_->AddExtension(ext3.get()); | 502 service_->AddExtension(ext3.get()); |
490 EXPECT_EQ(2u, service_->extensions()->size()); | 503 EXPECT_EQ(2u, service_->extensions()->size()); |
491 | 504 |
492 std::string master_prefs(kDistributionConfig); | 505 std::string master_prefs(kDistributionConfig); |
493 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); | 506 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); |
494 | 507 |
495 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); | 508 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); |
496 | 509 |
497 EXPECT_EQ(1u, service_->extensions()->size()); | 510 EXPECT_EQ(1u, service_->extensions()->size()); |
498 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); | 511 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); |
499 } | 512 } |
500 | 513 |
| 514 TEST_F(ProfileResetterTest, ResetExtensionsCheckTypeFilter) { |
| 515 base::ScopedTempDir temp_dir; |
| 516 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 517 |
| 518 scoped_refptr<Extension> ext1 = |
| 519 CreateExtension("example1", |
| 520 temp_dir.path(), |
| 521 Manifest::INVALID_LOCATION, |
| 522 extensions::Manifest::TYPE_THEME); |
| 523 service_->FinishInstallationForTest(ext1.get()); |
| 524 // Let ThemeService finish creating the theme pack. |
| 525 base::MessageLoop::current()->RunUntilIdle(); |
| 526 |
| 527 // ThemeService isn't compiled for Android. |
| 528 ThemeService* theme_service = |
| 529 ThemeServiceFactory::GetForProfile(profile()); |
| 530 EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| 531 |
| 532 scoped_refptr<Extension> ext2 = |
| 533 CreateExtension("example2", |
| 534 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), |
| 535 Manifest::INVALID_LOCATION, |
| 536 extensions::Manifest::TYPE_EXTENSION); |
| 537 service_->AddExtension(ext2.get()); |
| 538 |
| 539 scoped_refptr<Extension> ext3 = |
| 540 CreateExtension("example2", |
| 541 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), |
| 542 Manifest::INVALID_LOCATION, |
| 543 extensions::Manifest::TYPE_HOSTED_APP); |
| 544 service_->AddExtension(ext3.get()); |
| 545 EXPECT_EQ(3u, service_->extensions()->size()); |
| 546 |
| 547 ResetAndWait(ProfileResetter::EXTENSIONS); |
| 548 |
| 549 EXPECT_EQ(1u, service_->extensions()->size()); |
| 550 EXPECT_FALSE(service_->extensions()->Contains(ext1->id())); |
| 551 EXPECT_FALSE(service_->extensions()->Contains(ext2->id())); |
| 552 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); |
| 553 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
| 554 } |
| 555 |
501 TEST_F(ProfileResetterTest, ResetStartPage) { | 556 TEST_F(ProfileResetterTest, ResetStartPage) { |
502 PrefService* prefs = profile()->GetPrefs(); | 557 PrefService* prefs = profile()->GetPrefs(); |
503 DCHECK(prefs); | 558 DCHECK(prefs); |
504 | 559 |
505 SessionStartupPref startup_pref(SessionStartupPref::URLS); | 560 SessionStartupPref startup_pref(SessionStartupPref::URLS); |
506 startup_pref.urls.push_back(GURL("http://foo")); | 561 startup_pref.urls.push_back(GURL("http://foo")); |
507 startup_pref.urls.push_back(GURL("http://bar")); | 562 startup_pref.urls.push_back(GURL("http://bar")); |
508 SessionStartupPref::SetStartupPref(prefs, startup_pref); | 563 SessionStartupPref::SetStartupPref(prefs, startup_pref); |
509 | 564 |
510 ResetAndWait(ProfileResetter::STARTUP_PAGES); | 565 ResetAndWait(ProfileResetter::STARTUP_PAGES); |
(...skipping 16 matching lines...) Expand all Loading... |
527 EXPECT_EQ(SessionStartupPref::URLS, startup_pref.type); | 582 EXPECT_EQ(SessionStartupPref::URLS, startup_pref.type); |
528 const GURL urls[] = {GURL("http://goo.gl"), GURL("http://foo.de")}; | 583 const GURL urls[] = {GURL("http://goo.gl"), GURL("http://foo.de")}; |
529 EXPECT_EQ(std::vector<GURL>(urls, urls + arraysize(urls)), startup_pref.urls); | 584 EXPECT_EQ(std::vector<GURL>(urls, urls + arraysize(urls)), startup_pref.urls); |
530 } | 585 } |
531 | 586 |
532 TEST_F(PinnedTabsResetTest, ResetPinnedTabs) { | 587 TEST_F(PinnedTabsResetTest, ResetPinnedTabs) { |
533 scoped_refptr<Extension> extension_app = CreateExtension( | 588 scoped_refptr<Extension> extension_app = CreateExtension( |
534 "hello!", | 589 "hello!", |
535 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 590 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
536 Manifest::INVALID_LOCATION, | 591 Manifest::INVALID_LOCATION, |
537 false); | 592 extensions::Manifest::TYPE_HOSTED_APP); |
538 scoped_ptr<content::WebContents> contents1(CreateWebContents()); | 593 scoped_ptr<content::WebContents> contents1(CreateWebContents()); |
539 extensions::TabHelper::CreateForWebContents(contents1.get()); | 594 extensions::TabHelper::CreateForWebContents(contents1.get()); |
540 extensions::TabHelper::FromWebContents(contents1.get())-> | 595 extensions::TabHelper::FromWebContents(contents1.get())-> |
541 SetExtensionApp(extension_app.get()); | 596 SetExtensionApp(extension_app.get()); |
542 scoped_ptr<content::WebContents> contents2(CreateWebContents()); | 597 scoped_ptr<content::WebContents> contents2(CreateWebContents()); |
543 scoped_ptr<content::WebContents> contents3(CreateWebContents()); | 598 scoped_ptr<content::WebContents> contents3(CreateWebContents()); |
544 scoped_ptr<content::WebContents> contents4(CreateWebContents()); | 599 scoped_ptr<content::WebContents> contents4(CreateWebContents()); |
545 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 600 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
546 | 601 |
547 tab_strip_model->AppendWebContents(contents4.get(), true); | 602 tab_strip_model->AppendWebContents(contents4.get(), true); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE), | 756 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE), |
702 dict->GetString("homepage", &homepage)); | 757 dict->GetString("homepage", &homepage)); |
703 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE_IS_NTP), | 758 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE_IS_NTP), |
704 dict->GetBoolean("homepage_is_ntp", &homepage_is_ntp)); | 759 dict->GetBoolean("homepage_is_ntp", &homepage_is_ntp)); |
705 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::DSE_URL), | 760 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::DSE_URL), |
706 dict->GetString("default_search_engine", &default_search_engine)); | 761 dict->GetString("default_search_engine", &default_search_engine)); |
707 } | 762 } |
708 } | 763 } |
709 | 764 |
710 } // namespace | 765 } // namespace |
OLD | NEW |