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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // we should see the interstitial page. | 372 // we should see the interstitial page. |
373 SBFullHashResult malware_full_hash; | 373 SBFullHashResult malware_full_hash; |
374 int chunk_id = 0; | 374 int chunk_id = 0; |
375 GenUrlFullhashResult(url, safe_browsing_util::kMalwareList, chunk_id, | 375 GenUrlFullhashResult(url, safe_browsing_util::kMalwareList, chunk_id, |
376 &malware_full_hash); | 376 &malware_full_hash); |
377 SetupResponseForUrl(url, malware_full_hash); | 377 SetupResponseForUrl(url, malware_full_hash); |
378 ui_test_utils::NavigateToURL(browser(), url); | 378 ui_test_utils::NavigateToURL(browser(), url); |
379 EXPECT_TRUE(ShowingInterstitialPage()); | 379 EXPECT_TRUE(ShowingInterstitialPage()); |
380 } | 380 } |
381 | 381 |
| 382 const char kPrefetchMalwarePage[] = "files/safe_browsing/prefetch_malware.html"; |
| 383 |
| 384 // This test confirms that prefetches don't themselves get the |
| 385 // interstitial treatment. |
| 386 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, Prefetch) { |
| 387 GURL url = test_server()->GetURL(kPrefetchMalwarePage); |
| 388 GURL malware_url = test_server()->GetURL(kMalwarePage); |
| 389 |
| 390 class SetPrefetchForTest { |
| 391 public: |
| 392 explicit SetPrefetchForTest(bool prefetch) |
| 393 : old_prefetch_state_(ResourceDispatcherHost::is_prefetch_enabled()) { |
| 394 ResourceDispatcherHost::set_is_prefetch_enabled(prefetch); |
| 395 } |
| 396 |
| 397 ~SetPrefetchForTest() { |
| 398 ResourceDispatcherHost::set_is_prefetch_enabled(old_prefetch_state_); |
| 399 } |
| 400 private: |
| 401 bool old_prefetch_state_; |
| 402 } set_prefetch_for_test(true); |
| 403 |
| 404 // Even though we have added this uri to the safebrowsing database and |
| 405 // getfullhash result, we should not see the interstitial page since the |
| 406 // only malware was a prefetch target. |
| 407 SBFullHashResult malware_full_hash; |
| 408 int chunk_id = 0; |
| 409 GenUrlFullhashResult(malware_url, safe_browsing_util::kMalwareList, |
| 410 chunk_id, &malware_full_hash); |
| 411 SetupResponseForUrl(malware_url, malware_full_hash); |
| 412 ui_test_utils::NavigateToURL(browser(), url); |
| 413 EXPECT_FALSE(ShowingInterstitialPage()); |
| 414 |
| 415 // However, when we navigate to the malware page, we should still get |
| 416 // the interstitial. |
| 417 ui_test_utils::NavigateToURL(browser(), malware_url); |
| 418 EXPECT_TRUE(ShowingInterstitialPage()); |
| 419 } |
| 420 |
382 } // namespace | 421 } // namespace |
383 | 422 |
384 class TestSBClient | 423 class TestSBClient |
385 : public base::RefCountedThreadSafe<TestSBClient>, | 424 : public base::RefCountedThreadSafe<TestSBClient>, |
386 public SafeBrowsingService::Client { | 425 public SafeBrowsingService::Client { |
387 public: | 426 public: |
388 TestSBClient() : result_(SafeBrowsingService::SAFE), | 427 TestSBClient() : result_(SafeBrowsingService::SAFE), |
389 safe_browsing_service_(g_browser_process-> | 428 safe_browsing_service_(g_browser_process-> |
390 resource_dispatcher_host()-> | 429 resource_dispatcher_host()-> |
391 safe_browsing_service()) { | 430 safe_browsing_service()) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 client->CheckDownloadHash(full_hash); | 593 client->CheckDownloadHash(full_hash); |
555 | 594 |
556 // There should be a timeout and the hash would be considered as safe. | 595 // There should be a timeout and the hash would be considered as safe. |
557 EXPECT_EQ(SafeBrowsingService::SAFE, client->GetResult()); | 596 EXPECT_EQ(SafeBrowsingService::SAFE, client->GetResult()); |
558 | 597 |
559 // Need to set the timeout back to the default value. | 598 // Need to set the timeout back to the default value. |
560 SetDownloadHashCheckTimeout(sb_service, default_hashcheck_timeout); | 599 SetDownloadHashCheckTimeout(sb_service, default_hashcheck_timeout); |
561 } | 600 } |
562 | 601 |
563 } // namespace | 602 } // namespace |
OLD | NEW |