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

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

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

Powered by Google App Engine
This is Rietveld 408576698