OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/download/download_crx_util.h" | 8 #include "chrome/browser/download/download_crx_util.h" |
9 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
10 #include "chrome/browser/extensions/crx_installer.h" | 10 #include "chrome/browser/extensions/crx_installer.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_install_prompt.h" | 12 #include "chrome/browser/extensions/extension_install_prompt.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_util.h" | 14 #include "chrome/browser/extensions/extension_util.h" |
15 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" | 15 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
16 #include "chrome/browser/extensions/test_extension_dir.h" | |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/download_manager.h" | 24 #include "content/public/browser/download_manager.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/download_test_observer.h" | 27 #include "content/public/test/download_test_observer.h" |
27 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
29 #include "extensions/browser/extension_registry.h" | |
28 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
29 #include "extensions/browser/management_policy.h" | 31 #include "extensions/browser/management_policy.h" |
30 #include "extensions/browser/notification_types.h" | 32 #include "extensions/browser/notification_types.h" |
31 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
32 #include "extensions/common/feature_switch.h" | 34 #include "extensions/common/feature_switch.h" |
33 #include "extensions/common/file_util.h" | 35 #include "extensions/common/file_util.h" |
34 #include "extensions/common/permissions/permission_set.h" | 36 #include "extensions/common/permissions/permission_set.h" |
35 #include "extensions/common/switches.h" | 37 #include "extensions/common/switches.h" |
36 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
37 | 39 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 ->GetGrantedPermissions(mock_prompt->extension_id()); | 231 ->GetGrantedPermissions(mock_prompt->extension_id()); |
230 ASSERT_TRUE(permissions.get()); | 232 ASSERT_TRUE(permissions.get()); |
231 } | 233 } |
232 }; | 234 }; |
233 | 235 |
234 // This test is skipped on ChromeOS because it requires the NPAPI, | 236 // This test is skipped on ChromeOS because it requires the NPAPI, |
235 // which is not available on that platform. | 237 // which is not available on that platform. |
236 #if !defined(OS_CHROMEOS) | 238 #if !defined(OS_CHROMEOS) |
237 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { | 239 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { |
238 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; | 240 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; |
239 ExtensionService* service = extensions::ExtensionSystem::Get( | 241 ExtensionRegistry* registry = ExtensionRegistry::Get( |
240 browser()->profile())->extension_service(); | 242 browser()->profile()); |
241 | 243 |
242 // Even whitelisted extensions with NPAPI should not prompt. | 244 // Even whitelisted extensions with NPAPI should not prompt. |
243 scoped_refptr<MockPromptProxy> mock_prompt = | 245 scoped_refptr<MockPromptProxy> mock_prompt = |
244 CreateMockPromptProxyForBrowser(browser()); | 246 CreateMockPromptProxyForBrowser(browser()); |
245 InstallWithPrompt("uitest/plugins", id, mock_prompt); | 247 InstallWithPrompt("uitest/plugins", id, mock_prompt); |
246 EXPECT_FALSE(mock_prompt->confirmation_requested()); | 248 EXPECT_FALSE(mock_prompt->confirmation_requested()); |
247 EXPECT_TRUE(service->GetExtensionById(id, false)); | 249 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); |
248 } | 250 } |
249 #endif | 251 #endif |
250 | 252 |
251 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, | 253 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
252 GalleryInstallGetsExperimental) { | 254 GalleryInstallGetsExperimental) { |
253 // We must modify the command line temporarily in order to pack an extension | 255 // We must modify the command line temporarily in order to pack an extension |
254 // that requests the experimental permission. | 256 // that requests the experimental permission. |
255 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 257 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
256 CommandLine old_command_line = *command_line; | 258 CommandLine old_command_line = *command_line; |
257 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 259 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 } | 366 } |
365 } | 367 } |
366 | 368 |
367 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { | 369 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { |
368 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); | 370 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); |
369 crx_path = crx_path.AppendASCII("theme_hidpi.crx"); | 371 crx_path = crx_path.AppendASCII("theme_hidpi.crx"); |
370 | 372 |
371 ASSERT_TRUE(InstallExtension(crx_path, 1)); | 373 ASSERT_TRUE(InstallExtension(crx_path, 1)); |
372 | 374 |
373 const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); | 375 const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); |
374 ExtensionService* service = extensions::ExtensionSystem::Get( | 376 ExtensionRegistry* registry = ExtensionRegistry::Get( |
375 browser()->profile())->extension_service(); | 377 browser()->profile()); |
376 ASSERT_TRUE(service); | |
377 const extensions::Extension* extension = | 378 const extensions::Extension* extension = |
378 service->GetExtensionById(extension_id, false); | 379 registry->enabled_extensions().GetByID(extension_id); |
379 ASSERT_TRUE(extension); | 380 ASSERT_TRUE(extension); |
380 EXPECT_EQ(extension_id, extension->id()); | 381 EXPECT_EQ(extension_id, extension->id()); |
381 | 382 |
382 UninstallExtension(extension_id); | 383 UninstallExtension(extension_id); |
383 EXPECT_FALSE(service->GetExtensionById(extension_id, false)); | 384 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); |
384 } | 385 } |
385 | 386 |
386 // See http://crbug.com/315299. | 387 // See http://crbug.com/315299. |
387 #if defined(OS_WIN) || defined(OS_LINUX) | 388 #if defined(OS_WIN) || defined(OS_LINUX) |
388 #define MAYBE_InstallDelayedUntilNextUpdate \ | 389 #define MAYBE_InstallDelayedUntilNextUpdate \ |
389 DISABLED_InstallDelayedUntilNextUpdate | 390 DISABLED_InstallDelayedUntilNextUpdate |
390 #else | 391 #else |
391 #define MAYBE_InstallDelayedUntilNextUpdate InstallDelayedUntilNextUpdate | 392 #define MAYBE_InstallDelayedUntilNextUpdate InstallDelayedUntilNextUpdate |
392 #endif | 393 #endif |
393 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, | 394 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
394 MAYBE_InstallDelayedUntilNextUpdate) { | 395 MAYBE_InstallDelayedUntilNextUpdate) { |
395 const std::string extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf"); | 396 const std::string extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf"); |
396 base::FilePath crx_path = test_data_dir_.AppendASCII("delayed_install"); | 397 base::FilePath crx_path = test_data_dir_.AppendASCII("delayed_install"); |
397 ExtensionSystem* extension_system = extensions::ExtensionSystem::Get( | 398 ExtensionSystem* extension_system = extensions::ExtensionSystem::Get( |
398 browser()->profile()); | 399 browser()->profile()); |
399 ExtensionService* service = extension_system->extension_service(); | 400 ExtensionService* service = extension_system->extension_service(); |
400 ASSERT_TRUE(service); | 401 ASSERT_TRUE(service); |
402 ExtensionRegistry* registry = ExtensionRegistry::Get( | |
403 browser()->profile()); | |
404 ASSERT_TRUE(registry); | |
401 | 405 |
402 // Install version 1 of the test extension. This extension does not have | 406 // Install version 1 of the test extension. This extension does not have |
403 // a background page but does have a browser action. | 407 // a background page but does have a browser action. |
404 ASSERT_TRUE(InstallExtension(crx_path.AppendASCII("v1.crx"), 1)); | 408 ASSERT_TRUE(InstallExtension(crx_path.AppendASCII("v1.crx"), 1)); |
405 const extensions::Extension* extension = | 409 const extensions::Extension* extension = |
406 service->GetExtensionById(extension_id, false); | 410 registry->enabled_extensions().GetByID(extension_id); |
407 ASSERT_TRUE(extension); | 411 ASSERT_TRUE(extension); |
408 ASSERT_EQ(extension_id, extension->id()); | 412 ASSERT_EQ(extension_id, extension->id()); |
409 ASSERT_EQ("1.0", extension->version()->GetString()); | 413 ASSERT_EQ("1.0", extension->version()->GetString()); |
410 | 414 |
411 // Make test extension non-idle by opening the extension's browser action | 415 // Make test extension non-idle by opening the extension's browser action |
412 // popup. This should cause the installation to be delayed. | 416 // popup. This should cause the installation to be delayed. |
413 content::WindowedNotificationObserver loading_observer( | 417 content::WindowedNotificationObserver loading_observer( |
414 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 418 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
415 content::Source<Profile>(profile())); | 419 content::Source<Profile>(profile())); |
416 BrowserActionTestUtil util(browser()); | 420 BrowserActionTestUtil util(browser()); |
417 // There is only one extension, so just click the first browser action. | 421 // There is only one extension, so just click the first browser action. |
418 ASSERT_EQ(1, util.NumberOfBrowserActions()); | 422 ASSERT_EQ(1, util.NumberOfBrowserActions()); |
419 util.Press(0); | 423 util.Press(0); |
420 loading_observer.Wait(); | 424 loading_observer.Wait(); |
421 ExtensionHost* extension_host = | 425 ExtensionHost* extension_host = |
422 content::Details<ExtensionHost>(loading_observer.details()).ptr(); | 426 content::Details<ExtensionHost>(loading_observer.details()).ptr(); |
423 | 427 |
424 // Install version 2 of the extension and check that it is indeed delayed. | 428 // Install version 2 of the extension and check that it is indeed delayed. |
425 ASSERT_TRUE(UpdateExtensionWaitForIdle( | 429 ASSERT_TRUE(UpdateExtensionWaitForIdle( |
426 extension_id, crx_path.AppendASCII("v2.crx"), 0)); | 430 extension_id, crx_path.AppendASCII("v2.crx"), 0)); |
427 | 431 |
428 ASSERT_EQ(1u, service->delayed_installs()->size()); | 432 ASSERT_EQ(1u, service->delayed_installs()->size()); |
429 extension = service->GetExtensionById(extension_id, false); | 433 extension = registry->enabled_extensions().GetByID(extension_id); |
430 ASSERT_EQ("1.0", extension->version()->GetString()); | 434 ASSERT_EQ("1.0", extension->version()->GetString()); |
431 | 435 |
432 // Make the extension idle again by closing the popup. This should not trigger | 436 // Make the extension idle again by closing the popup. This should not trigger |
433 // the delayed install. | 437 // the delayed install. |
434 content::RenderProcessHostWatcher terminated_observer( | 438 content::RenderProcessHostWatcher terminated_observer( |
435 extension_host->render_process_host(), | 439 extension_host->render_process_host(), |
436 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 440 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
437 extension_host->render_view_host()->ClosePage(); | 441 extension_host->render_view_host()->ClosePage(); |
438 terminated_observer.Wait(); | 442 terminated_observer.Wait(); |
439 ASSERT_EQ(1u, service->delayed_installs()->size()); | 443 ASSERT_EQ(1u, service->delayed_installs()->size()); |
440 | 444 |
441 // Install version 3 of the extension. Because the extension is idle, | 445 // Install version 3 of the extension. Because the extension is idle, |
442 // this install should succeed. | 446 // this install should succeed. |
443 ASSERT_TRUE(UpdateExtensionWaitForIdle( | 447 ASSERT_TRUE(UpdateExtensionWaitForIdle( |
444 extension_id, crx_path.AppendASCII("v3.crx"), 0)); | 448 extension_id, crx_path.AppendASCII("v3.crx"), 0)); |
445 extension = service->GetExtensionById(extension_id, false); | 449 extension = registry->enabled_extensions().GetByID(extension_id); |
446 ASSERT_EQ("3.0", extension->version()->GetString()); | 450 ASSERT_EQ("3.0", extension->version()->GetString()); |
447 | 451 |
448 // The version 2 delayed install should be cleaned up, and finishing | 452 // The version 2 delayed install should be cleaned up, and finishing |
449 // delayed extension installation shouldn't break anything. | 453 // delayed extension installation shouldn't break anything. |
450 ASSERT_EQ(0u, service->delayed_installs()->size()); | 454 ASSERT_EQ(0u, service->delayed_installs()->size()); |
451 service->MaybeFinishDelayedInstallations(); | 455 service->MaybeFinishDelayedInstallations(); |
452 extension = service->GetExtensionById(extension_id, false); | 456 extension = registry->enabled_extensions().GetByID(extension_id); |
453 ASSERT_EQ("3.0", extension->version()->GetString()); | 457 ASSERT_EQ("3.0", extension->version()->GetString()); |
454 } | 458 } |
455 | 459 |
456 #if defined(FULL_SAFE_BROWSING) | 460 #if defined(FULL_SAFE_BROWSING) |
457 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Blacklist) { | 461 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Blacklist) { |
458 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( | 462 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
459 new FakeSafeBrowsingDatabaseManager(true)); | 463 new FakeSafeBrowsingDatabaseManager(true)); |
460 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); | 464 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
461 | 465 |
462 blacklist_db->SetUnsafe("gllekhaobjnhgeagipipnkpmmmpchacm"); | 466 blacklist_db->SetUnsafe("gllekhaobjnhgeagipipnkpmmmpchacm"); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 | 517 |
514 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); | 518 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
515 const extensions::Extension* extension = InstallExtension( | 519 const extensions::Extension* extension = InstallExtension( |
516 crx_path, 1, extensions::Manifest::EXTERNAL_PREF); | 520 crx_path, 1, extensions::Manifest::EXTERNAL_PREF); |
517 base::FilePath extension_path = extension->path(); | 521 base::FilePath extension_path = extension->path(); |
518 EXPECT_TRUE(cache_dir.path().IsParent(extension_path)); | 522 EXPECT_TRUE(cache_dir.path().IsParent(extension_path)); |
519 EXPECT_TRUE(base::PathExists(extension_path)); | 523 EXPECT_TRUE(base::PathExists(extension_path)); |
520 | 524 |
521 std::string extension_id = extension->id(); | 525 std::string extension_id = extension->id(); |
522 UninstallExtension(extension_id); | 526 UninstallExtension(extension_id); |
523 ExtensionService* service = extensions::ExtensionSystem::Get( | 527 ExtensionRegistry* registry = ExtensionRegistry::Get( |
524 browser()->profile())->extension_service(); | 528 browser()->profile()); |
525 EXPECT_FALSE(service->GetExtensionById(extension_id, false)); | 529 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); |
526 | 530 |
527 // In the worst case you need to repeat this up to 3 times to make sure that | 531 // In the worst case you need to repeat this up to 3 times to make sure that |
528 // all pending tasks we sent from UI thread to task runner and back to UI. | 532 // all pending tasks we sent from UI thread to task runner and back to UI. |
529 for (int i = 0; i < 3; i++) { | 533 for (int i = 0; i < 3; i++) { |
530 // Wait for background task completion that sends replay to UI thread. | 534 // Wait for background task completion that sends replay to UI thread. |
531 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 535 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
532 // Wait for UI thread task completion. | 536 // Wait for UI thread task completion. |
533 base::RunLoop().RunUntilIdle(); | 537 base::RunLoop().RunUntilIdle(); |
534 } | 538 } |
535 | 539 |
(...skipping 21 matching lines...) Expand all Loading... | |
557 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ManagementPolicy) { | 561 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ManagementPolicy) { |
558 ManagementPolicyMock policy; | 562 ManagementPolicyMock policy; |
559 extensions::ExtensionSystem::Get(profile()) | 563 extensions::ExtensionSystem::Get(profile()) |
560 ->management_policy() | 564 ->management_policy() |
561 ->RegisterProvider(&policy); | 565 ->RegisterProvider(&policy); |
562 | 566 |
563 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); | 567 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
564 EXPECT_FALSE(InstallExtension(crx_path, 0)); | 568 EXPECT_FALSE(InstallExtension(crx_path, 0)); |
565 } | 569 } |
566 | 570 |
571 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, WithheldElevationCheck) { | |
572 // Enable consent flag and install extension. The <all_hosts> permission will | |
573 // be withheld. | |
574 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( | |
575 new FeatureSwitch::ScopedOverride( | |
576 FeatureSwitch::scripts_require_action(), true)); | |
577 | |
578 const char kManifest[] = | |
579 "{" | |
580 " \"name\": \"Withheld test\"," | |
581 " \"version\": \"1.0\"," | |
582 " \"permissions\": [" | |
583 " \"http://*/*\"" | |
584 " ]," | |
585 " \"manifest_version\": 2" | |
586 "}"; | |
587 TestExtensionDir dir; | |
588 dir.WriteManifest(kManifest); | |
589 base::FilePath crx_path = dir.Pack(); | |
590 EXPECT_FALSE(crx_path.empty()); | |
591 const extensions::Extension* extension = InstallExtension(crx_path, 1); | |
Devlin
2014/09/10 21:52:02
nit: no prefix.
gpdavis
2014/09/11 00:51:01
Done (will arrive in next patch set).
| |
592 EXPECT_TRUE(base::PathExists(extension->path())); | |
593 | |
594 std::string extension_id = extension->id(); | |
595 ExtensionRegistry* registry = ExtensionRegistry::Get( | |
596 browser()->profile()); | |
597 EXPECT_TRUE(registry->enabled_extensions().GetByID(extension_id)); | |
598 | |
599 // Disable consent flag and reinstall extension. It should now be disabled | |
600 // because previously withheld permissions are now being requested. | |
601 enable_scripts_switch.reset(); | |
602 extension = InstallExtension(crx_path, -1); | |
Devlin
2014/09/10 21:52:02
This part still isn't quite right. Ideally, what
gpdavis
2014/09/11 00:51:01
ReloadExtensionsForTest is problematic in the brow
| |
603 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); | |
604 } | |
605 | |
567 } // namespace extensions | 606 } // namespace extensions |
OLD | NEW |