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 "chrome/browser/previews/previews_infobar_delegate.h" | 5 #include "chrome/browser/previews/previews_infobar_delegate.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 void TearDown() override { | 166 void TearDown() override { |
167 drp_test_context_->DestroySettings(); | 167 drp_test_context_->DestroySettings(); |
168 ChromeRenderViewHostTestHarness::TearDown(); | 168 ChromeRenderViewHostTestHarness::TearDown(); |
169 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); | 169 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
170 } | 170 } |
171 | 171 |
172 PreviewsInfoBarDelegate* CreateInfoBar(previews::PreviewsType type, | 172 PreviewsInfoBarDelegate* CreateInfoBar(previews::PreviewsType type, |
173 base::Time previews_freshness, | 173 base::Time previews_freshness, |
174 bool is_data_saver_user) { | 174 bool is_data_saver_user, |
| 175 bool is_reload) { |
175 PreviewsInfoBarDelegate::Create( | 176 PreviewsInfoBarDelegate::Create( |
176 web_contents(), type, previews_freshness, is_data_saver_user, | 177 web_contents(), type, previews_freshness, is_data_saver_user, is_reload, |
177 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar, | 178 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar, |
178 base::Unretained(this))); | 179 base::Unretained(this))); |
179 | 180 |
180 InfoBarService* infobar_service = | 181 InfoBarService* infobar_service = |
181 InfoBarService::FromWebContents(web_contents()); | 182 InfoBarService::FromWebContents(web_contents()); |
182 EXPECT_EQ(1U, infobar_service->infobar_count()); | 183 EXPECT_EQ(1U, infobar_service->infobar_count()); |
183 | 184 |
184 return static_cast<PreviewsInfoBarDelegate*>( | 185 return static_cast<PreviewsInfoBarDelegate*>( |
185 infobar_service->infobar_at(0)->delegate()); | 186 infobar_service->infobar_at(0)->delegate()); |
186 } | 187 } |
(...skipping 13 matching lines...) Expand all Loading... |
200 | 201 |
201 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 202 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
202 feature_list->RegisterFieldTrialOverride( | 203 feature_list->RegisterFieldTrialOverride( |
203 previews::features::kStalePreviewsTimestamp.name, | 204 previews::features::kStalePreviewsTimestamp.name, |
204 base::FeatureList::OVERRIDE_ENABLE_FEATURE, field_trial); | 205 base::FeatureList::OVERRIDE_ENABLE_FEATURE, field_trial); |
205 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); | 206 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); |
206 } | 207 } |
207 | 208 |
208 void TestStalePreviews( | 209 void TestStalePreviews( |
209 int staleness_in_minutes, | 210 int staleness_in_minutes, |
| 211 bool is_reload, |
210 base::string16 expected_timestamp, | 212 base::string16 expected_timestamp, |
211 PreviewsInfoBarDelegate::PreviewsInfoBarTimestamp expected_bucket) { | 213 PreviewsInfoBarDelegate::PreviewsInfoBarTimestamp expected_bucket) { |
212 PreviewsInfoBarDelegate* infobar = CreateInfoBar( | 214 PreviewsInfoBarDelegate* infobar = CreateInfoBar( |
213 previews::PreviewsType::LITE_PAGE, | 215 previews::PreviewsType::LITE_PAGE, |
214 base::Time::Now() - base::TimeDelta::FromMinutes(staleness_in_minutes), | 216 base::Time::Now() - base::TimeDelta::FromMinutes(staleness_in_minutes), |
215 true /* is_data_saver_user */); | 217 true /* is_data_saver_user */, is_reload); |
216 EXPECT_EQ(expected_timestamp, infobar->GetTimestampText()); | 218 EXPECT_EQ(expected_timestamp, infobar->GetTimestampText()); |
217 tester_->ExpectBucketCount(kUMAPreviewsInfoBarTimestamp, expected_bucket, | 219 tester_->ExpectBucketCount(kUMAPreviewsInfoBarTimestamp, expected_bucket, |
218 1); | 220 1); |
219 // Dismiss the infobar. | 221 // Dismiss the infobar. |
220 InfoBarService::FromWebContents(web_contents())->RemoveAllInfoBars(false); | 222 InfoBarService::FromWebContents(web_contents())->RemoveAllInfoBars(false); |
221 PreviewsInfoBarTabHelper::FromWebContents(web_contents()) | 223 PreviewsInfoBarTabHelper::FromWebContents(web_contents()) |
222 ->set_displayed_preview_infobar(false); | 224 ->set_displayed_preview_infobar(false); |
223 } | 225 } |
224 | 226 |
225 void OnDismissPreviewsInfobar(bool user_opt_out) { | 227 void OnDismissPreviewsInfobar(bool user_opt_out) { |
226 user_opt_out_ = user_opt_out; | 228 user_opt_out_ = user_opt_out; |
227 } | 229 } |
228 | 230 |
229 InfoBarService* infobar_service() { | 231 InfoBarService* infobar_service() { |
230 return InfoBarService::FromWebContents(web_contents()); | 232 return InfoBarService::FromWebContents(web_contents()); |
231 } | 233 } |
232 | 234 |
233 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> | 235 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> |
234 drp_test_context_; | 236 drp_test_context_; |
235 | 237 |
236 base::Optional<bool> user_opt_out_; | 238 base::Optional<bool> user_opt_out_; |
237 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 239 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
238 base::test::ScopedFeatureList scoped_feature_list_; | 240 base::test::ScopedFeatureList scoped_feature_list_; |
239 std::unique_ptr<base::HistogramTester> tester_; | 241 std::unique_ptr<base::HistogramTester> tester_; |
240 }; | 242 }; |
241 | 243 |
242 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { | 244 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { |
243 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 245 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
244 true /* is_data_saver_user */); | 246 true /* is_data_saver_user */, false /* is_reload */); |
245 | 247 |
246 // Try showing a second infobar. Another should not be shown since the page | 248 // Try showing a second infobar. Another should not be shown since the page |
247 // has not navigated. | 249 // has not navigated. |
248 PreviewsInfoBarDelegate::Create( | 250 PreviewsInfoBarDelegate::Create( |
249 web_contents(), previews::PreviewsType::LOFI, | 251 web_contents(), previews::PreviewsType::LOFI, |
250 base::Time() /* previews_freshness */, true /* is_data_saver_user */, | 252 base::Time() /* previews_freshness */, true /* is_data_saver_user */, |
| 253 false /* is_reload */, |
251 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 254 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
252 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 255 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
253 | 256 |
254 // Navigate and make sure the infobar is dismissed. | 257 // Navigate and make sure the infobar is dismissed. |
255 NavigateAndCommit(GURL(kTestUrl)); | 258 NavigateAndCommit(GURL(kTestUrl)); |
256 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 259 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
257 EXPECT_FALSE(user_opt_out_.value()); | 260 EXPECT_FALSE(user_opt_out_.value()); |
258 | 261 |
259 tester_->ExpectBucketCount( | 262 tester_->ExpectBucketCount( |
260 kUMAPreviewsInfoBarActionLoFi, | 263 kUMAPreviewsInfoBarActionLoFi, |
261 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); | 264 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); |
262 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 265 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
263 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 266 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
264 } | 267 } |
265 | 268 |
266 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { | 269 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { |
267 // Navigate to test URL, so we can reload later. | 270 // Navigate to test URL, so we can reload later. |
268 NavigateAndCommit(GURL(kTestUrl)); | 271 NavigateAndCommit(GURL(kTestUrl)); |
269 | 272 |
270 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 273 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
271 true /* is_data_saver_user */); | 274 true /* is_data_saver_user */, false /* is_reload */); |
272 | 275 |
273 // Try showing a second infobar. Another should not be shown since the page | 276 // Try showing a second infobar. Another should not be shown since the page |
274 // has not navigated. | 277 // has not navigated. |
275 PreviewsInfoBarDelegate::Create( | 278 PreviewsInfoBarDelegate::Create( |
276 web_contents(), previews::PreviewsType::LOFI, | 279 web_contents(), previews::PreviewsType::LOFI, |
277 base::Time() /* previews_freshness */, true /* is_data_saver_user */, | 280 base::Time() /* previews_freshness */, true /* is_data_saver_user */, |
| 281 false /* is_reload */, |
278 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 282 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
279 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 283 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
280 | 284 |
281 // Navigate to test URL as a reload to dismiss the infobar. | 285 // Navigate to test URL as a reload to dismiss the infobar. |
282 controller().LoadURL(GURL(kTestUrl), content::Referrer(), | 286 controller().LoadURL(GURL(kTestUrl), content::Referrer(), |
283 ui::PAGE_TRANSITION_RELOAD, std::string()); | 287 ui::PAGE_TRANSITION_RELOAD, std::string()); |
284 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 288 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
285 | 289 |
286 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 290 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
287 EXPECT_FALSE(user_opt_out_.value()); | 291 EXPECT_FALSE(user_opt_out_.value()); |
288 | 292 |
289 tester_->ExpectBucketCount( | 293 tester_->ExpectBucketCount( |
290 kUMAPreviewsInfoBarActionLoFi, | 294 kUMAPreviewsInfoBarActionLoFi, |
291 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, 1); | 295 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, 1); |
292 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 296 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
293 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 297 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
294 | 298 |
295 auto* data_reduction_proxy_settings = | 299 auto* data_reduction_proxy_settings = |
296 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 300 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
297 web_contents()->GetBrowserContext()); | 301 web_contents()->GetBrowserContext()); |
298 | 302 |
299 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 303 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
300 ->pingback_client() | 304 ->pingback_client() |
301 ->OptOutsSizeForTesting()); | 305 ->OptOutsSizeForTesting()); |
302 } | 306 } |
303 | 307 |
304 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { | 308 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { |
305 ConfirmInfoBarDelegate* infobar = | 309 ConfirmInfoBarDelegate* infobar = |
306 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 310 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
307 true /* is_data_saver_user */); | 311 true /* is_data_saver_user */, false /* is_reload */); |
308 | 312 |
309 // Simulate dismissing the infobar. | 313 // Simulate dismissing the infobar. |
310 infobar->InfoBarDismissed(); | 314 infobar->InfoBarDismissed(); |
311 infobar_service()->infobar_at(0)->RemoveSelf(); | 315 infobar_service()->infobar_at(0)->RemoveSelf(); |
312 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 316 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
313 | 317 |
314 tester_->ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, | 318 tester_->ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, |
315 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, | 319 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, |
316 1); | 320 1); |
317 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 321 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
318 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 322 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
319 EXPECT_FALSE(user_opt_out_.value()); | 323 EXPECT_FALSE(user_opt_out_.value()); |
320 } | 324 } |
321 | 325 |
322 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) { | 326 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) { |
323 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 327 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
324 true /* is_data_saver_user */); | 328 true /* is_data_saver_user */, false /* is_reload */); |
325 | 329 |
326 // Delete the infobar without any other infobar actions. | 330 // Delete the infobar without any other infobar actions. |
327 infobar_service()->infobar_at(0)->RemoveSelf(); | 331 infobar_service()->infobar_at(0)->RemoveSelf(); |
328 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 332 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
329 | 333 |
330 tester_->ExpectBucketCount( | 334 tester_->ExpectBucketCount( |
331 kUMAPreviewsInfoBarActionLoFi, | 335 kUMAPreviewsInfoBarActionLoFi, |
332 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); | 336 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); |
333 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 337 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
334 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 338 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
(...skipping 16 matching lines...) Expand all Loading... |
351 base::FieldTrialList::CreateFieldTrial( | 355 base::FieldTrialList::CreateFieldTrial( |
352 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); | 356 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); |
353 } | 357 } |
354 | 358 |
355 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. | 359 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. |
356 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); | 360 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); |
357 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 361 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
358 | 362 |
359 ConfirmInfoBarDelegate* infobar = | 363 ConfirmInfoBarDelegate* infobar = |
360 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 364 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
361 true /* is_data_saver_user */); | 365 true /* is_data_saver_user */, false /* is_reload */); |
362 | 366 |
363 // Simulate clicking the infobar link. | 367 // Simulate clicking the infobar link. |
364 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 368 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
365 infobar_service()->infobar_at(0)->RemoveSelf(); | 369 infobar_service()->infobar_at(0)->RemoveSelf(); |
366 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 370 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
367 | 371 |
368 tester_->ExpectBucketCount( | 372 tester_->ExpectBucketCount( |
369 kUMAPreviewsInfoBarActionLoFi, | 373 kUMAPreviewsInfoBarActionLoFi, |
370 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 374 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
371 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, | 375 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, |
372 drp_test_context_->pref_service()->GetInteger( | 376 drp_test_context_->pref_service()->GetInteger( |
373 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 377 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
374 EXPECT_TRUE(user_opt_out_.value()); | 378 EXPECT_TRUE(user_opt_out_.value()); |
375 | 379 |
376 auto* data_reduction_proxy_settings = | 380 auto* data_reduction_proxy_settings = |
377 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 381 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
378 web_contents()->GetBrowserContext()); | 382 web_contents()->GetBrowserContext()); |
379 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 383 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
380 ->pingback_client() | 384 ->pingback_client() |
381 ->OptOutsSizeForTesting()); | 385 ->OptOutsSizeForTesting()); |
382 } | 386 } |
383 } | 387 } |
384 | 388 |
385 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { | 389 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { |
386 NavigateAndCommit(GURL(kTestUrl)); | 390 NavigateAndCommit(GURL(kTestUrl)); |
387 | 391 |
388 ConfirmInfoBarDelegate* infobar = | 392 ConfirmInfoBarDelegate* infobar = |
389 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 393 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
390 true /* is_data_saver_user */); | 394 true /* is_data_saver_user */, false /* is_reload */); |
391 | 395 |
392 // Simulate clicking the infobar link. | 396 // Simulate clicking the infobar link. |
393 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 397 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
394 infobar_service()->infobar_at(0)->RemoveSelf(); | 398 infobar_service()->infobar_at(0)->RemoveSelf(); |
395 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 399 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
396 | 400 |
397 tester_->ExpectBucketCount( | 401 tester_->ExpectBucketCount( |
398 kUMAPreviewsInfoBarActionLitePage, | 402 kUMAPreviewsInfoBarActionLitePage, |
399 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 403 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
400 | 404 |
401 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 405 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
402 | 406 |
403 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 407 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
404 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 408 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
405 ->last_navigation_reload_type()); | 409 ->last_navigation_reload_type()); |
406 | 410 |
407 auto* data_reduction_proxy_settings = | 411 auto* data_reduction_proxy_settings = |
408 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 412 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
409 web_contents()->GetBrowserContext()); | 413 web_contents()->GetBrowserContext()); |
410 | 414 |
411 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 415 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
412 ->pingback_client() | 416 ->pingback_client() |
413 ->OptOutsSizeForTesting()); | 417 ->OptOutsSizeForTesting()); |
414 } | 418 } |
415 | 419 |
416 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { | 420 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { |
417 ConfirmInfoBarDelegate* infobar = | 421 ConfirmInfoBarDelegate* infobar = |
418 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 422 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
419 true /* is_data_saver_user */); | 423 true /* is_data_saver_user */, false /* is_reload */); |
420 | 424 |
421 // Simulate dismissing the infobar. | 425 // Simulate dismissing the infobar. |
422 infobar->InfoBarDismissed(); | 426 infobar->InfoBarDismissed(); |
423 infobar_service()->infobar_at(0)->RemoveSelf(); | 427 infobar_service()->infobar_at(0)->RemoveSelf(); |
424 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 428 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
425 | 429 |
426 PreviewsInfoBarDelegate::Create( | 430 PreviewsInfoBarDelegate::Create( |
427 web_contents(), previews::PreviewsType::LOFI, | 431 web_contents(), previews::PreviewsType::LOFI, |
428 base::Time() /* previews_freshness */, true /* is_data_saver_user */, | 432 base::Time() /* previews_freshness */, true /* is_data_saver_user */, |
| 433 false /* is_reload */, |
429 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 434 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
430 | 435 |
431 // Infobar should not be shown again since a navigation hasn't happened. | 436 // Infobar should not be shown again since a navigation hasn't happened. |
432 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 437 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
433 | 438 |
434 // Navigate and show infobar again. | 439 // Navigate and show infobar again. |
435 NavigateAndCommit(GURL(kTestUrl)); | 440 NavigateAndCommit(GURL(kTestUrl)); |
436 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 441 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
437 true /* is_data_saver_user */); | 442 true /* is_data_saver_user */, false /* is_reload */); |
438 } | 443 } |
439 | 444 |
440 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { | 445 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { |
441 ConfirmInfoBarDelegate* infobar = | 446 ConfirmInfoBarDelegate* infobar = |
442 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 447 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
443 true /* is_data_saver_user */); | 448 true /* is_data_saver_user */, false /* is_reload */); |
444 | 449 |
445 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, | 450 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, |
446 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 451 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
447 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( | 452 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( |
448 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 453 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
449 | 454 |
450 ASSERT_TRUE(infobar); | 455 ASSERT_TRUE(infobar); |
451 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 456 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
452 infobar->GetMessageText()); | 457 infobar->GetMessageText()); |
453 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 458 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
454 infobar->GetLinkText()); | 459 infobar->GetLinkText()); |
455 #if defined(OS_ANDROID) | 460 #if defined(OS_ANDROID) |
456 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 461 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
457 #else | 462 #else |
458 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 463 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
459 #endif | 464 #endif |
460 } | 465 } |
461 | 466 |
462 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { | 467 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { |
463 PreviewsInfoBarDelegate* infobar = | 468 PreviewsInfoBarDelegate* infobar = |
464 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 469 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
465 true /* is_data_saver_user */); | 470 true /* is_data_saver_user */, false /* is_reload */); |
466 | 471 |
467 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, | 472 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, |
468 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 473 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
469 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( | 474 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( |
470 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 475 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
471 | 476 |
472 // Check the strings. | 477 // Check the strings. |
473 ASSERT_TRUE(infobar); | 478 ASSERT_TRUE(infobar); |
474 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 479 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
475 infobar->GetMessageText()); | 480 infobar->GetMessageText()); |
476 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 481 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
477 infobar->GetLinkText()); | 482 infobar->GetLinkText()); |
478 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); | 483 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); |
479 #if defined(OS_ANDROID) | 484 #if defined(OS_ANDROID) |
480 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 485 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
481 #else | 486 #else |
482 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 487 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
483 #endif | 488 #endif |
484 } | 489 } |
485 | 490 |
486 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) { | 491 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) { |
487 PreviewsInfoBarDelegate* infobar = | 492 PreviewsInfoBarDelegate* infobar = |
488 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 493 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
489 false /* is_data_saver_user */); | 494 false /* is_data_saver_user */, false /* is_reload */); |
490 | 495 |
491 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 496 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
492 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 497 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
493 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 498 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
494 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 499 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
495 | 500 |
496 // Check the strings. | 501 // Check the strings. |
497 ASSERT_TRUE(infobar); | 502 ASSERT_TRUE(infobar); |
498 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), | 503 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), |
499 infobar->GetMessageText()); | 504 infobar->GetMessageText()); |
500 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 505 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
501 infobar->GetLinkText()); | 506 infobar->GetLinkText()); |
502 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); | 507 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); |
503 #if defined(OS_ANDROID) | 508 #if defined(OS_ANDROID) |
504 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 509 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
505 #else | 510 #else |
506 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 511 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
507 #endif | 512 #endif |
508 } | 513 } |
509 | 514 |
510 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) { | 515 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) { |
511 PreviewsInfoBarDelegate* infobar = | 516 PreviewsInfoBarDelegate* infobar = |
512 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 517 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
513 true /* is_data_saver_user */); | 518 true /* is_data_saver_user */, false /* is_reload */); |
514 | 519 |
515 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 520 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
516 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 521 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
517 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 522 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
518 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 523 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
519 | 524 |
520 // Check the strings. | 525 // Check the strings. |
521 ASSERT_TRUE(infobar); | 526 ASSERT_TRUE(infobar); |
522 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 527 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
523 infobar->GetMessageText()); | 528 infobar->GetMessageText()); |
524 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 529 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
525 infobar->GetLinkText()); | 530 infobar->GetLinkText()); |
526 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); | 531 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); |
527 #if defined(OS_ANDROID) | 532 #if defined(OS_ANDROID) |
528 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 533 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
529 #else | 534 #else |
530 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 535 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
531 #endif | 536 #endif |
532 } | 537 } |
533 | 538 |
534 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { | 539 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { |
535 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 540 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
536 ->set_should_have_page_id(false); | 541 ->set_should_have_page_id(false); |
537 | 542 |
538 NavigateAndCommit(GURL(kTestUrl)); | 543 NavigateAndCommit(GURL(kTestUrl)); |
539 | 544 |
540 ConfirmInfoBarDelegate* infobar = | 545 ConfirmInfoBarDelegate* infobar = |
541 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 546 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
542 true /* is_data_saver_user */); | 547 true /* is_data_saver_user */, false /* is_reload */); |
543 | 548 |
544 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 549 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
545 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 550 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
546 | 551 |
547 // Simulate clicking the infobar link. | 552 // Simulate clicking the infobar link. |
548 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 553 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
549 infobar_service()->infobar_at(0)->RemoveSelf(); | 554 infobar_service()->infobar_at(0)->RemoveSelf(); |
550 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 555 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
551 | 556 |
552 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 557 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
553 | 558 |
554 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 559 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
555 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 560 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
556 ->last_navigation_reload_type()); | 561 ->last_navigation_reload_type()); |
557 | 562 |
558 auto* data_reduction_proxy_settings = | 563 auto* data_reduction_proxy_settings = |
559 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 564 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
560 web_contents()->GetBrowserContext()); | 565 web_contents()->GetBrowserContext()); |
561 | 566 |
562 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 567 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
563 ->pingback_client() | 568 ->pingback_client() |
564 ->OptOutsSizeForTesting()); | 569 ->OptOutsSizeForTesting()); |
565 } | 570 } |
566 | 571 |
567 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { | 572 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { |
568 NavigateAndCommit(GURL(kTestUrl)); | 573 NavigateAndCommit(GURL(kTestUrl)); |
569 | 574 |
570 ConfirmInfoBarDelegate* infobar = | 575 ConfirmInfoBarDelegate* infobar = |
571 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 576 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
572 true /* is_data_saver_user */); | 577 true /* is_data_saver_user */, false /* is_reload */); |
573 | 578 |
574 // Simulate clicking the infobar link. | 579 // Simulate clicking the infobar link. |
575 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 580 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
576 infobar_service()->infobar_at(0)->RemoveSelf(); | 581 infobar_service()->infobar_at(0)->RemoveSelf(); |
577 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 582 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
578 | 583 |
579 tester_->ExpectBucketCount( | 584 tester_->ExpectBucketCount( |
580 kUMAPreviewsInfoBarActionLitePage, | 585 kUMAPreviewsInfoBarActionLitePage, |
581 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 586 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
582 | 587 |
(...skipping 30 matching lines...) Expand all Loading... |
613 ->OptOutsSizeForTesting()); | 618 ->OptOutsSizeForTesting()); |
614 } | 619 } |
615 | 620 |
616 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampMinutesTest) { | 621 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampMinutesTest) { |
617 // Use default params. | 622 // Use default params. |
618 std::map<std::string, std::string> variation_params; | 623 std::map<std::string, std::string> variation_params; |
619 EnableStalePreviewsTimestamp(variation_params); | 624 EnableStalePreviewsTimestamp(variation_params); |
620 int staleness_in_minutes = 5; | 625 int staleness_in_minutes = 5; |
621 | 626 |
622 TestStalePreviews( | 627 TestStalePreviews( |
623 staleness_in_minutes, | 628 staleness_in_minutes, false /* is_reload */, |
624 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, | 629 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, |
625 base::IntToString16(staleness_in_minutes)), | 630 base::IntToString16(staleness_in_minutes)), |
626 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); | 631 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
627 } | 632 } |
628 | 633 |
629 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHourTest) { | 634 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHourTest) { |
630 // Use default variation_params. | 635 // Use default variation_params. |
631 std::map<std::string, std::string> variation_params; | 636 std::map<std::string, std::string> variation_params; |
632 EnableStalePreviewsTimestamp(variation_params); | 637 EnableStalePreviewsTimestamp(variation_params); |
633 int staleness_in_minutes = 65; | 638 int staleness_in_minutes = 65; |
634 | 639 |
635 TestStalePreviews( | 640 TestStalePreviews( |
636 staleness_in_minutes, | 641 staleness_in_minutes, false /* is_reload */, |
637 l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR), | 642 l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR), |
638 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); | 643 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
639 } | 644 } |
640 | 645 |
641 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHoursTest) { | 646 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHoursTest) { |
642 // Use default variation_params. | 647 // Use default variation_params. |
643 std::map<std::string, std::string> variation_params; | 648 std::map<std::string, std::string> variation_params; |
644 EnableStalePreviewsTimestamp(variation_params); | 649 EnableStalePreviewsTimestamp(variation_params); |
645 int staleness_in_hours = 2; | 650 int staleness_in_hours = 2; |
646 | 651 |
647 TestStalePreviews( | 652 TestStalePreviews( |
648 staleness_in_hours * 60, | 653 staleness_in_hours * 60, false /* is_reload */, |
649 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, | 654 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, |
650 base::IntToString16(staleness_in_hours)), | 655 base::IntToString16(staleness_in_hours)), |
651 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); | 656 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
652 } | 657 } |
653 | 658 |
654 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampFinchParamsUMA) { | 659 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampFinchParamsUMA) { |
655 std::map<std::string, std::string> variation_params; | 660 std::map<std::string, std::string> variation_params; |
656 variation_params["min_staleness_in_minutes"] = "1"; | 661 variation_params["min_staleness_in_minutes"] = "1"; |
657 variation_params["max_staleness_in_minutes"] = "5"; | 662 variation_params["max_staleness_in_minutes"] = "5"; |
658 EnableStalePreviewsTimestamp(variation_params); | 663 EnableStalePreviewsTimestamp(variation_params); |
659 | 664 |
660 TestStalePreviews( | 665 TestStalePreviews( |
661 1, | 666 1, false /* is_reload */, |
662 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, | 667 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, |
663 base::IntToString16(1)), | 668 base::IntToString16(1)), |
664 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); | 669 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
665 | 670 |
666 TestStalePreviews( | 671 TestStalePreviews( |
667 6, base::string16(), | 672 6, false /* is_reload */, base::string16(), |
668 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); | 673 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); |
669 } | 674 } |
670 | 675 |
671 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampUMA) { | 676 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampUMA) { |
672 // Use default params. | 677 // Use default params. |
673 std::map<std::string, std::string> variation_params; | 678 std::map<std::string, std::string> variation_params; |
674 EnableStalePreviewsTimestamp(variation_params); | 679 EnableStalePreviewsTimestamp(variation_params); |
675 | 680 |
676 TestStalePreviews( | 681 TestStalePreviews( |
677 1, base::string16(), | 682 1, false /* is_reload */, base::string16(), |
678 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_PREVIEW_NOT_STALE); | 683 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_PREVIEW_NOT_STALE); |
679 TestStalePreviews( | 684 TestStalePreviews( |
680 -1, base::string16(), | 685 -1, false /* is_reload */, base::string16(), |
681 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_NEGATIVE); | 686 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_NEGATIVE); |
682 TestStalePreviews( | 687 TestStalePreviews( |
683 1441, base::string16(), | 688 1441, false /* is_reload */, base::string16(), |
684 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); | 689 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); |
685 } | 690 } |
| 691 |
| 692 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampReloadTest) { |
| 693 // Use default params. |
| 694 std::map<std::string, std::string> variation_params; |
| 695 EnableStalePreviewsTimestamp(variation_params); |
| 696 int staleness_in_minutes = 5; |
| 697 |
| 698 TestStalePreviews( |
| 699 staleness_in_minutes, false /* is_reload */, |
| 700 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, |
| 701 base::IntToString16(staleness_in_minutes)), |
| 702 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
| 703 |
| 704 staleness_in_minutes = 1; |
| 705 TestStalePreviews( |
| 706 staleness_in_minutes, true /* is_reload */, |
| 707 l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_UPDATED_NOW), |
| 708 PreviewsInfoBarDelegate::TIMESTAMP_UPDATED_NOW_SHOWN); |
| 709 } |
OLD | NEW |