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

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

Issue 2472863002: Adding offline navigations to the previews blacklist (Closed)
Patch Set: rebase Created 4 years, 1 month 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 8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/optional.h"
9 #include "base/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
10 #include "chrome/browser/android/android_theme_resources.h" 13 #include "chrome/browser/android/android_theme_resources.h"
11 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 15 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
14 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 17 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
15 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 base::ThreadTaskRunnerHandle::Get()); 77 base::ThreadTaskRunnerHandle::Get());
75 } 78 }
76 79
77 void TearDown() override { 80 void TearDown() override {
78 drp_test_context_->DestroySettings(); 81 drp_test_context_->DestroySettings();
79 ChromeRenderViewHostTestHarness::TearDown(); 82 ChromeRenderViewHostTestHarness::TearDown();
80 } 83 }
81 84
82 ConfirmInfoBarDelegate* CreateInfoBar( 85 ConfirmInfoBarDelegate* CreateInfoBar(
83 PreviewsInfoBarDelegate::PreviewsInfoBarType type) { 86 PreviewsInfoBarDelegate::PreviewsInfoBarType type) {
84 PreviewsInfoBarDelegate::Create(web_contents(), type); 87 PreviewsInfoBarDelegate::Create(
88 web_contents(), type,
89 base::Bind(&PreviewsInfoBarDelegateUnitTest::infobar_reload_by_user,
90 base::Unretained(this)));
85 91
86 InfoBarService* infobar_service = 92 InfoBarService* infobar_service =
87 InfoBarService::FromWebContents(web_contents()); 93 InfoBarService::FromWebContents(web_contents());
88 EXPECT_EQ(1U, infobar_service->infobar_count()); 94 EXPECT_EQ(1U, infobar_service->infobar_count());
89 95
90 return infobar_service->infobar_at(0) 96 return infobar_service->infobar_at(0)
91 ->delegate() 97 ->delegate()
92 ->AsConfirmInfoBarDelegate(); 98 ->AsConfirmInfoBarDelegate();
93 } 99 }
94 100
101 void infobar_reload_by_user(bool infobar_reload_by_user) {
megjablon 2016/11/09 00:19:11 Use camel case and if you rename OnDismissPreviews
RyanSturm 2016/11/09 18:47:13 Done.
102 infobar_reload_by_user_ = infobar_reload_by_user;
103 }
104
95 InfoBarService* infobar_service() { 105 InfoBarService* infobar_service() {
96 return InfoBarService::FromWebContents(web_contents()); 106 return InfoBarService::FromWebContents(web_contents());
97 } 107 }
98 108
99 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> 109 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
100 drp_test_context_; 110 drp_test_context_;
111
112 base::Optional<bool> infobar_reload_by_user_;
101 }; 113 };
102 114
103 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { 115 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) {
104 base::HistogramTester tester; 116 base::HistogramTester tester;
105 117
106 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 118 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
107 119
108 // Try showing a second infobar. Another should not be shown since the page 120 // Try showing a second infobar. Another should not be shown since the page
109 // has not navigated. 121 // has not navigated.
110 PreviewsInfoBarDelegate::Create(web_contents(), 122 PreviewsInfoBarDelegate::Create(
111 PreviewsInfoBarDelegate::LOFI); 123 web_contents(), PreviewsInfoBarDelegate::LOFI,
124 PreviewsInfoBarDelegate::PreviewsUserLeavePreviewCallback());
112 EXPECT_EQ(1U, infobar_service()->infobar_count()); 125 EXPECT_EQ(1U, infobar_service()->infobar_count());
113 126
114 // Navigate and make sure the infobar is dismissed. 127 // Navigate and make sure the infobar is dismissed.
115 content::WebContentsTester::For(web_contents()) 128 content::WebContentsTester::For(web_contents())
116 ->NavigateAndCommit(GURL(kTestUrl)); 129 ->NavigateAndCommit(GURL(kTestUrl));
117 EXPECT_EQ(0U, infobar_service()->infobar_count()); 130 EXPECT_EQ(0U, infobar_service()->infobar_count());
131 EXPECT_FALSE(infobar_reload_by_user_.value());
118 132
119 tester.ExpectBucketCount( 133 tester.ExpectBucketCount(
120 kUMAPreviewsInfoBarActionLoFi, 134 kUMAPreviewsInfoBarActionLoFi,
121 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); 135 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1);
122 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 136 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
123 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 137 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
124 } 138 }
125 139
126 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { 140 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) {
127 base::HistogramTester tester; 141 base::HistogramTester tester;
128 142
129 ConfirmInfoBarDelegate* infobar = 143 ConfirmInfoBarDelegate* infobar =
130 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 144 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
131 145
132 // Simulate dismissing the infobar. 146 // Simulate dismissing the infobar.
133 infobar->InfoBarDismissed(); 147 infobar->InfoBarDismissed();
134 infobar_service()->infobar_at(0)->RemoveSelf(); 148 infobar_service()->infobar_at(0)->RemoveSelf();
135 EXPECT_EQ(0U, infobar_service()->infobar_count()); 149 EXPECT_EQ(0U, infobar_service()->infobar_count());
136 150
137 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, 151 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
138 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, 152 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER,
139 1); 153 1);
140 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 154 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
141 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 155 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
156 EXPECT_FALSE(infobar_reload_by_user_.value());
142 } 157 }
143 158
144 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLink) { 159 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLink) {
145 base::HistogramTester tester; 160 base::HistogramTester tester;
146 161
147 ConfirmInfoBarDelegate* infobar = 162 ConfirmInfoBarDelegate* infobar =
148 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 163 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
149 164
150 // Simulate clicking the infobar link. 165 // Simulate clicking the infobar link.
151 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 166 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
152 infobar_service()->infobar_at(0)->RemoveSelf(); 167 infobar_service()->infobar_at(0)->RemoveSelf();
153 EXPECT_EQ(0U, infobar_service()->infobar_count()); 168 EXPECT_EQ(0U, infobar_service()->infobar_count());
154 169
155 tester.ExpectBucketCount( 170 tester.ExpectBucketCount(
156 kUMAPreviewsInfoBarActionLoFi, 171 kUMAPreviewsInfoBarActionLoFi,
157 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 172 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
158 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 173 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
159 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 174 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
175 EXPECT_TRUE(infobar_reload_by_user_.value());
160 } 176 }
161 177
162 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { 178 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) {
163 ConfirmInfoBarDelegate* infobar = 179 ConfirmInfoBarDelegate* infobar =
164 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 180 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
165 181
166 // Simulate dismissing the infobar. 182 // Simulate dismissing the infobar.
167 infobar->InfoBarDismissed(); 183 infobar->InfoBarDismissed();
168 infobar_service()->infobar_at(0)->RemoveSelf(); 184 infobar_service()->infobar_at(0)->RemoveSelf();
169 EXPECT_EQ(0U, infobar_service()->infobar_count()); 185 EXPECT_EQ(0U, infobar_service()->infobar_count());
170 186
171 PreviewsInfoBarDelegate::Create(web_contents(), 187 PreviewsInfoBarDelegate::Create(
172 PreviewsInfoBarDelegate::LOFI); 188 web_contents(), PreviewsInfoBarDelegate::LOFI,
189 PreviewsInfoBarDelegate::PreviewsUserLeavePreviewCallback());
173 190
174 // Infobar should not be shown again since a navigation hasn't happened. 191 // Infobar should not be shown again since a navigation hasn't happened.
175 EXPECT_EQ(0U, infobar_service()->infobar_count()); 192 EXPECT_EQ(0U, infobar_service()->infobar_count());
176 193
177 // Navigate and show infobar again. 194 // Navigate and show infobar again.
178 content::WebContentsTester::For(web_contents()) 195 content::WebContentsTester::For(web_contents())
179 ->NavigateAndCommit(GURL(kTestUrl)); 196 ->NavigateAndCommit(GURL(kTestUrl));
180 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 197 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
181 } 198 }
182 199
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), 260 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE),
244 infobar->GetMessageText()); 261 infobar->GetMessageText());
245 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 262 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
246 infobar->GetLinkText()); 263 infobar->GetLinkText());
247 #if defined(OS_ANDROID) 264 #if defined(OS_ANDROID)
248 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 265 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
249 #else 266 #else
250 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 267 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
251 #endif 268 #endif
252 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698