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

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

Issue 3166023: When extension is blacklisted by admin policy, it should be removed if alread... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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/extensions_service.cc ('k') | chrome/browser/profile_impl.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions_service_unittest.h" 5 #include "chrome/browser/extensions/extensions_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 1837
1838 // Now whitelist this particular extension. 1838 // Now whitelist this particular extension.
1839 whitelist->Append(Value::CreateStringValue(good_crx)); 1839 whitelist->Append(Value::CreateStringValue(good_crx));
1840 1840
1841 // Ensure we can now install good_crx. 1841 // Ensure we can now install good_crx.
1842 service_->InstallExtension(path); 1842 service_->InstallExtension(path);
1843 loop_.RunAllPending(); 1843 loop_.RunAllPending();
1844 EXPECT_EQ(1u, service_->extensions()->size()); 1844 EXPECT_EQ(1u, service_->extensions()->size());
1845 } 1845 }
1846 1846
1847 // Extension blacklisted by policy get unloaded after installing.
1848 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyRemovedIfRunning) {
1849 InitializeEmptyExtensionsService();
1850
1851 // Install good_crx.
1852 FilePath extensions_path;
1853 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1854 extensions_path = extensions_path.AppendASCII("extensions");
1855 FilePath path = extensions_path.AppendASCII("good.crx");
1856 service_->InstallExtension(path);
1857 loop_.RunAllPending();
1858 EXPECT_EQ(1u, service_->extensions()->size());
1859
1860 ListValue* blacklist = prefs_->GetMutableList("extensions.install.denylist");
1861 ASSERT_TRUE(blacklist != NULL);
1862
1863 // Blacklist this extension.
1864 blacklist->Append(Value::CreateStringValue(good_crx));
1865 prefs_->ScheduleSavePersistentPrefs();
1866
1867 // Programmatically appending to the prefs doesn't seem to notify the
1868 // observers... :/
1869 prefs_->pref_notifier()->FireObservers("extensions.install.denylist");
1870
1871 // Extension should not be running now.
1872 loop_.RunAllPending();
1873 EXPECT_EQ(0u, service_->extensions()->size());
1874 }
1875
1847 // Tests disabling extensions 1876 // Tests disabling extensions
1848 TEST_F(ExtensionsServiceTest, DisableExtension) { 1877 TEST_F(ExtensionsServiceTest, DisableExtension) {
1849 InitializeEmptyExtensionsService(); 1878 InitializeEmptyExtensionsService();
1850 FilePath extensions_path; 1879 FilePath extensions_path;
1851 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 1880 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
1852 extensions_path = extensions_path.AppendASCII("extensions"); 1881 extensions_path = extensions_path.AppendASCII("extensions");
1853 1882
1854 // A simple extension that should install without error. 1883 // A simple extension that should install without error.
1855 FilePath path = extensions_path.AppendASCII("good.crx"); 1884 FilePath path = extensions_path.AppendASCII("good.crx");
1856 InstallExtension(path, true); 1885 InstallExtension(path, true);
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 }; 2387 };
2359 2388
2360 // Test that we get enabled/disabled correctly for all the pref/command-line 2389 // Test that we get enabled/disabled correctly for all the pref/command-line
2361 // combinations. We don't want to derive from the ExtensionsServiceTest class 2390 // combinations. We don't want to derive from the ExtensionsServiceTest class
2362 // for this test, so we use ExtensionsServiceTestSimple. 2391 // for this test, so we use ExtensionsServiceTestSimple.
2363 // 2392 //
2364 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are 2393 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are
2365 // enabled or not. 2394 // enabled or not.
2366 TEST(ExtensionsServiceTestSimple, Enabledness) { 2395 TEST(ExtensionsServiceTestSimple, Enabledness) {
2367 ExtensionsReadyRecorder recorder; 2396 ExtensionsReadyRecorder recorder;
2368 TestingProfile profile; 2397 scoped_ptr<TestingProfile> profile(new TestingProfile());
2369 MessageLoop loop; 2398 MessageLoop loop;
2370 ChromeThread ui_thread(ChromeThread::UI, &loop); 2399 ChromeThread ui_thread(ChromeThread::UI, &loop);
2371 ChromeThread file_thread(ChromeThread::FILE, &loop); 2400 ChromeThread file_thread(ChromeThread::FILE, &loop);
2372 scoped_ptr<CommandLine> command_line; 2401 scoped_ptr<CommandLine> command_line;
2373 scoped_refptr<ExtensionsService> service; 2402 scoped_refptr<ExtensionsService> service;
2374 FilePath install_dir = profile.GetPath() 2403 FilePath install_dir = profile->GetPath()
2375 .AppendASCII(ExtensionsService::kInstallDirectoryName); 2404 .AppendASCII(ExtensionsService::kInstallDirectoryName);
2376 2405
2377 // By default, we are enabled. 2406 // By default, we are enabled.
2378 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); 2407 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY));
2379 service = new ExtensionsService(&profile, command_line.get(), 2408 service = new ExtensionsService(profile.get(), command_line.get(),
2380 profile.GetPrefs(), install_dir, false); 2409 profile->GetPrefs(), install_dir, false);
2381 EXPECT_TRUE(service->extensions_enabled()); 2410 EXPECT_TRUE(service->extensions_enabled());
2382 service->Init(); 2411 service->Init();
2383 loop.RunAllPending(); 2412 loop.RunAllPending();
2384 EXPECT_TRUE(recorder.ready()); 2413 EXPECT_TRUE(recorder.ready());
2385 2414
2386 // If either the command line or pref is set, we are disabled. 2415 // If either the command line or pref is set, we are disabled.
2387 recorder.set_ready(false); 2416 recorder.set_ready(false);
2417 profile.reset(new TestingProfile());
2388 command_line->AppendSwitch(switches::kDisableExtensions); 2418 command_line->AppendSwitch(switches::kDisableExtensions);
2389 service = new ExtensionsService(&profile, command_line.get(), 2419 service = new ExtensionsService(profile.get(), command_line.get(),
2390 profile.GetPrefs(), install_dir, false); 2420 profile->GetPrefs(), install_dir, false);
2391 EXPECT_FALSE(service->extensions_enabled()); 2421 EXPECT_FALSE(service->extensions_enabled());
2392 service->Init(); 2422 service->Init();
2393 loop.RunAllPending(); 2423 loop.RunAllPending();
2394 EXPECT_TRUE(recorder.ready()); 2424 EXPECT_TRUE(recorder.ready());
2395 2425
2396 recorder.set_ready(false); 2426 recorder.set_ready(false);
2397 profile.GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); 2427 profile.reset(new TestingProfile());
2398 service = new ExtensionsService(&profile, command_line.get(), 2428 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
2399 profile.GetPrefs(), install_dir, false); 2429 service = new ExtensionsService(profile.get(), command_line.get(),
2430 profile->GetPrefs(), install_dir, false);
2400 EXPECT_FALSE(service->extensions_enabled()); 2431 EXPECT_FALSE(service->extensions_enabled());
2401 service->Init(); 2432 service->Init();
2402 loop.RunAllPending(); 2433 loop.RunAllPending();
2403 EXPECT_TRUE(recorder.ready()); 2434 EXPECT_TRUE(recorder.ready());
2404 2435
2405 recorder.set_ready(false); 2436 recorder.set_ready(false);
2437 profile.reset(new TestingProfile());
2438 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
2406 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); 2439 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY));
2407 service = new ExtensionsService(&profile, command_line.get(), 2440 service = new ExtensionsService(profile.get(), command_line.get(),
2408 profile.GetPrefs(), install_dir, false); 2441 profile->GetPrefs(), install_dir, false);
2409 EXPECT_FALSE(service->extensions_enabled()); 2442 EXPECT_FALSE(service->extensions_enabled());
2410 service->Init(); 2443 service->Init();
2411 loop.RunAllPending(); 2444 loop.RunAllPending();
2412 EXPECT_TRUE(recorder.ready()); 2445 EXPECT_TRUE(recorder.ready());
2413 } 2446 }
2414 2447
2415 // Test loading extensions that require limited and unlimited storage quotas. 2448 // Test loading extensions that require limited and unlimited storage quotas.
2416 TEST_F(ExtensionsServiceTest, StorageQuota) { 2449 TEST_F(ExtensionsServiceTest, StorageQuota) {
2417 InitializeEmptyExtensionsService(); 2450 InitializeEmptyExtensionsService();
2418 2451
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 // Component extensions shouldn't get recourded in the prefs. 2536 // Component extensions shouldn't get recourded in the prefs.
2504 ValidatePrefKeyCount(0); 2537 ValidatePrefKeyCount(0);
2505 2538
2506 // Reload all extensions, and make sure it comes back. 2539 // Reload all extensions, and make sure it comes back.
2507 std::string extension_id = service_->extensions()->at(0)->id(); 2540 std::string extension_id = service_->extensions()->at(0)->id();
2508 loaded_.clear(); 2541 loaded_.clear();
2509 service_->ReloadExtensions(); 2542 service_->ReloadExtensions();
2510 ASSERT_EQ(1u, service_->extensions()->size()); 2543 ASSERT_EQ(1u, service_->extensions()->size());
2511 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); 2544 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id());
2512 } 2545 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698