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

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

Issue 2581533003: Show the Data Saver string for offline previews when Data Saver is enabled (Closed)
Patch Set: bengr comments Created 4 years 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" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 base::ThreadTaskRunnerHandle::Get(), 76 base::ThreadTaskRunnerHandle::Get(),
77 base::ThreadTaskRunnerHandle::Get()); 77 base::ThreadTaskRunnerHandle::Get());
78 } 78 }
79 79
80 void TearDown() override { 80 void TearDown() override {
81 drp_test_context_->DestroySettings(); 81 drp_test_context_->DestroySettings();
82 ChromeRenderViewHostTestHarness::TearDown(); 82 ChromeRenderViewHostTestHarness::TearDown();
83 } 83 }
84 84
85 ConfirmInfoBarDelegate* CreateInfoBar( 85 ConfirmInfoBarDelegate* CreateInfoBar(
86 PreviewsInfoBarDelegate::PreviewsInfoBarType type) { 86 PreviewsInfoBarDelegate::PreviewsInfoBarType type,
87 bool is_data_saver_user) {
87 PreviewsInfoBarDelegate::Create( 88 PreviewsInfoBarDelegate::Create(
88 web_contents(), type, 89 web_contents(), type, is_data_saver_user,
89 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar, 90 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar,
90 base::Unretained(this))); 91 base::Unretained(this)));
91 92
92 InfoBarService* infobar_service = 93 InfoBarService* infobar_service =
93 InfoBarService::FromWebContents(web_contents()); 94 InfoBarService::FromWebContents(web_contents());
94 EXPECT_EQ(1U, infobar_service->infobar_count()); 95 EXPECT_EQ(1U, infobar_service->infobar_count());
95 96
96 return infobar_service->infobar_at(0) 97 return infobar_service->infobar_at(0)
97 ->delegate() 98 ->delegate()
98 ->AsConfirmInfoBarDelegate(); 99 ->AsConfirmInfoBarDelegate();
99 } 100 }
100 101
101 void OnDismissPreviewsInfobar(bool user_opt_out) { 102 void OnDismissPreviewsInfobar(bool user_opt_out) {
102 user_opt_out_ = user_opt_out; 103 user_opt_out_ = user_opt_out;
103 } 104 }
104 105
105 InfoBarService* infobar_service() { 106 InfoBarService* infobar_service() {
106 return InfoBarService::FromWebContents(web_contents()); 107 return InfoBarService::FromWebContents(web_contents());
107 } 108 }
108 109
109 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> 110 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
110 drp_test_context_; 111 drp_test_context_;
111 112
112 base::Optional<bool> user_opt_out_; 113 base::Optional<bool> user_opt_out_;
113 }; 114 };
114 115
115 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { 116 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) {
116 base::HistogramTester tester; 117 base::HistogramTester tester;
117 118
118 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 119 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
119 120
120 // Try showing a second infobar. Another should not be shown since the page 121 // Try showing a second infobar. Another should not be shown since the page
121 // has not navigated. 122 // has not navigated.
122 PreviewsInfoBarDelegate::Create( 123 PreviewsInfoBarDelegate::Create(
123 web_contents(), PreviewsInfoBarDelegate::LOFI, 124 web_contents(), PreviewsInfoBarDelegate::LOFI,
125 true /* is_data_saver_user */,
124 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 126 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
125 EXPECT_EQ(1U, infobar_service()->infobar_count()); 127 EXPECT_EQ(1U, infobar_service()->infobar_count());
126 128
127 // Navigate and make sure the infobar is dismissed. 129 // Navigate and make sure the infobar is dismissed.
128 content::WebContentsTester::For(web_contents()) 130 content::WebContentsTester::For(web_contents())
129 ->NavigateAndCommit(GURL(kTestUrl)); 131 ->NavigateAndCommit(GURL(kTestUrl));
130 EXPECT_EQ(0U, infobar_service()->infobar_count()); 132 EXPECT_EQ(0U, infobar_service()->infobar_count());
131 EXPECT_FALSE(user_opt_out_.value()); 133 EXPECT_FALSE(user_opt_out_.value());
132 134
133 tester.ExpectBucketCount( 135 tester.ExpectBucketCount(
134 kUMAPreviewsInfoBarActionLoFi, 136 kUMAPreviewsInfoBarActionLoFi,
135 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); 137 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1);
136 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 138 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
137 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 139 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
138 } 140 }
139 141
140 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { 142 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) {
141 base::HistogramTester tester; 143 base::HistogramTester tester;
142 144
143 ConfirmInfoBarDelegate* infobar = 145 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
144 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 146 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
145 147
146 // Simulate dismissing the infobar. 148 // Simulate dismissing the infobar.
147 infobar->InfoBarDismissed(); 149 infobar->InfoBarDismissed();
148 infobar_service()->infobar_at(0)->RemoveSelf(); 150 infobar_service()->infobar_at(0)->RemoveSelf();
149 EXPECT_EQ(0U, infobar_service()->infobar_count()); 151 EXPECT_EQ(0U, infobar_service()->infobar_count());
150 152
151 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, 153 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
152 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, 154 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER,
153 1); 155 1);
154 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 156 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
155 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 157 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
156 EXPECT_FALSE(user_opt_out_.value()); 158 EXPECT_FALSE(user_opt_out_.value());
157 } 159 }
158 160
159 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLink) { 161 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLink) {
160 base::HistogramTester tester; 162 base::HistogramTester tester;
161 163
162 ConfirmInfoBarDelegate* infobar = 164 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
163 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 165 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
164 166
165 // Simulate clicking the infobar link. 167 // Simulate clicking the infobar link.
166 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 168 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
167 infobar_service()->infobar_at(0)->RemoveSelf(); 169 infobar_service()->infobar_at(0)->RemoveSelf();
168 EXPECT_EQ(0U, infobar_service()->infobar_count()); 170 EXPECT_EQ(0U, infobar_service()->infobar_count());
169 171
170 tester.ExpectBucketCount( 172 tester.ExpectBucketCount(
171 kUMAPreviewsInfoBarActionLoFi, 173 kUMAPreviewsInfoBarActionLoFi,
172 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 174 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
173 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 175 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
174 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 176 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
175 EXPECT_TRUE(user_opt_out_.value()); 177 EXPECT_TRUE(user_opt_out_.value());
176 } 178 }
177 179
178 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { 180 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) {
179 ConfirmInfoBarDelegate* infobar = 181 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
180 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 182 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
181 183
182 // Simulate dismissing the infobar. 184 // Simulate dismissing the infobar.
183 infobar->InfoBarDismissed(); 185 infobar->InfoBarDismissed();
184 infobar_service()->infobar_at(0)->RemoveSelf(); 186 infobar_service()->infobar_at(0)->RemoveSelf();
185 EXPECT_EQ(0U, infobar_service()->infobar_count()); 187 EXPECT_EQ(0U, infobar_service()->infobar_count());
186 188
187 PreviewsInfoBarDelegate::Create( 189 PreviewsInfoBarDelegate::Create(
188 web_contents(), PreviewsInfoBarDelegate::LOFI, 190 web_contents(), PreviewsInfoBarDelegate::LOFI,
191 true /* is_data_saver_user */,
189 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 192 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
190 193
191 // Infobar should not be shown again since a navigation hasn't happened. 194 // Infobar should not be shown again since a navigation hasn't happened.
192 EXPECT_EQ(0U, infobar_service()->infobar_count()); 195 EXPECT_EQ(0U, infobar_service()->infobar_count());
193 196
194 // Navigate and show infobar again. 197 // Navigate and show infobar again.
195 content::WebContentsTester::For(web_contents()) 198 content::WebContentsTester::For(web_contents())
196 ->NavigateAndCommit(GURL(kTestUrl)); 199 ->NavigateAndCommit(GURL(kTestUrl));
197 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 200 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
198 } 201 }
199 202
200 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { 203 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) {
201 base::HistogramTester tester; 204 base::HistogramTester tester;
202 205
203 ConfirmInfoBarDelegate* infobar = 206 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
204 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 207 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */);
205 208
206 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, 209 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi,
207 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 210 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
208 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 211 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
209 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 212 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
210 213
211 ASSERT_TRUE(infobar); 214 ASSERT_TRUE(infobar);
212 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 215 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
213 infobar->GetMessageText()); 216 infobar->GetMessageText());
214 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 217 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
215 infobar->GetLinkText()); 218 infobar->GetLinkText());
216 #if defined(OS_ANDROID) 219 #if defined(OS_ANDROID)
217 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 220 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
218 #else 221 #else
219 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 222 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
220 #endif 223 #endif
221 } 224 }
222 225
223 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { 226 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) {
224 base::HistogramTester tester; 227 base::HistogramTester tester;
225 228
226 ConfirmInfoBarDelegate* infobar = 229 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
227 CreateInfoBar(PreviewsInfoBarDelegate::LITE_PAGE); 230 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */);
228 231
229 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, 232 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage,
230 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 233 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
231 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 234 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
232 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 235 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
233 236
234 // Check the strings. 237 // Check the strings.
235 ASSERT_TRUE(infobar); 238 ASSERT_TRUE(infobar);
236 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 239 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
237 infobar->GetMessageText()); 240 infobar->GetMessageText());
238 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 241 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
239 infobar->GetLinkText()); 242 infobar->GetLinkText());
240 #if defined(OS_ANDROID) 243 #if defined(OS_ANDROID)
241 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 244 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
242 #else 245 #else
243 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 246 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
244 #endif 247 #endif
245 } 248 }
246 249
247 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarTest) { 250 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) {
248 base::HistogramTester tester; 251 base::HistogramTester tester;
249 252
250 ConfirmInfoBarDelegate* infobar = 253 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
251 CreateInfoBar(PreviewsInfoBarDelegate::OFFLINE); 254 PreviewsInfoBarDelegate::OFFLINE, false /* is_data_saver_user */);
252 255
253 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 256 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
254 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 257 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
255 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 258 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
256 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 259 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
257 260
258 // Check the strings. 261 // Check the strings.
259 ASSERT_TRUE(infobar); 262 ASSERT_TRUE(infobar);
260 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), 263 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE),
261 infobar->GetMessageText()); 264 infobar->GetMessageText());
262 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 265 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
263 infobar->GetLinkText()); 266 infobar->GetLinkText());
264 #if defined(OS_ANDROID) 267 #if defined(OS_ANDROID)
265 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 268 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
266 #else 269 #else
267 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 270 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
268 #endif 271 #endif
269 } 272 }
273
274 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) {
275 base::HistogramTester tester;
276
277 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
278 PreviewsInfoBarDelegate::OFFLINE, true /* is_data_saver_user */);
279
280 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
281 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
282 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
283 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
284
285 // Check the strings.
286 ASSERT_TRUE(infobar);
287 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
288 infobar->GetMessageText());
289 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
290 infobar->GetLinkText());
291 #if defined(OS_ANDROID)
292 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
293 #else
294 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
295 #endif
296 }
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_delegate.cc ('k') | chrome/browser/previews/previews_infobar_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698