OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
7 // service. | 7 // service. |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // we should see the interstitial page. | 348 // we should see the interstitial page. |
349 SBFullHashResult malware_full_hash; | 349 SBFullHashResult malware_full_hash; |
350 int chunk_id = 0; | 350 int chunk_id = 0; |
351 GenUrlFullhashResult(url, safe_browsing_util::kMalwareList, chunk_id, | 351 GenUrlFullhashResult(url, safe_browsing_util::kMalwareList, chunk_id, |
352 &malware_full_hash); | 352 &malware_full_hash); |
353 SetupResponseForUrl(url, malware_full_hash); | 353 SetupResponseForUrl(url, malware_full_hash); |
354 ui_test_utils::NavigateToURL(browser(), url); | 354 ui_test_utils::NavigateToURL(browser(), url); |
355 EXPECT_TRUE(ShowingInterstitialPage()); | 355 EXPECT_TRUE(ShowingInterstitialPage()); |
356 } | 356 } |
357 | 357 |
| 358 const char kPrefetchMalwarePage[] = "files/safe_browsing/prefetch_malware.html"; |
| 359 |
| 360 // This test confirms that prefetches don't themselves get the |
| 361 // interstitial treatment. |
| 362 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, Prefetch) { |
| 363 GURL url = test_server()->GetURL(kPrefetchMalwarePage); |
| 364 GURL malware_url = test_server()->GetURL(kMalwarePage); |
| 365 |
| 366 class SetPrefetchForTest { |
| 367 public: |
| 368 explicit SetPrefetchForTest(bool prefetch) |
| 369 : old_prefetch_state_(ResourceDispatcherHost::is_prefetch_enabled()) { |
| 370 ResourceDispatcherHost::set_is_prefetch_enabled(prefetch); |
| 371 } |
| 372 |
| 373 ~SetPrefetchForTest() { |
| 374 ResourceDispatcherHost::set_is_prefetch_enabled(old_prefetch_state_); |
| 375 } |
| 376 private: |
| 377 bool old_prefetch_state_; |
| 378 } set_prefetch_for_test(true); |
| 379 |
| 380 // After adding the url to safebrowsing database and getfullhash result, |
| 381 // we should see the interstitial page. |
| 382 SBFullHashResult malware_full_hash; |
| 383 int chunk_id = 0; |
| 384 GenUrlFullhashResult(malware_url, safe_browsing_util::kMalwareList, |
| 385 chunk_id, &malware_full_hash); |
| 386 SetupResponseForUrl(malware_url, malware_full_hash); |
| 387 ui_test_utils::NavigateToURL(browser(), url); |
| 388 EXPECT_FALSE(ShowingInterstitialPage()); |
| 389 } |
| 390 |
358 // This test uses SafeBrowsingService::Client to directly interact with | 391 // This test uses SafeBrowsingService::Client to directly interact with |
359 // SafeBrowsingService. | 392 // SafeBrowsingService. |
360 class TestSBClient | 393 class TestSBClient |
361 : public base::RefCountedThreadSafe<TestSBClient>, | 394 : public base::RefCountedThreadSafe<TestSBClient>, |
362 public SafeBrowsingService::Client { | 395 public SafeBrowsingService::Client { |
363 public: | 396 public: |
364 TestSBClient() : result_(SafeBrowsingService::SAFE), | 397 TestSBClient() : result_(SafeBrowsingService::SAFE), |
365 safe_browsing_service_(g_browser_process-> | 398 safe_browsing_service_(g_browser_process-> |
366 resource_dispatcher_host()-> | 399 resource_dispatcher_host()-> |
367 safe_browsing_service()) { | 400 safe_browsing_service()) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 GenDigestFullhashResult(full_hash, safe_browsing_util::kBinHashList, | 492 GenDigestFullhashResult(full_hash, safe_browsing_util::kBinHashList, |
460 chunk_id, &full_hash_result); | 493 chunk_id, &full_hash_result); |
461 SetupResponseForDigest(full_hash, full_hash_result); | 494 SetupResponseForDigest(full_hash, full_hash_result); |
462 | 495 |
463 client->CheckDownloadHash(full_hash); | 496 client->CheckDownloadHash(full_hash); |
464 | 497 |
465 // Now, the badbin_url is not safe since it is added to download database. | 498 // Now, the badbin_url is not safe since it is added to download database. |
466 EXPECT_EQ(SafeBrowsingService::BINARY_MALWARE_HASH, client->GetResult()); | 499 EXPECT_EQ(SafeBrowsingService::BINARY_MALWARE_HASH, client->GetResult()); |
467 } | 500 } |
468 } // namespace | 501 } // namespace |
OLD | NEW |