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