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

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 23868042: Mark supervised profiles as such immediately when they're created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 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
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/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 int expected_creation_flags_; 437 int expected_creation_flags_;
438 scoped_ptr<extensions::ExternalProviderImpl> provider_; 438 scoped_ptr<extensions::ExternalProviderImpl> provider_;
439 scoped_ptr<DictionaryValue> prefs_; 439 scoped_ptr<DictionaryValue> prefs_;
440 scoped_ptr<TestingProfile> profile_; 440 scoped_ptr<TestingProfile> profile_;
441 441
442 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 442 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
443 }; 443 };
444 444
445 ExtensionServiceTestBase::ExtensionServiceInitParams:: 445 ExtensionServiceTestBase::ExtensionServiceInitParams::
446 ExtensionServiceInitParams() 446 ExtensionServiceInitParams()
447 : autoupdate_enabled(false), is_first_run(true) { 447 : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) {
448 } 448 }
449 449
450 // Our message loop may be used in tests which require it to be an IO loop. 450 // Our message loop may be used in tests which require it to be an IO loop.
451 ExtensionServiceTestBase::ExtensionServiceTestBase() 451 ExtensionServiceTestBase::ExtensionServiceTestBase()
452 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 452 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
453 service_(NULL), 453 service_(NULL),
454 management_policy_(NULL), 454 management_policy_(NULL),
455 expected_extensions_count_(0) { 455 expected_extensions_count_(0) {
456 base::FilePath test_data_dir; 456 base::FilePath test_data_dir;
457 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 457 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
(...skipping 17 matching lines...) Expand all
475 if (!params.pref_file.empty()) { 475 if (!params.pref_file.empty()) {
476 builder.WithUserFilePrefs(params.pref_file, 476 builder.WithUserFilePrefs(params.pref_file,
477 base::MessageLoopProxy::current().get()); 477 base::MessageLoopProxy::current().get());
478 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 478 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
479 new user_prefs::PrefRegistrySyncable); 479 new user_prefs::PrefRegistrySyncable);
480 scoped_ptr<PrefServiceSyncable> prefs( 480 scoped_ptr<PrefServiceSyncable> prefs(
481 builder.CreateSyncable(registry.get())); 481 builder.CreateSyncable(registry.get()));
482 chrome::RegisterUserProfilePrefs(registry.get()); 482 chrome::RegisterUserProfilePrefs(registry.get());
483 profile_builder.SetPrefService(prefs.Pass()); 483 profile_builder.SetPrefService(prefs.Pass());
484 } 484 }
485
486 if (params.profile_is_managed)
487 profile_builder.SetManagedUserId("asdf");
488
485 profile_builder.SetPath(params.profile_path); 489 profile_builder.SetPath(params.profile_path);
486 profile_ = profile_builder.Build(); 490 profile_ = profile_builder.Build();
487 491
488 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( 492 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
489 ExtensionSystem::Get(profile_.get())); 493 ExtensionSystem::Get(profile_.get()));
490 if (!params.is_first_run) { 494 if (!params.is_first_run) {
491 ExtensionPrefs* prefs = system->CreateExtensionPrefs( 495 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
492 CommandLine::ForCurrentProcess(), 496 CommandLine::ForCurrentProcess(),
493 params.extensions_install_dir); 497 params.extensions_install_dir);
494 prefs->SetAlertSystemFirstRun(); 498 prefs->SetAlertSystemFirstRun();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 base::FilePath source_install_dir = data_dir_ 551 base::FilePath source_install_dir = data_dir_
548 .AppendASCII("good") 552 .AppendASCII("good")
549 .AppendASCII("Extensions"); 553 .AppendASCII("Extensions");
550 base::FilePath pref_path = source_install_dir 554 base::FilePath pref_path = source_install_dir
551 .DirName() 555 .DirName()
552 .AppendASCII("Preferences"); 556 .AppendASCII("Preferences");
553 InitializeInstalledExtensionService(pref_path, source_install_dir); 557 InitializeInstalledExtensionService(pref_path, source_install_dir);
554 } 558 }
555 559
556 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { 560 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
557 InitializeExtensionServiceHelper(false, true); 561 ExtensionServiceInitParams params;
562 InitializeExtensionServiceParams(&params);
563 InitializeExtensionService(params);
558 } 564 }
559 565
560 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { 566 void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
561 static_cast<extensions::TestExtensionSystem*>( 567 static_cast<extensions::TestExtensionSystem*>(
562 ExtensionSystem::Get(profile_.get()))-> 568 ExtensionSystem::Get(profile_.get()))->
563 CreateExtensionProcessManager(); 569 CreateExtensionProcessManager();
564 } 570 }
565 571
566 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 572 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
567 InitializeExtensionServiceHelper(true, true); 573 ExtensionServiceInitParams params;
574 InitializeExtensionServiceParams(&params);
575 params.autoupdate_enabled = true;
576 InitializeExtensionService(params);
568 service_->updater()->Start(); 577 service_->updater()->Start();
569 } 578 }
570 579
571 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( 580 void ExtensionServiceTestBase::InitializeExtensionServiceParams(
572 bool autoupdate_enabled, bool is_first_run) { 581 ExtensionServiceInitParams* params) {
573 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 582 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
574 base::FilePath path = temp_dir_.path(); 583 base::FilePath path = temp_dir_.path();
575 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 584 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
576 base::DeleteFile(path, true); 585 base::DeleteFile(path, true);
577 file_util::CreateDirectory(path); 586 file_util::CreateDirectory(path);
578 base::FilePath prefs_filename = 587 base::FilePath prefs_filename =
579 path.Append(FILE_PATH_LITERAL("TestPreferences")); 588 path.Append(FILE_PATH_LITERAL("TestPreferences"));
580 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); 589 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions"));
581 base::DeleteFile(extensions_install_dir_, true); 590 base::DeleteFile(extensions_install_dir_, true);
582 file_util::CreateDirectory(extensions_install_dir_); 591 file_util::CreateDirectory(extensions_install_dir_);
583 592
584 ExtensionServiceInitParams params; 593 params->profile_path = path;
585 params.profile_path = path; 594 params->pref_file = prefs_filename;
586 params.pref_file = prefs_filename; 595 params->extensions_install_dir = extensions_install_dir_;
587 params.extensions_install_dir = extensions_install_dir_;
588 params.autoupdate_enabled = autoupdate_enabled;
589 params.is_first_run = is_first_run;
590 InitializeExtensionService(params);
591 } 596 }
592 597
593 // static 598 // static
594 void ExtensionServiceTestBase::SetUpTestCase() { 599 void ExtensionServiceTestBase::SetUpTestCase() {
595 ExtensionErrorReporter::Init(false); // no noisy errors 600 ExtensionErrorReporter::Init(false); // no noisy errors
596 } 601 }
597 602
598 void ExtensionServiceTestBase::SetUp() { 603 void ExtensionServiceTestBase::SetUp() {
599 ExtensionErrorReporter::GetInstance()->ClearErrors(); 604 ExtensionErrorReporter::GetInstance()->ClearErrors();
600 content::RenderProcessHost::SetRunRendererInProcess(true); 605 content::RenderProcessHost::SetRunRendererInProcess(true);
(...skipping 5744 matching lines...) Expand 10 before | Expand all | Expand 10 after
6345 } 6350 }
6346 6351
6347 // Test that there is a bubble for external extensions that update 6352 // Test that there is a bubble for external extensions that update
6348 // from the webstore if the profile is not new. 6353 // from the webstore if the profile is not new.
6349 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { 6354 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) {
6350 FeatureSwitch::ScopedOverride prompt( 6355 FeatureSwitch::ScopedOverride prompt(
6351 FeatureSwitch::prompt_for_external_extensions(), true); 6356 FeatureSwitch::prompt_for_external_extensions(), true);
6352 6357
6353 // This sets up the ExtensionPrefs used by our ExtensionService to be 6358 // This sets up the ExtensionPrefs used by our ExtensionService to be
6354 // post-first run. 6359 // post-first run.
6355 InitializeExtensionServiceHelper(false, false); 6360 ExtensionServiceInitParams params;
6361 InitializeExtensionServiceParams(&params);
6362 params.is_first_run = false;
6363 InitializeExtensionService(params);
6356 6364
6357 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6365 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx");
6358 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6366 PackCRX(data_dir_.AppendASCII("update_from_webstore"),
6359 data_dir_.AppendASCII("update_from_webstore.pem"), 6367 data_dir_.AppendASCII("update_from_webstore.pem"),
6360 crx_path); 6368 crx_path);
6361 6369
6362 MockExtensionProvider* provider = 6370 MockExtensionProvider* provider =
6363 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6371 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6364 AddMockExternalProvider(provider); 6372 AddMockExternalProvider(provider);
6365 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6373 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
6430 EXPECT_TRUE(notifications.CheckNotifications( 6438 EXPECT_TRUE(notifications.CheckNotifications(
6431 chrome::NOTIFICATION_EXTENSION_INSTALLED)); 6439 chrome::NOTIFICATION_EXTENSION_INSTALLED));
6432 6440
6433 EXPECT_TRUE(service_->GetInstalledExtension(id)); 6441 EXPECT_TRUE(service_->GetInstalledExtension(id));
6434 EXPECT_FALSE(service_->extensions()->Contains(id)); 6442 EXPECT_FALSE(service_->extensions()->Contains(id));
6435 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); 6443 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id));
6436 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); 6444 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id));
6437 EXPECT_TRUE( 6445 EXPECT_TRUE(
6438 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); 6446 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id));
6439 } 6447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698