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 is a customized version of content::WindowedNotificationObserver that |
| 459 // waits until either of the two provided notification types is observed. |
| 460 // See content::WindowedNotificationObserver for further documentation. |
| 461 class OneOfTwoNotificationsObserver : public content::NotificationObserver { |
| 462 public: |
| 463 // Set up to wait for one of two notifications. |
| 464 OneOfTwoNotificationsObserver(int notification_type1, int notification_type2); |
| 465 virtual ~OneOfTwoNotificationsObserver(); |
| 466 |
| 467 // Wait until one of the specified notifications is observed. If either |
| 468 // notification has already been received, Wait() returns immediately. |
| 469 void Wait(); |
| 470 |
| 471 // content::NotificationObserver: |
| 472 virtual void Observe(int type, |
| 473 const content::NotificationSource& source, |
| 474 const content::NotificationDetails& details) OVERRIDE; |
| 475 |
| 476 private: |
| 477 bool seen_; |
| 478 bool running_; |
| 479 content::NotificationRegistrar registrar_; |
| 480 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 481 |
| 482 DISALLOW_COPY_AND_ASSIGN(OneOfTwoNotificationsObserver); |
| 483 }; |
| 484 |
| 485 OneOfTwoNotificationsObserver::OneOfTwoNotificationsObserver( |
| 486 int notification_type1, int notification_type2) |
| 487 : seen_(false), running_(false) { |
| 488 registrar_.Add(this, notification_type1, |
| 489 content::NotificationService::AllSources()); |
| 490 registrar_.Add(this, notification_type2, |
| 491 content::NotificationService::AllSources()); |
| 492 } |
| 493 |
| 494 OneOfTwoNotificationsObserver::~OneOfTwoNotificationsObserver() {} |
| 495 |
| 496 void OneOfTwoNotificationsObserver::Wait() { |
| 497 if (seen_) |
| 498 return; |
| 499 running_ = true; |
| 500 message_loop_runner_ = new content::MessageLoopRunner; |
| 501 message_loop_runner_->Run(); |
| 502 EXPECT_TRUE(seen_); |
| 503 } |
| 504 |
| 505 // NotificationObserver: |
| 506 void OneOfTwoNotificationsObserver::Observe(int type, |
| 507 const content::NotificationSource& source, |
| 508 const content::NotificationDetails& details) { |
| 509 seen_ = true; |
| 510 if (!running_) |
| 511 return; |
| 512 message_loop_runner_->Quit(); |
| 513 running_ = false; |
| 514 } |
| 515 |
452 } // namespace | 516 } // namespace |
453 | 517 |
454 class PolicyTest : public InProcessBrowserTest { | 518 class PolicyTest : public InProcessBrowserTest { |
455 protected: | 519 protected: |
456 PolicyTest() {} | 520 PolicyTest() {} |
457 virtual ~PolicyTest() {} | 521 virtual ~PolicyTest() {} |
458 | 522 |
459 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 523 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
460 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); | 524 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); |
461 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 525 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 | 1459 |
1396 const base::Version* new_version = | 1460 const base::Version* new_version = |
1397 service->GetExtensionById(kGoodCrxId, true)->version(); | 1461 service->GetExtensionById(kGoodCrxId, true)->version(); |
1398 ASSERT_TRUE(new_version->IsValid()); | 1462 ASSERT_TRUE(new_version->IsValid()); |
1399 base::Version old_version(old_version_number); | 1463 base::Version old_version(old_version_number); |
1400 ASSERT_TRUE(old_version.IsValid()); | 1464 ASSERT_TRUE(old_version.IsValid()); |
1401 | 1465 |
1402 EXPECT_EQ(1, new_version->CompareTo(old_version)); | 1466 EXPECT_EQ(1, new_version->CompareTo(old_version)); |
1403 | 1467 |
1404 EXPECT_EQ(0u, interceptor.GetPendingSize()); | 1468 EXPECT_EQ(0u, interceptor.GetPendingSize()); |
| 1469 |
| 1470 // Wait until any background pages belonging to force-installed extensions |
| 1471 // have been loaded. |
| 1472 ExtensionProcessManager* manager = |
| 1473 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 1474 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); |
| 1475 for (ExtensionProcessManager::ViewSet::const_iterator iter = |
| 1476 all_views.begin(); |
| 1477 iter != all_views.end();) { |
| 1478 if (!(*iter)->IsLoading()) { |
| 1479 ++iter; |
| 1480 } else { |
| 1481 OneOfTwoNotificationsObserver( |
| 1482 content::NOTIFICATION_LOAD_STOP, |
| 1483 content::NOTIFICATION_WEB_CONTENTS_DESTROYED).Wait(); |
| 1484 |
| 1485 // Test activity may have modified the set of extension processes during |
| 1486 // message processing, so re-start the iteration to catch added/removed |
| 1487 // processes. |
| 1488 all_views = manager->GetAllViews(); |
| 1489 iter = all_views.begin(); |
| 1490 } |
| 1491 } |
| 1492 |
| 1493 // Test policy-installed extensions are reloaded when killed. |
| 1494 BackgroundContentsService:: |
| 1495 SetCrashDelaysForForceInstalledAppsAndExtensionsForTesting(0, 0); |
| 1496 content::WindowedNotificationObserver extension_crashed_observer( |
| 1497 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 1498 content::NotificationService::AllSources()); |
| 1499 content::WindowedNotificationObserver extension_loaded_observer( |
| 1500 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 1501 content::NotificationService::AllSources()); |
| 1502 extensions::ExtensionHost* extension_host = |
| 1503 extensions::ExtensionSystem::Get(browser()->profile())-> |
| 1504 process_manager()->GetBackgroundHostForExtension(kGoodCrxId); |
| 1505 base::KillProcess(extension_host->render_process_host()->GetHandle(), |
| 1506 content::RESULT_CODE_KILLED, false); |
| 1507 extension_crashed_observer.Wait(); |
| 1508 extension_loaded_observer.Wait(); |
1405 } | 1509 } |
1406 | 1510 |
1407 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { | 1511 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { |
1408 // Verifies that extensions are blocked if policy specifies an allowed types | 1512 // Verifies that extensions are blocked if policy specifies an allowed types |
1409 // list and the extension's type is not on that list. | 1513 // list and the extension's type is not on that list. |
1410 ExtensionService* service = extension_service(); | 1514 ExtensionService* service = extension_service(); |
1411 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1515 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1412 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); | 1516 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); |
1413 | 1517 |
1414 base::ListValue allowed_types; | 1518 base::ListValue allowed_types; |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2502 chrome_variations::VariationsService::GetVariationsServerURL( | 2606 chrome_variations::VariationsService::GetVariationsServerURL( |
2503 g_browser_process->local_state()); | 2607 g_browser_process->local_state()); |
2504 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2608 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
2505 std::string value; | 2609 std::string value; |
2506 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2610 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
2507 EXPECT_EQ("restricted", value); | 2611 EXPECT_EQ("restricted", value); |
2508 } | 2612 } |
2509 #endif | 2613 #endif |
2510 | 2614 |
2511 } // namespace policy | 2615 } // namespace policy |
OLD | NEW |