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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc

Issue 330753002: Browser and unit tests for the SB interstitial V3 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed rebase-induced bugs Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 5 #include <list>
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/safe_browsing/malware_details.h" 10 #include "chrome/browser/safe_browsing/malware_details.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 const UnsafeResourceList& unsafe_resources) 55 const UnsafeResourceList& unsafe_resources)
56 : SafeBrowsingBlockingPageV2(manager, web_contents, unsafe_resources) { 56 : SafeBrowsingBlockingPageV2(manager, web_contents, unsafe_resources) {
57 // Don't delay details at all for the unittest. 57 // Don't delay details at all for the unittest.
58 malware_details_proceed_delay_ms_ = 0; 58 malware_details_proceed_delay_ms_ = 0;
59 59
60 // Don't create a view. 60 // Don't create a view.
61 interstitial_page()->DontCreateViewForTesting(); 61 interstitial_page()->DontCreateViewForTesting();
62 } 62 }
63 }; 63 };
64 64
65 // A SafeBrowingBlockingPage class that does not create windows.
66 class TestSafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPageV3 {
67 public:
68 TestSafeBrowsingBlockingPageV3(SafeBrowsingUIManager* manager,
69 WebContents* web_contents,
70 const UnsafeResourceList& unsafe_resources)
71 : SafeBrowsingBlockingPageV3(manager, web_contents, unsafe_resources) {
72 // Don't delay details at all for the unittest.
73 malware_details_proceed_delay_ms_ = 0;
74
75 // Don't create a view.
76 interstitial_page()->DontCreateViewForTesting();
77 }
78 };
79
65 class TestSafeBrowsingUIManager: public SafeBrowsingUIManager { 80 class TestSafeBrowsingUIManager: public SafeBrowsingUIManager {
66 public: 81 public:
67 explicit TestSafeBrowsingUIManager(SafeBrowsingService* service) 82 explicit TestSafeBrowsingUIManager(SafeBrowsingService* service)
68 : SafeBrowsingUIManager(service) { 83 : SafeBrowsingUIManager(service) {
69 } 84 }
70 85
71 virtual void SendSerializedMalwareDetails( 86 virtual void SendSerializedMalwareDetails(
72 const std::string& serialized) OVERRIDE { 87 const std::string& serialized) OVERRIDE {
73 details_.push_back(serialized); 88 details_.push_back(serialized);
74 } 89 }
75 90
76 std::list<std::string>* GetDetails() { 91 std::list<std::string>* GetDetails() {
77 return &details_; 92 return &details_;
78 } 93 }
79 94
80 private: 95 private:
81 virtual ~TestSafeBrowsingUIManager() {} 96 virtual ~TestSafeBrowsingUIManager() {}
82 97
83 std::list<std::string> details_; 98 std::list<std::string> details_;
84 }; 99 };
85 100
101 template <class SBInterstitialPage>
86 class TestSafeBrowsingBlockingPageFactory 102 class TestSafeBrowsingBlockingPageFactory
87 : public SafeBrowsingBlockingPageFactory { 103 : public SafeBrowsingBlockingPageFactory {
88 public: 104 public:
89 TestSafeBrowsingBlockingPageFactory() { } 105 TestSafeBrowsingBlockingPageFactory() { }
90 virtual ~TestSafeBrowsingBlockingPageFactory() { } 106 virtual ~TestSafeBrowsingBlockingPageFactory() { }
91 107
92 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 108 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
93 SafeBrowsingUIManager* manager, 109 SafeBrowsingUIManager* manager,
94 WebContents* web_contents, 110 WebContents* web_contents,
95 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) 111 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
96 OVERRIDE { 112 OVERRIDE {
97 // TODO(mattm): remove this when SafeBrowsingBlockingPageV2 supports 113 // TODO(mattm): remove this when SafeBrowsingBlockingPageV2 supports
98 // multi-threat warnings. 114 // multi-threat warnings.
99 if (unsafe_resources.size() == 1 && 115 if (unsafe_resources.size() == 1 &&
100 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || 116 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE ||
101 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING)) { 117 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING)) {
102 return new TestSafeBrowsingBlockingPageV2(manager, web_contents, 118 return new SBInterstitialPage(manager, web_contents, unsafe_resources);
103 unsafe_resources);
104 } 119 }
105 return new TestSafeBrowsingBlockingPageV1(manager, web_contents, 120 return new TestSafeBrowsingBlockingPageV1(manager, web_contents,
106 unsafe_resources); 121 unsafe_resources);
107 } 122 }
108 }; 123 };
109 124
110 } // namespace 125 } // namespace
111 126
127 template <class SBInterstitialPage>
112 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { 128 class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness {
113 public: 129 public:
114 // The decision the user made. 130 // The decision the user made.
115 enum UserResponse { 131 enum UserResponse {
116 PENDING, 132 PENDING,
117 OK, 133 OK,
118 CANCEL 134 CANCEL
119 }; 135 };
120 136
121 SafeBrowsingBlockingPageTest() { 137 SafeBrowsingBlockingPageTest() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 resource->url = url; 240 resource->url = url;
225 resource->is_subresource = is_subresource; 241 resource->is_subresource = is_subresource;
226 resource->threat_type = SB_THREAT_TYPE_URL_MALWARE; 242 resource->threat_type = SB_THREAT_TYPE_URL_MALWARE;
227 resource->render_process_host_id = 243 resource->render_process_host_id =
228 web_contents()->GetRenderProcessHost()->GetID(); 244 web_contents()->GetRenderProcessHost()->GetID();
229 resource->render_view_id = 245 resource->render_view_id =
230 web_contents()->GetRenderViewHost()->GetRoutingID(); 246 web_contents()->GetRenderViewHost()->GetRoutingID();
231 } 247 }
232 248
233 UserResponse user_response_; 249 UserResponse user_response_;
234 TestSafeBrowsingBlockingPageFactory factory_; 250 TestSafeBrowsingBlockingPageFactory<SBInterstitialPage> factory_;
235 }; 251 };
236 252
253 typedef ::testing::Types<TestSafeBrowsingBlockingPageV2,
254 TestSafeBrowsingBlockingPageV3> InterstitialTestTypes;
255 TYPED_TEST_CASE(SafeBrowsingBlockingPageTest, InterstitialTestTypes);
256
237 // Tests showing a blocking page for a malware page and not proceeding. 257 // Tests showing a blocking page for a malware page and not proceeding.
238 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { 258 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) {
239 // Enable malware details. 259 // Enable malware details.
240 Profile* profile = Profile::FromBrowserContext( 260 Profile* profile = Profile::FromBrowserContext(
241 web_contents()->GetBrowserContext()); 261 this->web_contents()->GetBrowserContext());
242 profile->GetPrefs()->SetBoolean( 262 profile->GetPrefs()->SetBoolean(
243 prefs::kSafeBrowsingExtendedReportingEnabled, true); 263 prefs::kSafeBrowsingExtendedReportingEnabled, true);
244 264
245 // Start a load. 265 // Start a load.
246 controller().LoadURL(GURL(kBadURL), content::Referrer(), 266 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
247 content::PAGE_TRANSITION_TYPED, std::string()); 267 content::PAGE_TRANSITION_TYPED, std::string());
248 268
249 269
250 // Simulate the load causing a safe browsing interstitial to be shown. 270 // Simulate the load causing a safe browsing interstitial to be shown.
251 ShowInterstitial(false, kBadURL); 271 this->ShowInterstitial(false, kBadURL);
252 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 272 SafeBrowsingBlockingPage* sb_interstitial =
273 this->GetSafeBrowsingBlockingPage();
253 ASSERT_TRUE(sb_interstitial); 274 ASSERT_TRUE(sb_interstitial);
254 275
255 base::RunLoop().RunUntilIdle(); 276 base::RunLoop().RunUntilIdle();
256 277
257 // Simulate the user clicking "don't proceed". 278 // Simulate the user clicking "don't proceed".
258 DontProceedThroughInterstitial(sb_interstitial); 279 this->DontProceedThroughInterstitial(sb_interstitial);
259 280
260 // The interstitial should be gone. 281 // The interstitial should be gone.
261 EXPECT_EQ(CANCEL, user_response()); 282 EXPECT_EQ(this->CANCEL, this->user_response());
262 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 283 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
263 284
264 // We did not proceed, the pending entry should be gone. 285 // We did not proceed, the pending entry should be gone.
265 EXPECT_FALSE(controller().GetPendingEntry()); 286 EXPECT_FALSE(this->controller().GetPendingEntry());
266 287
267 // A report should have been sent. 288 // A report should have been sent.
268 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 289 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
269 ui_manager_->GetDetails()->clear(); 290 this->ui_manager_->GetDetails()->clear();
270 } 291 }
271 292
272 // Tests showing a blocking page for a malware page and then proceeding. 293 // Tests showing a blocking page for a malware page and then proceeding.
273 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { 294 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwarePageProceed) {
274 // Enable malware reports. 295 // Enable malware reports.
275 Profile* profile = Profile::FromBrowserContext( 296 Profile* profile = Profile::FromBrowserContext(
276 web_contents()->GetBrowserContext()); 297 this->web_contents()->GetBrowserContext());
277 profile->GetPrefs()->SetBoolean( 298 profile->GetPrefs()->SetBoolean(
278 prefs::kSafeBrowsingExtendedReportingEnabled, true); 299 prefs::kSafeBrowsingExtendedReportingEnabled, true);
279 300
280 // Start a load. 301 // Start a load.
281 controller().LoadURL(GURL(kBadURL), content::Referrer(), 302 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
282 content::PAGE_TRANSITION_TYPED, std::string()); 303 content::PAGE_TRANSITION_TYPED, std::string());
283 304
284 // Simulate the load causing a safe browsing interstitial to be shown. 305 // Simulate the load causing a safe browsing interstitial to be shown.
285 ShowInterstitial(false, kBadURL); 306 this->ShowInterstitial(false, kBadURL);
286 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 307 SafeBrowsingBlockingPage* sb_interstitial =
308 this->GetSafeBrowsingBlockingPage();
287 ASSERT_TRUE(sb_interstitial); 309 ASSERT_TRUE(sb_interstitial);
288 310
289 // Simulate the user clicking "proceed". 311 // Simulate the user clicking "proceed".
290 ProceedThroughInterstitial(sb_interstitial); 312 this->ProceedThroughInterstitial(sb_interstitial);
291 313
292 // The interstitial is shown until the navigation commits. 314 // The interstitial is shown until the navigation commits.
293 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents())); 315 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(this->web_contents()));
294 // Commit the navigation. 316 // Commit the navigation.
295 Navigate(kBadURL, 1); 317 this->Navigate(kBadURL, 1);
296 // The interstitial should be gone now. 318 // The interstitial should be gone now.
297 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents())); 319 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(this->web_contents()));
298 320
299 // A report should have been sent. 321 // A report should have been sent.
300 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 322 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
301 ui_manager_->GetDetails()->clear(); 323 this->ui_manager_->GetDetails()->clear();
302 } 324 }
303 325
304 // Tests showing a blocking page for a page that contains malware subresources 326 // Tests showing a blocking page for a page that contains malware subresources
305 // and not proceeding. 327 // and not proceeding.
306 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { 328 TYPED_TEST(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) {
307 // Enable malware reports. 329 // Enable malware reports.
308 Profile* profile = Profile::FromBrowserContext( 330 Profile* profile = Profile::FromBrowserContext(
309 web_contents()->GetBrowserContext()); 331 this->web_contents()->GetBrowserContext());
310 profile->GetPrefs()->SetBoolean( 332 profile->GetPrefs()->SetBoolean(
311 prefs::kSafeBrowsingExtendedReportingEnabled, true); 333 prefs::kSafeBrowsingExtendedReportingEnabled, true);
312 334
313 // Navigate somewhere. 335 // Navigate somewhere.
314 Navigate(kGoogleURL, 1); 336 this->Navigate(kGoogleURL, 1);
315 337
316 // Navigate somewhere else. 338 // Navigate somewhere else.
317 Navigate(kGoodURL, 2); 339 this->Navigate(kGoodURL, 2);
318 340
319 // Simulate that page loading a bad-resource triggering an interstitial. 341 // Simulate that page loading a bad-resource triggering an interstitial.
320 ShowInterstitial(true, kBadURL); 342 this->ShowInterstitial(true, kBadURL);
321 343
322 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 344 SafeBrowsingBlockingPage* sb_interstitial =
345 this->GetSafeBrowsingBlockingPage();
323 ASSERT_TRUE(sb_interstitial); 346 ASSERT_TRUE(sb_interstitial);
324 347
325 // Simulate the user clicking "don't proceed". 348 // Simulate the user clicking "don't proceed".
326 DontProceedThroughSubresourceInterstitial(sb_interstitial); 349 this->DontProceedThroughSubresourceInterstitial(sb_interstitial);
327 EXPECT_EQ(CANCEL, user_response()); 350 EXPECT_EQ(this->CANCEL, this->user_response());
328 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 351 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
329 352
330 // We did not proceed, we should be back to the first page, the 2nd one should 353 // We did not proceed, we should be back to the first page, the 2nd one should
331 // have been removed from the navigation controller. 354 // have been removed from the navigation controller.
332 ASSERT_EQ(1, controller().GetEntryCount()); 355 ASSERT_EQ(1, this->controller().GetEntryCount());
333 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); 356 EXPECT_EQ(kGoogleURL, this->controller().GetActiveEntry()->GetURL().spec());
334 357
335 // A report should have been sent. 358 // A report should have been sent.
336 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 359 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
337 ui_manager_->GetDetails()->clear(); 360 this->ui_manager_->GetDetails()->clear();
338 } 361 }
339 362
340 // Tests showing a blocking page for a page that contains malware subresources 363 // Tests showing a blocking page for a page that contains malware subresources
341 // and proceeding. 364 // and proceeding.
342 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { 365 TYPED_TEST(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) {
343 // Enable malware reports. 366 // Enable malware reports.
344 Profile* profile = Profile::FromBrowserContext( 367 Profile* profile = Profile::FromBrowserContext(
345 web_contents()->GetBrowserContext()); 368 this->web_contents()->GetBrowserContext());
346 profile->GetPrefs()->SetBoolean( 369 profile->GetPrefs()->SetBoolean(
347 prefs::kSafeBrowsingExtendedReportingEnabled, true); 370 prefs::kSafeBrowsingExtendedReportingEnabled, true);
348 371
349 // Navigate somewhere. 372 // Navigate somewhere.
350 Navigate(kGoodURL, 1); 373 this->Navigate(kGoodURL, 1);
351 374
352 // Simulate that page loading a bad-resource triggering an interstitial. 375 // Simulate that page loading a bad-resource triggering an interstitial.
353 ShowInterstitial(true, kBadURL); 376 this->ShowInterstitial(true, kBadURL);
354 377
355 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 378 SafeBrowsingBlockingPage* sb_interstitial =
379 this->GetSafeBrowsingBlockingPage();
356 ASSERT_TRUE(sb_interstitial); 380 ASSERT_TRUE(sb_interstitial);
357 381
358 // Simulate the user clicking "proceed". 382 // Simulate the user clicking "proceed".
359 ProceedThroughInterstitial(sb_interstitial); 383 this->ProceedThroughInterstitial(sb_interstitial);
360 EXPECT_EQ(OK, user_response()); 384 EXPECT_EQ(this->OK, this->user_response());
361 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 385 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
362 386
363 // We did proceed, we should be back to showing the page. 387 // We did proceed, we should be back to showing the page.
364 ASSERT_EQ(1, controller().GetEntryCount()); 388 ASSERT_EQ(1, this->controller().GetEntryCount());
365 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); 389 EXPECT_EQ(kGoodURL, this->controller().GetActiveEntry()->GetURL().spec());
366 390
367 // A report should have been sent. 391 // A report should have been sent.
368 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 392 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
369 ui_manager_->GetDetails()->clear(); 393 this->ui_manager_->GetDetails()->clear();
370 } 394 }
371 395
372 // Tests showing a blocking page for a page that contains multiple malware 396 // Tests showing a blocking page for a page that contains multiple malware
373 // subresources and not proceeding. This just tests that the extra malware 397 // subresources and not proceeding. This just tests that the extra malware
374 // subresources (which trigger queued interstitial pages) do not break anything. 398 // subresources (which trigger queued interstitial pages) do not break anything.
375 TEST_F(SafeBrowsingBlockingPageTest, 399 TYPED_TEST(SafeBrowsingBlockingPageTest,
376 PageWithMultipleMalwareResourceDontProceed) { 400 PageWithMultipleMalwareResourceDontProceed) {
377 // Enable malware reports. 401 // Enable malware reports.
378 Profile* profile = Profile::FromBrowserContext( 402 Profile* profile = Profile::FromBrowserContext(
379 web_contents()->GetBrowserContext()); 403 this->web_contents()->GetBrowserContext());
380 profile->GetPrefs()->SetBoolean( 404 profile->GetPrefs()->SetBoolean(
381 prefs::kSafeBrowsingExtendedReportingEnabled, true); 405 prefs::kSafeBrowsingExtendedReportingEnabled, true);
382 406
383 // Navigate somewhere. 407 // Navigate somewhere.
384 Navigate(kGoogleURL, 1); 408 this->Navigate(kGoogleURL, 1);
385 409
386 // Navigate somewhere else. 410 // Navigate somewhere else.
387 Navigate(kGoodURL, 2); 411 this->Navigate(kGoodURL, 2);
388 412
389 // Simulate that page loading a bad-resource triggering an interstitial. 413 // Simulate that page loading a bad-resource triggering an interstitial.
390 ShowInterstitial(true, kBadURL); 414 this->ShowInterstitial(true, kBadURL);
391 415
392 // More bad resources loading causing more interstitials. The new 416 // More bad resources loading causing more interstitials. The new
393 // interstitials should be queued. 417 // interstitials should be queued.
394 ShowInterstitial(true, kBadURL2); 418 this->ShowInterstitial(true, kBadURL2);
395 ShowInterstitial(true, kBadURL3); 419 this->ShowInterstitial(true, kBadURL3);
396 420
397 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 421 SafeBrowsingBlockingPage* sb_interstitial =
422 this->GetSafeBrowsingBlockingPage();
398 ASSERT_TRUE(sb_interstitial); 423 ASSERT_TRUE(sb_interstitial);
399 424
400 // Simulate the user clicking "don't proceed". 425 // Simulate the user clicking "don't proceed".
401 DontProceedThroughSubresourceInterstitial(sb_interstitial); 426 this->DontProceedThroughSubresourceInterstitial(sb_interstitial);
402 EXPECT_EQ(CANCEL, user_response()); 427 EXPECT_EQ(this->CANCEL, this->user_response());
403 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 428 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
404 429
405 // We did not proceed, we should be back to the first page, the 2nd one should 430 // We did not proceed, we should be back to the first page, the 2nd one should
406 // have been removed from the navigation controller. 431 // have been removed from the navigation controller.
407 ASSERT_EQ(1, controller().GetEntryCount()); 432 ASSERT_EQ(1, this->controller().GetEntryCount());
408 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); 433 EXPECT_EQ(kGoogleURL, this->controller().GetActiveEntry()->GetURL().spec());
409 434
410 // A report should have been sent. 435 // A report should have been sent.
411 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 436 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
412 ui_manager_->GetDetails()->clear(); 437 this->ui_manager_->GetDetails()->clear();
413 } 438 }
414 439
415 // Tests showing a blocking page for a page that contains multiple malware 440 // Tests showing a blocking page for a page that contains multiple malware
416 // subresources and proceeding through the first interstitial, but not the next. 441 // subresources and proceeding through the first interstitial, but not the next.
417 TEST_F(SafeBrowsingBlockingPageTest, 442 TYPED_TEST(SafeBrowsingBlockingPageTest,
418 PageWithMultipleMalwareResourceProceedThenDontProceed) { 443 PageWithMultipleMalwareResourceProceedThenDontProceed) {
419 // Enable malware reports. 444 // Enable malware reports.
420 Profile* profile = Profile::FromBrowserContext( 445 Profile* profile = Profile::FromBrowserContext(
421 web_contents()->GetBrowserContext()); 446 this->web_contents()->GetBrowserContext());
422 profile->GetPrefs()->SetBoolean( 447 profile->GetPrefs()->SetBoolean(
423 prefs::kSafeBrowsingExtendedReportingEnabled, true); 448 prefs::kSafeBrowsingExtendedReportingEnabled, true);
424 449
425 // Navigate somewhere. 450 // Navigate somewhere.
426 Navigate(kGoogleURL, 1); 451 this->Navigate(kGoogleURL, 1);
427 452
428 // Navigate somewhere else. 453 // Navigate somewhere else.
429 Navigate(kGoodURL, 2); 454 this->Navigate(kGoodURL, 2);
430 455
431 // Simulate that page loading a bad-resource triggering an interstitial. 456 // Simulate that page loading a bad-resource triggering an interstitial.
432 ShowInterstitial(true, kBadURL); 457 this->ShowInterstitial(true, kBadURL);
433 458
434 // More bad resources loading causing more interstitials. The new 459 // More bad resources loading causing more interstitials. The new
435 // interstitials should be queued. 460 // interstitials should be queued.
436 ShowInterstitial(true, kBadURL2); 461 this->ShowInterstitial(true, kBadURL2);
437 ShowInterstitial(true, kBadURL3); 462 this->ShowInterstitial(true, kBadURL3);
438 463
439 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 464 SafeBrowsingBlockingPage* sb_interstitial =
465 this->GetSafeBrowsingBlockingPage();
440 ASSERT_TRUE(sb_interstitial); 466 ASSERT_TRUE(sb_interstitial);
441 467
442 // Proceed through the 1st interstitial. 468 // Proceed through the 1st interstitial.
443 ProceedThroughInterstitial(sb_interstitial); 469 this->ProceedThroughInterstitial(sb_interstitial);
444 EXPECT_EQ(OK, user_response()); 470 EXPECT_EQ(this->OK, this->user_response());
445 471
446 // A report should have been sent. 472 // A report should have been sent.
447 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 473 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
448 ui_manager_->GetDetails()->clear(); 474 this->ui_manager_->GetDetails()->clear();
449 475
450 ResetUserResponse(); 476 this->ResetUserResponse();
451 477
452 // We should land to a 2nd interstitial (aggregating all the malware resources 478 // We should land to a 2nd interstitial (aggregating all the malware resources
453 // loaded while the 1st interstitial was showing). 479 // loaded while the 1st interstitial was showing).
454 sb_interstitial = GetSafeBrowsingBlockingPage(); 480 sb_interstitial = this->GetSafeBrowsingBlockingPage();
455 ASSERT_TRUE(sb_interstitial); 481 ASSERT_TRUE(sb_interstitial);
456 482
457 // Don't proceed through the 2nd interstitial. 483 // Don't proceed through the 2nd interstitial.
458 DontProceedThroughSubresourceInterstitial(sb_interstitial); 484 this->DontProceedThroughSubresourceInterstitial(sb_interstitial);
459 EXPECT_EQ(CANCEL, user_response()); 485 EXPECT_EQ(this->CANCEL, this->user_response());
460 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 486 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
461 487
462 // We did not proceed, we should be back to the first page, the 2nd one should 488 // We did not proceed, we should be back to the first page, the 2nd one should
463 // have been removed from the navigation controller. 489 // have been removed from the navigation controller.
464 ASSERT_EQ(1, controller().GetEntryCount()); 490 ASSERT_EQ(1, this->controller().GetEntryCount());
465 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); 491 EXPECT_EQ(kGoogleURL, this->controller().GetActiveEntry()->GetURL().spec());
466 492
467 // No report should have been sent -- we don't create a report the 493 // No report should have been sent -- we don't create a report the
468 // second time. 494 // second time.
469 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); 495 EXPECT_EQ(0u, this->ui_manager_->GetDetails()->size());
470 ui_manager_->GetDetails()->clear(); 496 this->ui_manager_->GetDetails()->clear();
471 } 497 }
472 498
473 // Tests showing a blocking page for a page that contains multiple malware 499 // Tests showing a blocking page for a page that contains multiple malware
474 // subresources and proceeding through the multiple interstitials. 500 // subresources and proceeding through the multiple interstitials.
475 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { 501 TYPED_TEST(SafeBrowsingBlockingPageTest,
476 // Enable malware reports. 502 PageWithMultipleMalwareResourceProceed) {
477 Profile* profile = Profile::FromBrowserContext( 503 // Enable malware reports.
478 web_contents()->GetBrowserContext()); 504 Profile* profile = Profile::FromBrowserContext(
505 this->web_contents()->GetBrowserContext());
479 profile->GetPrefs()->SetBoolean( 506 profile->GetPrefs()->SetBoolean(
480 prefs::kSafeBrowsingExtendedReportingEnabled, true); 507 prefs::kSafeBrowsingExtendedReportingEnabled, true);
481 508
482 // Navigate somewhere else. 509 // Navigate somewhere else.
483 Navigate(kGoodURL, 1); 510 this->Navigate(kGoodURL, 1);
484 511
485 // Simulate that page loading a bad-resource triggering an interstitial. 512 // Simulate that page loading a bad-resource triggering an interstitial.
486 ShowInterstitial(true, kBadURL); 513 this->ShowInterstitial(true, kBadURL);
487 514
488 // More bad resources loading causing more interstitials. The new 515 // More bad resources loading causing more interstitials. The new
489 // interstitials should be queued. 516 // interstitials should be queued.
490 ShowInterstitial(true, kBadURL2); 517 this->ShowInterstitial(true, kBadURL2);
491 ShowInterstitial(true, kBadURL3); 518 this->ShowInterstitial(true, kBadURL3);
492 519
493 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 520 SafeBrowsingBlockingPage* sb_interstitial =
521 this->GetSafeBrowsingBlockingPage();
494 ASSERT_TRUE(sb_interstitial); 522 ASSERT_TRUE(sb_interstitial);
495 523
496 // Proceed through the 1st interstitial. 524 // Proceed through the 1st interstitial.
497 ProceedThroughInterstitial(sb_interstitial); 525 this->ProceedThroughInterstitial(sb_interstitial);
498 EXPECT_EQ(OK, user_response()); 526 EXPECT_EQ(this->OK, this->user_response());
499 527
500 // A report should have been sent. 528 // A report should have been sent.
501 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 529 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
502 ui_manager_->GetDetails()->clear(); 530 this->ui_manager_->GetDetails()->clear();
503 531
504 ResetUserResponse(); 532 this->ResetUserResponse();
505 533
506 // We should land to a 2nd interstitial (aggregating all the malware resources 534 // We should land to a 2nd interstitial (aggregating all the malware resources
507 // loaded while the 1st interstitial was showing). 535 // loaded while the 1st interstitial was showing).
508 sb_interstitial = GetSafeBrowsingBlockingPage(); 536 sb_interstitial = this->GetSafeBrowsingBlockingPage();
509 ASSERT_TRUE(sb_interstitial); 537 ASSERT_TRUE(sb_interstitial);
510 538
511 // Proceed through the 2nd interstitial. 539 // Proceed through the 2nd interstitial.
512 ProceedThroughInterstitial(sb_interstitial); 540 this->ProceedThroughInterstitial(sb_interstitial);
513 EXPECT_EQ(OK, user_response()); 541 EXPECT_EQ(this->OK, this->user_response());
514 542
515 // We did proceed, we should be back to the initial page. 543 // We did proceed, we should be back to the initial page.
516 ASSERT_EQ(1, controller().GetEntryCount()); 544 ASSERT_EQ(1, this->controller().GetEntryCount());
517 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); 545 EXPECT_EQ(kGoodURL, this->controller().GetActiveEntry()->GetURL().spec());
518 546
519 // No report should have been sent -- we don't create a report the 547 // No report should have been sent -- we don't create a report the
520 // second time. 548 // second time.
521 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); 549 EXPECT_EQ(0u, this->ui_manager_->GetDetails()->size());
522 ui_manager_->GetDetails()->clear(); 550 this->ui_manager_->GetDetails()->clear();
523 } 551 }
524 552
525 // Tests showing a blocking page then navigating back and forth to make sure the 553 // Tests showing a blocking page then navigating back and forth to make sure the
526 // controller entries are OK. http://crbug.com/17627 554 // controller entries are OK. http://crbug.com/17627
527 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { 555 TYPED_TEST(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) {
528 // Enable malware reports. 556 // Enable malware reports.
529 Profile* profile = Profile::FromBrowserContext( 557 Profile* profile = Profile::FromBrowserContext(
530 web_contents()->GetBrowserContext()); 558 this->web_contents()->GetBrowserContext());
531 profile->GetPrefs()->SetBoolean( 559 profile->GetPrefs()->SetBoolean(
532 prefs::kSafeBrowsingExtendedReportingEnabled, true); 560 prefs::kSafeBrowsingExtendedReportingEnabled, true);
533 561
534 // Navigate somewhere. 562 // Navigate somewhere.
535 Navigate(kGoodURL, 1); 563 this->Navigate(kGoodURL, 1);
536 564
537 // Now navigate to a bad page triggerring an interstitial. 565 // Now navigate to a bad page triggerring an interstitial.
538 controller().LoadURL(GURL(kBadURL), content::Referrer(), 566 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
539 content::PAGE_TRANSITION_TYPED, std::string()); 567 content::PAGE_TRANSITION_TYPED, std::string());
540 ShowInterstitial(false, kBadURL); 568 this->ShowInterstitial(false, kBadURL);
541 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 569 SafeBrowsingBlockingPage* sb_interstitial =
570 this->GetSafeBrowsingBlockingPage();
542 ASSERT_TRUE(sb_interstitial); 571 ASSERT_TRUE(sb_interstitial);
543 572
544 // Proceed, then navigate back. 573 // Proceed, then navigate back.
545 ProceedThroughInterstitial(sb_interstitial); 574 this->ProceedThroughInterstitial(sb_interstitial);
546 Navigate(kBadURL, 2); // Commit the navigation. 575 this->Navigate(kBadURL, 2); // Commit the navigation.
547 GoBack(true); 576 this->GoBack(true);
548 577
549 // We are back on the good page. 578 // We are back on the good page.
550 sb_interstitial = GetSafeBrowsingBlockingPage(); 579 sb_interstitial = this->GetSafeBrowsingBlockingPage();
551 ASSERT_FALSE(sb_interstitial); 580 ASSERT_FALSE(sb_interstitial);
552 ASSERT_EQ(2, controller().GetEntryCount()); 581 ASSERT_EQ(2, this->controller().GetEntryCount());
553 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); 582 EXPECT_EQ(kGoodURL, this->controller().GetActiveEntry()->GetURL().spec());
554 583
555 // Navigate forward to the malware URL. 584 // Navigate forward to the malware URL.
556 web_contents()->GetController().GoForward(); 585 this->web_contents()->GetController().GoForward();
557 ShowInterstitial(false, kBadURL); 586 this->ShowInterstitial(false, kBadURL);
558 sb_interstitial = GetSafeBrowsingBlockingPage(); 587 sb_interstitial = this->GetSafeBrowsingBlockingPage();
559 ASSERT_TRUE(sb_interstitial); 588 ASSERT_TRUE(sb_interstitial);
560 589
561 // Let's proceed and make sure everything is OK (bug 17627). 590 // Let's proceed and make sure everything is OK (bug 17627).
562 ProceedThroughInterstitial(sb_interstitial); 591 this->ProceedThroughInterstitial(sb_interstitial);
563 Navigate(kBadURL, 2); // Commit the navigation. 592 this->Navigate(kBadURL, 2); // Commit the navigation.
564 sb_interstitial = GetSafeBrowsingBlockingPage(); 593 sb_interstitial = this->GetSafeBrowsingBlockingPage();
565 ASSERT_FALSE(sb_interstitial); 594 ASSERT_FALSE(sb_interstitial);
566 ASSERT_EQ(2, controller().GetEntryCount()); 595 ASSERT_EQ(2, this->controller().GetEntryCount());
567 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); 596 EXPECT_EQ(kBadURL, this->controller().GetActiveEntry()->GetURL().spec());
568 597
569 // Two reports should have been sent. 598 // Two reports should have been sent.
570 EXPECT_EQ(2u, ui_manager_->GetDetails()->size()); 599 EXPECT_EQ(2u, this->ui_manager_->GetDetails()->size());
571 ui_manager_->GetDetails()->clear(); 600 this->ui_manager_->GetDetails()->clear();
572 } 601 }
573 602
574 // Tests that calling "don't proceed" after "proceed" has been called doesn't 603 // Tests that calling "don't proceed" after "proceed" has been called doesn't
575 // cause problems. http://crbug.com/30079 604 // cause problems. http://crbug.com/30079
576 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { 605 TYPED_TEST(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) {
577 // Enable malware reports. 606 // Enable malware reports.
578 Profile* profile = Profile::FromBrowserContext( 607 Profile* profile = Profile::FromBrowserContext(
579 web_contents()->GetBrowserContext()); 608 this->web_contents()->GetBrowserContext());
580 profile->GetPrefs()->SetBoolean( 609 profile->GetPrefs()->SetBoolean(
581 prefs::kSafeBrowsingExtendedReportingEnabled, true); 610 prefs::kSafeBrowsingExtendedReportingEnabled, true);
582 611
583 // Start a load. 612 // Start a load.
584 controller().LoadURL(GURL(kBadURL), content::Referrer(), 613 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
585 content::PAGE_TRANSITION_TYPED, std::string()); 614 content::PAGE_TRANSITION_TYPED, std::string());
586 615
587 // Simulate the load causing a safe browsing interstitial to be shown. 616 // Simulate the load causing a safe browsing interstitial to be shown.
588 ShowInterstitial(false, kBadURL); 617 this->ShowInterstitial(false, kBadURL);
589 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 618 SafeBrowsingBlockingPage* sb_interstitial =
619 this->GetSafeBrowsingBlockingPage();
590 ASSERT_TRUE(sb_interstitial); 620 ASSERT_TRUE(sb_interstitial);
591 621
592 base::RunLoop().RunUntilIdle(); 622 base::RunLoop().RunUntilIdle();
593 623
594 // Simulate the user clicking "proceed" then "don't proceed" (before the 624 // Simulate the user clicking "proceed" then "don't proceed" (before the
595 // interstitial is shown). 625 // interstitial is shown).
596 sb_interstitial->interstitial_page_->Proceed(); 626 sb_interstitial->interstitial_page_->Proceed();
597 sb_interstitial->interstitial_page_->DontProceed(); 627 sb_interstitial->interstitial_page_->DontProceed();
598 // Proceed() and DontProceed() post a task to update the 628 // Proceed() and DontProceed() post a task to update the
599 // SafeBrowsingService::Client. 629 // SafeBrowsingService::Client.
600 base::RunLoop().RunUntilIdle(); 630 base::RunLoop().RunUntilIdle();
601 631
602 // The interstitial should be gone. 632 // The interstitial should be gone.
603 EXPECT_EQ(OK, user_response()); 633 EXPECT_EQ(this->OK, this->user_response());
604 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 634 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
605 635
606 // Only one report should have been sent. 636 // Only one report should have been sent.
607 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 637 EXPECT_EQ(1u, this->ui_manager_->GetDetails()->size());
608 ui_manager_->GetDetails()->clear(); 638 this->ui_manager_->GetDetails()->clear();
609 } 639 }
610 640
611 // Tests showing a blocking page for a malware page with reports disabled. 641 // Tests showing a blocking page for a malware page with reports disabled.
612 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { 642 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) {
613 // Disable malware reports. 643 // Disable malware reports.
614 Profile* profile = Profile::FromBrowserContext( 644 Profile* profile = Profile::FromBrowserContext(
615 web_contents()->GetBrowserContext()); 645 this->web_contents()->GetBrowserContext());
616 profile->GetPrefs()->SetBoolean( 646 profile->GetPrefs()->SetBoolean(
617 prefs::kSafeBrowsingExtendedReportingEnabled, false); 647 prefs::kSafeBrowsingExtendedReportingEnabled, false);
618 648
619 // Start a load. 649 // Start a load.
620 controller().LoadURL(GURL(kBadURL), content::Referrer(), 650 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
621 content::PAGE_TRANSITION_TYPED, std::string()); 651 content::PAGE_TRANSITION_TYPED, std::string());
622 652
623 // Simulate the load causing a safe browsing interstitial to be shown. 653 // Simulate the load causing a safe browsing interstitial to be shown.
624 ShowInterstitial(false, kBadURL); 654 this->ShowInterstitial(false, kBadURL);
625 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 655 SafeBrowsingBlockingPage* sb_interstitial =
656 this->GetSafeBrowsingBlockingPage();
626 ASSERT_TRUE(sb_interstitial); 657 ASSERT_TRUE(sb_interstitial);
627 658
628 base::RunLoop().RunUntilIdle(); 659 base::RunLoop().RunUntilIdle();
629 660
630 // Simulate the user clicking "don't proceed". 661 // Simulate the user clicking "don't proceed".
631 DontProceedThroughInterstitial(sb_interstitial); 662 this->DontProceedThroughInterstitial(sb_interstitial);
632 663
633 // The interstitial should be gone. 664 // The interstitial should be gone.
634 EXPECT_EQ(CANCEL, user_response()); 665 EXPECT_EQ(this->CANCEL, this->user_response());
635 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 666 EXPECT_FALSE(this->GetSafeBrowsingBlockingPage());
636 667
637 // We did not proceed, the pending entry should be gone. 668 // We did not proceed, the pending entry should be gone.
638 EXPECT_FALSE(controller().GetPendingEntry()); 669 EXPECT_FALSE(this->controller().GetPendingEntry());
639 670
640 // No report should have been sent. 671 // No report should have been sent.
641 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); 672 EXPECT_EQ(0u, this->ui_manager_->GetDetails()->size());
642 ui_manager_->GetDetails()->clear(); 673 this->ui_manager_->GetDetails()->clear();
643 } 674 }
644 675
645 // Test that toggling the checkbox has the anticipated effects. 676 // Test that toggling the checkbox has the anticipated effects.
646 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) { 677 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwareReportsToggling) {
647 // Disable malware reports. 678 // Disable malware reports.
648 Profile* profile = Profile::FromBrowserContext( 679 Profile* profile = Profile::FromBrowserContext(
649 web_contents()->GetBrowserContext()); 680 this->web_contents()->GetBrowserContext());
650 profile->GetPrefs()->SetBoolean( 681 profile->GetPrefs()->SetBoolean(
651 prefs::kSafeBrowsingExtendedReportingEnabled, false); 682 prefs::kSafeBrowsingExtendedReportingEnabled, false);
652 683
653 // Start a load. 684 // Start a load.
654 controller().LoadURL(GURL(kBadURL), content::Referrer(), 685 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
655 content::PAGE_TRANSITION_TYPED, std::string()); 686 content::PAGE_TRANSITION_TYPED, std::string());
656 687
657 // Simulate the load causing a safe browsing interstitial to be shown. 688 // Simulate the load causing a safe browsing interstitial to be shown.
658 ShowInterstitial(false, kBadURL); 689 this->ShowInterstitial(false, kBadURL);
659 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 690 SafeBrowsingBlockingPage* sb_interstitial =
691 this->GetSafeBrowsingBlockingPage();
660 ASSERT_TRUE(sb_interstitial); 692 ASSERT_TRUE(sb_interstitial);
661 693
662 base::RunLoop().RunUntilIdle(); 694 base::RunLoop().RunUntilIdle();
663 695
664 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 696 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
665 prefs::kSafeBrowsingExtendedReportingEnabled)); 697 prefs::kSafeBrowsingExtendedReportingEnabled));
666 698
667 // Simulate the user check the report agreement checkbox. 699 // Simulate the user check the report agreement checkbox.
668 sb_interstitial->SetReportingPreference(true); 700 sb_interstitial->SetReportingPreference(true);
669 701
670 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 702 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
671 prefs::kSafeBrowsingExtendedReportingEnabled)); 703 prefs::kSafeBrowsingExtendedReportingEnabled));
672 704
673 // Simulate the user uncheck the report agreement checkbox. 705 // Simulate the user uncheck the report agreement checkbox.
674 sb_interstitial->SetReportingPreference(false); 706 sb_interstitial->SetReportingPreference(false);
675 707
676 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 708 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
677 prefs::kSafeBrowsingExtendedReportingEnabled)); 709 prefs::kSafeBrowsingExtendedReportingEnabled));
678 } 710 }
679 711
680 // Test that the transition from old to new preference works. 712 // Test that the transition from old to new preference works.
681 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsTransitionEnabled) { 713 TYPED_TEST(SafeBrowsingBlockingPageTest,
714 DISABLED_MalwareReportsTransitionEnabled) {
mattm 2014/06/17 18:38:48 and this got marked disabled?
felt 2014/06/17 18:40:14 This had to be disabled because the checkbox isn't
682 // The old pref is enabled. 715 // The old pref is enabled.
683 Profile* profile = Profile::FromBrowserContext( 716 Profile* profile = Profile::FromBrowserContext(
684 web_contents()->GetBrowserContext()); 717 this->web_contents()->GetBrowserContext());
685 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); 718 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
686 719
687 // Start a load. 720 // Start a load.
688 controller().LoadURL(GURL(kBadURL), content::Referrer(), 721 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
689 content::PAGE_TRANSITION_TYPED, std::string()); 722 content::PAGE_TRANSITION_TYPED, std::string());
690 723
691 // Simulate the load causing a safe browsing interstitial to be shown. 724 // Simulate the load causing a safe browsing interstitial to be shown.
692 ShowInterstitial(false, kBadURL); 725 this->ShowInterstitial(false, kBadURL);
693 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 726 SafeBrowsingBlockingPage* sb_interstitial =
727 this->GetSafeBrowsingBlockingPage();
694 ASSERT_TRUE(sb_interstitial); 728 ASSERT_TRUE(sb_interstitial);
695 729
696 base::RunLoop().RunUntilIdle(); 730 base::RunLoop().RunUntilIdle();
697 731
698 // At this point, nothing should have changed yet. 732 // At this point, nothing should have changed yet.
699 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 733 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
700 prefs::kSafeBrowsingExtendedReportingEnabled)); 734 prefs::kSafeBrowsingExtendedReportingEnabled));
701 735
702 ProceedThroughInterstitial(sb_interstitial); 736 this->ProceedThroughInterstitial(sb_interstitial);
703 737
704 // Since the user has proceeded without changing the checkbox, the new pref 738 // Since the user has proceeded without changing the checkbox, the new pref
705 // has been updated. 739 // has been updated.
706 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 740 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
707 prefs::kSafeBrowsingExtendedReportingEnabled)); 741 prefs::kSafeBrowsingExtendedReportingEnabled));
708 } 742 }
709 743
710 // Test that the transition from old to new preference still respects the 744 // Test that the transition from old to new preference still respects the
711 // user's checkbox preferences. 745 // user's checkbox preferences.
712 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsTransitionDisabled) { 746 TYPED_TEST(SafeBrowsingBlockingPageTest, MalwareReportsTransitionDisabled) {
713 // The old pref is enabled. 747 // The old pref is enabled.
714 Profile* profile = Profile::FromBrowserContext( 748 Profile* profile = Profile::FromBrowserContext(
715 web_contents()->GetBrowserContext()); 749 this->web_contents()->GetBrowserContext());
716 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); 750 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
717 751
718 // Start a load. 752 // Start a load.
719 controller().LoadURL(GURL(kBadURL), content::Referrer(), 753 this->controller().LoadURL(GURL(kBadURL), content::Referrer(),
720 content::PAGE_TRANSITION_TYPED, std::string()); 754 content::PAGE_TRANSITION_TYPED, std::string());
721 755
722 // Simulate the load causing a safe browsing interstitial to be shown. 756 // Simulate the load causing a safe browsing interstitial to be shown.
723 ShowInterstitial(false, kBadURL); 757 this->ShowInterstitial(false, kBadURL);
724 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 758 SafeBrowsingBlockingPage* sb_interstitial =
759 this->GetSafeBrowsingBlockingPage();
725 ASSERT_TRUE(sb_interstitial); 760 ASSERT_TRUE(sb_interstitial);
726 761
727 base::RunLoop().RunUntilIdle(); 762 base::RunLoop().RunUntilIdle();
728 763
729 // At this point, nothing should have changed yet. 764 // At this point, nothing should have changed yet.
730 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 765 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
731 prefs::kSafeBrowsingExtendedReportingEnabled)); 766 prefs::kSafeBrowsingExtendedReportingEnabled));
732 767
733 // Simulate the user uncheck the report agreement checkbox. 768 // Simulate the user uncheck the report agreement checkbox.
734 sb_interstitial->SetReportingPreference(false); 769 sb_interstitial->SetReportingPreference(false);
735 770
736 ProceedThroughInterstitial(sb_interstitial); 771 this->ProceedThroughInterstitial(sb_interstitial);
737 772
738 // The new pref is turned off. 773 // The new pref is turned off.
739 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 774 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
740 prefs::kSafeBrowsingExtendedReportingEnabled)); 775 prefs::kSafeBrowsingExtendedReportingEnabled));
741 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 776 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
742 prefs::kSafeBrowsingReportingEnabled)); 777 prefs::kSafeBrowsingReportingEnabled));
743 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 778 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
744 prefs::kSafeBrowsingDownloadFeedbackEnabled)); 779 prefs::kSafeBrowsingDownloadFeedbackEnabled));
745 } 780 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698