| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
| 12 #include "content/public/browser/navigation_data.h" |
| 13 #include "content/public/test/test_browser_thread.h" |
| 14 #include "net/base/request_priority.h" |
| 15 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_context.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 class ChromeResourceDispatcherHostDelegateTest : public testing::Test { |
| 20 public: |
| 21 ChromeResourceDispatcherHostDelegateTest() |
| 22 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| 23 ~ChromeResourceDispatcherHostDelegateTest() override {} |
| 24 |
| 25 private: |
| 26 base::MessageLoopForIO message_loop_; |
| 27 content::TestBrowserThread ui_thread_; |
| 28 }; |
| 29 |
| 30 TEST_F(ChromeResourceDispatcherHostDelegateTest, GetNavigationDataWithDRPData) { |
| 31 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
| 32 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( |
| 33 GURL("content.request.any.port"), net::RequestPriority::IDLE, nullptr)); |
| 34 // Add DRP data to URLRequest |
| 35 data_reduction_proxy::DataReductionProxyData* drp_data = |
| 36 data_reduction_proxy::DataReductionProxyData::DataForRequest( |
| 37 fake_request.get(), true); |
| 38 drp_data->set_used_data_reduction_proxy(true); |
| 39 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
| 40 new ChromeResourceDispatcherHostDelegate()); |
| 41 std::unique_ptr<content::NavigationData> navigation_data = |
| 42 delegate->GetNavigationData(fake_request.get()); |
| 43 ChromeNavigationData* chrome_navigation_data = |
| 44 static_cast<ChromeNavigationData*>(navigation_data.get()); |
| 45 data_reduction_proxy::DataReductionProxyData* drp_data_copy = |
| 46 chrome_navigation_data->GetDataReductionProxyData(); |
| 47 // The DRP_data should be a copy off the one on URLRequest |
| 48 EXPECT_NE(drp_data_copy, drp_data); |
| 49 // Make sure DRP Data was copied. |
| 50 EXPECT_TRUE(drp_data_copy->get_used_data_reduction_proxy()); |
| 51 } |
| 52 |
| 53 TEST_F(ChromeResourceDispatcherHostDelegateTest, |
| 54 GetNavigationDataWithoutDRPData) { |
| 55 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
| 56 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( |
| 57 GURL("content.request.any.port"), net::RequestPriority::IDLE, nullptr)); |
| 58 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
| 59 new ChromeResourceDispatcherHostDelegate()); |
| 60 std::unique_ptr<content::NavigationData> navigation_data = |
| 61 delegate->GetNavigationData(fake_request.get()); |
| 62 ChromeNavigationData* chrome_navigation_data = |
| 63 static_cast<ChromeNavigationData*>(navigation_data.get()); |
| 64 EXPECT_TRUE(!chrome_navigation_data->GetDataReductionProxyData()); |
| 65 } |
| OLD | NEW |