| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/renderer_host/chrome_navigation_data.h" |
| 11 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
| 13 #include "content/public/browser/navigation_data.h" |
| 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "net/base/request_priority.h" |
| 16 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_context.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "url/gurl.h" |
| 20 |
| 21 class ChromeResourceDispatcherHostDelegateTest : public testing::Test { |
| 22 public: |
| 23 ChromeResourceDispatcherHostDelegateTest() |
| 24 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| 25 ~ChromeResourceDispatcherHostDelegateTest() override {} |
| 26 |
| 27 private: |
| 28 base::MessageLoopForIO message_loop_; |
| 29 content::TestBrowserThread ui_thread_; |
| 30 }; |
| 31 |
| 32 TEST_F(ChromeResourceDispatcherHostDelegateTest, |
| 33 GetNavigationDataWithDataReductionProxyData) { |
| 34 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
| 35 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( |
| 36 GURL("google.com"), net::RequestPriority::IDLE, nullptr)); |
| 37 // Add DataReductionProxyData to URLRequest |
| 38 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data = |
| 39 data_reduction_proxy::DataReductionProxyData::GetDataAndCreateIfNecessary( |
| 40 fake_request.get()); |
| 41 data_reduction_proxy_data->set_used_data_reduction_proxy(true); |
| 42 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
| 43 new ChromeResourceDispatcherHostDelegate()); |
| 44 ChromeNavigationData* chrome_navigation_data = |
| 45 static_cast<ChromeNavigationData*>( |
| 46 delegate->GetNavigationData(fake_request.get())); |
| 47 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data_copy = |
| 48 chrome_navigation_data->GetDataReductionProxyData(); |
| 49 // The DataReductionProxyData should be a copy of the one on URLRequest |
| 50 EXPECT_NE(data_reduction_proxy_data_copy, data_reduction_proxy_data); |
| 51 // Make sure DataReductionProxyData was copied. |
| 52 EXPECT_TRUE(data_reduction_proxy_data_copy->used_data_reduction_proxy()); |
| 53 EXPECT_EQ( |
| 54 chrome_navigation_data, |
| 55 ChromeNavigationData::GetDataAndCreateIfNecessary(fake_request.get())); |
| 56 } |
| 57 |
| 58 TEST_F(ChromeResourceDispatcherHostDelegateTest, |
| 59 GetNavigationDataWithoutDataReductionProxyData) { |
| 60 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
| 61 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( |
| 62 GURL("google.com"), net::RequestPriority::IDLE, nullptr)); |
| 63 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
| 64 new ChromeResourceDispatcherHostDelegate()); |
| 65 ChromeNavigationData* chrome_navigation_data = |
| 66 static_cast<ChromeNavigationData*>( |
| 67 delegate->GetNavigationData(fake_request.get())); |
| 68 EXPECT_FALSE(chrome_navigation_data->GetDataReductionProxyData()); |
| 69 } |
| OLD | NEW |