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

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

Issue 2833523002: Adding opt out and previews type information to DRP pingback (Closed)
Patch Set: bengr comments Created 3 years, 8 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/optional.h" 13 #include "base/optional.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/android/android_theme_resources.h" 16 #include "chrome/browser/android/android_theme_resources.h"
17 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/loader/chrome_navigation_data.h"
18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 20 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
20 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 21 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
21 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
24 #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"
26 #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"
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 29 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
25 #include "components/infobars/core/confirm_infobar_delegate.h" 30 #include "components/infobars/core/confirm_infobar_delegate.h"
26 #include "components/infobars/core/infobar.h" 31 #include "components/infobars/core/infobar.h"
27 #include "components/infobars/core/infobar_delegate.h" 32 #include "components/infobars/core/infobar_delegate.h"
28 #include "components/prefs/pref_registry_simple.h" 33 #include "components/prefs/pref_registry_simple.h"
29 #include "components/proxy_config/proxy_config_pref_names.h" 34 #include "components/proxy_config/proxy_config_pref_names.h"
30 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/navigation_handle.h" 36 #include "content/public/browser/navigation_handle.h"
32 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
(...skipping 27 matching lines...) Expand all
60 public: 65 public:
61 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents) 66 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents)
62 : content::WebContentsObserver(web_contents), 67 : content::WebContentsObserver(web_contents),
63 last_navigation_reload_type_(content::ReloadType::NONE) {} 68 last_navigation_reload_type_(content::ReloadType::NONE) {}
64 ~TestPreviewsWebContentsObserver() override {} 69 ~TestPreviewsWebContentsObserver() override {}
65 70
66 content::ReloadType last_navigation_reload_type() { 71 content::ReloadType last_navigation_reload_type() {
67 return last_navigation_reload_type_; 72 return last_navigation_reload_type_;
68 } 73 }
69 74
75 void DidStartNavigation(
76 content::NavigationHandle* navigation_handle) override {
77 ChromeNavigationData* chrome_navigation_data = new ChromeNavigationData();
78 content::WebContentsTester::For(web_contents())
79 ->SetNavigationData(navigation_handle,
80 base::WrapUnique(chrome_navigation_data));
81 data_reduction_proxy::DataReductionProxyData* data =
82 new data_reduction_proxy::DataReductionProxyData();
83 chrome_navigation_data->SetDataReductionProxyData(base::WrapUnique(data));
84 data->set_used_data_reduction_proxy(true);
85 data->set_page_id(1u);
86 }
87
70 void DidFinishNavigation( 88 void DidFinishNavigation(
71 content::NavigationHandle* navigation_handle) override { 89 content::NavigationHandle* navigation_handle) override {
72 last_navigation_reload_type_ = navigation_handle->GetReloadType(); 90 last_navigation_reload_type_ = navigation_handle->GetReloadType();
73 } 91 }
74 92
75 private: 93 private:
76 content::ReloadType last_navigation_reload_type_; 94 content::ReloadType last_navigation_reload_type_;
77 }; 95 };
78 96
79 } // namespace 97 } // namespace
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 213 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
196 214
197 EXPECT_EQ(0U, infobar_service()->infobar_count()); 215 EXPECT_EQ(0U, infobar_service()->infobar_count());
198 EXPECT_FALSE(user_opt_out_.value()); 216 EXPECT_FALSE(user_opt_out_.value());
199 217
200 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, 218 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
201 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, 219 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD,
202 1); 220 1);
203 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 221 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
204 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 222 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
223
224 auto* data_reduction_proxy_settings =
225 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
226 web_contents()->GetBrowserContext());
227
228 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
229 ->pingback_client()
230 ->OptOutsSizeForTesting());
205 } 231 }
206 232
207 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { 233 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) {
208 base::HistogramTester tester; 234 base::HistogramTester tester;
209 235
210 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 236 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
211 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 237 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
212 238
213 // Simulate dismissing the infobar. 239 // Simulate dismissing the infobar.
214 infobar->InfoBarDismissed(); 240 infobar->InfoBarDismissed();
(...skipping 21 matching lines...) Expand all
236 kUMAPreviewsInfoBarActionLoFi, 262 kUMAPreviewsInfoBarActionLoFi,
237 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); 263 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1);
238 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 264 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
239 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 265 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
240 EXPECT_FALSE(user_opt_out_.value()); 266 EXPECT_FALSE(user_opt_out_.value());
241 } 267 }
242 268
243 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) { 269 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLoFi) {
244 base::HistogramTester tester; 270 base::HistogramTester tester;
245 271
272 NavigateAndCommit(GURL(kTestUrl));
273
246 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 274 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
247 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 275 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
248 276
249 // Simulate clicking the infobar link. 277 // Simulate clicking the infobar link.
250 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 278 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
251 infobar_service()->infobar_at(0)->RemoveSelf(); 279 infobar_service()->infobar_at(0)->RemoveSelf();
252 EXPECT_EQ(0U, infobar_service()->infobar_count()); 280 EXPECT_EQ(0U, infobar_service()->infobar_count());
253 281
254 tester.ExpectBucketCount( 282 tester.ExpectBucketCount(
255 kUMAPreviewsInfoBarActionLoFi, 283 kUMAPreviewsInfoBarActionLoFi,
256 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 284 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
257 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 285 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
258 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 286 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
259 EXPECT_TRUE(user_opt_out_.value()); 287 EXPECT_TRUE(user_opt_out_.value());
288
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());
260 } 296 }
261 297
262 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { 298 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) {
263 base::HistogramTester tester; 299 base::HistogramTester tester;
264 300
265 NavigateAndCommit(GURL(kTestUrl)); 301 NavigateAndCommit(GURL(kTestUrl));
266 302
267 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 303 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
268 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); 304 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */);
269 305
270 // Simulate clicking the infobar link. 306 // Simulate clicking the infobar link.
271 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 307 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
272 infobar_service()->infobar_at(0)->RemoveSelf(); 308 infobar_service()->infobar_at(0)->RemoveSelf();
273 EXPECT_EQ(0U, infobar_service()->infobar_count()); 309 EXPECT_EQ(0U, infobar_service()->infobar_count());
274 310
275 tester.ExpectBucketCount( 311 tester.ExpectBucketCount(
276 kUMAPreviewsInfoBarActionLitePage, 312 kUMAPreviewsInfoBarActionLitePage,
277 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 313 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
278 314
279 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 315 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
280 316
281 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, 317 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE,
282 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) 318 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
283 ->last_navigation_reload_type()); 319 ->last_navigation_reload_type());
320
321 auto* data_reduction_proxy_settings =
322 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
323 web_contents()->GetBrowserContext());
324
325 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
326 ->pingback_client()
327 ->OptOutsSizeForTesting());
284 } 328 }
285 329
286 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { 330 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) {
287 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 331 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
288 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 332 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
289 333
290 // Simulate dismissing the infobar. 334 // Simulate dismissing the infobar.
291 infobar->InfoBarDismissed(); 335 infobar->InfoBarDismissed();
292 infobar_service()->infobar_at(0)->RemoveSelf(); 336 infobar_service()->infobar_at(0)->RemoveSelf();
293 EXPECT_EQ(0U, infobar_service()->infobar_count()); 337 EXPECT_EQ(0U, infobar_service()->infobar_count());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // Simulate clicking the infobar link. 458 // Simulate clicking the infobar link.
415 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 459 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
416 infobar_service()->infobar_at(0)->RemoveSelf(); 460 infobar_service()->infobar_at(0)->RemoveSelf();
417 EXPECT_EQ(0U, infobar_service()->infobar_count()); 461 EXPECT_EQ(0U, infobar_service()->infobar_count());
418 462
419 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 463 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
420 464
421 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, 465 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE,
422 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) 466 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
423 ->last_navigation_reload_type()); 467 ->last_navigation_reload_type());
468
469 auto* data_reduction_proxy_settings =
470 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
471 web_contents()->GetBrowserContext());
472
473 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
474 ->pingback_client()
475 ->OptOutsSizeForTesting());
424 } 476 }
477
478 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) {
479 base::HistogramTester tester;
480
481 NavigateAndCommit(GURL(kTestUrl));
482
483 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
484 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */);
485
486 // Simulate clicking the infobar link.
487 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
488 infobar_service()->infobar_at(0)->RemoveSelf();
489 EXPECT_EQ(0U, infobar_service()->infobar_count());
490
491 tester.ExpectBucketCount(
492 kUMAPreviewsInfoBarActionLitePage,
493 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
494
495 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
496
497 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE,
498 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
499 ->last_navigation_reload_type());
500
501 auto* data_reduction_proxy_settings =
502 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
503 web_contents()->GetBrowserContext());
504
505 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
506 ->pingback_client()
507 ->OptOutsSizeForTesting());
508
509 {
510 std::unique_ptr<content::NavigationHandle> navigation_handle(
511 content::NavigationHandle::CreateNavigationHandleForTesting(
512 GURL("url"), main_rfh(), true));
513 }
514
515 SetContents(nullptr);
516
517 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
518 ->pingback_client()
519 ->OptOutsSizeForTesting());
520
521 drp_test_context_->RunUntilIdle();
522
523 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
524 ->pingback_client()
525 ->OptOutsSizeForTesting());
526 }
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_delegate.cc ('k') | chrome/browser/previews/previews_infobar_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698