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

Side by Side Diff: chrome/browser/profile_resetter/profile_resetter_unittest.cc

Issue 22145004: Profile Reset: Don't disable defaults apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Grammar Created 7 years, 4 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
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bool installed_by_default) {
232 DictionaryValue manifest; 233 DictionaryValue manifest;
233 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); 234 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0");
234 manifest.SetString(extension_manifest_keys::kName, name); 235 manifest.SetString(extension_manifest_keys::kName, name);
235 manifest.SetString("app.launch.web_url", "http://www.google.com"); 236 switch (type) {
236 if (theme) 237 case extensions::Manifest::TYPE_THEME:
237 manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue); 238 manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue);
239 break;
240 case extensions::Manifest::TYPE_HOSTED_APP:
241 manifest.SetString(extension_manifest_keys::kLaunchWebURL,
242 "http://www.google.com");
243 manifest.SetString(extension_manifest_keys::kUpdateURL,
244 "http://clients2.google.com/service/update2/crx");
245 break;
246 case extensions::Manifest::TYPE_EXTENSION:
247 // do nothing
248 break;
249 default:
250 NOTREACHED();
251 }
238 manifest.SetString(extension_manifest_keys::kOmniboxKeyword, name); 252 manifest.SetString(extension_manifest_keys::kOmniboxKeyword, name);
239 std::string error; 253 std::string error;
240 scoped_refptr<Extension> extension = Extension::Create( 254 scoped_refptr<Extension> extension = Extension::Create(
241 path, 255 path,
242 location, 256 location,
243 manifest, 257 manifest,
244 Extension::NO_FLAGS, 258 installed_by_default ? Extension::WAS_INSTALLED_BY_DEFAULT
259 : Extension::NO_FLAGS,
245 &error); 260 &error);
246 EXPECT_TRUE(extension.get() != NULL) << error; 261 EXPECT_TRUE(extension.get() != NULL) << error;
247 return extension; 262 return extension;
248 } 263 }
249 264
250 void ReplaceString(std::string* str, 265 void ReplaceString(std::string* str,
251 const std::string& placeholder, 266 const std::string& placeholder,
252 const std::string& substitution) { 267 const std::string& substitution) {
253 ASSERT_NE(static_cast<std::string*>(NULL), str); 268 ASSERT_NE(static_cast<std::string*>(NULL), str);
254 size_t placeholder_pos = str->find(placeholder); 269 size_t placeholder_pos = str->find(placeholder);
255 ASSERT_NE(std::string::npos, placeholder_pos); 270 ASSERT_NE(std::string::npos, placeholder_pos);
256 str->replace(placeholder_pos, placeholder.size(), substitution); 271 str->replace(placeholder_pos, placeholder.size(), substitution);
257 } 272 }
258 273
259 274
260 /********************* Tests *********************/ 275 /********************* Tests *********************/
261 276
262 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) { 277 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) {
263 // Search engine's logic is tested by 278 // Search engine's logic is tested by
264 // TemplateURLServiceTest.ResetURLs. 279 // TemplateURLServiceTest.ResetURLs.
265 PrefService* prefs = profile()->GetPrefs(); 280 PrefService* prefs = profile()->GetPrefs();
266 DCHECK(prefs); 281 DCHECK(prefs);
267 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/"); 282 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/");
268 283
269 scoped_refptr<Extension> extension = CreateExtension( 284 scoped_refptr<Extension> extension = CreateExtension(
270 "xxx", 285 "xxx",
271 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 286 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
272 Manifest::COMPONENT, 287 Manifest::COMPONENT,
288 extensions::Manifest::TYPE_EXTENSION,
273 false); 289 false);
274 service_->AddExtension(extension.get()); 290 service_->AddExtension(extension.get());
275 291
276 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); 292 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE);
277 293
278 // TemplateURLService should reset extension search engines. 294 // TemplateURLService should reset extension search engines.
279 TemplateURLService* model = 295 TemplateURLService* model =
280 TemplateURLServiceFactory::GetForProfile(profile()); 296 TemplateURLServiceFactory::GetForProfile(profile());
281 TemplateURL* ext_url = model->GetTemplateURLForKeyword(ASCIIToUTF16("xxx")); 297 TemplateURL* ext_url = model->GetTemplateURLForKeyword(ASCIIToUTF16("xxx"));
282 ASSERT_TRUE(ext_url); 298 ASSERT_TRUE(ext_url);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 443 }
428 } 444 }
429 } 445 }
430 446
431 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { 447 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) {
432 service_->Init(); 448 service_->Init();
433 449
434 base::ScopedTempDir temp_dir; 450 base::ScopedTempDir temp_dir;
435 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 451 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
436 452
437 scoped_refptr<Extension> theme = CreateExtension("example1", temp_dir.path(), 453 scoped_refptr<Extension> theme =
438 Manifest::INVALID_LOCATION, 454 CreateExtension("example1",
439 true); 455 temp_dir.path(),
456 Manifest::INVALID_LOCATION,
457 extensions::Manifest::TYPE_THEME,
458 false);
440 service_->FinishInstallationForTest(theme.get()); 459 service_->FinishInstallationForTest(theme.get());
441 // Let ThemeService finish creating the theme pack. 460 // Let ThemeService finish creating the theme pack.
442 base::MessageLoop::current()->RunUntilIdle(); 461 base::MessageLoop::current()->RunUntilIdle();
443 462
444 // ThemeService isn't compiled for Android.
445 ThemeService* theme_service = 463 ThemeService* theme_service =
446 ThemeServiceFactory::GetForProfile(profile()); 464 ThemeServiceFactory::GetForProfile(profile());
447 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 465 EXPECT_FALSE(theme_service->UsingDefaultTheme());
448 466
449 scoped_refptr<Extension> ext2 = CreateExtension( 467 scoped_refptr<Extension> ext2 = CreateExtension(
450 "example2", 468 "example2",
451 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 469 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
452 Manifest::INVALID_LOCATION, 470 Manifest::INVALID_LOCATION,
471 extensions::Manifest::TYPE_EXTENSION,
453 false); 472 false);
454 service_->AddExtension(ext2.get()); 473 service_->AddExtension(ext2.get());
455 // Components and external policy extensions shouldn't be deleted. 474 // Components and external policy extensions shouldn't be deleted.
456 scoped_refptr<Extension> ext3 = CreateExtension( 475 scoped_refptr<Extension> ext3 = CreateExtension(
457 "example3", 476 "example3",
458 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), 477 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")),
459 Manifest::COMPONENT, 478 Manifest::COMPONENT,
479 extensions::Manifest::TYPE_EXTENSION,
460 false); 480 false);
461 service_->AddExtension(ext3.get()); 481 service_->AddExtension(ext3.get());
462 scoped_refptr<Extension> ext4 = 482 scoped_refptr<Extension> ext4 =
463 CreateExtension("example4", 483 CreateExtension("example4",
464 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), 484 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")),
465 Manifest::EXTERNAL_POLICY_DOWNLOAD, 485 Manifest::EXTERNAL_POLICY_DOWNLOAD,
486 extensions::Manifest::TYPE_EXTENSION,
466 false); 487 false);
467 service_->AddExtension(ext4.get()); 488 service_->AddExtension(ext4.get());
468 EXPECT_EQ(4u, service_->extensions()->size()); 489 EXPECT_EQ(4u, service_->extensions()->size());
469 490
470 ResetAndWait(ProfileResetter::EXTENSIONS); 491 ResetAndWait(ProfileResetter::EXTENSIONS);
471
472 EXPECT_EQ(2u, service_->extensions()->size()); 492 EXPECT_EQ(2u, service_->extensions()->size());
493 EXPECT_FALSE(service_->extensions()->Contains(theme->id()));
494 EXPECT_FALSE(service_->extensions()->Contains(ext2->id()));
473 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); 495 EXPECT_TRUE(service_->extensions()->Contains(ext3->id()));
474 EXPECT_TRUE(service_->extensions()->Contains(ext4->id())); 496 EXPECT_TRUE(service_->extensions()->Contains(ext4->id()));
475 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 497 EXPECT_TRUE(theme_service->UsingDefaultTheme());
476 } 498 }
477 499
478 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { 500 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) {
479 scoped_refptr<Extension> ext2 = CreateExtension( 501 scoped_refptr<Extension> ext2 = CreateExtension(
480 "example2", 502 "example2",
481 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 503 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
482 Manifest::INVALID_LOCATION, 504 Manifest::INVALID_LOCATION,
505 extensions::Manifest::TYPE_EXTENSION,
483 false); 506 false);
484 service_->AddExtension(ext2.get()); 507 service_->AddExtension(ext2.get());
485 // Components and external policy extensions shouldn't be deleted. 508 // Components and external policy extensions shouldn't be deleted.
486 scoped_refptr<Extension> ext3 = CreateExtension( 509 scoped_refptr<Extension> ext3 = CreateExtension(
487 "example3", 510 "example3",
488 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), 511 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")),
489 Manifest::INVALID_LOCATION, 512 Manifest::INVALID_LOCATION,
513 extensions::Manifest::TYPE_EXTENSION,
490 false); 514 false);
491 service_->AddExtension(ext3.get()); 515 service_->AddExtension(ext3.get());
492 EXPECT_EQ(2u, service_->extensions()->size()); 516 EXPECT_EQ(2u, service_->extensions()->size());
493 517
494 std::string master_prefs(kDistributionConfig); 518 std::string master_prefs(kDistributionConfig);
495 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); 519 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id());
496 520
497 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); 521 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs);
498 522
499 EXPECT_EQ(1u, service_->extensions()->size()); 523 EXPECT_EQ(1u, service_->extensions()->size());
500 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); 524 EXPECT_TRUE(service_->extensions()->Contains(ext3->id()));
501 } 525 }
502 526
527 TEST_F(ProfileResetterTest, ResetExtensionsAndDefaultApps) {
528 service_->Init();
529
530 base::ScopedTempDir temp_dir;
531 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
532
533 scoped_refptr<Extension> ext1 =
534 CreateExtension("example1",
535 temp_dir.path(),
536 Manifest::INVALID_LOCATION,
537 extensions::Manifest::TYPE_THEME,
538 false);
539 service_->FinishInstallationForTest(ext1.get());
540 // Let ThemeService finish creating the theme pack.
541 base::MessageLoop::current()->RunUntilIdle();
542
543 ThemeService* theme_service =
544 ThemeServiceFactory::GetForProfile(profile());
545 EXPECT_FALSE(theme_service->UsingDefaultTheme());
546
547 scoped_refptr<Extension> ext2 =
548 CreateExtension("example2",
549 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")),
550 Manifest::INVALID_LOCATION,
551 extensions::Manifest::TYPE_EXTENSION,
552 false);
553 service_->AddExtension(ext2.get());
554
555 scoped_refptr<Extension> ext3 =
556 CreateExtension("example2",
557 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")),
558 Manifest::INVALID_LOCATION,
559 extensions::Manifest::TYPE_HOSTED_APP,
560 true);
561 service_->AddExtension(ext3.get());
562 EXPECT_EQ(3u, service_->extensions()->size());
563
564 ResetAndWait(ProfileResetter::EXTENSIONS);
565
566 EXPECT_EQ(1u, service_->extensions()->size());
567 EXPECT_FALSE(service_->extensions()->Contains(ext1->id()));
568 EXPECT_FALSE(service_->extensions()->Contains(ext2->id()));
569 EXPECT_TRUE(service_->extensions()->Contains(ext3->id()));
570 EXPECT_TRUE(theme_service->UsingDefaultTheme());
571 }
572
503 TEST_F(ProfileResetterTest, ResetStartPage) { 573 TEST_F(ProfileResetterTest, ResetStartPage) {
504 PrefService* prefs = profile()->GetPrefs(); 574 PrefService* prefs = profile()->GetPrefs();
505 DCHECK(prefs); 575 DCHECK(prefs);
506 576
507 SessionStartupPref startup_pref(SessionStartupPref::URLS); 577 SessionStartupPref startup_pref(SessionStartupPref::URLS);
508 startup_pref.urls.push_back(GURL("http://foo")); 578 startup_pref.urls.push_back(GURL("http://foo"));
509 startup_pref.urls.push_back(GURL("http://bar")); 579 startup_pref.urls.push_back(GURL("http://bar"));
510 SessionStartupPref::SetStartupPref(prefs, startup_pref); 580 SessionStartupPref::SetStartupPref(prefs, startup_pref);
511 581
512 ResetAndWait(ProfileResetter::STARTUP_PAGES); 582 ResetAndWait(ProfileResetter::STARTUP_PAGES);
(...skipping 16 matching lines...) Expand all
529 EXPECT_EQ(SessionStartupPref::URLS, startup_pref.type); 599 EXPECT_EQ(SessionStartupPref::URLS, startup_pref.type);
530 const GURL urls[] = {GURL("http://goo.gl"), GURL("http://foo.de")}; 600 const GURL urls[] = {GURL("http://goo.gl"), GURL("http://foo.de")};
531 EXPECT_EQ(std::vector<GURL>(urls, urls + arraysize(urls)), startup_pref.urls); 601 EXPECT_EQ(std::vector<GURL>(urls, urls + arraysize(urls)), startup_pref.urls);
532 } 602 }
533 603
534 TEST_F(PinnedTabsResetTest, ResetPinnedTabs) { 604 TEST_F(PinnedTabsResetTest, ResetPinnedTabs) {
535 scoped_refptr<Extension> extension_app = CreateExtension( 605 scoped_refptr<Extension> extension_app = CreateExtension(
536 "hello!", 606 "hello!",
537 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 607 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
538 Manifest::INVALID_LOCATION, 608 Manifest::INVALID_LOCATION,
609 extensions::Manifest::TYPE_HOSTED_APP,
539 false); 610 false);
540 scoped_ptr<content::WebContents> contents1(CreateWebContents()); 611 scoped_ptr<content::WebContents> contents1(CreateWebContents());
541 extensions::TabHelper::CreateForWebContents(contents1.get()); 612 extensions::TabHelper::CreateForWebContents(contents1.get());
542 extensions::TabHelper::FromWebContents(contents1.get())-> 613 extensions::TabHelper::FromWebContents(contents1.get())->
543 SetExtensionApp(extension_app.get()); 614 SetExtensionApp(extension_app.get());
544 scoped_ptr<content::WebContents> contents2(CreateWebContents()); 615 scoped_ptr<content::WebContents> contents2(CreateWebContents());
545 scoped_ptr<content::WebContents> contents3(CreateWebContents()); 616 scoped_ptr<content::WebContents> contents3(CreateWebContents());
546 scoped_ptr<content::WebContents> contents4(CreateWebContents()); 617 scoped_ptr<content::WebContents> contents4(CreateWebContents());
547 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 618 TabStripModel* tab_strip_model = browser()->tab_strip_model();
548 619
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE), 774 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE),
704 dict->GetString("homepage", &homepage)); 775 dict->GetString("homepage", &homepage));
705 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE_IS_NTP), 776 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::HOMEPAGE_IS_NTP),
706 dict->GetBoolean("homepage_is_ntp", &homepage_is_ntp)); 777 dict->GetBoolean("homepage_is_ntp", &homepage_is_ntp));
707 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::DSE_URL), 778 EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::DSE_URL),
708 dict->GetString("default_search_engine", &default_search_engine)); 779 dict->GetString("default_search_engine", &default_search_engine));
709 } 780 }
710 } 781 }
711 782
712 } // namespace 783 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698