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

Side by Side Diff: components/previews/core/previews_io_data_unittest.cc

Issue 2760063002: Add support to previews/ for Server LoFi and LitePages (Closed)
Patch Set: tbansal comment Created 3 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
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/previews/core/previews_io_data.h" 5 #include "components/previews/core/previews_io_data.h"
6 6
7 #include <initializer_list> 7 #include <initializer_list>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 22 matching lines...) Expand all
33 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" 33 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
34 #include "net/url_request/url_request.h" 34 #include "net/url_request/url_request.h"
35 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "url/gurl.h" 37 #include "url/gurl.h"
38 38
39 namespace previews { 39 namespace previews {
40 40
41 namespace { 41 namespace {
42 42
43 // TODO(sclittle): Tests should be testing the actual prod code that checks if 43 // This method simulates the actual behavior of the passed in callback, which is
44 // the appropriate field trial is enabled for the preview, instead of testing 44 // validated in other tests. For simplicity, offline, lite page, and server LoFi
45 // this function here. Consider moving that code out of 45 // use the offline previews check. Client LoFi uses a seperate check to verify
46 // chrome/browser/previews/previews_service.cc and into the previews/ component. 46 // that types are treated differently.
47 bool IsPreviewFieldTrialEnabled(PreviewsType type) { 47 bool IsPreviewFieldTrialEnabled(PreviewsType type) {
48 switch (type) { 48 switch (type) {
49 case PreviewsType::OFFLINE: 49 case PreviewsType::OFFLINE:
50 case PreviewsType::LITE_PAGE:
51 case PreviewsType::SERVER_LOFI:
50 return params::IsOfflinePreviewsEnabled(); 52 return params::IsOfflinePreviewsEnabled();
51 case PreviewsType::CLIENT_LOFI: 53 case PreviewsType::CLIENT_LOFI:
52 return params::IsClientLoFiEnabled(); 54 return params::IsClientLoFiEnabled();
53 case PreviewsType::NONE: 55 case PreviewsType::NONE:
54 case PreviewsType::LAST: 56 case PreviewsType::LAST:
55 break; 57 break;
56 } 58 }
57 NOTREACHED(); 59 NOTREACHED();
58 return false; 60 return false;
59 } 61 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 268
267 base::HistogramTester histogram_tester; 269 base::HistogramTester histogram_tester;
268 EXPECT_FALSE( 270 EXPECT_FALSE(
269 io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::OFFLINE)); 271 io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::OFFLINE));
270 histogram_tester.ExpectUniqueSample( 272 histogram_tester.ExpectUniqueSample(
271 "Previews.EligibilityReason.Offline", 273 "Previews.EligibilityReason.Offline",
272 static_cast<int>(PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE), 274 static_cast<int>(PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE),
273 1); 275 1);
274 } 276 }
275 277
278 TEST_F(PreviewsIODataTest, TestAllowLoFiLitePageWhenNetworkQualityFast) {
279 // LoFi and LitePage check NQE on their own.
280 InitializeUIService();
281 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled",
282 {{"show_offline_pages", "true"},
283 {"max_allowed_effective_connection_type", "2G"}});
284
285 network_quality_estimator()->set_effective_connection_type(
286 net::EFFECTIVE_CONNECTION_TYPE_3G);
287
288 base::HistogramTester histogram_tester;
289 EXPECT_TRUE(io_data()->ShouldAllowPreview(*CreateRequest(),
290 PreviewsType::SERVER_LOFI));
291 EXPECT_TRUE(
292 io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::LITE_PAGE));
293 histogram_tester.ExpectUniqueSample(
294 "Previews.EligibilityReason.LoFi",
295 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
296 histogram_tester.ExpectUniqueSample(
297 "Previews.EligibilityReason.LitePage",
298 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
299 }
300
276 TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityFast) { 301 TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityFast) {
277 InitializeUIService(); 302 InitializeUIService();
278 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", 303 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled",
279 {{"show_offline_pages", "true"}, 304 {{"show_offline_pages", "true"},
280 {"max_allowed_effective_connection_type", "2G"}}); 305 {"max_allowed_effective_connection_type", "2G"}});
281 306
282 network_quality_estimator()->set_effective_connection_type( 307 network_quality_estimator()->set_effective_connection_type(
283 net::EFFECTIVE_CONNECTION_TYPE_3G); 308 net::EFFECTIVE_CONNECTION_TYPE_3G);
284 309
285 base::HistogramTester histogram_tester; 310 base::HistogramTester histogram_tester;
(...skipping 13 matching lines...) Expand all
299 network_quality_estimator()->set_effective_connection_type( 324 network_quality_estimator()->set_effective_connection_type(
300 net::EFFECTIVE_CONNECTION_TYPE_2G); 325 net::EFFECTIVE_CONNECTION_TYPE_2G);
301 326
302 std::unique_ptr<net::URLRequest> request = CreateRequest(); 327 std::unique_ptr<net::URLRequest> request = CreateRequest();
303 request->SetLoadFlags(net::LOAD_BYPASS_CACHE); 328 request->SetLoadFlags(net::LOAD_BYPASS_CACHE);
304 329
305 base::HistogramTester histogram_tester; 330 base::HistogramTester histogram_tester;
306 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE)); 331 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
307 histogram_tester.ExpectUniqueSample( 332 histogram_tester.ExpectUniqueSample(
308 "Previews.EligibilityReason.Offline", 333 "Previews.EligibilityReason.Offline",
309 static_cast<int>( 334 static_cast<int>(PreviewsEligibilityReason::RELOAD_DISALLOWED), 1);
310 PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE),
311 1);
312 } 335 }
313 336
314 TEST_F(PreviewsIODataTest, TestAllowOffline) { 337 TEST_F(PreviewsIODataTest, TestAllowOffline) {
315 InitializeUIService(); 338 InitializeUIService();
316 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", 339 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled",
317 {{"show_offline_pages", "true"}, 340 {{"show_offline_pages", "true"},
318 {"max_allowed_effective_connection_type", "2G"}}); 341 {"max_allowed_effective_connection_type", "2G"}});
319 342
320 network_quality_estimator()->set_effective_connection_type( 343 network_quality_estimator()->set_effective_connection_type(
321 net::EFFECTIVE_CONNECTION_TYPE_2G); 344 net::EFFECTIVE_CONNECTION_TYPE_2G);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 EXPECT_TRUE( 433 EXPECT_TRUE(
411 io_data()->ShouldAllowPreview(*request, PreviewsType::CLIENT_LOFI)); 434 io_data()->ShouldAllowPreview(*request, PreviewsType::CLIENT_LOFI));
412 histogram_tester.ExpectUniqueSample( 435 histogram_tester.ExpectUniqueSample(
413 "Previews.EligibilityReason.ClientLoFi", 436 "Previews.EligibilityReason.ClientLoFi",
414 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1); 437 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
415 } 438 }
416 439
417 } // namespace 440 } // namespace
418 441
419 } // namespace previews 442 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698