Chromium Code Reviews| Index: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate_unittest.cc |
| diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate_unittest.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..601e56cb39bb55d9d7ab73ae0f434623ce051ca2 |
| --- /dev/null |
| +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate_unittest.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
bengr
2016/04/29 21:14:21
Wrong year.
RyanSturm
2016/05/02 19:52:20
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h" |
| + |
| +#include <memory> |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "chrome/browser/renderer_host/chrome_navigation_data.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
| +#include "content/public/browser/navigation_data.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "net/base/request_priority.h" |
| +#include "net/url_request/url_request.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +class ChromeResourceDispatcherHostDelegateTest : public testing::Test { |
| + public: |
| + ChromeResourceDispatcherHostDelegateTest() |
| + : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| + ~ChromeResourceDispatcherHostDelegateTest() override {} |
| + |
| + private: |
| + base::MessageLoopForIO message_loop_; |
| + content::TestBrowserThread ui_thread_; |
| +}; |
| + |
| +TEST_F(ChromeResourceDispatcherHostDelegateTest, GetNavigationDataWithDRPData) { |
| + std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
| + std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( |
| + GURL("content.request.any.port"), net::RequestPriority::IDLE, nullptr)); |
|
bengr
2016/04/29 21:14:21
#include "url/gurl.h"
RyanSturm
2016/05/02 19:52:20
Done.
|
| + // Add DRP data to URLRequest |
|
bengr
2016/04/29 21:14:21
Add DataReductionProxyData to the URLRequest.
RyanSturm
2016/05/02 19:52:20
Done.
|
| + data_reduction_proxy::DataReductionProxyData* drp_data = |
| + data_reduction_proxy::DataReductionProxyData::DataForRequest( |
| + fake_request.get(), true); |
| + drp_data->set_used_data_reduction_proxy(true); |
| + std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
|
bengr
2016/04/29 21:14:21
#include "chrome/browser/renderer_host/chrome_reso
RyanSturm
2016/05/02 19:52:20
Done.
|
| + new ChromeResourceDispatcherHostDelegate()); |
| + std::unique_ptr<content::NavigationData> navigation_data = |
| + delegate->GetNavigationData(fake_request.get()); |
| + ChromeNavigationData* chrome_navigation_data = |
| + static_cast<ChromeNavigationData*>(navigation_data.get()); |
| + data_reduction_proxy::DataReductionProxyData* drp_data_copy = |
|
bengr
2016/04/29 21:14:21
You should spell out every drp as data_reduction_p
RyanSturm
2016/05/02 19:52:20
Done.
|
| + chrome_navigation_data->GetDataReductionProxyData(); |
| + // The DRP_data should be a copy off the one on URLRequest |
|
bengr
2016/04/29 21:14:21
copy off -> deep copy of
RyanSturm
2016/05/02 19:52:20
Done.
|
| + EXPECT_NE(drp_data_copy, drp_data); |
| + // Make sure DRP Data was copied. |
|
bengr
2016/04/29 21:14:21
DataReductionProxyData
RyanSturm
2016/05/02 19:52:20
Done.
|
| + EXPECT_TRUE(drp_data_copy->get_used_data_reduction_proxy()); |
| +} |
| + |
| +TEST_F(ChromeResourceDispatcherHostDelegateTest, |
| + GetNavigationDataWithoutDRPData) { |
| + std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); |
| + std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( |
| + GURL("content.request.any.port"), net::RequestPriority::IDLE, nullptr)); |
| + std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate( |
| + new ChromeResourceDispatcherHostDelegate()); |
| + std::unique_ptr<content::NavigationData> navigation_data = |
| + delegate->GetNavigationData(fake_request.get()); |
| + ChromeNavigationData* chrome_navigation_data = |
| + static_cast<ChromeNavigationData*>(navigation_data.get()); |
| + EXPECT_TRUE(!chrome_navigation_data->GetDataReductionProxyData()); |
| +} |