| 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 <memory> | 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
| 13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/field_trial_param_associator.h" |
| 15 #include "base/metrics/field_trial_params.h" | 17 #include "base/metrics/field_trial_params.h" |
| 16 #include "base/optional.h" | 18 #include "base/optional.h" |
| 19 #include "base/strings/string16.h" |
| 17 #include "base/test/histogram_tester.h" | 20 #include "base/test/histogram_tester.h" |
| 18 #include "base/test/scoped_feature_list.h" | 21 #include "base/test/scoped_feature_list.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 21 #include "chrome/browser/android/android_theme_resources.h" | 24 #include "chrome/browser/android/android_theme_resources.h" |
| 22 #include "chrome/browser/infobars/infobar_service.h" | 25 #include "chrome/browser/infobars/infobar_service.h" |
| 23 #include "chrome/browser/loader/chrome_navigation_data.h" | 26 #include "chrome/browser/loader/chrome_navigation_data.h" |
| 24 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 27 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 25 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 28 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 26 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 29 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; | 67 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
| 65 | 68 |
| 66 // Key of the UMA Previews.InfoBarAction.Offline histogram. | 69 // Key of the UMA Previews.InfoBarAction.Offline histogram. |
| 67 const char kUMAPreviewsInfoBarActionOffline[] = | 70 const char kUMAPreviewsInfoBarActionOffline[] = |
| 68 "Previews.InfoBarAction.Offline"; | 71 "Previews.InfoBarAction.Offline"; |
| 69 | 72 |
| 70 // Key of the UMA Previews.InfoBarAction.LitePage histogram. | 73 // Key of the UMA Previews.InfoBarAction.LitePage histogram. |
| 71 const char kUMAPreviewsInfoBarActionLitePage[] = | 74 const char kUMAPreviewsInfoBarActionLitePage[] = |
| 72 "Previews.InfoBarAction.LitePage"; | 75 "Previews.InfoBarAction.LitePage"; |
| 73 | 76 |
| 77 // Key of the UMA Previews.InfoBarTimestamp histogram. |
| 78 const char kUMAPreviewsInfoBarTimestamp[] = "Previews.InfoBarTimestamp"; |
| 79 |
| 74 class TestPreviewsWebContentsObserver | 80 class TestPreviewsWebContentsObserver |
| 75 : public content::WebContentsObserver, | 81 : public content::WebContentsObserver, |
| 76 public content::WebContentsUserData<TestPreviewsWebContentsObserver> { | 82 public content::WebContentsUserData<TestPreviewsWebContentsObserver> { |
| 77 public: | 83 public: |
| 78 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents) | 84 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents) |
| 79 : content::WebContentsObserver(web_contents), | 85 : content::WebContentsObserver(web_contents), |
| 80 last_navigation_reload_type_(content::ReloadType::NONE), | 86 last_navigation_reload_type_(content::ReloadType::NONE), |
| 81 should_have_page_id_(true) {} | 87 should_have_page_id_(true) {} |
| 82 ~TestPreviewsWebContentsObserver() override {} | 88 ~TestPreviewsWebContentsObserver() override {} |
| 83 | 89 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 113 bool should_have_page_id_; | 119 bool should_have_page_id_; |
| 114 }; | 120 }; |
| 115 | 121 |
| 116 } // namespace | 122 } // namespace |
| 117 | 123 |
| 118 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver); | 124 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver); |
| 119 | 125 |
| 120 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness { | 126 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness { |
| 121 protected: | 127 protected: |
| 122 PreviewsInfoBarDelegateUnitTest() | 128 PreviewsInfoBarDelegateUnitTest() |
| 123 : field_trial_list_(new base::FieldTrialList(nullptr)) {} | 129 : field_trial_list_(new base::FieldTrialList(nullptr)), |
| 130 tester_(new base::HistogramTester()) {} |
| 124 | 131 |
| 125 void SetUp() override { | 132 void SetUp() override { |
| 126 ChromeRenderViewHostTestHarness::SetUp(); | 133 ChromeRenderViewHostTestHarness::SetUp(); |
| 127 InfoBarService::CreateForWebContents(web_contents()); | 134 InfoBarService::CreateForWebContents(web_contents()); |
| 128 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); | 135 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); |
| 129 TestPreviewsWebContentsObserver::CreateForWebContents(web_contents()); | 136 TestPreviewsWebContentsObserver::CreateForWebContents(web_contents()); |
| 130 | 137 |
| 131 drp_test_context_ = | 138 drp_test_context_ = |
| 132 data_reduction_proxy::DataReductionProxyTestContext::Builder() | 139 data_reduction_proxy::DataReductionProxyTestContext::Builder() |
| 133 .WithMockConfig() | 140 .WithMockConfig() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 base::Unretained(this))); | 178 base::Unretained(this))); |
| 172 | 179 |
| 173 InfoBarService* infobar_service = | 180 InfoBarService* infobar_service = |
| 174 InfoBarService::FromWebContents(web_contents()); | 181 InfoBarService::FromWebContents(web_contents()); |
| 175 EXPECT_EQ(1U, infobar_service->infobar_count()); | 182 EXPECT_EQ(1U, infobar_service->infobar_count()); |
| 176 | 183 |
| 177 return static_cast<PreviewsInfoBarDelegate*>( | 184 return static_cast<PreviewsInfoBarDelegate*>( |
| 178 infobar_service->infobar_at(0)->delegate()); | 185 infobar_service->infobar_at(0)->delegate()); |
| 179 } | 186 } |
| 180 | 187 |
| 181 void EnableStalePreviewsTimestamp() { | 188 void EnableStalePreviewsTimestamp( |
| 189 const std::map<std::string, std::string>& variation_params) { |
| 190 field_trial_list_.reset(); |
| 191 field_trial_list_.reset(new base::FieldTrialList(nullptr)); |
| 192 base::FieldTrialParamAssociator::GetInstance()->ClearAllParamsForTesting(); |
| 193 |
| 182 const std::string kTrialName = "TrialName"; | 194 const std::string kTrialName = "TrialName"; |
| 183 const std::string kGroupName = "GroupName"; | 195 const std::string kGroupName = "GroupName"; |
| 184 | 196 |
| 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); | 197 base::AssociateFieldTrialParams(kTrialName, kGroupName, variation_params); |
| 190 base::FieldTrial* field_trial = | 198 base::FieldTrial* field_trial = |
| 191 base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName); | 199 base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName); |
| 192 | 200 |
| 193 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 201 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 194 feature_list->RegisterFieldTrialOverride( | 202 feature_list->RegisterFieldTrialOverride( |
| 195 previews::features::kStalePreviewsTimestamp.name, | 203 previews::features::kStalePreviewsTimestamp.name, |
| 196 base::FeatureList::OVERRIDE_ENABLE_FEATURE, field_trial); | 204 base::FeatureList::OVERRIDE_ENABLE_FEATURE, field_trial); |
| 197 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); | 205 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); |
| 198 } | 206 } |
| 199 | 207 |
| 208 void TestStalePreviews( |
| 209 int staleness_in_minutes, |
| 210 base::string16 expected_timestamp, |
| 211 PreviewsInfoBarDelegate::PreviewsInfoBarTimestamp expected_bucket) { |
| 212 PreviewsInfoBarDelegate* infobar = CreateInfoBar( |
| 213 previews::PreviewsType::LITE_PAGE, |
| 214 base::Time::Now() - base::TimeDelta::FromMinutes(staleness_in_minutes), |
| 215 true /* is_data_saver_user */); |
| 216 EXPECT_EQ(expected_timestamp, infobar->GetTimestampText()); |
| 217 tester_->ExpectBucketCount(kUMAPreviewsInfoBarTimestamp, expected_bucket, |
| 218 1); |
| 219 // Dismiss the infobar. |
| 220 InfoBarService::FromWebContents(web_contents())->RemoveAllInfoBars(false); |
| 221 PreviewsInfoBarTabHelper::FromWebContents(web_contents()) |
| 222 ->set_displayed_preview_infobar(false); |
| 223 } |
| 224 |
| 200 void OnDismissPreviewsInfobar(bool user_opt_out) { | 225 void OnDismissPreviewsInfobar(bool user_opt_out) { |
| 201 user_opt_out_ = user_opt_out; | 226 user_opt_out_ = user_opt_out; |
| 202 } | 227 } |
| 203 | 228 |
| 204 InfoBarService* infobar_service() { | 229 InfoBarService* infobar_service() { |
| 205 return InfoBarService::FromWebContents(web_contents()); | 230 return InfoBarService::FromWebContents(web_contents()); |
| 206 } | 231 } |
| 207 | 232 |
| 208 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> | 233 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> |
| 209 drp_test_context_; | 234 drp_test_context_; |
| 210 | 235 |
| 211 base::Optional<bool> user_opt_out_; | 236 base::Optional<bool> user_opt_out_; |
| 212 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 237 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
| 213 base::test::ScopedFeatureList scoped_feature_list_; | 238 base::test::ScopedFeatureList scoped_feature_list_; |
| 239 std::unique_ptr<base::HistogramTester> tester_; |
| 214 }; | 240 }; |
| 215 | 241 |
| 216 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { | 242 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { |
| 217 base::HistogramTester tester; | |
| 218 | |
| 219 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 243 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 220 true /* is_data_saver_user */); | 244 true /* is_data_saver_user */); |
| 221 | 245 |
| 222 // Try showing a second infobar. Another should not be shown since the page | 246 // Try showing a second infobar. Another should not be shown since the page |
| 223 // has not navigated. | 247 // has not navigated. |
| 224 PreviewsInfoBarDelegate::Create( | 248 PreviewsInfoBarDelegate::Create( |
| 225 web_contents(), previews::PreviewsType::LOFI, | 249 web_contents(), previews::PreviewsType::LOFI, |
| 226 base::Time() /* previews_freshness */, true /* is_data_saver_user */, | 250 base::Time() /* previews_freshness */, true /* is_data_saver_user */, |
| 227 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 251 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
| 228 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 252 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 229 | 253 |
| 230 // Navigate and make sure the infobar is dismissed. | 254 // Navigate and make sure the infobar is dismissed. |
| 231 NavigateAndCommit(GURL(kTestUrl)); | 255 NavigateAndCommit(GURL(kTestUrl)); |
| 232 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 256 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 233 EXPECT_FALSE(user_opt_out_.value()); | 257 EXPECT_FALSE(user_opt_out_.value()); |
| 234 | 258 |
| 235 tester.ExpectBucketCount( | 259 tester_->ExpectBucketCount( |
| 236 kUMAPreviewsInfoBarActionLoFi, | 260 kUMAPreviewsInfoBarActionLoFi, |
| 237 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); | 261 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); |
| 238 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 262 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 239 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 263 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 240 } | 264 } |
| 241 | 265 |
| 242 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { | 266 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { |
| 243 base::HistogramTester tester; | |
| 244 | |
| 245 // Navigate to test URL, so we can reload later. | 267 // Navigate to test URL, so we can reload later. |
| 246 NavigateAndCommit(GURL(kTestUrl)); | 268 NavigateAndCommit(GURL(kTestUrl)); |
| 247 | 269 |
| 248 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 270 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 249 true /* is_data_saver_user */); | 271 true /* is_data_saver_user */); |
| 250 | 272 |
| 251 // Try showing a second infobar. Another should not be shown since the page | 273 // Try showing a second infobar. Another should not be shown since the page |
| 252 // has not navigated. | 274 // has not navigated. |
| 253 PreviewsInfoBarDelegate::Create( | 275 PreviewsInfoBarDelegate::Create( |
| 254 web_contents(), previews::PreviewsType::LOFI, | 276 web_contents(), previews::PreviewsType::LOFI, |
| 255 base::Time() /* previews_freshness */, true /* is_data_saver_user */, | 277 base::Time() /* previews_freshness */, true /* is_data_saver_user */, |
| 256 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 278 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
| 257 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 279 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 258 | 280 |
| 259 // Navigate to test URL as a reload to dismiss the infobar. | 281 // Navigate to test URL as a reload to dismiss the infobar. |
| 260 controller().LoadURL(GURL(kTestUrl), content::Referrer(), | 282 controller().LoadURL(GURL(kTestUrl), content::Referrer(), |
| 261 ui::PAGE_TRANSITION_RELOAD, std::string()); | 283 ui::PAGE_TRANSITION_RELOAD, std::string()); |
| 262 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 284 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 263 | 285 |
| 264 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 286 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 265 EXPECT_FALSE(user_opt_out_.value()); | 287 EXPECT_FALSE(user_opt_out_.value()); |
| 266 | 288 |
| 267 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, | 289 tester_->ExpectBucketCount( |
| 268 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, | 290 kUMAPreviewsInfoBarActionLoFi, |
| 269 1); | 291 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, 1); |
| 270 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 292 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 271 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 293 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 272 | 294 |
| 273 auto* data_reduction_proxy_settings = | 295 auto* data_reduction_proxy_settings = |
| 274 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 296 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 275 web_contents()->GetBrowserContext()); | 297 web_contents()->GetBrowserContext()); |
| 276 | 298 |
| 277 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 299 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 278 ->pingback_client() | 300 ->pingback_client() |
| 279 ->OptOutsSizeForTesting()); | 301 ->OptOutsSizeForTesting()); |
| 280 } | 302 } |
| 281 | 303 |
| 282 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { | 304 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { |
| 283 base::HistogramTester tester; | |
| 284 | |
| 285 ConfirmInfoBarDelegate* infobar = | 305 ConfirmInfoBarDelegate* infobar = |
| 286 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 306 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 287 true /* is_data_saver_user */); | 307 true /* is_data_saver_user */); |
| 288 | 308 |
| 289 // Simulate dismissing the infobar. | 309 // Simulate dismissing the infobar. |
| 290 infobar->InfoBarDismissed(); | 310 infobar->InfoBarDismissed(); |
| 291 infobar_service()->infobar_at(0)->RemoveSelf(); | 311 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 292 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 312 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 293 | 313 |
| 294 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, | 314 tester_->ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, |
| 295 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, | 315 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, |
| 296 1); | 316 1); |
| 297 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 317 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 298 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 318 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 299 EXPECT_FALSE(user_opt_out_.value()); | 319 EXPECT_FALSE(user_opt_out_.value()); |
| 300 } | 320 } |
| 301 | 321 |
| 302 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) { | 322 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) { |
| 303 base::HistogramTester tester; | |
| 304 | |
| 305 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 323 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 306 true /* is_data_saver_user */); | 324 true /* is_data_saver_user */); |
| 307 | 325 |
| 308 // Delete the infobar without any other infobar actions. | 326 // Delete the infobar without any other infobar actions. |
| 309 infobar_service()->infobar_at(0)->RemoveSelf(); | 327 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 310 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 328 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 311 | 329 |
| 312 tester.ExpectBucketCount( | 330 tester_->ExpectBucketCount( |
| 313 kUMAPreviewsInfoBarActionLoFi, | 331 kUMAPreviewsInfoBarActionLoFi, |
| 314 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); | 332 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); |
| 315 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 333 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 316 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 334 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 317 EXPECT_FALSE(user_opt_out_.value()); | 335 EXPECT_FALSE(user_opt_out_.value()); |
| 318 } | 336 } |
| 319 | 337 |
| 320 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) { | 338 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) { |
| 321 NavigateAndCommit(GURL(kTestUrl)); | 339 NavigateAndCommit(GURL(kTestUrl)); |
| 322 const struct { | 340 const struct { |
| 323 bool using_previews_blacklist; | 341 bool using_previews_blacklist; |
| 324 } tests[] = { | 342 } tests[] = { |
| 325 {true}, {false}, | 343 {true}, {false}, |
| 326 }; | 344 }; |
| 327 for (const auto test : tests) { | 345 for (const auto test : tests) { |
| 346 tester_.reset(new base::HistogramTester()); |
| 328 drp_test_context_->config()->ResetLoFiStatusForTest(); | 347 drp_test_context_->config()->ResetLoFiStatusForTest(); |
| 329 field_trial_list_.reset(); | 348 field_trial_list_.reset(); |
| 330 field_trial_list_.reset(new base::FieldTrialList(nullptr)); | 349 field_trial_list_.reset(new base::FieldTrialList(nullptr)); |
| 331 if (test.using_previews_blacklist) { | 350 if (test.using_previews_blacklist) { |
| 332 base::FieldTrialList::CreateFieldTrial( | 351 base::FieldTrialList::CreateFieldTrial( |
| 333 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); | 352 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); |
| 334 } | 353 } |
| 335 base::HistogramTester tester; | 354 |
| 336 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. | 355 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. |
| 337 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); | 356 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); |
| 338 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 357 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 339 | 358 |
| 340 ConfirmInfoBarDelegate* infobar = | 359 ConfirmInfoBarDelegate* infobar = |
| 341 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 360 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 342 true /* is_data_saver_user */); | 361 true /* is_data_saver_user */); |
| 343 | 362 |
| 344 // Simulate clicking the infobar link. | 363 // Simulate clicking the infobar link. |
| 345 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 364 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
| 346 infobar_service()->infobar_at(0)->RemoveSelf(); | 365 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 347 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 366 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 348 | 367 |
| 349 tester.ExpectBucketCount( | 368 tester_->ExpectBucketCount( |
| 350 kUMAPreviewsInfoBarActionLoFi, | 369 kUMAPreviewsInfoBarActionLoFi, |
| 351 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 370 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
| 352 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, | 371 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, |
| 353 drp_test_context_->pref_service()->GetInteger( | 372 drp_test_context_->pref_service()->GetInteger( |
| 354 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 373 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 355 EXPECT_TRUE(user_opt_out_.value()); | 374 EXPECT_TRUE(user_opt_out_.value()); |
| 356 | 375 |
| 357 auto* data_reduction_proxy_settings = | 376 auto* data_reduction_proxy_settings = |
| 358 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 377 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 359 web_contents()->GetBrowserContext()); | 378 web_contents()->GetBrowserContext()); |
| 360 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 379 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 361 ->pingback_client() | 380 ->pingback_client() |
| 362 ->OptOutsSizeForTesting()); | 381 ->OptOutsSizeForTesting()); |
| 363 } | 382 } |
| 364 } | 383 } |
| 365 | 384 |
| 366 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { | 385 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { |
| 367 base::HistogramTester tester; | |
| 368 | |
| 369 NavigateAndCommit(GURL(kTestUrl)); | 386 NavigateAndCommit(GURL(kTestUrl)); |
| 370 | 387 |
| 371 ConfirmInfoBarDelegate* infobar = | 388 ConfirmInfoBarDelegate* infobar = |
| 372 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 389 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
| 373 true /* is_data_saver_user */); | 390 true /* is_data_saver_user */); |
| 374 | 391 |
| 375 // Simulate clicking the infobar link. | 392 // Simulate clicking the infobar link. |
| 376 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 393 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
| 377 infobar_service()->infobar_at(0)->RemoveSelf(); | 394 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 378 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 395 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 379 | 396 |
| 380 tester.ExpectBucketCount( | 397 tester_->ExpectBucketCount( |
| 381 kUMAPreviewsInfoBarActionLitePage, | 398 kUMAPreviewsInfoBarActionLitePage, |
| 382 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 399 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
| 383 | 400 |
| 384 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 401 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 385 | 402 |
| 386 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 403 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
| 387 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 404 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
| 388 ->last_navigation_reload_type()); | 405 ->last_navigation_reload_type()); |
| 389 | 406 |
| 390 auto* data_reduction_proxy_settings = | 407 auto* data_reduction_proxy_settings = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 414 // Infobar should not be shown again since a navigation hasn't happened. | 431 // Infobar should not be shown again since a navigation hasn't happened. |
| 415 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 432 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 416 | 433 |
| 417 // Navigate and show infobar again. | 434 // Navigate and show infobar again. |
| 418 NavigateAndCommit(GURL(kTestUrl)); | 435 NavigateAndCommit(GURL(kTestUrl)); |
| 419 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 436 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 420 true /* is_data_saver_user */); | 437 true /* is_data_saver_user */); |
| 421 } | 438 } |
| 422 | 439 |
| 423 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { | 440 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { |
| 424 base::HistogramTester tester; | |
| 425 | |
| 426 ConfirmInfoBarDelegate* infobar = | 441 ConfirmInfoBarDelegate* infobar = |
| 427 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 442 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
| 428 true /* is_data_saver_user */); | 443 true /* is_data_saver_user */); |
| 429 | 444 |
| 430 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, | 445 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, |
| 431 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 446 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
| 432 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( | 447 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( |
| 433 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 448 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
| 434 | 449 |
| 435 ASSERT_TRUE(infobar); | 450 ASSERT_TRUE(infobar); |
| 436 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 451 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
| 437 infobar->GetMessageText()); | 452 infobar->GetMessageText()); |
| 438 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 453 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
| 439 infobar->GetLinkText()); | 454 infobar->GetLinkText()); |
| 440 #if defined(OS_ANDROID) | 455 #if defined(OS_ANDROID) |
| 441 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 456 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
| 442 #else | 457 #else |
| 443 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 458 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
| 444 #endif | 459 #endif |
| 445 } | 460 } |
| 446 | 461 |
| 447 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { | 462 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { |
| 448 base::HistogramTester tester; | |
| 449 | |
| 450 PreviewsInfoBarDelegate* infobar = | 463 PreviewsInfoBarDelegate* infobar = |
| 451 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 464 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
| 452 true /* is_data_saver_user */); | 465 true /* is_data_saver_user */); |
| 453 | 466 |
| 454 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, | 467 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, |
| 455 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 468 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
| 456 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( | 469 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( |
| 457 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 470 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
| 458 | 471 |
| 459 // Check the strings. | 472 // Check the strings. |
| 460 ASSERT_TRUE(infobar); | 473 ASSERT_TRUE(infobar); |
| 461 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 474 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
| 462 infobar->GetMessageText()); | 475 infobar->GetMessageText()); |
| 463 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 476 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
| 464 infobar->GetLinkText()); | 477 infobar->GetLinkText()); |
| 465 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); | 478 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); |
| 466 #if defined(OS_ANDROID) | 479 #if defined(OS_ANDROID) |
| 467 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 480 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
| 468 #else | 481 #else |
| 469 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 482 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
| 470 #endif | 483 #endif |
| 471 } | 484 } |
| 472 | 485 |
| 473 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) { | 486 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) { |
| 474 base::HistogramTester tester; | |
| 475 | |
| 476 PreviewsInfoBarDelegate* infobar = | 487 PreviewsInfoBarDelegate* infobar = |
| 477 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 488 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
| 478 false /* is_data_saver_user */); | 489 false /* is_data_saver_user */); |
| 479 | 490 |
| 480 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 491 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
| 481 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 492 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
| 482 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 493 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 483 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 494 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
| 484 | 495 |
| 485 // Check the strings. | 496 // Check the strings. |
| 486 ASSERT_TRUE(infobar); | 497 ASSERT_TRUE(infobar); |
| 487 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), | 498 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), |
| 488 infobar->GetMessageText()); | 499 infobar->GetMessageText()); |
| 489 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 500 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
| 490 infobar->GetLinkText()); | 501 infobar->GetLinkText()); |
| 491 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); | 502 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); |
| 492 #if defined(OS_ANDROID) | 503 #if defined(OS_ANDROID) |
| 493 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 504 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
| 494 #else | 505 #else |
| 495 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 506 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
| 496 #endif | 507 #endif |
| 497 } | 508 } |
| 498 | 509 |
| 499 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) { | 510 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) { |
| 500 base::HistogramTester tester; | |
| 501 | |
| 502 PreviewsInfoBarDelegate* infobar = | 511 PreviewsInfoBarDelegate* infobar = |
| 503 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 512 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
| 504 true /* is_data_saver_user */); | 513 true /* is_data_saver_user */); |
| 505 | 514 |
| 506 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 515 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
| 507 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 516 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
| 508 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 517 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 509 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); | 518 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); |
| 510 | 519 |
| 511 // Check the strings. | 520 // Check the strings. |
| 512 ASSERT_TRUE(infobar); | 521 ASSERT_TRUE(infobar); |
| 513 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 522 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
| 514 infobar->GetMessageText()); | 523 infobar->GetMessageText()); |
| 515 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 524 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
| 516 infobar->GetLinkText()); | 525 infobar->GetLinkText()); |
| 517 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); | 526 ASSERT_EQ(base::string16(), infobar->GetTimestampText()); |
| 518 #if defined(OS_ANDROID) | 527 #if defined(OS_ANDROID) |
| 519 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 528 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
| 520 #else | 529 #else |
| 521 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 530 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
| 522 #endif | 531 #endif |
| 523 } | 532 } |
| 524 | 533 |
| 525 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { | 534 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { |
| 526 base::HistogramTester tester; | |
| 527 | |
| 528 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 535 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
| 529 ->set_should_have_page_id(false); | 536 ->set_should_have_page_id(false); |
| 530 | 537 |
| 531 NavigateAndCommit(GURL(kTestUrl)); | 538 NavigateAndCommit(GURL(kTestUrl)); |
| 532 | 539 |
| 533 ConfirmInfoBarDelegate* infobar = | 540 ConfirmInfoBarDelegate* infobar = |
| 534 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 541 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
| 535 true /* is_data_saver_user */); | 542 true /* is_data_saver_user */); |
| 536 | 543 |
| 537 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 544 tester_->ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
| 538 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 545 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
| 539 | 546 |
| 540 // Simulate clicking the infobar link. | 547 // Simulate clicking the infobar link. |
| 541 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 548 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
| 542 infobar_service()->infobar_at(0)->RemoveSelf(); | 549 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 543 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 550 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 544 | 551 |
| 545 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 552 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 546 | 553 |
| 547 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 554 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
| 548 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 555 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
| 549 ->last_navigation_reload_type()); | 556 ->last_navigation_reload_type()); |
| 550 | 557 |
| 551 auto* data_reduction_proxy_settings = | 558 auto* data_reduction_proxy_settings = |
| 552 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 559 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 553 web_contents()->GetBrowserContext()); | 560 web_contents()->GetBrowserContext()); |
| 554 | 561 |
| 555 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 562 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 556 ->pingback_client() | 563 ->pingback_client() |
| 557 ->OptOutsSizeForTesting()); | 564 ->OptOutsSizeForTesting()); |
| 558 } | 565 } |
| 559 | 566 |
| 560 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { | 567 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { |
| 561 base::HistogramTester tester; | |
| 562 | |
| 563 NavigateAndCommit(GURL(kTestUrl)); | 568 NavigateAndCommit(GURL(kTestUrl)); |
| 564 | 569 |
| 565 ConfirmInfoBarDelegate* infobar = | 570 ConfirmInfoBarDelegate* infobar = |
| 566 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 571 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
| 567 true /* is_data_saver_user */); | 572 true /* is_data_saver_user */); |
| 568 | 573 |
| 569 // Simulate clicking the infobar link. | 574 // Simulate clicking the infobar link. |
| 570 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 575 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
| 571 infobar_service()->infobar_at(0)->RemoveSelf(); | 576 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 572 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 577 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 573 | 578 |
| 574 tester.ExpectBucketCount( | 579 tester_->ExpectBucketCount( |
| 575 kUMAPreviewsInfoBarActionLitePage, | 580 kUMAPreviewsInfoBarActionLitePage, |
| 576 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 581 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
| 577 | 582 |
| 578 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 583 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 579 | 584 |
| 580 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 585 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
| 581 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 586 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
| 582 ->last_navigation_reload_type()); | 587 ->last_navigation_reload_type()); |
| 583 | 588 |
| 584 auto* data_reduction_proxy_settings = | 589 auto* data_reduction_proxy_settings = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 601 ->pingback_client() | 606 ->pingback_client() |
| 602 ->OptOutsSizeForTesting()); | 607 ->OptOutsSizeForTesting()); |
| 603 | 608 |
| 604 drp_test_context_->RunUntilIdle(); | 609 drp_test_context_->RunUntilIdle(); |
| 605 | 610 |
| 606 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 611 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 607 ->pingback_client() | 612 ->pingback_client() |
| 608 ->OptOutsSizeForTesting()); | 613 ->OptOutsSizeForTesting()); |
| 609 } | 614 } |
| 610 | 615 |
| 611 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampMintuesTest) { | 616 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampMinutesTest) { |
| 612 EnableStalePreviewsTimestamp(); | 617 // Use default params. |
| 613 | 618 std::map<std::string, std::string> variation_params; |
| 619 EnableStalePreviewsTimestamp(variation_params); |
| 614 int staleness_in_minutes = 5; | 620 int staleness_in_minutes = 5; |
| 615 | 621 |
| 616 PreviewsInfoBarDelegate* infobar = CreateInfoBar( | 622 TestStalePreviews( |
| 617 previews::PreviewsType::LITE_PAGE, | 623 staleness_in_minutes, |
| 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, | 624 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, |
| 623 base::IntToString16(staleness_in_minutes)), | 625 base::IntToString16(staleness_in_minutes)), |
| 624 infobar->GetTimestampText()); | 626 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
| 625 } | 627 } |
| 626 | 628 |
| 627 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHourTest) { | 629 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHourTest) { |
| 628 EnableStalePreviewsTimestamp(); | 630 // Use default variation_params. |
| 629 | 631 std::map<std::string, std::string> variation_params; |
| 632 EnableStalePreviewsTimestamp(variation_params); |
| 630 int staleness_in_minutes = 65; | 633 int staleness_in_minutes = 65; |
| 631 | 634 |
| 632 PreviewsInfoBarDelegate* infobar = CreateInfoBar( | 635 TestStalePreviews( |
| 633 previews::PreviewsType::LITE_PAGE, | 636 staleness_in_minutes, |
| 634 base::Time::Now() - base::TimeDelta::FromMinutes(staleness_in_minutes), | 637 l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR), |
| 635 true /* is_data_saver_user */); | 638 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
| 636 | |
| 637 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR), | |
| 638 infobar->GetTimestampText()); | |
| 639 } | 639 } |
| 640 | 640 |
| 641 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHoursTest) { | 641 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampHoursTest) { |
| 642 EnableStalePreviewsTimestamp(); | 642 // Use default variation_params. |
| 643 | 643 std::map<std::string, std::string> variation_params; |
| 644 EnableStalePreviewsTimestamp(variation_params); |
| 644 int staleness_in_hours = 2; | 645 int staleness_in_hours = 2; |
| 645 | 646 |
| 646 PreviewsInfoBarDelegate* infobar = CreateInfoBar( | 647 TestStalePreviews( |
| 647 previews::PreviewsType::LITE_PAGE, | 648 staleness_in_hours * 60, |
| 648 base::Time::Now() - base::TimeDelta::FromHours(staleness_in_hours), | 649 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, |
| 649 true /* is_data_saver_user */); | 650 base::IntToString16(staleness_in_hours)), |
| 651 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
| 652 } |
| 650 | 653 |
| 651 ASSERT_EQ(l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, | 654 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampFinchParamsUMA) { |
| 652 base::IntToString16(staleness_in_hours)), | 655 std::map<std::string, std::string> variation_params; |
| 653 infobar->GetTimestampText()); | 656 variation_params["min_staleness_in_minutes"] = "1"; |
| 657 variation_params["max_staleness_in_minutes"] = "5"; |
| 658 EnableStalePreviewsTimestamp(variation_params); |
| 659 |
| 660 TestStalePreviews( |
| 661 1, |
| 662 l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, |
| 663 base::IntToString16(1)), |
| 664 PreviewsInfoBarDelegate::TIMESTAMP_SHOWN); |
| 665 |
| 666 TestStalePreviews( |
| 667 6, base::string16(), |
| 668 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); |
| 654 } | 669 } |
| 670 |
| 671 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTimestampUMA) { |
| 672 // Use default params. |
| 673 std::map<std::string, std::string> variation_params; |
| 674 EnableStalePreviewsTimestamp(variation_params); |
| 675 |
| 676 TestStalePreviews( |
| 677 1, base::string16(), |
| 678 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_PREVIEW_NOT_STALE); |
| 679 TestStalePreviews( |
| 680 -1, base::string16(), |
| 681 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_NEGATIVE); |
| 682 TestStalePreviews( |
| 683 1441, base::string16(), |
| 684 PreviewsInfoBarDelegate::TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); |
| 685 } |
| OLD | NEW |