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

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

Issue 2563493002: Disallow showing offline previews on a reload. (Closed)
Patch Set: tbansal comments Created 4 years 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
« no previous file with comments | « components/previews/core/previews_io_data.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/test/histogram_tester.h" 20 #include "base/test/histogram_tester.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "components/previews/core/previews_black_list.h" 23 #include "components/previews/core/previews_black_list.h"
24 #include "components/previews/core/previews_black_list_item.h" 24 #include "components/previews/core/previews_black_list_item.h"
25 #include "components/previews/core/previews_opt_out_store.h" 25 #include "components/previews/core/previews_opt_out_store.h"
26 #include "components/previews/core/previews_ui_service.h" 26 #include "components/previews/core/previews_ui_service.h"
27 #include "components/variations/variations_associated_data.h" 27 #include "components/variations/variations_associated_data.h"
28 #include "net/base/load_flags.h"
28 #include "net/nqe/effective_connection_type.h" 29 #include "net/nqe/effective_connection_type.h"
29 #include "net/nqe/network_quality_estimator_test_util.h" 30 #include "net/nqe/network_quality_estimator_test_util.h"
30 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_test_util.h" 32 #include "net/url_request/url_request_test_util.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 #include "url/gurl.h" 34 #include "url/gurl.h"
34 35
35 namespace previews { 36 namespace previews {
36 37
37 namespace { 38 namespace {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 net::EFFECTIVE_CONNECTION_TYPE_2G); 206 net::EFFECTIVE_CONNECTION_TYPE_2G);
206 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE)); 207 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
207 histogram_tester.ExpectBucketCount( 208 histogram_tester.ExpectBucketCount(
208 "Previews.EligibilityReason.Offline", 209 "Previews.EligibilityReason.Offline",
209 static_cast<int>(PreviewsEligibilityReason::NETWORK_NOT_SLOW), 1); 210 static_cast<int>(PreviewsEligibilityReason::NETWORK_NOT_SLOW), 1);
210 211
211 // Set NQE type to slow. 212 // Set NQE type to slow.
212 network_quality_estimator.set_effective_connection_type( 213 network_quality_estimator.set_effective_connection_type(
213 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 214 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
214 215
216 request->SetLoadFlags(net::LOAD_BYPASS_CACHE);
217 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
218 histogram_tester.ExpectBucketCount(
219 "Previews.EligibilityReason.Offline",
220 static_cast<int>(
221 PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE),
222 1);
223
224 request->SetLoadFlags(0);
215 EXPECT_TRUE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE)); 225 EXPECT_TRUE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
216 histogram_tester.ExpectBucketCount( 226 histogram_tester.ExpectBucketCount(
217 "Previews.EligibilityReason.Offline", 227 "Previews.EligibilityReason.Offline",
218 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1); 228 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
219 229
220 histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 6); 230 histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 7);
221 231
222 variations::testing::ClearAllVariationParams(); 232 variations::testing::ClearAllVariationParams();
223 } 233 }
224 234
225 } // namespace previews 235 } // namespace previews
OLDNEW
« no previous file with comments | « components/previews/core/previews_io_data.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698