Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate_unittest.cc

Issue 1721813002: Adding DRP specfic UMA for FirstContentfulPaint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing drp -> data_reduction_proxy Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 std::unique_ptr<content::NavigationData> navigation_data =
45 delegate->GetNavigationData(fake_request.get());
46 ChromeNavigationData* chrome_navigation_data =
47 static_cast<ChromeNavigationData*>(navigation_data.get());
48 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data_copy =
49 chrome_navigation_data->GetDataReductionProxyData();
50 // The DataReductionProxyData should be a copy of the one on URLRequest
51 EXPECT_NE(data_reduction_proxy_data_copy, data_reduction_proxy_data);
52 // Make sure DataReductionProxyData was copied.
53 EXPECT_TRUE(data_reduction_proxy_data_copy->used_data_reduction_proxy());
54 }
55
56 TEST_F(ChromeResourceDispatcherHostDelegateTest,
57 GetNavigationDataWithoutDataReductionProxyData) {
58 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext());
59 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest(
60 GURL("google.com"), net::RequestPriority::IDLE, nullptr));
61 std::unique_ptr<ChromeResourceDispatcherHostDelegate> delegate(
62 new ChromeResourceDispatcherHostDelegate());
63 std::unique_ptr<content::NavigationData> navigation_data =
64 delegate->GetNavigationData(fake_request.get());
65 ChromeNavigationData* chrome_navigation_data =
66 static_cast<ChromeNavigationData*>(navigation_data.get());
67 EXPECT_TRUE(!chrome_navigation_data->GetDataReductionProxyData());
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698