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

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

Issue 2875993002: Converging the two previews type enums (Closed)
Patch Set: megjablon nit 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"
(...skipping 15 matching lines...) Expand all
26 #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"
27 #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"
28 #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"
29 #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"
30 #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"
31 #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"
32 #include "components/infobars/core/confirm_infobar_delegate.h" 32 #include "components/infobars/core/confirm_infobar_delegate.h"
33 #include "components/infobars/core/infobar.h" 33 #include "components/infobars/core/infobar.h"
34 #include "components/infobars/core/infobar_delegate.h" 34 #include "components/infobars/core/infobar_delegate.h"
35 #include "components/prefs/pref_registry_simple.h" 35 #include "components/prefs/pref_registry_simple.h"
36 #include "components/previews/core/previews_experiments.h"
36 #include "components/proxy_config/proxy_config_pref_names.h" 37 #include "components/proxy_config/proxy_config_pref_names.h"
37 #include "content/public/browser/navigation_entry.h" 38 #include "content/public/browser/navigation_entry.h"
38 #include "content/public/browser/navigation_handle.h" 39 #include "content/public/browser/navigation_handle.h"
39 #include "content/public/browser/reload_type.h" 40 #include "content/public/browser/reload_type.h"
40 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
41 #include "content/public/browser/web_contents_observer.h" 42 #include "content/public/browser/web_contents_observer.h"
42 #include "content/public/browser/web_contents_user_data.h" 43 #include "content/public/browser/web_contents_user_data.h"
43 #include "content/public/common/referrer.h" 44 #include "content/public/common/referrer.h"
44 #include "content/public/test/test_renderer_host.h" 45 #include "content/public/test/test_renderer_host.h"
45 #include "content/public/test/web_contents_tester.h" 46 #include "content/public/test/web_contents_tester.h"
(...skipping 15 matching lines...) Expand all
61 // Key of the UMA Previews.InfoBarAction.LitePage histogram. 62 // Key of the UMA Previews.InfoBarAction.LitePage histogram.
62 const char kUMAPreviewsInfoBarActionLitePage[] = 63 const char kUMAPreviewsInfoBarActionLitePage[] =
63 "Previews.InfoBarAction.LitePage"; 64 "Previews.InfoBarAction.LitePage";
64 65
65 class TestPreviewsWebContentsObserver 66 class TestPreviewsWebContentsObserver
66 : public content::WebContentsObserver, 67 : public content::WebContentsObserver,
67 public content::WebContentsUserData<TestPreviewsWebContentsObserver> { 68 public content::WebContentsUserData<TestPreviewsWebContentsObserver> {
68 public: 69 public:
69 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents) 70 explicit TestPreviewsWebContentsObserver(content::WebContents* web_contents)
70 : content::WebContentsObserver(web_contents), 71 : content::WebContentsObserver(web_contents),
71 last_navigation_reload_type_(content::ReloadType::NONE) {} 72 last_navigation_reload_type_(content::ReloadType::NONE),
73 should_have_page_id_(true) {}
72 ~TestPreviewsWebContentsObserver() override {} 74 ~TestPreviewsWebContentsObserver() override {}
73 75
74 content::ReloadType last_navigation_reload_type() { 76 content::ReloadType last_navigation_reload_type() {
75 return last_navigation_reload_type_; 77 return last_navigation_reload_type_;
76 } 78 }
77 79
78 void DidStartNavigation( 80 void DidStartNavigation(
79 content::NavigationHandle* navigation_handle) override { 81 content::NavigationHandle* navigation_handle) override {
80 ChromeNavigationData* chrome_navigation_data = new ChromeNavigationData(); 82 ChromeNavigationData* chrome_navigation_data = new ChromeNavigationData();
81 content::WebContentsTester::For(web_contents()) 83 content::WebContentsTester::For(web_contents())
82 ->SetNavigationData(navigation_handle, 84 ->SetNavigationData(navigation_handle,
83 base::WrapUnique(chrome_navigation_data)); 85 base::WrapUnique(chrome_navigation_data));
84 data_reduction_proxy::DataReductionProxyData* data = 86 data_reduction_proxy::DataReductionProxyData* data =
85 new data_reduction_proxy::DataReductionProxyData(); 87 new data_reduction_proxy::DataReductionProxyData();
86 chrome_navigation_data->SetDataReductionProxyData(base::WrapUnique(data)); 88 chrome_navigation_data->SetDataReductionProxyData(base::WrapUnique(data));
87 data->set_used_data_reduction_proxy(true); 89 data->set_used_data_reduction_proxy(true);
88 data->set_page_id(1u); 90 if (should_have_page_id_)
91 data->set_page_id(1u);
89 } 92 }
90 93
91 void DidFinishNavigation( 94 void DidFinishNavigation(
92 content::NavigationHandle* navigation_handle) override { 95 content::NavigationHandle* navigation_handle) override {
93 last_navigation_reload_type_ = navigation_handle->GetReloadType(); 96 last_navigation_reload_type_ = navigation_handle->GetReloadType();
94 } 97 }
95 98
99 void set_should_have_page_id(bool should_have_page_id) {
100 should_have_page_id_ = should_have_page_id;
101 }
102
96 private: 103 private:
97 content::ReloadType last_navigation_reload_type_; 104 content::ReloadType last_navigation_reload_type_;
105 bool should_have_page_id_;
98 }; 106 };
99 107
100 } // namespace 108 } // namespace
101 109
102 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver); 110 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver);
103 111
104 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness { 112 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness {
105 protected: 113 protected:
106 void SetUp() override { 114 void SetUp() override {
107 ChromeRenderViewHostTestHarness::SetUp(); 115 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 23 matching lines...) Expand all
131 base::WrapUnique(new data_reduction_proxy::DataStore()), 139 base::WrapUnique(new data_reduction_proxy::DataStore()),
132 base::ThreadTaskRunnerHandle::Get(), 140 base::ThreadTaskRunnerHandle::Get(),
133 base::ThreadTaskRunnerHandle::Get()); 141 base::ThreadTaskRunnerHandle::Get());
134 } 142 }
135 143
136 void TearDown() override { 144 void TearDown() override {
137 drp_test_context_->DestroySettings(); 145 drp_test_context_->DestroySettings();
138 ChromeRenderViewHostTestHarness::TearDown(); 146 ChromeRenderViewHostTestHarness::TearDown();
139 } 147 }
140 148
141 ConfirmInfoBarDelegate* CreateInfoBar( 149 ConfirmInfoBarDelegate* CreateInfoBar(previews::PreviewsType type,
142 PreviewsInfoBarDelegate::PreviewsInfoBarType type, 150 bool is_data_saver_user) {
143 bool is_data_saver_user) {
144 PreviewsInfoBarDelegate::Create( 151 PreviewsInfoBarDelegate::Create(
145 web_contents(), type, is_data_saver_user, 152 web_contents(), type, is_data_saver_user,
146 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar, 153 base::Bind(&PreviewsInfoBarDelegateUnitTest::OnDismissPreviewsInfobar,
147 base::Unretained(this))); 154 base::Unretained(this)));
148 155
149 InfoBarService* infobar_service = 156 InfoBarService* infobar_service =
150 InfoBarService::FromWebContents(web_contents()); 157 InfoBarService::FromWebContents(web_contents());
151 EXPECT_EQ(1U, infobar_service->infobar_count()); 158 EXPECT_EQ(1U, infobar_service->infobar_count());
152 159
153 return infobar_service->infobar_at(0) 160 return infobar_service->infobar_at(0)
(...skipping 11 matching lines...) Expand all
165 172
166 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> 173 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext>
167 drp_test_context_; 174 drp_test_context_;
168 175
169 base::Optional<bool> user_opt_out_; 176 base::Optional<bool> user_opt_out_;
170 }; 177 };
171 178
172 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { 179 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) {
173 base::HistogramTester tester; 180 base::HistogramTester tester;
174 181
175 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 182 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */);
176 183
177 // Try showing a second infobar. Another should not be shown since the page 184 // Try showing a second infobar. Another should not be shown since the page
178 // has not navigated. 185 // has not navigated.
179 PreviewsInfoBarDelegate::Create( 186 PreviewsInfoBarDelegate::Create(
180 web_contents(), PreviewsInfoBarDelegate::LOFI, 187 web_contents(), previews::PreviewsType::LOFI,
181 true /* is_data_saver_user */, 188 true /* is_data_saver_user */,
182 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 189 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
183 EXPECT_EQ(1U, infobar_service()->infobar_count()); 190 EXPECT_EQ(1U, infobar_service()->infobar_count());
184 191
185 // Navigate and make sure the infobar is dismissed. 192 // Navigate and make sure the infobar is dismissed.
186 NavigateAndCommit(GURL(kTestUrl)); 193 NavigateAndCommit(GURL(kTestUrl));
187 EXPECT_EQ(0U, infobar_service()->infobar_count()); 194 EXPECT_EQ(0U, infobar_service()->infobar_count());
188 EXPECT_FALSE(user_opt_out_.value()); 195 EXPECT_FALSE(user_opt_out_.value());
189 196
190 tester.ExpectBucketCount( 197 tester.ExpectBucketCount(
191 kUMAPreviewsInfoBarActionLoFi, 198 kUMAPreviewsInfoBarActionLoFi,
192 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); 199 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1);
193 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 200 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
194 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 201 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
195 } 202 }
196 203
197 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { 204 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) {
198 base::HistogramTester tester; 205 base::HistogramTester tester;
199 206
200 // Navigate to test URL, so we can reload later. 207 // Navigate to test URL, so we can reload later.
201 NavigateAndCommit(GURL(kTestUrl)); 208 NavigateAndCommit(GURL(kTestUrl));
202 209
203 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 210 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */);
204 211
205 // Try showing a second infobar. Another should not be shown since the page 212 // Try showing a second infobar. Another should not be shown since the page
206 // has not navigated. 213 // has not navigated.
207 PreviewsInfoBarDelegate::Create( 214 PreviewsInfoBarDelegate::Create(
208 web_contents(), PreviewsInfoBarDelegate::LOFI, 215 web_contents(), previews::PreviewsType::LOFI,
209 true /* is_data_saver_user */, 216 true /* is_data_saver_user */,
210 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 217 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
211 EXPECT_EQ(1U, infobar_service()->infobar_count()); 218 EXPECT_EQ(1U, infobar_service()->infobar_count());
212 219
213 // Navigate to test URL as a reload to dismiss the infobar. 220 // Navigate to test URL as a reload to dismiss the infobar.
214 controller().LoadURL(GURL(kTestUrl), content::Referrer(), 221 controller().LoadURL(GURL(kTestUrl), content::Referrer(),
215 ui::PAGE_TRANSITION_RELOAD, std::string()); 222 ui::PAGE_TRANSITION_RELOAD, std::string());
216 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 223 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
217 224
218 EXPECT_EQ(0U, infobar_service()->infobar_count()); 225 EXPECT_EQ(0U, infobar_service()->infobar_count());
(...skipping 11 matching lines...) Expand all
230 237
231 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() 238 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
232 ->pingback_client() 239 ->pingback_client()
233 ->OptOutsSizeForTesting()); 240 ->OptOutsSizeForTesting());
234 } 241 }
235 242
236 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { 243 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) {
237 base::HistogramTester tester; 244 base::HistogramTester tester;
238 245
239 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 246 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
240 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 247 previews::PreviewsType::LOFI, true /* is_data_saver_user */);
241 248
242 // Simulate dismissing the infobar. 249 // Simulate dismissing the infobar.
243 infobar->InfoBarDismissed(); 250 infobar->InfoBarDismissed();
244 infobar_service()->infobar_at(0)->RemoveSelf(); 251 infobar_service()->infobar_at(0)->RemoveSelf();
245 EXPECT_EQ(0U, infobar_service()->infobar_count()); 252 EXPECT_EQ(0U, infobar_service()->infobar_count());
246 253
247 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, 254 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
248 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER, 255 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_USER,
249 1); 256 1);
250 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 257 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
251 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 258 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
252 EXPECT_FALSE(user_opt_out_.value()); 259 EXPECT_FALSE(user_opt_out_.value());
253 } 260 }
254 261
255 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) { 262 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestTabClosedDismissal) {
256 base::HistogramTester tester; 263 base::HistogramTester tester;
257 264
258 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 265 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */);
259 266
260 // Delete the infobar without any other infobar actions. 267 // Delete the infobar without any other infobar actions.
261 infobar_service()->infobar_at(0)->RemoveSelf(); 268 infobar_service()->infobar_at(0)->RemoveSelf();
262 EXPECT_EQ(0U, infobar_service()->infobar_count()); 269 EXPECT_EQ(0U, infobar_service()->infobar_count());
263 270
264 tester.ExpectBucketCount( 271 tester.ExpectBucketCount(
265 kUMAPreviewsInfoBarActionLoFi, 272 kUMAPreviewsInfoBarActionLoFi,
266 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1); 273 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_TAB_CLOSURE, 1);
267 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 274 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
268 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 275 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
(...skipping 13 matching lines...) Expand all
282 if (test.using_previews_blacklist) { 289 if (test.using_previews_blacklist) {
283 base::FieldTrialList::CreateFieldTrial( 290 base::FieldTrialList::CreateFieldTrial(
284 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); 291 "DataReductionProxyPreviewsBlackListTransition", "Enabled_");
285 } 292 }
286 base::HistogramTester tester; 293 base::HistogramTester tester;
287 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. 294 // Call Reload and CommitPendingNavigation to force DidFinishNavigation.
288 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); 295 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
289 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 296 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
290 297
291 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 298 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
292 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 299 previews::PreviewsType::LOFI, true /* is_data_saver_user */);
293 300
294 // Simulate clicking the infobar link. 301 // Simulate clicking the infobar link.
295 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 302 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
296 infobar_service()->infobar_at(0)->RemoveSelf(); 303 infobar_service()->infobar_at(0)->RemoveSelf();
297 EXPECT_EQ(0U, infobar_service()->infobar_count()); 304 EXPECT_EQ(0U, infobar_service()->infobar_count());
298 305
299 tester.ExpectBucketCount( 306 tester.ExpectBucketCount(
300 kUMAPreviewsInfoBarActionLoFi, 307 kUMAPreviewsInfoBarActionLoFi,
301 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 308 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
302 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, 309 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1,
303 drp_test_context_->pref_service()->GetInteger( 310 drp_test_context_->pref_service()->GetInteger(
304 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 311 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
305 EXPECT_TRUE(user_opt_out_.value()); 312 EXPECT_TRUE(user_opt_out_.value());
306 313
307 auto* data_reduction_proxy_settings = 314 auto* data_reduction_proxy_settings =
308 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 315 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
309 web_contents()->GetBrowserContext()); 316 web_contents()->GetBrowserContext());
310 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 317 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
311 ->pingback_client() 318 ->pingback_client()
312 ->OptOutsSizeForTesting()); 319 ->OptOutsSizeForTesting());
313 } 320 }
314 } 321 }
315 322
316 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { 323 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) {
317 base::HistogramTester tester; 324 base::HistogramTester tester;
318 325
319 NavigateAndCommit(GURL(kTestUrl)); 326 NavigateAndCommit(GURL(kTestUrl));
320 327
321 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 328 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
322 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); 329 previews::PreviewsType::LITE_PAGE, true /* is_data_saver_user */);
323 330
324 // Simulate clicking the infobar link. 331 // Simulate clicking the infobar link.
325 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 332 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
326 infobar_service()->infobar_at(0)->RemoveSelf(); 333 infobar_service()->infobar_at(0)->RemoveSelf();
327 EXPECT_EQ(0U, infobar_service()->infobar_count()); 334 EXPECT_EQ(0U, infobar_service()->infobar_count());
328 335
329 tester.ExpectBucketCount( 336 tester.ExpectBucketCount(
330 kUMAPreviewsInfoBarActionLitePage, 337 kUMAPreviewsInfoBarActionLitePage,
331 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 338 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
332 339
333 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 340 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
334 341
335 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, 342 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE,
336 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) 343 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
337 ->last_navigation_reload_type()); 344 ->last_navigation_reload_type());
338 345
339 auto* data_reduction_proxy_settings = 346 auto* data_reduction_proxy_settings =
340 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 347 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
341 web_contents()->GetBrowserContext()); 348 web_contents()->GetBrowserContext());
342 349
343 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 350 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
344 ->pingback_client() 351 ->pingback_client()
345 ->OptOutsSizeForTesting()); 352 ->OptOutsSizeForTesting());
346 } 353 }
347 354
348 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { 355 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) {
349 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 356 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
350 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 357 previews::PreviewsType::LOFI, true /* is_data_saver_user */);
351 358
352 // Simulate dismissing the infobar. 359 // Simulate dismissing the infobar.
353 infobar->InfoBarDismissed(); 360 infobar->InfoBarDismissed();
354 infobar_service()->infobar_at(0)->RemoveSelf(); 361 infobar_service()->infobar_at(0)->RemoveSelf();
355 EXPECT_EQ(0U, infobar_service()->infobar_count()); 362 EXPECT_EQ(0U, infobar_service()->infobar_count());
356 363
357 PreviewsInfoBarDelegate::Create( 364 PreviewsInfoBarDelegate::Create(
358 web_contents(), PreviewsInfoBarDelegate::LOFI, 365 web_contents(), previews::PreviewsType::LOFI,
359 true /* is_data_saver_user */, 366 true /* is_data_saver_user */,
360 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); 367 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
361 368
362 // Infobar should not be shown again since a navigation hasn't happened. 369 // Infobar should not be shown again since a navigation hasn't happened.
363 EXPECT_EQ(0U, infobar_service()->infobar_count()); 370 EXPECT_EQ(0U, infobar_service()->infobar_count());
364 371
365 // Navigate and show infobar again. 372 // Navigate and show infobar again.
366 NavigateAndCommit(GURL(kTestUrl)); 373 NavigateAndCommit(GURL(kTestUrl));
367 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 374 CreateInfoBar(previews::PreviewsType::LOFI, true /* is_data_saver_user */);
368 } 375 }
369 376
370 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) { 377 TEST_F(PreviewsInfoBarDelegateUnitTest, LoFiInfobarTest) {
371 base::HistogramTester tester; 378 base::HistogramTester tester;
372 379
373 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 380 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
374 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); 381 previews::PreviewsType::LOFI, true /* is_data_saver_user */);
375 382
376 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi, 383 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLoFi,
377 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 384 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
378 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 385 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
379 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 386 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
380 387
381 ASSERT_TRUE(infobar); 388 ASSERT_TRUE(infobar);
382 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 389 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
383 infobar->GetMessageText()); 390 infobar->GetMessageText());
384 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 391 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
385 infobar->GetLinkText()); 392 infobar->GetLinkText());
386 #if defined(OS_ANDROID) 393 #if defined(OS_ANDROID)
387 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 394 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
388 #else 395 #else
389 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 396 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
390 #endif 397 #endif
391 } 398 }
392 399
393 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) { 400 TEST_F(PreviewsInfoBarDelegateUnitTest, PreviewInfobarTest) {
394 base::HistogramTester tester; 401 base::HistogramTester tester;
395 402
396 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 403 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
397 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); 404 previews::PreviewsType::LITE_PAGE, true /* is_data_saver_user */);
398 405
399 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage, 406 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionLitePage,
400 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 407 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
401 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger( 408 EXPECT_EQ(1, drp_test_context_->pref_service()->GetInteger(
402 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 409 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
403 410
404 // Check the strings. 411 // Check the strings.
405 ASSERT_TRUE(infobar); 412 ASSERT_TRUE(infobar);
406 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 413 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
407 infobar->GetMessageText()); 414 infobar->GetMessageText());
408 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 415 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
409 infobar->GetLinkText()); 416 infobar->GetLinkText());
410 #if defined(OS_ANDROID) 417 #if defined(OS_ANDROID)
411 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 418 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
412 #else 419 #else
413 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 420 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
414 #endif 421 #endif
415 } 422 }
416 423
417 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) { 424 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarNonDataSaverUserTest) {
418 base::HistogramTester tester; 425 base::HistogramTester tester;
419 426
420 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 427 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
421 PreviewsInfoBarDelegate::OFFLINE, false /* is_data_saver_user */); 428 previews::PreviewsType::OFFLINE, false /* is_data_saver_user */);
422 429
423 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 430 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
424 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 431 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
425 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 432 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
426 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 433 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
427 434
428 // Check the strings. 435 // Check the strings.
429 ASSERT_TRUE(infobar); 436 ASSERT_TRUE(infobar);
430 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), 437 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE),
431 infobar->GetMessageText()); 438 infobar->GetMessageText());
432 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 439 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
433 infobar->GetLinkText()); 440 infobar->GetLinkText());
434 #if defined(OS_ANDROID) 441 #if defined(OS_ANDROID)
435 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 442 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
436 #else 443 #else
437 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 444 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
438 #endif 445 #endif
439 } 446 }
440 447
441 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) { 448 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDataSaverUserTest) {
442 base::HistogramTester tester; 449 base::HistogramTester tester;
443 450
444 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 451 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
445 PreviewsInfoBarDelegate::OFFLINE, true /* is_data_saver_user */); 452 previews::PreviewsType::OFFLINE, true /* is_data_saver_user */);
446 453
447 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 454 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
448 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 455 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
449 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 456 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
450 data_reduction_proxy::prefs::kLoFiUIShownPerSession)); 457 data_reduction_proxy::prefs::kLoFiUIShownPerSession));
451 458
452 // Check the strings. 459 // Check the strings.
453 ASSERT_TRUE(infobar); 460 ASSERT_TRUE(infobar);
454 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), 461 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE),
455 infobar->GetMessageText()); 462 infobar->GetMessageText());
456 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 463 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
457 infobar->GetLinkText()); 464 infobar->GetLinkText());
458 #if defined(OS_ANDROID) 465 #if defined(OS_ANDROID)
459 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 466 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
460 #else 467 #else
461 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 468 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
462 #endif 469 #endif
463 } 470 }
464 471
465 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { 472 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) {
466 base::HistogramTester tester; 473 base::HistogramTester tester;
467 474
475 TestPreviewsWebContentsObserver::FromWebContents(web_contents())
476 ->set_should_have_page_id(false);
477
468 NavigateAndCommit(GURL(kTestUrl)); 478 NavigateAndCommit(GURL(kTestUrl));
469 479
470 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 480 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
471 PreviewsInfoBarDelegate::OFFLINE, true /* is_data_saver_user */); 481 previews::PreviewsType::OFFLINE, true /* is_data_saver_user */);
472 482
473 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, 483 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline,
474 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); 484 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1);
475 485
476 // Simulate clicking the infobar link. 486 // Simulate clicking the infobar link.
477 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 487 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
478 infobar_service()->infobar_at(0)->RemoveSelf(); 488 infobar_service()->infobar_at(0)->RemoveSelf();
479 EXPECT_EQ(0U, infobar_service()->infobar_count()); 489 EXPECT_EQ(0U, infobar_service()->infobar_count());
480 490
481 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 491 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
(...skipping 10 matching lines...) Expand all
492 ->pingback_client() 502 ->pingback_client()
493 ->OptOutsSizeForTesting()); 503 ->OptOutsSizeForTesting());
494 } 504 }
495 505
496 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { 506 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) {
497 base::HistogramTester tester; 507 base::HistogramTester tester;
498 508
499 NavigateAndCommit(GURL(kTestUrl)); 509 NavigateAndCommit(GURL(kTestUrl));
500 510
501 ConfirmInfoBarDelegate* infobar = CreateInfoBar( 511 ConfirmInfoBarDelegate* infobar = CreateInfoBar(
502 PreviewsInfoBarDelegate::LITE_PAGE, true /* is_data_saver_user */); 512 previews::PreviewsType::LITE_PAGE, true /* is_data_saver_user */);
503 513
504 // Simulate clicking the infobar link. 514 // Simulate clicking the infobar link.
505 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) 515 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB))
506 infobar_service()->infobar_at(0)->RemoveSelf(); 516 infobar_service()->infobar_at(0)->RemoveSelf();
507 EXPECT_EQ(0U, infobar_service()->infobar_count()); 517 EXPECT_EQ(0U, infobar_service()->infobar_count());
508 518
509 tester.ExpectBucketCount( 519 tester.ExpectBucketCount(
510 kUMAPreviewsInfoBarActionLitePage, 520 kUMAPreviewsInfoBarActionLitePage,
511 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); 521 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1);
512 522
(...skipping 22 matching lines...) Expand all
535 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() 545 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service()
536 ->pingback_client() 546 ->pingback_client()
537 ->OptOutsSizeForTesting()); 547 ->OptOutsSizeForTesting());
538 548
539 drp_test_context_->RunUntilIdle(); 549 drp_test_context_->RunUntilIdle();
540 550
541 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() 551 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service()
542 ->pingback_client() 552 ->pingback_client()
543 ->OptOutsSizeForTesting()); 553 ->OptOutsSizeForTesting());
544 } 554 }
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