Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/test/test_file_util.h" | 25 #include "base/test/test_file_util.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "base/values.h" | 27 #include "base/values.h" |
| 28 #include "chrome/app/chrome_command_ids.h" | 28 #include "chrome/app/chrome_command_ids.h" |
| 29 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 29 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 30 #include "chrome/browser/background/background_contents_service.h" | |
| 30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 31 #include "chrome/browser/chrome_notification_types.h" | 32 #include "chrome/browser/chrome_notification_types.h" |
| 32 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 33 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 33 #include "chrome/browser/devtools/devtools_window.h" | 34 #include "chrome/browser/devtools/devtools_window.h" |
| 34 #include "chrome/browser/download/download_prefs.h" | 35 #include "chrome/browser/download/download_prefs.h" |
| 35 #include "chrome/browser/extensions/crx_installer.h" | 36 #include "chrome/browser/extensions/crx_installer.h" |
| 37 #include "chrome/browser/extensions/extension_host.h" | |
| 38 #include "chrome/browser/extensions/extension_process_manager.h" | |
| 36 #include "chrome/browser/extensions/extension_service.h" | 39 #include "chrome/browser/extensions/extension_service.h" |
| 37 #include "chrome/browser/extensions/extension_system.h" | 40 #include "chrome/browser/extensions/extension_system.h" |
| 38 #include "chrome/browser/extensions/unpacked_installer.h" | 41 #include "chrome/browser/extensions/unpacked_installer.h" |
| 39 #include "chrome/browser/extensions/updater/extension_updater.h" | 42 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 40 #include "chrome/browser/infobars/infobar_service.h" | 43 #include "chrome/browser/infobars/infobar_service.h" |
| 41 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 44 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 42 #include "chrome/browser/media/media_stream_devices_controller.h" | 45 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 43 #include "chrome/browser/metrics/variations/variations_service.h" | 46 #include "chrome/browser/metrics/variations/variations_service.h" |
| 44 #include "chrome/browser/net/url_request_mock_util.h" | 47 #include "chrome/browser/net/url_request_mock_util.h" |
| 45 #include "chrome/browser/plugins/plugin_prefs.h" | 48 #include "chrome/browser/plugins/plugin_prefs.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 #include "chrome/common/url_constants.h" | 82 #include "chrome/common/url_constants.h" |
| 80 #include "chrome/test/base/in_process_browser_test.h" | 83 #include "chrome/test/base/in_process_browser_test.h" |
| 81 #include "chrome/test/base/test_switches.h" | 84 #include "chrome/test/base/test_switches.h" |
| 82 #include "chrome/test/base/ui_test_utils.h" | 85 #include "chrome/test/base/ui_test_utils.h" |
| 83 #include "content/public/browser/browser_child_process_host_iterator.h" | 86 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 84 #include "content/public/browser/browser_context.h" | 87 #include "content/public/browser/browser_context.h" |
| 85 #include "content/public/browser/browser_thread.h" | 88 #include "content/public/browser/browser_thread.h" |
| 86 #include "content/public/browser/child_process_data.h" | 89 #include "content/public/browser/child_process_data.h" |
| 87 #include "content/public/browser/download_item.h" | 90 #include "content/public/browser/download_item.h" |
| 88 #include "content/public/browser/download_manager.h" | 91 #include "content/public/browser/download_manager.h" |
| 92 #include "content/public/browser/notification_details.h" | |
| 93 #include "content/public/browser/notification_observer.h" | |
| 89 #include "content/public/browser/notification_registrar.h" | 94 #include "content/public/browser/notification_registrar.h" |
| 90 #include "content/public/browser/notification_service.h" | 95 #include "content/public/browser/notification_service.h" |
| 91 #include "content/public/browser/notification_source.h" | 96 #include "content/public/browser/notification_source.h" |
| 92 #include "content/public/browser/notification_types.h" | 97 #include "content/public/browser/notification_types.h" |
| 93 #include "content/public/browser/plugin_service.h" | 98 #include "content/public/browser/plugin_service.h" |
| 94 #include "content/public/browser/render_process_host.h" | 99 #include "content/public/browser/render_process_host.h" |
| 95 #include "content/public/browser/render_view_host.h" | 100 #include "content/public/browser/render_view_host.h" |
| 96 #include "content/public/browser/web_contents.h" | 101 #include "content/public/browser/web_contents.h" |
| 97 #include "content/public/common/content_constants.h" | 102 #include "content/public/common/content_constants.h" |
| 98 #include "content/public/common/content_paths.h" | 103 #include "content/public/common/content_paths.h" |
| 99 #include "content/public/common/page_transition_types.h" | 104 #include "content/public/common/page_transition_types.h" |
| 100 #include "content/public/common/process_type.h" | 105 #include "content/public/common/process_type.h" |
| 106 #include "content/public/common/result_codes.h" | |
| 101 #include "content/public/common/url_constants.h" | 107 #include "content/public/common/url_constants.h" |
| 102 #include "content/public/common/webplugininfo.h" | 108 #include "content/public/common/webplugininfo.h" |
| 103 #include "content/public/test/browser_test_utils.h" | 109 #include "content/public/test/browser_test_utils.h" |
| 104 #include "content/public/test/download_test_observer.h" | 110 #include "content/public/test/download_test_observer.h" |
| 105 #include "content/public/test/mock_notification_observer.h" | 111 #include "content/public/test/mock_notification_observer.h" |
| 106 #include "content/public/test/test_navigation_observer.h" | 112 #include "content/public/test/test_navigation_observer.h" |
| 107 #include "content/public/test/test_utils.h" | 113 #include "content/public/test/test_utils.h" |
| 108 #include "content/test/net/url_request_failed_job.h" | 114 #include "content/test/net/url_request_failed_job.h" |
| 109 #include "content/test/net/url_request_mock_http_job.h" | 115 #include "content/test/net/url_request_mock_http_job.h" |
| 110 #include "grit/generated_resources.h" | 116 #include "grit/generated_resources.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 ++output_mute_changed_count_; | 448 ++output_mute_changed_count_; |
| 443 } | 449 } |
| 444 | 450 |
| 445 private: | 451 private: |
| 446 int output_mute_changed_count_; | 452 int output_mute_changed_count_; |
| 447 | 453 |
| 448 DISALLOW_COPY_AND_ASSIGN(TestAudioObserver); | 454 DISALLOW_COPY_AND_ASSIGN(TestAudioObserver); |
| 449 }; | 455 }; |
| 450 #endif | 456 #endif |
| 451 | 457 |
| 458 // This class is a customised version of WindowedNotificationObserver to allow | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: s/WindowedNotificationObserver/content::Windo
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 459 // us to register and wait until one of two simple events has occurred. See | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: "simple events" is nomenclature I introduced
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 460 // WindowedNotificationObserver for further documentation. | |
| 461 class OneOfTwoNotificationsObserver : public content::NotificationObserver { | |
| 462 public: | |
| 463 // Set up to wait for one of two conditions. The condition is met when a | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: As above, "condition" is not the right term h
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 464 // notification of either |notification_type1| or |notification_type1| is | |
| 465 // received. | |
| 466 OneOfTwoNotificationsObserver(int notification_type1, int notification_type2); | |
| 467 | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: Remove this blank line.
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 468 virtual ~OneOfTwoNotificationsObserver(); | |
| 469 | |
| 470 // Wait until the specified condition is met. If the condition is already met | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: As above, "notification" instead of "conditio
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 471 // (that is, the expected notification has already been received), Wait() | |
| 472 // returns immediately. | |
| 473 void Wait(); | |
| 474 | |
| 475 // NotificationObserver: | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: s/NotificationObserver/content::NotificationO
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 476 virtual void Observe(int type, | |
| 477 const content::NotificationSource& source, | |
| 478 const content::NotificationDetails& details) OVERRIDE; | |
| 479 | |
| 480 private: | |
| 481 bool seen_; | |
| 482 bool running_; | |
| 483 content::NotificationRegistrar registrar_; | |
| 484 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 485 | |
| 486 DISALLOW_COPY_AND_ASSIGN(OneOfTwoNotificationsObserver); | |
| 487 }; | |
| 488 | |
| 489 OneOfTwoNotificationsObserver::OneOfTwoNotificationsObserver( | |
| 490 int notification_type1, int notification_type2) | |
| 491 : seen_(false), running_(false) { | |
| 492 registrar_.Add(this, notification_type1, | |
| 493 content::NotificationService::AllSources()); | |
| 494 registrar_.Add(this, notification_type2, | |
| 495 content::NotificationService::AllSources()); | |
| 496 } | |
| 497 | |
| 498 OneOfTwoNotificationsObserver::~OneOfTwoNotificationsObserver() {} | |
| 499 | |
| 500 void OneOfTwoNotificationsObserver::Wait() { | |
| 501 if (seen_) | |
| 502 return; | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: Indent 2 spaces, not 4.
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 503 running_ = true; | |
| 504 message_loop_runner_ = new content::MessageLoopRunner; | |
| 505 message_loop_runner_->Run(); | |
| 506 EXPECT_TRUE(seen_); | |
| 507 } | |
| 508 | |
| 509 // NotificationObserver: | |
| 510 void OneOfTwoNotificationsObserver::Observe(int type, | |
| 511 const content::NotificationSource& source, | |
| 512 const content::NotificationDetails& details) OVERRIDE { | |
| 513 seen_ = true; | |
| 514 if (!running_) | |
| 515 return; | |
| 516 message_loop_runner_->Quit(); | |
| 517 running_ = false; | |
| 518 } | |
| 519 | |
| 452 } // namespace | 520 } // namespace |
| 453 | 521 |
| 454 class PolicyTest : public InProcessBrowserTest { | 522 class PolicyTest : public InProcessBrowserTest { |
| 455 protected: | 523 protected: |
| 456 PolicyTest() {} | 524 PolicyTest() {} |
| 457 virtual ~PolicyTest() {} | 525 virtual ~PolicyTest() {} |
| 458 | 526 |
| 459 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 527 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 460 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); | 528 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); |
| 461 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 529 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1385 | 1453 |
| 1386 // Updating the force-installed extension. | 1454 // Updating the force-installed extension. |
| 1387 extensions::ExtensionUpdater* updater = service->updater(); | 1455 extensions::ExtensionUpdater* updater = service->updater(); |
| 1388 extensions::ExtensionUpdater::CheckParams params; | 1456 extensions::ExtensionUpdater::CheckParams params; |
| 1389 params.install_immediately = true; | 1457 params.install_immediately = true; |
| 1390 content::WindowedNotificationObserver update_observer( | 1458 content::WindowedNotificationObserver update_observer( |
| 1391 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 1459 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 1392 content::NotificationService::AllSources()); | 1460 content::NotificationService::AllSources()); |
| 1393 updater->CheckNow(params); | 1461 updater->CheckNow(params); |
| 1394 update_observer.Wait(); | 1462 update_observer.Wait(); |
| 1395 | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: Why remove the blank line?
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 1396 const base::Version* new_version = | 1463 const base::Version* new_version = |
| 1397 service->GetExtensionById(kGoodCrxId, true)->version(); | 1464 service->GetExtensionById(kGoodCrxId, true)->version(); |
| 1398 ASSERT_TRUE(new_version->IsValid()); | 1465 ASSERT_TRUE(new_version->IsValid()); |
| 1399 base::Version old_version(old_version_number); | 1466 base::Version old_version(old_version_number); |
| 1400 ASSERT_TRUE(old_version.IsValid()); | 1467 ASSERT_TRUE(old_version.IsValid()); |
| 1401 | 1468 |
| 1402 EXPECT_EQ(1, new_version->CompareTo(old_version)); | 1469 EXPECT_EQ(1, new_version->CompareTo(old_version)); |
| 1403 | 1470 |
| 1404 EXPECT_EQ(0u, interceptor.GetPendingSize()); | 1471 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
| 1472 | |
| 1473 // Wait for all the extension render view hosts that exist to finish loading. | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: Technically, this comment is correct. But it
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 1474 ExtensionProcessManager* manager = | |
| 1475 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); | |
| 1476 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); | |
| 1477 for (ExtensionProcessManager::ViewSet::const_iterator iter = | |
| 1478 all_views.begin(); | |
| 1479 iter != all_views.end();) { | |
| 1480 if (!(*iter)->IsLoading()) { | |
| 1481 ++iter; | |
| 1482 } else { | |
| 1483 OneOfTwoNotificationsObserver( | |
| 1484 content::NOTIFICATION_LOAD_STOP, | |
| 1485 content::NOTIFICATION_WEB_CONTENTS_DESTROYED).Wait(); | |
| 1486 | |
| 1487 // Test activity may have modified the set of extension processes during | |
| 1488 // message processing, so re-start the iteration to catch added/removed | |
| 1489 // processes. | |
| 1490 all_views = manager->GetAllViews(); | |
| 1491 iter = all_views.begin(); | |
| 1492 } | |
| 1493 } | |
| 1494 // Test policy-installed extensions are reloaded when killed. | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: Add a blank line above.
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 1495 BackgroundContentsService::SetCrashDelaysForTesting( | |
| 1496 base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(0)); | |
| 1497 content::WindowedNotificationObserver extension_crashed_observer( | |
| 1498 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | |
| 1499 content::NotificationService::AllSources()); | |
| 1500 content::WindowedNotificationObserver extension_loaded_observer( | |
| 1501 chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 1502 content::NotificationService::AllSources()); | |
| 1503 extensions::ExtensionHost* extension_host = | |
| 1504 extensions::ExtensionSystem::Get(browser()->profile())-> | |
| 1505 process_manager()->GetBackgroundHostForExtension(kGoodCrxId); | |
| 1506 base::KillProcess(extension_host->render_process_host()->GetHandle(), | |
| 1507 content::RESULT_CODE_KILLED, false); | |
| 1508 extension_crashed_observer.Wait(); | |
| 1509 extension_loaded_observer.Wait(); | |
| 1405 } | 1510 } |
| 1406 | 1511 |
| 1407 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { | 1512 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { |
| 1408 // Verifies that extensions are blocked if policy specifies an allowed types | 1513 // Verifies that extensions are blocked if policy specifies an allowed types |
| 1409 // list and the extension's type is not on that list. | 1514 // list and the extension's type is not on that list. |
| 1410 ExtensionService* service = extension_service(); | 1515 ExtensionService* service = extension_service(); |
| 1411 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1516 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 1412 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); | 1517 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); |
| 1413 | 1518 |
| 1414 base::ListValue allowed_types; | 1519 base::ListValue allowed_types; |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2502 chrome_variations::VariationsService::GetVariationsServerURL( | 2607 chrome_variations::VariationsService::GetVariationsServerURL( |
| 2503 g_browser_process->local_state()); | 2608 g_browser_process->local_state()); |
| 2504 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2609 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
| 2505 std::string value; | 2610 std::string value; |
| 2506 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2611 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 2507 EXPECT_EQ("restricted", value); | 2612 EXPECT_EQ("restricted", value); |
| 2508 } | 2613 } |
| 2509 #endif | 2614 #endif |
| 2510 | 2615 |
| 2511 } // namespace policy | 2616 } // namespace policy |
| OLD | NEW |