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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_data_unittest.cc

Issue 2833523002: Adding opt out and previews type information to DRP pingback (Closed)
Patch Set: moved definition up Created 3 years, 8 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
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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 25 matching lines...) Expand all
36 EXPECT_TRUE(data->used_data_reduction_proxy()); 36 EXPECT_TRUE(data->used_data_reduction_proxy());
37 data->set_used_data_reduction_proxy(false); 37 data->set_used_data_reduction_proxy(false);
38 EXPECT_FALSE(data->used_data_reduction_proxy()); 38 EXPECT_FALSE(data->used_data_reduction_proxy());
39 39
40 EXPECT_FALSE(data->lofi_requested()); 40 EXPECT_FALSE(data->lofi_requested());
41 data->set_lofi_requested(true); 41 data->set_lofi_requested(true);
42 EXPECT_TRUE(data->lofi_requested()); 42 EXPECT_TRUE(data->lofi_requested());
43 data->set_lofi_requested(false); 43 data->set_lofi_requested(false);
44 EXPECT_FALSE(data->lofi_requested()); 44 EXPECT_FALSE(data->lofi_requested());
45 45
46 EXPECT_FALSE(data->lite_page_received());
47 data->set_lite_page_received(true);
48 EXPECT_TRUE(data->lite_page_received());
49 data->set_lite_page_received(false);
50 EXPECT_FALSE(data->lite_page_received());
51
52 EXPECT_FALSE(data->lofi_received());
53 data->set_lofi_received(true);
54 EXPECT_TRUE(data->lofi_received());
55 data->set_lofi_received(false);
56 EXPECT_FALSE(data->lofi_received());
57
46 EXPECT_EQ(std::string(), data->session_key()); 58 EXPECT_EQ(std::string(), data->session_key());
bengr 2017/04/20 17:36:19 #include <string>
RyanSturm 2017/04/20 20:25:45 Done.
47 EXPECT_EQ(GURL(std::string()), data->request_url());
48 std::string session_key = "test-key"; 59 std::string session_key = "test-key";
49 data->set_session_key(session_key); 60 data->set_session_key(session_key);
50 EXPECT_EQ(session_key, data->session_key()); 61 EXPECT_EQ(session_key, data->session_key());
62
63 EXPECT_EQ(GURL(std::string()), data->request_url());
51 GURL test_url("test-url"); 64 GURL test_url("test-url");
52 data->set_request_url(test_url); 65 data->set_request_url(test_url);
53 EXPECT_EQ(test_url, data->request_url()); 66 EXPECT_EQ(test_url, data->request_url());
67
54 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 68 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
55 data->effective_connection_type()); 69 data->effective_connection_type());
56 data->set_effective_connection_type(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); 70 data->set_effective_connection_type(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
57 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE, 71 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE,
58 data->effective_connection_type()); 72 data->effective_connection_type());
73
74 EXPECT_FALSE(data->page_id());
59 uint64_t page_id = 1; 75 uint64_t page_id = 1;
60 EXPECT_FALSE(data->page_id());
61 data->set_page_id(page_id); 76 data->set_page_id(page_id);
62 EXPECT_EQ(page_id, data->page_id().value()); 77 EXPECT_EQ(page_id, data->page_id().value());
63 } 78 }
64 79
65 TEST_F(DataReductionProxyDataTest, AddToURLRequest) { 80 TEST_F(DataReductionProxyDataTest, AddToURLRequest) {
66 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); 81 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext());
67 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( 82 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest(
68 GURL("http://www.google.com"), net::RequestPriority::IDLE, nullptr)); 83 GURL("http://www.google.com"), net::RequestPriority::IDLE, nullptr));
69 DataReductionProxyData* data = 84 DataReductionProxyData* data =
70 DataReductionProxyData::GetData(*fake_request.get()); 85 DataReductionProxyData::GetData(*fake_request.get());
71 EXPECT_FALSE(data); 86 EXPECT_FALSE(data);
72 data = 87 data =
73 DataReductionProxyData::GetDataAndCreateIfNecessary(fake_request.get()); 88 DataReductionProxyData::GetDataAndCreateIfNecessary(fake_request.get());
74 EXPECT_TRUE(data); 89 EXPECT_TRUE(data);
75 data = DataReductionProxyData::GetData(*fake_request.get()); 90 data = DataReductionProxyData::GetData(*fake_request.get());
76 EXPECT_TRUE(data); 91 EXPECT_TRUE(data);
77 DataReductionProxyData* data2 = 92 DataReductionProxyData* data2 =
78 DataReductionProxyData::GetDataAndCreateIfNecessary(fake_request.get()); 93 DataReductionProxyData::GetDataAndCreateIfNecessary(fake_request.get());
79 EXPECT_EQ(data, data2); 94 EXPECT_EQ(data, data2);
80 } 95 }
81 96
82 TEST_F(DataReductionProxyDataTest, DeepCopy) { 97 TEST_F(DataReductionProxyDataTest, DeepCopy) {
83 const struct { 98 const struct {
84 bool data_reduction_used; 99 bool data_reduction_used;
85 bool lofi_on; 100 bool lofi_test_value;
86 } tests[] = { 101 } tests[] = {
87 { 102 {
88 false, true, 103 false, true,
89 }, 104 },
90 { 105 {
91 false, false, 106 false, false,
92 }, 107 },
93 { 108 {
94 true, false, 109 true, false,
95 }, 110 },
96 { 111 {
97 true, true, 112 true, true,
98 }, 113 },
99 }; 114 };
100 115
101 for (size_t i = 0; i < arraysize(tests); ++i) { 116 for (size_t i = 0; i < arraysize(tests); ++i) {
102 static const char kSessionKey[] = "test-key"; 117 static const char kSessionKey[] = "test-key";
103 static const GURL kTestURL("test-url"); 118 static const GURL kTestURL("test-url");
104 std::unique_ptr<DataReductionProxyData> data(new DataReductionProxyData()); 119 std::unique_ptr<DataReductionProxyData> data(new DataReductionProxyData());
105 data->set_used_data_reduction_proxy(tests[i].data_reduction_used); 120 data->set_used_data_reduction_proxy(tests[i].data_reduction_used);
106 data->set_lofi_requested(tests[i].lofi_on); 121 data->set_lofi_requested(tests[i].lofi_test_value);
122 data->set_lite_page_received(tests[i].lofi_test_value);
123 data->set_lofi_received(tests[i].lofi_test_value);
107 data->set_session_key(kSessionKey); 124 data->set_session_key(kSessionKey);
108 data->set_request_url(kTestURL); 125 data->set_request_url(kTestURL);
109 data->set_effective_connection_type(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE); 126 data->set_effective_connection_type(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
110 data->set_page_id(2u); 127 data->set_page_id(2u);
111 std::unique_ptr<DataReductionProxyData> copy = data->DeepCopy(); 128 std::unique_ptr<DataReductionProxyData> copy = data->DeepCopy();
112 EXPECT_EQ(tests[i].lofi_on, copy->lofi_requested()); 129 EXPECT_EQ(tests[i].lofi_test_value, copy->lofi_requested());
130 EXPECT_EQ(tests[i].lofi_test_value, copy->lite_page_received());
131 EXPECT_EQ(tests[i].lofi_test_value, copy->lofi_received());
113 EXPECT_EQ(tests[i].data_reduction_used, copy->used_data_reduction_proxy()); 132 EXPECT_EQ(tests[i].data_reduction_used, copy->used_data_reduction_proxy());
114 EXPECT_EQ(kSessionKey, copy->session_key()); 133 EXPECT_EQ(kSessionKey, copy->session_key());
115 EXPECT_EQ(kTestURL, copy->request_url()); 134 EXPECT_EQ(kTestURL, copy->request_url());
116 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE, 135 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE,
117 copy->effective_connection_type()); 136 copy->effective_connection_type());
118 EXPECT_EQ(2u, data->page_id().value()); 137 EXPECT_EQ(2u, data->page_id().value());
119 } 138 }
120 } 139 }
121 140
122 TEST_F(DataReductionProxyDataTest, ClearData) { 141 TEST_F(DataReductionProxyDataTest, ClearData) {
123 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext()); 142 std::unique_ptr<net::URLRequestContext> context(new net::URLRequestContext());
124 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest( 143 std::unique_ptr<net::URLRequest> fake_request(context->CreateRequest(
125 GURL("http://www.google.com"), net::RequestPriority::IDLE, nullptr)); 144 GURL("http://www.google.com"), net::RequestPriority::IDLE, nullptr));
126 145
127 DataReductionProxyData* data = 146 DataReductionProxyData* data =
128 DataReductionProxyData::GetDataAndCreateIfNecessary(fake_request.get()); 147 DataReductionProxyData::GetDataAndCreateIfNecessary(fake_request.get());
129 EXPECT_TRUE(data); 148 EXPECT_TRUE(data);
130 DataReductionProxyData::ClearData(fake_request.get()); 149 DataReductionProxyData::ClearData(fake_request.get());
131 data = DataReductionProxyData::GetData(*fake_request.get()); 150 data = DataReductionProxyData::GetData(*fake_request.get());
132 EXPECT_FALSE(data); 151 EXPECT_FALSE(data);
133 } 152 }
134 153
135 } // namespace 154 } // namespace
136 155
137 } // namespace data_reduction_proxy 156 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698