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