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

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: leak Created 7 years, 2 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 int expected_creation_flags_; 442 int expected_creation_flags_;
443 scoped_ptr<extensions::ExternalProviderImpl> provider_; 443 scoped_ptr<extensions::ExternalProviderImpl> provider_;
444 scoped_ptr<DictionaryValue> prefs_; 444 scoped_ptr<DictionaryValue> prefs_;
445 scoped_ptr<TestingProfile> profile_; 445 scoped_ptr<TestingProfile> profile_;
446 446
447 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 447 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
448 }; 448 };
449 449
450 ExtensionServiceTestBase::ExtensionServiceInitParams:: 450 ExtensionServiceTestBase::ExtensionServiceInitParams::
451 ExtensionServiceInitParams() 451 ExtensionServiceInitParams()
452 : autoupdate_enabled(false), is_first_run(true) { 452 : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) {
453 } 453 }
454 454
455 // Our message loop may be used in tests which require it to be an IO loop. 455 // Our message loop may be used in tests which require it to be an IO loop.
456 ExtensionServiceTestBase::ExtensionServiceTestBase() 456 ExtensionServiceTestBase::ExtensionServiceTestBase()
457 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 457 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
458 service_(NULL), 458 service_(NULL),
459 management_policy_(NULL), 459 management_policy_(NULL),
460 expected_extensions_count_(0) { 460 expected_extensions_count_(0) {
461 base::FilePath test_data_dir; 461 base::FilePath test_data_dir;
462 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 462 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
(...skipping 17 matching lines...) Expand all
480 if (!params.pref_file.empty()) { 480 if (!params.pref_file.empty()) {
481 builder.WithUserFilePrefs(params.pref_file, 481 builder.WithUserFilePrefs(params.pref_file,
482 base::MessageLoopProxy::current().get()); 482 base::MessageLoopProxy::current().get());
483 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 483 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
484 new user_prefs::PrefRegistrySyncable); 484 new user_prefs::PrefRegistrySyncable);
485 scoped_ptr<PrefServiceSyncable> prefs( 485 scoped_ptr<PrefServiceSyncable> prefs(
486 builder.CreateSyncable(registry.get())); 486 builder.CreateSyncable(registry.get()));
487 chrome::RegisterUserProfilePrefs(registry.get()); 487 chrome::RegisterUserProfilePrefs(registry.get());
488 profile_builder.SetPrefService(prefs.Pass()); 488 profile_builder.SetPrefService(prefs.Pass());
489 } 489 }
490
491 if (params.profile_is_managed)
492 profile_builder.SetManagedUserId("asdf");
493
490 profile_builder.SetPath(params.profile_path); 494 profile_builder.SetPath(params.profile_path);
491 profile_ = profile_builder.Build(); 495 profile_ = profile_builder.Build();
492 496
493 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( 497 TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
494 ExtensionSystem::Get(profile_.get())); 498 ExtensionSystem::Get(profile_.get()));
495 if (!params.is_first_run) { 499 if (!params.is_first_run) {
496 ExtensionPrefs* prefs = system->CreateExtensionPrefs( 500 ExtensionPrefs* prefs = system->CreateExtensionPrefs(
497 CommandLine::ForCurrentProcess(), 501 CommandLine::ForCurrentProcess(),
498 params.extensions_install_dir); 502 params.extensions_install_dir);
499 prefs->SetAlertSystemFirstRun(); 503 prefs->SetAlertSystemFirstRun();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 base::FilePath source_install_dir = data_dir_ 556 base::FilePath source_install_dir = data_dir_
553 .AppendASCII("good") 557 .AppendASCII("good")
554 .AppendASCII("Extensions"); 558 .AppendASCII("Extensions");
555 base::FilePath pref_path = source_install_dir 559 base::FilePath pref_path = source_install_dir
556 .DirName() 560 .DirName()
557 .AppendASCII("Preferences"); 561 .AppendASCII("Preferences");
558 InitializeInstalledExtensionService(pref_path, source_install_dir); 562 InitializeInstalledExtensionService(pref_path, source_install_dir);
559 } 563 }
560 564
561 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { 565 void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
562 InitializeExtensionServiceHelper(false, true); 566 ExtensionServiceInitParams params;
567 InitializeExtensionServiceParams(&params);
568 InitializeExtensionService(params);
not at google - send to devlin 2013/10/16 21:12:50 this 1 -> 3 line thing is awkward. Can you make In
Bernhard Bauer 2013/10/17 14:12:03 Done.
563 } 569 }
564 570
565 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { 571 void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
566 static_cast<extensions::TestExtensionSystem*>( 572 static_cast<extensions::TestExtensionSystem*>(
567 ExtensionSystem::Get(profile_.get()))-> 573 ExtensionSystem::Get(profile_.get()))->
568 CreateExtensionProcessManager(); 574 CreateExtensionProcessManager();
569 } 575 }
570 576
571 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 577 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
572 InitializeExtensionServiceHelper(true, true); 578 ExtensionServiceInitParams params;
579 InitializeExtensionServiceParams(&params);
580 params.autoupdate_enabled = true;
581 InitializeExtensionService(params);
573 service_->updater()->Start(); 582 service_->updater()->Start();
574 } 583 }
575 584
576 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( 585 void ExtensionServiceTestBase::InitializeExtensionServiceParams(
577 bool autoupdate_enabled, bool is_first_run) { 586 ExtensionServiceInitParams* params) {
578 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 587 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
579 base::FilePath path = temp_dir_.path(); 588 base::FilePath path = temp_dir_.path();
580 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); 589 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath"));
581 base::DeleteFile(path, true); 590 base::DeleteFile(path, true);
582 file_util::CreateDirectory(path); 591 file_util::CreateDirectory(path);
583 base::FilePath prefs_filename = 592 base::FilePath prefs_filename =
584 path.Append(FILE_PATH_LITERAL("TestPreferences")); 593 path.Append(FILE_PATH_LITERAL("TestPreferences"));
585 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); 594 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions"));
586 base::DeleteFile(extensions_install_dir_, true); 595 base::DeleteFile(extensions_install_dir_, true);
587 file_util::CreateDirectory(extensions_install_dir_); 596 file_util::CreateDirectory(extensions_install_dir_);
588 597
589 ExtensionServiceInitParams params; 598 params->profile_path = path;
590 params.profile_path = path; 599 params->pref_file = prefs_filename;
591 params.pref_file = prefs_filename; 600 params->extensions_install_dir = extensions_install_dir_;
592 params.extensions_install_dir = extensions_install_dir_;
593 params.autoupdate_enabled = autoupdate_enabled;
594 params.is_first_run = is_first_run;
595 InitializeExtensionService(params);
596 } 601 }
597 602
598 // static 603 // static
599 void ExtensionServiceTestBase::SetUpTestCase() { 604 void ExtensionServiceTestBase::SetUpTestCase() {
600 ExtensionErrorReporter::Init(false); // no noisy errors 605 ExtensionErrorReporter::Init(false); // no noisy errors
601 } 606 }
602 607
603 void ExtensionServiceTestBase::SetUp() { 608 void ExtensionServiceTestBase::SetUp() {
604 ExtensionErrorReporter::GetInstance()->ClearErrors(); 609 ExtensionErrorReporter::GetInstance()->ClearErrors();
605 content::RenderProcessHost::SetRunRendererInProcess(true); 610 content::RenderProcessHost::SetRunRendererInProcess(true);
(...skipping 5862 matching lines...) Expand 10 before | Expand all | Expand 10 after
6468 } 6473 }
6469 6474
6470 // Test that there is a bubble for external extensions that update 6475 // Test that there is a bubble for external extensions that update
6471 // from the webstore if the profile is not new. 6476 // from the webstore if the profile is not new.
6472 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { 6477 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) {
6473 FeatureSwitch::ScopedOverride prompt( 6478 FeatureSwitch::ScopedOverride prompt(
6474 FeatureSwitch::prompt_for_external_extensions(), true); 6479 FeatureSwitch::prompt_for_external_extensions(), true);
6475 6480
6476 // This sets up the ExtensionPrefs used by our ExtensionService to be 6481 // This sets up the ExtensionPrefs used by our ExtensionService to be
6477 // post-first run. 6482 // post-first run.
6478 InitializeExtensionServiceHelper(false, false); 6483 ExtensionServiceInitParams params;
6484 InitializeExtensionServiceParams(&params);
6485 params.is_first_run = false;
6486 InitializeExtensionService(params);
6479 6487
6480 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); 6488 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx");
6481 PackCRX(data_dir_.AppendASCII("update_from_webstore"), 6489 PackCRX(data_dir_.AppendASCII("update_from_webstore"),
6482 data_dir_.AppendASCII("update_from_webstore.pem"), 6490 data_dir_.AppendASCII("update_from_webstore.pem"),
6483 crx_path); 6491 crx_path);
6484 6492
6485 MockExtensionProvider* provider = 6493 MockExtensionProvider* provider =
6486 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); 6494 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
6487 AddMockExternalProvider(provider); 6495 AddMockExternalProvider(provider);
6488 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); 6496 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
6616 // ReconcileKnownDisabled(). 6624 // ReconcileKnownDisabled().
6617 service_->EnableExtension(good2); 6625 service_->EnableExtension(good2);
6618 service_->ReconcileKnownDisabled(); 6626 service_->ReconcileKnownDisabled();
6619 expected_extensions.insert(good2); 6627 expected_extensions.insert(good2);
6620 expected_disabled_extensions.erase(good2); 6628 expected_disabled_extensions.erase(good2);
6621 6629
6622 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); 6630 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs());
6623 EXPECT_EQ(expected_disabled_extensions, 6631 EXPECT_EQ(expected_disabled_extensions,
6624 service_->disabled_extensions()->GetIDs()); 6632 service_->disabled_extensions()->GetIDs());
6625 } 6633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698