Chromium Code Reviews| 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 <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/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/field_trial.h" | |
| 13 #include "base/optional.h" | 14 #include "base/optional.h" |
| 14 #include "base/test/histogram_tester.h" | 15 #include "base/test/histogram_tester.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/android/android_theme_resources.h" | 17 #include "chrome/browser/android/android_theme_resources.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 18 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/loader/chrome_navigation_data.h" | 19 #include "chrome/browser/loader/chrome_navigation_data.h" |
| 19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 20 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 20 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | 21 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" |
| 21 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 22 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
| 22 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 | 289 |
| 289 auto* data_reduction_proxy_settings = | 290 auto* data_reduction_proxy_settings = |
| 290 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 291 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 291 web_contents()->GetBrowserContext()); | 292 web_contents()->GetBrowserContext()); |
| 292 | 293 |
| 293 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 294 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 294 ->pingback_client() | 295 ->pingback_client() |
| 295 ->OptOutsSizeForTesting()); | 296 ->OptOutsSizeForTesting()); |
| 296 } | 297 } |
| 297 | 298 |
| 299 TEST_F(PreviewsInfoBarDelegateUnitTest, | |
| 300 InfobarTestClickLinkLoFiBlackListExperiment) { | |
|
megjablon
2017/05/09 19:58:33
Instead of duplicating all this code can we just a
RyanSturm
2017/05/09 22:35:18
Done.
RyanSturm
2017/05/10 16:01:45
NavigateAndCommit doesn't really do the right thin
| |
| 301 base::HistogramTester tester; | |
| 302 | |
| 303 base::FieldTrialList field_trial_list(nullptr); | |
| 304 base::FieldTrialList::CreateFieldTrial( | |
| 305 "DataReductionProxyPreviewsBlacklistTransition", "Enabled_"); | |
| 306 | |
| 307 NavigateAndCommit(GURL(kTestUrl)); | |
| 308 | |
| 309 ConfirmInfoBarDelegate* infobar = CreateInfoBar( | |
| 310 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); | |
| 311 | |
| 312 // Simulate clicking the infobar link. | |
| 313 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | |
| 314 infobar_service()->infobar_at(0)->RemoveSelf(); | |
| 315 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
| 316 | |
| 317 tester.ExpectBucketCount( | |
| 318 kUMAPreviewsInfoBarActionLoFi, | |
| 319 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | |
| 320 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | |
| 321 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | |
| 322 EXPECT_TRUE(user_opt_out_.value()); | |
| 323 | |
| 324 auto* data_reduction_proxy_settings = | |
| 325 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | |
| 326 web_contents()->GetBrowserContext()); | |
| 327 | |
| 328 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | |
| 329 ->pingback_client() | |
| 330 ->OptOutsSizeForTesting()); | |
| 331 } | |
| 332 | |
| 298 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { | 333 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { |
| 299 base::HistogramTester tester; | 334 base::HistogramTester tester; |
| 300 | 335 |
| 301 NavigateAndCommit(GURL(kTestUrl)); | 336 NavigateAndCommit(GURL(kTestUrl)); |
| 302 | 337 |
| 303 ConfirmInfoBarDelegate* infobar = CreateInfoBar( | 338 ConfirmInfoBarDelegate* infobar = CreateInfoBar( |
| 304 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); | 339 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); |
| 305 | 340 |
| 306 // Simulate clicking the infobar link. | 341 // Simulate clicking the infobar link. |
| 307 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 342 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 552 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 518 ->pingback_client() | 553 ->pingback_client() |
| 519 ->OptOutsSizeForTesting()); | 554 ->OptOutsSizeForTesting()); |
| 520 | 555 |
| 521 drp_test_context_->RunUntilIdle(); | 556 drp_test_context_->RunUntilIdle(); |
| 522 | 557 |
| 523 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 558 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 524 ->pingback_client() | 559 ->pingback_client() |
| 525 ->OptOutsSizeForTesting()); | 560 ->OptOutsSizeForTesting()); |
| 526 } | 561 } |
| OLD | NEW |