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 "chrome/browser/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
21 #include "base/task_scheduler/task_scheduler.h" | 21 #include "base/task_scheduler/task_scheduler.h" |
| 22 #include "base/test/scoped_feature_list.h" |
22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
23 #include "base/values.h" | 24 #include "base/values.h" |
24 #include "base/version.h" | 25 #include "base/version.h" |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
28 #include "chrome/browser/net/url_request_mock_util.h" | 29 #include "chrome/browser/net/url_request_mock_util.h" |
29 #include "chrome/browser/profiles/chrome_version_service.h" | 30 #include "chrome/browser/profiles/chrome_version_service.h" |
30 #include "chrome/browser/profiles/profile_impl.h" | 31 #include "chrome/browser/profiles/profile_impl.h" |
31 #include "chrome/browser/profiles/profile_manager.h" | 32 #include "chrome/browser/profiles/profile_manager.h" |
32 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
34 #include "chrome/common/chrome_constants.h" | 35 #include "chrome/common/chrome_constants.h" |
35 #include "chrome/common/chrome_features.h" | 36 #include "chrome/common/chrome_features.h" |
36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
37 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
38 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
39 #include "components/bookmarks/browser/startup_task_runner_service.h" | 40 #include "components/bookmarks/browser/startup_task_runner_service.h" |
40 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
41 #include "components/version_info/version_info.h" | 42 #include "components/version_info/version_info.h" |
42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/storage_partition.h" | 44 #include "content/public/browser/storage_partition.h" |
44 #include "content/public/test/test_utils.h" | 45 #include "content/public/test/test_utils.h" |
45 #include "extensions/browser/extension_registry.h" | 46 #include "extensions/browser/extension_registry.h" |
46 #include "extensions/common/extension.h" | 47 #include "extensions/common/extension.h" |
47 #include "extensions/common/extension_builder.h" | 48 #include "extensions/common/extension_builder.h" |
48 #include "extensions/common/value_builder.h" | 49 #include "extensions/common/value_builder.h" |
49 #include "net/base/net_errors.h" | 50 #include "net/base/net_errors.h" |
50 #include "net/dns/mock_host_resolver.h" | 51 #include "net/dns/mock_host_resolver.h" |
| 52 #include "net/reporting/reporting_feature.h" |
51 #include "net/test/embedded_test_server/embedded_test_server.h" | 53 #include "net/test/embedded_test_server/embedded_test_server.h" |
52 #include "net/test/embedded_test_server/http_request.h" | 54 #include "net/test/embedded_test_server/http_request.h" |
53 #include "net/test/embedded_test_server/http_response.h" | 55 #include "net/test/embedded_test_server/http_response.h" |
54 #include "net/test/url_request/url_request_failed_job.h" | 56 #include "net/test/url_request/url_request_failed_job.h" |
55 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 57 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
56 #include "net/url_request/url_fetcher.h" | 58 #include "net/url_request/url_fetcher.h" |
57 #include "net/url_request/url_fetcher_delegate.h" | 59 #include "net/url_request/url_fetcher_delegate.h" |
58 #include "net/url_request/url_request_context_getter.h" | 60 #include "net/url_request/url_request_context_getter.h" |
59 #include "net/url_request/url_request_status.h" | 61 #include "net/url_request/url_request_status.h" |
60 #include "testing/gmock/include/gmock/gmock.h" | 62 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 545 |
544 void CompareURLRequestContexts( | 546 void CompareURLRequestContexts( |
545 net::URLRequestContextGetter* extension_context_getter, | 547 net::URLRequestContextGetter* extension_context_getter, |
546 net::URLRequestContextGetter* main_context_getter) { | 548 net::URLRequestContextGetter* main_context_getter) { |
547 net::URLRequestContext* extension_context = | 549 net::URLRequestContext* extension_context = |
548 extension_context_getter->GetURLRequestContext(); | 550 extension_context_getter->GetURLRequestContext(); |
549 net::URLRequestContext* main_context = | 551 net::URLRequestContext* main_context = |
550 main_context_getter->GetURLRequestContext(); | 552 main_context_getter->GetURLRequestContext(); |
551 | 553 |
552 // Check that the URLRequestContexts are different and that their | 554 // Check that the URLRequestContexts are different and that their |
553 // ChannelIDServices and CookieStores are different. | 555 // ChannelIDServices, CookieStores, and ReportingServices are different. |
554 EXPECT_NE(extension_context, main_context); | 556 EXPECT_NE(extension_context, main_context); |
555 EXPECT_NE(extension_context->channel_id_service(), | 557 EXPECT_NE(extension_context->channel_id_service(), |
556 main_context->channel_id_service()); | 558 main_context->channel_id_service()); |
557 EXPECT_NE(extension_context->cookie_store(), main_context->cookie_store()); | 559 EXPECT_NE(extension_context->cookie_store(), main_context->cookie_store()); |
| 560 if (extension_context->reporting_service()) { |
| 561 EXPECT_NE(extension_context->reporting_service(), |
| 562 main_context->reporting_service()); |
| 563 } |
558 | 564 |
559 // Check that the ChannelIDService in the HttpNetworkSession is the same as | 565 // Check that the ChannelIDService in the HttpNetworkSession is the same as |
560 // the one directly on the URLRequestContext. | 566 // the one directly on the URLRequestContext. |
561 EXPECT_EQ(extension_context->http_transaction_factory() | 567 EXPECT_EQ(extension_context->http_transaction_factory() |
562 ->GetSession() | 568 ->GetSession() |
563 ->params() | 569 ->params() |
564 .channel_id_service, | 570 .channel_id_service, |
565 extension_context->channel_id_service()); | 571 extension_context->channel_id_service()); |
566 EXPECT_EQ(main_context->http_transaction_factory() | 572 EXPECT_EQ(main_context->http_transaction_factory() |
567 ->GetSession() | 573 ->GetSession() |
568 ->params() | 574 ->params() |
569 .channel_id_service, | 575 .channel_id_service, |
570 main_context->channel_id_service()); | 576 main_context->channel_id_service()); |
571 } | 577 } |
572 | 578 |
573 } // namespace | 579 } // namespace |
574 | 580 |
575 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) { | 581 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) { |
576 base::ThreadRestrictions::ScopedAllowIO allow_io; | 582 base::ThreadRestrictions::ScopedAllowIO allow_io; |
577 base::ScopedTempDir temp_dir; | 583 base::ScopedTempDir temp_dir; |
578 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 584 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
579 | 585 |
| 586 base::test::ScopedFeatureList feature_list; |
| 587 feature_list.InitAndEnableFeature(features::kReporting); |
| 588 |
580 MockProfileDelegate delegate; | 589 MockProfileDelegate delegate; |
581 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 590 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
582 | 591 |
583 { | 592 { |
584 std::unique_ptr<Profile> profile(CreateProfile( | 593 std::unique_ptr<Profile> profile(CreateProfile( |
585 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 594 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
586 | 595 |
587 scoped_refptr<const extensions::Extension> app = | 596 scoped_refptr<const extensions::Extension> app = |
588 BuildTestApp(profile.get()); | 597 BuildTestApp(profile.get()); |
589 content::StoragePartition* extension_partition = | 598 content::StoragePartition* extension_partition = |
(...skipping 16 matching lines...) Expand all Loading... |
606 | 615 |
607 FlushIoTaskRunnerAndSpinThreads(); | 616 FlushIoTaskRunnerAndSpinThreads(); |
608 } | 617 } |
609 | 618 |
610 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | 619 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
611 OffTheRecordURLRequestContextIsolation) { | 620 OffTheRecordURLRequestContextIsolation) { |
612 base::ThreadRestrictions::ScopedAllowIO allow_io; | 621 base::ThreadRestrictions::ScopedAllowIO allow_io; |
613 base::ScopedTempDir temp_dir; | 622 base::ScopedTempDir temp_dir; |
614 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 623 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
615 | 624 |
| 625 base::test::ScopedFeatureList feature_list; |
| 626 feature_list.InitAndEnableFeature(features::kReporting); |
| 627 |
616 MockProfileDelegate delegate; | 628 MockProfileDelegate delegate; |
617 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 629 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
618 | 630 |
619 { | 631 { |
620 std::unique_ptr<Profile> profile(CreateProfile( | 632 std::unique_ptr<Profile> profile(CreateProfile( |
621 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 633 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
622 Profile* otr_profile = profile->GetOffTheRecordProfile(); | 634 Profile* otr_profile = profile->GetOffTheRecordProfile(); |
623 | 635 |
624 scoped_refptr<const extensions::Extension> app = BuildTestApp(otr_profile); | 636 scoped_refptr<const extensions::Extension> app = BuildTestApp(otr_profile); |
625 content::StoragePartition* extension_partition = | 637 content::StoragePartition* extension_partition = |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 base::Bind(&SendReportHttpResponse, embedded_test_server()->base_url())); | 889 base::Bind(&SendReportHttpResponse, embedded_test_server()->base_url())); |
878 ASSERT_TRUE(hpkp_test_server.Start()); | 890 ASSERT_TRUE(hpkp_test_server.Start()); |
879 | 891 |
880 // To send a report, must use a non-numeric host name for the original | 892 // To send a report, must use a non-numeric host name for the original |
881 // request. This must not match the host name of the server that reports are | 893 // request. This must not match the host name of the server that reports are |
882 // sent to. | 894 // sent to. |
883 ui_test_utils::NavigateToURL(browser(), | 895 ui_test_utils::NavigateToURL(browser(), |
884 hpkp_test_server.GetURL("localhost", "/")); | 896 hpkp_test_server.GetURL("localhost", "/")); |
885 wait_for_report_loop.Run(); | 897 wait_for_report_loop.Run(); |
886 } | 898 } |
OLD | NEW |