OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/loader/chrome_resource_dispatcher_host_delegate.h" | 5 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "chrome/browser/loader/chrome_navigation_data.h" | 9 #include "chrome/browser/loader/chrome_navigation_data.h" |
10 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" | 10 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
11 #include "chrome/test/base/testing_browser_process.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
12 #include "chrome/test/base/testing_profile_manager.h" | 12 #include "chrome/test/base/testing_profile_manager.h" |
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" | 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
14 #include "content/public/browser/navigation_data.h" | 14 #include "content/public/browser/navigation_data.h" |
15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
| 17 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 class ChromeResourceDispatcherHostDelegateTest : public testing::Test { | 23 class ChromeResourceDispatcherHostDelegateTest : public testing::Test { |
23 public: | 24 public: |
24 ChromeResourceDispatcherHostDelegateTest() | 25 ChromeResourceDispatcherHostDelegateTest() |
25 : profile_manager_( | 26 : profile_manager_( |
26 new TestingProfileManager(TestingBrowserProcess::GetGlobal())) {} | 27 new TestingProfileManager(TestingBrowserProcess::GetGlobal())) {} |
27 ~ChromeResourceDispatcherHostDelegateTest() override {} | 28 ~ChromeResourceDispatcherHostDelegateTest() override {} |
28 | 29 |
29 void SetUp() override { ASSERT_TRUE(profile_manager_->SetUp()); } | 30 void SetUp() override { ASSERT_TRUE(profile_manager_->SetUp()); } |
30 | 31 |
31 private: | 32 private: |
32 content::TestBrowserThreadBundle thread_bundle_; | 33 content::TestBrowserThreadBundle thread_bundle_; |
33 // Set up TestingProfileManager for extensions::UserScriptListener. | 34 // Set up TestingProfileManager for extensions::UserScriptListener. |
34 std::unique_ptr<TestingProfileManager> profile_manager_; | 35 std::unique_ptr<TestingProfileManager> profile_manager_; |
35 }; | 36 }; |
36 | 37 |
37 TEST_F(ChromeResourceDispatcherHostDelegateTest, | 38 TEST_F(ChromeResourceDispatcherHostDelegateTest, |
38 GetNavigationDataWithDataReductionProxyData) { | 39 GetNavigationDataWithDataReductionProxyData) { |
39 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); | 40 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
40 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( | 41 std::unique_ptr<net::URLRequest> fake_request( |
41 GURL("google.com"), net::RequestPriority::IDLE, nullptr)); | 42 context->CreateRequest(GURL("google.com"), net::RequestPriority::IDLE, |
| 43 nullptr, TRAFFIC_ANNOTATION_FOR_TESTS)); |
42 // Add DataReductionProxyData to URLRequest | 44 // Add DataReductionProxyData to URLRequest |
43 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data = | 45 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data = |
44 data_reduction_proxy::DataReductionProxyData::GetDataAndCreateIfNecessary( | 46 data_reduction_proxy::DataReductionProxyData::GetDataAndCreateIfNecessary( |
45 fake_request.get()); | 47 fake_request.get()); |
46 data_reduction_proxy_data->set_used_data_reduction_proxy(true); | 48 data_reduction_proxy_data->set_used_data_reduction_proxy(true); |
47 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( | 49 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
48 new ChromeResourceDispatcherHostDelegate()); | 50 new ChromeResourceDispatcherHostDelegate()); |
49 ChromeNavigationData* chrome_navigation_data = | 51 ChromeNavigationData* chrome_navigation_data = |
50 static_cast<ChromeNavigationData*>( | 52 static_cast<ChromeNavigationData*>( |
51 delegate->GetNavigationData(fake_request.get())); | 53 delegate->GetNavigationData(fake_request.get())); |
52 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data_copy = | 54 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data_copy = |
53 chrome_navigation_data->GetDataReductionProxyData(); | 55 chrome_navigation_data->GetDataReductionProxyData(); |
54 // The DataReductionProxyData should be a copy of the one on URLRequest | 56 // The DataReductionProxyData should be a copy of the one on URLRequest |
55 EXPECT_NE(data_reduction_proxy_data_copy, data_reduction_proxy_data); | 57 EXPECT_NE(data_reduction_proxy_data_copy, data_reduction_proxy_data); |
56 // Make sure DataReductionProxyData was copied. | 58 // Make sure DataReductionProxyData was copied. |
57 EXPECT_TRUE(data_reduction_proxy_data_copy->used_data_reduction_proxy()); | 59 EXPECT_TRUE(data_reduction_proxy_data_copy->used_data_reduction_proxy()); |
58 EXPECT_EQ( | 60 EXPECT_EQ( |
59 chrome_navigation_data, | 61 chrome_navigation_data, |
60 ChromeNavigationData::GetDataAndCreateIfNecessary(fake_request.get())); | 62 ChromeNavigationData::GetDataAndCreateIfNecessary(fake_request.get())); |
61 } | 63 } |
62 | 64 |
63 TEST_F(ChromeResourceDispatcherHostDelegateTest, | 65 TEST_F(ChromeResourceDispatcherHostDelegateTest, |
64 GetNavigationDataWithoutDataReductionProxyData) { | 66 GetNavigationDataWithoutDataReductionProxyData) { |
65 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); | 67 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
66 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( | 68 std::unique_ptr<net::URLRequest> fake_request( |
67 GURL("google.com"), net::RequestPriority::IDLE, nullptr)); | 69 context->CreateRequest(GURL("google.com"), net::RequestPriority::IDLE, |
| 70 nullptr, TRAFFIC_ANNOTATION_FOR_TESTS)); |
68 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( | 71 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
69 new ChromeResourceDispatcherHostDelegate()); | 72 new ChromeResourceDispatcherHostDelegate()); |
70 ChromeNavigationData* chrome_navigation_data = | 73 ChromeNavigationData* chrome_navigation_data = |
71 static_cast<ChromeNavigationData*>( | 74 static_cast<ChromeNavigationData*>( |
72 delegate->GetNavigationData(fake_request.get())); | 75 delegate->GetNavigationData(fake_request.get())); |
73 EXPECT_FALSE(chrome_navigation_data->GetDataReductionProxyData()); | 76 EXPECT_FALSE(chrome_navigation_data->GetDataReductionProxyData()); |
74 } | 77 } |
OLD | NEW |