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

Side by Side Diff: chrome/browser/previews/previews_infobar_delegate_unittest.cc

Issue 2940083003: Add timestamp to infobar for stale Previews (Closed)
Patch Set: add GetMessageText comment Created 3 years, 6 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 "chrome/browser/previews/previews_infobar_delegate.h" 5 #include "chrome/browser/previews/previews_infobar_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/feature_list.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/metrics/field_trial_params.h"
14 #include "base/optional.h" 16 #include "base/optional.h"
15 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
18 #include "base/test/scoped_feature_list.h"
16 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h"
17 #include "chrome/browser/android/android_theme_resources.h" 21 #include "chrome/browser/android/android_theme_resources.h"
18 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/loader/chrome_navigation_data.h" 23 #include "chrome/browser/loader/chrome_navigation_data.h"
20 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 24 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
21 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 25 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
22 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 26 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
23 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
29 #include "chrome/test/base/testing_browser_process.h"
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" 30 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 31 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" 32 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h"
28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
29 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
30 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 35 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 36 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
32 #include "components/infobars/core/confirm_infobar_delegate.h" 37 #include "components/infobars/core/confirm_infobar_delegate.h"
33 #include "components/infobars/core/infobar.h" 38 #include "components/infobars/core/infobar.h"
34 #include "components/infobars/core/infobar_delegate.h" 39 #include "components/infobars/core/infobar_delegate.h"
40 #include "components/network_time/network_time_test_utils.h"
35 #include "components/prefs/pref_registry_simple.h" 41 #include "components/prefs/pref_registry_simple.h"
36 #include "components/previews/core/previews_experiments.h" 42 #include "components/previews/core/previews_experiments.h"
43 #include "components/previews/core/previews_features.h"
37 #include "components/proxy_config/proxy_config_pref_names.h" 44 #include "components/proxy_config/proxy_config_pref_names.h"
45 #include "components/variations/variations_associated_data.h"
38 #include "content/public/browser/navigation_entry.h" 46 #include "content/public/browser/navigation_entry.h"
39 #include "content/public/browser/navigation_handle.h" 47 #include "content/public/browser/navigation_handle.h"
40 #include "content/public/browser/reload_type.h" 48 #include "content/public/browser/reload_type.h"
41 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
42 #include "content/public/browser/web_contents_observer.h" 50 #include "content/public/browser/web_contents_observer.h"
43 #include "content/public/browser/web_contents_user_data.h" 51 #include "content/public/browser/web_contents_user_data.h"
44 #include "content/public/common/referrer.h" 52 #include "content/public/common/referrer.h"
45 #include "content/public/test/test_renderer_host.h" 53 #include "content/public/test/test_renderer_host.h"
46 #include "content/public/test/web_contents_tester.h" 54 #include "content/public/test/web_contents_tester.h"
47 #include "ui/base/l10n/l10n_util.h" 55 #include "ui/base/l10n/l10n_util.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 content::ReloadType last_navigation_reload_type_; 112 content::ReloadType last_navigation_reload_type_;
105 bool should_have_page_id_; 113 bool should_have_page_id_;
106 }; 114 };
107 115
108 } // namespace 116 } // namespace
109 117
110 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver); 118 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver);
111 119
112 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness { 120 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness {
113 protected: 121 protected:
122 PreviewsInfoBarDelegateUnitTest()
123 : field_trial_list_(new base::FieldTrialList(nullptr)) {}
124
114 void SetUp() override { 125 void SetUp() override {
115 ChromeRenderViewHostTestHarness::SetUp(); 126 ChromeRenderViewHostTestHarness::SetUp();
116 InfoBarService::CreateForWebContents(web_contents()); 127 InfoBarService::CreateForWebContents(web_contents());
117 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); 128 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents());
118 TestPreviewsWebContentsObserver::CreateForWebContents(web_contents()); 129 TestPreviewsWebContentsObserver::CreateForWebContents(web_contents());
119 130
120 drp_test_context_ = 131 drp_test_context_ =
121 data_reduction_proxy::DataReductionProxyTestContext::Builder() 132 data_reduction_proxy::DataReductionProxyTestContext::Builder()
122 .WithMockConfig() 133 .WithMockConfig()
123 .SkipSettingsInitialization() 134 .SkipSettingsInitialization()
124 .Build(); 135 .Build();
125 136
126 auto* data_reduction_proxy_settings = 137 auto* data_reduction_proxy_settings =
127 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 138 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
128 web_contents()->GetBrowserContext()); 139 web_contents()->GetBrowserContext());
129 140
130 PrefRegistrySimple* registry = 141 PrefRegistrySimple* registry =
131 drp_test_context_->pref_service()->registry(); 142 drp_test_context_->pref_service()->registry();
132 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy); 143 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy);
133 data_reduction_proxy_settings 144 data_reduction_proxy_settings
134 ->set_data_reduction_proxy_enabled_pref_name_for_test( 145 ->set_data_reduction_proxy_enabled_pref_name_for_test(
135 drp_test_context_->GetDataReductionProxyEnabledPrefName()); 146 drp_test_context_->GetDataReductionProxyEnabledPrefName());
136 data_reduction_proxy_settings->InitDataReductionProxySettings( 147 data_reduction_proxy_settings->InitDataReductionProxySettings(
137 drp_test_context_->io_data(), drp_test_context_->pref_service(), 148 drp_test_context_->io_data(), drp_test_context_->pref_service(),
138 drp_test_context_->request_context_getter(), 149 drp_test_context_->request_context_getter(),
139 base::WrapUnique(new data_reduction_proxy::DataStore()), 150 base::WrapUnique(new data_reduction_proxy::DataStore()),
140 base::ThreadTaskRunnerHandle::Get(), 151 base::ThreadTaskRunnerHandle::Get(),
141 base::ThreadTaskRunnerHandle::Get()); 152 base::ThreadTaskRunnerHandle::Get());
153
154 TestingBrowserProcess::GetGlobal()->SetLocalState(
155 drp_test_context_->pref_service());
156 network_time::NetworkTimeTracker::RegisterPrefs(registry);
142 } 157 }
143 158
144 void TearDown() override { 159 void TearDown() override {
145 drp_test_context_->DestroySettings(); 160 drp_test_context_->DestroySettings();
146 ChromeRenderViewHostTestHarness::TearDown(); 161 ChromeRenderViewHostTestHarness::TearDown();
162 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
147 } 163 }
148 164
149 ConfirmInfoBarDelegate* CreateInfoBar(previews::PreviewsType type, 165 PreviewsInfoBarDelegate* CreateInfoBar(previews::PreviewsType type,
150 bool is_data_saver_user) { 166 base::Time previews_freshness,
167 bool is_data_saver_user) {
151 PreviewsInfoBarDelegate::Create( 168 PreviewsInfoBarDelegate::Create(
152 web_contents(), type, is_data_saver_user, 169 web_contents(), type, previews_freshness, is_data_saver_user,
153 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar, 170 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar,
154 base::Unretained(this))); 171 base::Unretained(this)));
155 172
156 InfoBarService* infobar_service = 173 InfoBarService* infobar_service =
157 InfoBarService::FromWebContents(web_contents()); 174 InfoBarService::FromWebContents(web_contents());
158 EXPECT_EQ(1U, infobar_service->infobar_count()); 175 EXPECT_EQ(1U, infobar_service->infobar_count());
159 176
160 return infobar_service->infobar_at(0) 177 return static_cast<PreviewsInfoBarDelegate*>(
161 ->delegate() 178 infobar_service->infobar_at(0)->delegate());
162 ->AsConfirmInfoBarDelegate(); 179 }
180
181 void EnableStalePreviewsTimestamp() {
182 const std::string kTrialName = "TrialName";
183 const std::string kGroupName = "GroupName";
184
185 std::map<std::string, std::string> variation_params;
186 variation_params["min_staleness_in_minutes"] = "2";
187 variation_params["max_staleness_in_minutes"] = "1440";
188
189 base::AssociateFieldTrialParams(kTrialName, kGroupName, variation_params);
190 base::FieldTrial* field_trial =
191 base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName);
192
193 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
194 feature_list->RegisterFieldTrialOverride(
195 previews::features::kStalePreviewsTimestamp.name,
196 base::FeatureList::OVERRIDE_ENABLE_FEATURE, field_trial);
197 scoped_feature_list_.InitWithFeatureList(std::move(feature_list));
163 } 198 }
164 199
165 void OnDismissPreviewsInfobar(bool user_opt_out) { 200 void OnDismissPreviewsInfobar(bool user_opt_out) {
166 user_opt_out_ = user_opt_out; 201 user_opt_out_ = user_opt_out;
167 } 202 }
168 203
169 InfoBarService* infobar_service() { 204 InfoBarService* infobar_service() {
170 return InfoBarService::FromWebContents(web_contents()); 205 return InfoBarService::FromWebContents(web_contents());
171 } 206 }
172 207
173 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> 208 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
174 drp_test_context_; 209 drp_test_context_;
175 210
176 base::Optional<bool> user_opt_out_; 211 base::Optional<bool> user_opt_out_;
212 std::unique_ptr<base::FieldTrialList> field_trial_list_;
213 base::test::ScopedFeatureList scoped_feature_list_;
177 }; 214 };
178 215
179 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { 216 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) {
180 base::HistogramTester tester; 217 base::HistogramTester tester;
181 218
182 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */); 219 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
220 true /* is_data_saver_user */);
183 221
184 // Try showing a second infobar. Another should not be shown since the page 222 // Try showing a second infobar. Another should not be shown since the page
185 // has not navigated. 223 // has not navigated.
186 PreviewsInfoBarDelegate::Create( 224 PreviewsInfoBarDelegate::Create(
187 web_contents(), previews::PreviewsType::LOFI, 225 web_contents(), previews::PreviewsType::LOFI,
188 true /* is_data_saver_user */, 226 base::Time() /* previews_freshness */, true /* is_data_saver_user */,
189 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 227 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
190 EXPECT_EQ(1U, infobar_service()->infobar_count()); 228 EXPECT_EQ(1U, infobar_service()->infobar_count());
191 229
192 // Navigate and make sure the infobar is dismissed. 230 // Navigate and make sure the infobar is dismissed.
193 NavigateAndCommit(GURL(kTestUrl)); 231 NavigateAndCommit(GURL(kTestUrl));
194 EXPECT_EQ(0U, infobar_service()->infobar_count()); 232 EXPECT_EQ(0U, infobar_service()->infobar_count());
195 EXPECT_FALSE(user_opt_out_.value()); 233 EXPECT_FALSE(user_opt_out_.value());
196 234
197 tester.ExpectBucketCount( 235 tester.ExpectBucketCount(
198 kUMAPreviewsInfoBarActionLoFi, 236 kUMAPreviewsInfoBarActionLoFi,
199 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); 237 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1);
200 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 238 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
201 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 239 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
202 } 240 }
203 241
204 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { 242 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) {
205 base::HistogramTester tester; 243 base::HistogramTester tester;
206 244
207 // Navigate to test URL, so we can reload later. 245 // Navigate to test URL, so we can reload later.
208 NavigateAndCommit(GURL(kTestUrl)); 246 NavigateAndCommit(GURL(kTestUrl));
209 247
210 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */); 248 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
249 true /* is_data_saver_user */);
211 250
212 // Try showing a second infobar. Another should not be shown since the page 251 // Try showing a second infobar. Another should not be shown since the page
213 // has not navigated. 252 // has not navigated.
214 PreviewsInfoBarDelegate::Create( 253 PreviewsInfoBarDelegate::Create(
215 web_contents(), previews::PreviewsType::LOFI, 254 web_contents(), previews::PreviewsType::LOFI,
216 true /* is_data_saver_user */, 255 base::Time() /* previews_freshness */, true /* is_data_saver_user */,
217 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 256 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
218 EXPECT_EQ(1U, infobar_service()->infobar_count()); 257 EXPECT_EQ(1U, infobar_service()->infobar_count());
219 258
220 // Navigate to test URL as a reload to dismiss the infobar. 259 // Navigate to test URL as a reload to dismiss the infobar.
221 controller().LoadURL(GURL(kTestUrl), content::Referrer(), 260 controller().LoadURL(GURL(kTestUrl), content::Referrer(),
222 ui::PAGE_TRANSITION_RELOAD, std::string()); 261 ui::PAGE_TRANSITION_RELOAD, std::string());
223 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 262 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
224 263
225 EXPECT_EQ(0U, infobar_service()->infobar_count()); 264 EXPECT_EQ(0U, infobar_service()->infobar_count());
226 EXPECT_FALSE(user_opt_out_.value()); 265 EXPECT_FALSE(user_opt_out_.value());
227 266
228 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, 267 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
229 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, 268 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD,
230 1); 269 1);
231 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 270 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
232 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 271 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
233 272
234 auto* data_reduction_proxy_settings = 273 auto* data_reduction_proxy_settings =
235 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 274 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
236 web_contents()->GetBrowserContext()); 275 web_contents()->GetBrowserContext());
237 276
238 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() 277 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
239 ->pingback_client() 278 ->pingback_client()
240 ->OptOutsSizeForTesting()); 279 ->OptOutsSizeForTesting());
241 } 280 }
242 281
243 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { 282 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) {
244 base::HistogramTester tester; 283 base::HistogramTester tester;
245 284
246 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 285 ConfirmInfoBarDelegate* infobar =
247 previews::PreviewsType::LOFI, true /* is_data_saver_user */); 286 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
287 true /* is_data_saver_user */);
248 288
249 // Simulate dismissing the infobar. 289 // Simulate dismissing the infobar.
250 infobar->InfoBarDismissed(); 290 infobar->InfoBarDismissed();
251 infobar_service()->infobar_at(0)->RemoveSelf(); 291 infobar_service()->infobar_at(0)->RemoveSelf();
252 EXPECT_EQ(0U, infobar_service()->infobar_count()); 292 EXPECT_EQ(0U, infobar_service()->infobar_count());
253 293
254 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, 294 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
255 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, 295 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER,
256 1); 296 1);
257 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 297 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
258 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 298 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
259 EXPECT_FALSE(user_opt_out_.value()); 299 EXPECT_FALSE(user_opt_out_.value());
260 } 300 }
261 301
262 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) { 302 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) {
263 base::HistogramTester tester; 303 base::HistogramTester tester;
264 304
265 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */); 305 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
306 true /* is_data_saver_user */);
266 307
267 // Delete the infobar without any other infobar actions. 308 // Delete the infobar without any other infobar actions.
268 infobar_service()->infobar_at(0)->RemoveSelf(); 309 infobar_service()->infobar_at(0)->RemoveSelf();
269 EXPECT_EQ(0U, infobar_service()->infobar_count()); 310 EXPECT_EQ(0U, infobar_service()->infobar_count());
270 311
271 tester.ExpectBucketCount( 312 tester.ExpectBucketCount(
272 kUMAPreviewsInfoBarActionLoFi, 313 kUMAPreviewsInfoBarActionLoFi,
273 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); 314 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1);
274 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 315 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
275 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 316 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
276 EXPECT_FALSE(user_opt_out_.value()); 317 EXPECT_FALSE(user_opt_out_.value());
277 } 318 }
278 319
279 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) { 320 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) {
280 NavigateAndCommit(GURL(kTestUrl)); 321 NavigateAndCommit(GURL(kTestUrl));
281 const struct { 322 const struct {
282 bool using_previews_blacklist; 323 bool using_previews_blacklist;
283 } tests[] = { 324 } tests[] = {
284 {true}, {false}, 325 {true}, {false},
285 }; 326 };
286 for (const auto test : tests) { 327 for (const auto test : tests) {
287 drp_test_context_->config()->ResetLoFiStatusForTest(); 328 drp_test_context_->config()->ResetLoFiStatusForTest();
288 base::FieldTrialList field_trial_list(nullptr); 329 field_trial_list_.reset();
330 field_trial_list_.reset(new base::FieldTrialList(nullptr));
289 if (test.using_previews_blacklist) { 331 if (test.using_previews_blacklist) {
290 base::FieldTrialList::CreateFieldTrial( 332 base::FieldTrialList::CreateFieldTrial(
291 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); 333 "DataReductionProxyPreviewsBlackListTransition", "Enabled_");
292 } 334 }
293 base::HistogramTester tester; 335 base::HistogramTester tester;
294 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. 336 // Call Reload and CommitPendingNavigation to force DidFinishNavigation.
295 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); 337 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
296 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 338 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
297 339
298 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 340 ConfirmInfoBarDelegate* infobar =
299 previews::PreviewsType::LOFI, true /* is_data_saver_user */); 341 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
342 true /* is_data_saver_user */);
300 343
301 // Simulate clicking the infobar link. 344 // Simulate clicking the infobar link.
302 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 345 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
303 infobar_service()->infobar_at(0)->RemoveSelf(); 346 infobar_service()->infobar_at(0)->RemoveSelf();
304 EXPECT_EQ(0U, infobar_service()->infobar_count()); 347 EXPECT_EQ(0U, infobar_service()->infobar_count());
305 348
306 tester.ExpectBucketCount( 349 tester.ExpectBucketCount(
307 kUMAPreviewsInfoBarActionLoFi, 350 kUMAPreviewsInfoBarActionLoFi,
308 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 351 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
309 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, 352 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1,
310 drp_test_context_->pref_service()->GetInteger( 353 drp_test_context_->pref_service()->GetInteger(
311 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 354 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
312 EXPECT_TRUE(user_opt_out_.value()); 355 EXPECT_TRUE(user_opt_out_.value());
313 356
314 auto* data_reduction_proxy_settings = 357 auto* data_reduction_proxy_settings =
315 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 358 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
316 web_contents()->GetBrowserContext()); 359 web_contents()->GetBrowserContext());
317 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 360 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
318 ->pingback_client() 361 ->pingback_client()
319 ->OptOutsSizeForTesting()); 362 ->OptOutsSizeForTesting());
320 } 363 }
321 } 364 }
322 365
323 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { 366 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) {
324 base::HistogramTester tester; 367 base::HistogramTester tester;
325 368
326 NavigateAndCommit(GURL(kTestUrl)); 369 NavigateAndCommit(GURL(kTestUrl));
327 370
328 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 371 ConfirmInfoBarDelegate* infobar =
329 previews::PreviewsType::LITE_PAGE, true /* is_data_saver_user */); 372 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(),
373 true /* is_data_saver_user */);
330 374
331 // Simulate clicking the infobar link. 375 // Simulate clicking the infobar link.
332 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 376 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
333 infobar_service()->infobar_at(0)->RemoveSelf(); 377 infobar_service()->infobar_at(0)->RemoveSelf();
334 EXPECT_EQ(0U, infobar_service()->infobar_count()); 378 EXPECT_EQ(0U, infobar_service()->infobar_count());
335 379
336 tester.ExpectBucketCount( 380 tester.ExpectBucketCount(
337 kUMAPreviewsInfoBarActionLitePage, 381 kUMAPreviewsInfoBarActionLitePage,
338 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 382 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
339 383
340 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 384 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
341 385
342 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, 386 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE,
343 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) 387 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
344 ->last_navigation_reload_type()); 388 ->last_navigation_reload_type());
345 389
346 auto* data_reduction_proxy_settings = 390 auto* data_reduction_proxy_settings =
347 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 391 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
348 web_contents()->GetBrowserContext()); 392 web_contents()->GetBrowserContext());
349 393
350 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 394 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
351 ->pingback_client() 395 ->pingback_client()
352 ->OptOutsSizeForTesting()); 396 ->OptOutsSizeForTesting());
353 } 397 }
354 398
355 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { 399 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) {
356 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 400 ConfirmInfoBarDelegate* infobar =
357 previews::PreviewsType::LOFI, true /* is_data_saver_user */); 401 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
402 true /* is_data_saver_user */);
358 403
359 // Simulate dismissing the infobar. 404 // Simulate dismissing the infobar.
360 infobar->InfoBarDismissed(); 405 infobar->InfoBarDismissed();
361 infobar_service()->infobar_at(0)->RemoveSelf(); 406 infobar_service()->infobar_at(0)->RemoveSelf();
362 EXPECT_EQ(0U, infobar_service()->infobar_count()); 407 EXPECT_EQ(0U, infobar_service()->infobar_count());
363 408
364 PreviewsInfoBarDelegate::Create( 409 PreviewsInfoBarDelegate::Create(
365 web_contents(), previews::PreviewsType::LOFI, 410 web_contents(), previews::PreviewsType::LOFI,
366 true /* is_data_saver_user */, 411 base::Time() /* previews_freshness */, true /* is_data_saver_user */,
367 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 412 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
368 413
369 // Infobar should not be shown again since a navigation hasn't happened. 414 // Infobar should not be shown again since a navigation hasn't happened.
370 EXPECT_EQ(0U, infobar_service()->infobar_count()); 415 EXPECT_EQ(0U, infobar_service()->infobar_count());
371 416
372 // Navigate and show infobar again. 417 // Navigate and show infobar again.
373 NavigateAndCommit(GURL(kTestUrl)); 418 NavigateAndCommit(GURL(kTestUrl));
374 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */); 419 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
420 true /* is_data_saver_user */);
375 } 421 }
376 422
377 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { 423 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) {
378 base::HistogramTester tester; 424 base::HistogramTester tester;
379 425
380 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 426 ConfirmInfoBarDelegate* infobar =
381 previews::PreviewsType::LOFI, true /* is_data_saver_user */); 427 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(),
428 true /* is_data_saver_user */);
382 429
383 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, 430 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi,
384 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 431 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
385 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 432 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
386 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 433 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
387 434
388 ASSERT_TRUE(infobar); 435 ASSERT_TRUE(infobar);
389 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 436 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
390 infobar->GetMessageText()); 437 infobar->GetMessageText());
391 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 438 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
392 infobar->GetLinkText()); 439 infobar->GetLinkText());
393 #if defined(OS_ANDROID) 440 #if defined(OS_ANDROID)
394 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 441 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
395 #else 442 #else
396 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 443 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
397 #endif 444 #endif
398 } 445 }
399 446
400 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { 447 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) {
401 base::HistogramTester tester; 448 base::HistogramTester tester;
402 449
403 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 450 PreviewsInfoBarDelegate* infobar =
404 previews::PreviewsType::LITE_PAGE, true /* is_data_saver_user */); 451 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(),
452 true /* is_data_saver_user */);
405 453
406 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, 454 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage,
407 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 455 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
408 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 456 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
409 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 457 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
410 458
411 // Check the strings. 459 // Check the strings.
412 ASSERT_TRUE(infobar); 460 ASSERT_TRUE(infobar);
413 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 461 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
414 infobar->GetMessageText()); 462 infobar->GetMessageText());
415 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 463 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
416 infobar->GetLinkText()); 464 infobar->GetLinkText());
465 ASSERT_EQ(base::string16(), infobar->GetTimestampText());
417 #if defined(OS_ANDROID) 466 #if defined(OS_ANDROID)
418 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 467 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
419 #else 468 #else
420 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 469 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
421 #endif 470 #endif
422 } 471 }
423 472
424 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) { 473 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) {
425 base::HistogramTester tester; 474 base::HistogramTester tester;
426 475
427 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 476 PreviewsInfoBarDelegate* infobar =
428 previews::PreviewsType::OFFLINE, false /* is_data_saver_user */); 477 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(),
478 false /* is_data_saver_user */);
429 479
430 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 480 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
431 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 481 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
432 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 482 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
433 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 483 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
434 484
435 // Check the strings. 485 // Check the strings.
436 ASSERT_TRUE(infobar); 486 ASSERT_TRUE(infobar);
437 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), 487 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE),
438 infobar->GetMessageText()); 488 infobar->GetMessageText());
439 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 489 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
440 infobar->GetLinkText()); 490 infobar->GetLinkText());
491 ASSERT_EQ(base::string16(), infobar->GetTimestampText());
441 #if defined(OS_ANDROID) 492 #if defined(OS_ANDROID)
442 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 493 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
443 #else 494 #else
444 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 495 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
445 #endif 496 #endif
446 } 497 }
447 498
448 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) { 499 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) {
449 base::HistogramTester tester; 500 base::HistogramTester tester;
450 501
451 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 502 PreviewsInfoBarDelegate* infobar =
452 previews::PreviewsType::OFFLINE, true /* is_data_saver_user */); 503 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(),
504 true /* is_data_saver_user */);
453 505
454 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 506 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
455 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 507 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
456 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 508 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
457 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 509 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
458 510
459 // Check the strings. 511 // Check the strings.
460 ASSERT_TRUE(infobar); 512 ASSERT_TRUE(infobar);
461 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 513 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
462 infobar->GetMessageText()); 514 infobar->GetMessageText());
463 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 515 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
464 infobar->GetLinkText()); 516 infobar->GetLinkText());
517 ASSERT_EQ(base::string16(), infobar->GetTimestampText());
465 #if defined(OS_ANDROID) 518 #if defined(OS_ANDROID)
466 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 519 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
467 #else 520 #else
468 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 521 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
469 #endif 522 #endif
470 } 523 }
471 524
472 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { 525 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) {
473 base::HistogramTester tester; 526 base::HistogramTester tester;
474 527
475 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) 528 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
476 ->set_should_have_page_id(false); 529 ->set_should_have_page_id(false);
477 530
478 NavigateAndCommit(GURL(kTestUrl)); 531 NavigateAndCommit(GURL(kTestUrl));
479 532
480 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 533 ConfirmInfoBarDelegate* infobar =
481 previews::PreviewsType::OFFLINE, true /* is_data_saver_user */); 534 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(),
535 true /* is_data_saver_user */);
482 536
483 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 537 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
484 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 538 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
485 539
486 // Simulate clicking the infobar link. 540 // Simulate clicking the infobar link.
487 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 541 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
488 infobar_service()->infobar_at(0)->RemoveSelf(); 542 infobar_service()->infobar_at(0)->RemoveSelf();
489 EXPECT_EQ(0U, infobar_service()->infobar_count()); 543 EXPECT_EQ(0U, infobar_service()->infobar_count());
490 544
491 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 545 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
492 546
493 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, 547 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE,
494 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) 548 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
495 ->last_navigation_reload_type()); 549 ->last_navigation_reload_type());
496 550
497 auto* data_reduction_proxy_settings = 551 auto* data_reduction_proxy_settings =
498 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 552 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
499 web_contents()->GetBrowserContext()); 553 web_contents()->GetBrowserContext());
500 554
501 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() 555 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
502 ->pingback_client() 556 ->pingback_client()
503 ->OptOutsSizeForTesting()); 557 ->OptOutsSizeForTesting());
504 } 558 }
505 559
506 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { 560 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) {
507 base::HistogramTester tester; 561 base::HistogramTester tester;
508 562
509 NavigateAndCommit(GURL(kTestUrl)); 563 NavigateAndCommit(GURL(kTestUrl));
510 564
511 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 565 ConfirmInfoBarDelegate* infobar =
512 previews::PreviewsType::LITE_PAGE, true /* is_data_saver_user */); 566 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(),
567 true /* is_data_saver_user */);
513 568
514 // Simulate clicking the infobar link. 569 // Simulate clicking the infobar link.
515 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 570 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
516 infobar_service()->infobar_at(0)->RemoveSelf(); 571 infobar_service()->infobar_at(0)->RemoveSelf();
517 EXPECT_EQ(0U, infobar_service()->infobar_count()); 572 EXPECT_EQ(0U, infobar_service()->infobar_count());
518 573
519 tester.ExpectBucketCount( 574 tester.ExpectBucketCount(
520 kUMAPreviewsInfoBarActionLitePage, 575 kUMAPreviewsInfoBarActionLitePage,
521 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 576 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
522 577
(...skipping 22 matching lines...) Expand all
545 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 600 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
546 ->pingback_client() 601 ->pingback_client()
547 ->OptOutsSizeForTesting()); 602 ->OptOutsSizeForTesting());
548 603
549 drp_test_context_->RunUntilIdle(); 604 drp_test_context_->RunUntilIdle();
550 605
551 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() 606 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
552 ->pingback_client() 607 ->pingback_client()
553 ->OptOutsSizeForTesting()); 608 ->OptOutsSizeForTesting());
554 } 609 }
610
611 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampMintuesTest) {
612 EnableStalePreviewsTimestamp();
613
614 int staleness_in_minutes = 5;
615
616 PreviewsInfoBarDelegate* infobar = CreateInfoBar(
617 previews::PreviewsType::LITE_PAGE,
618 base::Time::Now() - base::TimeDelta::FromMinutes(staleness_in_minutes),
619 true /* is_data_saver_user */);
620
621 ASSERT_EQ(
622 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES,
623 base::IntToString16(staleness_in_minutes)),
624 infobar->GetTimestampText());
625 }
626
627 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHourTest) {
628 EnableStalePreviewsTimestamp();
629
630 int staleness_in_minutes = 65;
631
632 PreviewsInfoBarDelegate* infobar = CreateInfoBar(
633 previews::PreviewsType::LITE_PAGE,
634 base::Time::Now() - base::TimeDelta::FromMinutes(staleness_in_minutes),
635 true /* is_data_saver_user */);
636
637 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR),
638 infobar->GetTimestampText());
639 }
640
641 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHoursTest) {
642 EnableStalePreviewsTimestamp();
643
644 int staleness_in_hours = 2;
645
646 PreviewsInfoBarDelegate* infobar = CreateInfoBar(
647 previews::PreviewsType::LITE_PAGE,
648 base::Time::Now() - base::TimeDelta::FromHours(staleness_in_hours),
649 true /* is_data_saver_user */);
650
651 ASSERT_EQ(l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS,
652 base::IntToString16(staleness_in_hours)),
653 infobar->GetTimestampText());
654 }
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_delegate.cc ('k') | chrome/browser/previews/previews_infobar_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698