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

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

Issue 2864333003: Use the Previews Black List for server previews (Closed)
Patch Set: . Created 3 years, 7 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/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"
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" 27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h"
26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 29 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 30 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
29 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
30 #include "components/infobars/core/confirm_infobar_delegate.h" 32 #include "components/infobars/core/confirm_infobar_delegate.h"
31 #include "components/infobars/core/infobar.h" 33 #include "components/infobars/core/infobar.h"
32 #include "components/infobars/core/infobar_delegate.h" 34 #include "components/infobars/core/infobar_delegate.h"
33 #include "components/prefs/pref_registry_simple.h" 35 #include "components/prefs/pref_registry_simple.h"
34 #include "components/proxy_config/proxy_config_pref_names.h" 36 #include "components/proxy_config/proxy_config_pref_names.h"
35 #include "content/public/browser/navigation_entry.h" 37 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/navigation_handle.h" 38 #include "content/public/browser/navigation_handle.h"
39 #include "content/public/browser/reload_type.h"
37 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
38 #include "content/public/browser/web_contents_observer.h" 41 #include "content/public/browser/web_contents_observer.h"
39 #include "content/public/browser/web_contents_user_data.h" 42 #include "content/public/browser/web_contents_user_data.h"
40 #include "content/public/common/referrer.h" 43 #include "content/public/common/referrer.h"
41 #include "content/public/test/test_renderer_host.h" 44 #include "content/public/test/test_renderer_host.h"
42 #include "content/public/test/web_contents_tester.h" 45 #include "content/public/test/web_contents_tester.h"
43 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/page_transition_types.h" 47 #include "ui/base/page_transition_types.h"
45 #include "ui/base/window_open_disposition.h" 48 #include "ui/base/window_open_disposition.h"
46 49
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 263
261 tester.ExpectBucketCount( 264 tester.ExpectBucketCount(
262 kUMAPreviewsInfoBarActionLoFi, 265 kUMAPreviewsInfoBarActionLoFi,
263 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); 266 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1);
264 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 267 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
265 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 268 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
266 EXPECT_FALSE(user_opt_out_.value()); 269 EXPECT_FALSE(user_opt_out_.value());
267 } 270 }
268 271
269 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) { 272 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) {
270 base::HistogramTester tester; 273 NavigateAndCommit(GURL(kTestUrl));
274 const struct {
275 bool is_transitioned;
megjablon 2017/05/10 19:11:23 using_previews_black_list? or something that menti
RyanSturm 2017/05/10 19:57:02 Done.
276 } tests[] = {
277 {true}, {false},
278 };
279 for (const auto test : tests) {
280 drp_test_context_->config()->ResetLoFiStatusForTest();
281 base::FieldTrialList field_trial_list(nullptr);
282 if (test.is_transitioned) {
283 base::FieldTrialList::CreateFieldTrial(
284 "DataReductionProxyPreviewsBlackListTransition", "Enabled_");
285 }
286 base::HistogramTester tester;
287 // Call Reload and CommitPendingNavigation to force DidFinishNavigation.
288 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
289 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
271 290
272 NavigateAndCommit(GURL(kTestUrl)); 291 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
292 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
273 293
274 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 294 // Simulate clicking the infobar link.
275 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 295 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
296 infobar_service()->infobar_at(0)->RemoveSelf();
297 EXPECT_EQ(0U, infobar_service()->infobar_count());
276 298
277 // Simulate clicking the infobar link. 299 tester.ExpectBucketCount(
278 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 300 kUMAPreviewsInfoBarActionLoFi,
279 infobar_service()->infobar_at(0)->RemoveSelf(); 301 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
280 EXPECT_EQ(0U, infobar_service()->infobar_count()); 302 EXPECT_EQ(test.is_transitioned ? 0 : 1,
303 drp_test_context_->pref_service()->GetInteger(
304 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
305 EXPECT_TRUE(user_opt_out_.value());
281 306
282 tester.ExpectBucketCount( 307 auto* data_reduction_proxy_settings =
283 kUMAPreviewsInfoBarActionLoFi, 308 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
284 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 309 web_contents()->GetBrowserContext());
285 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 310 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
286 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 311 ->pingback_client()
287 EXPECT_TRUE(user_opt_out_.value()); 312 ->OptOutsSizeForTesting());
288 313 }
289 auto* data_reduction_proxy_settings =
290 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
291 web_contents()->GetBrowserContext());
292
293 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
294 ->pingback_client()
295 ->OptOutsSizeForTesting());
296 } 314 }
297 315
298 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { 316 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) {
299 base::HistogramTester tester; 317 base::HistogramTester tester;
300 318
301 NavigateAndCommit(GURL(kTestUrl)); 319 NavigateAndCommit(GURL(kTestUrl));
302 320
303 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 321 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
304 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); 322 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */);
305 323
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 535 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
518 ->pingback_client() 536 ->pingback_client()
519 ->OptOutsSizeForTesting()); 537 ->OptOutsSizeForTesting());
520 538
521 drp_test_context_->RunUntilIdle(); 539 drp_test_context_->RunUntilIdle();
522 540
523 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() 541 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
524 ->pingback_client() 542 ->pingback_client()
525 ->OptOutsSizeForTesting()); 543 ->OptOutsSizeForTesting());
526 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698