Chromium Code Reviews| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 // we should see the interstitial page. | 374 // we should see the interstitial page. |
| 375 SBFullHashResult malware_full_hash; | 375 SBFullHashResult malware_full_hash; |
| 376 int chunk_id = 0; | 376 int chunk_id = 0; |
| 377 GenUrlFullhashResult(url, safe_browsing_util::kMalwareList, chunk_id, | 377 GenUrlFullhashResult(url, safe_browsing_util::kMalwareList, chunk_id, |
| 378 &malware_full_hash); | 378 &malware_full_hash); |
| 379 SetupResponseForUrl(url, malware_full_hash); | 379 SetupResponseForUrl(url, malware_full_hash); |
| 380 ui_test_utils::NavigateToURL(browser(), url); | 380 ui_test_utils::NavigateToURL(browser(), url); |
| 381 EXPECT_TRUE(ShowingInterstitialPage()); | 381 EXPECT_TRUE(ShowingInterstitialPage()); |
| 382 } | 382 } |
| 383 | 383 |
| 384 const char kPrefetchMalwarePage[] = "files/safe_browsing/prefetch_malware.html"; | |
| 385 | |
| 386 // This test confirms that prefetches don't themselves get the | |
| 387 // interstitial treatment. | |
| 388 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, Prefetch) { | |
| 389 GURL url = test_server()->GetURL(kPrefetchMalwarePage); | |
| 390 GURL malware_url = test_server()->GetURL(kMalwarePage); | |
| 391 | |
| 392 class SetPrefetchForTest { | |
| 393 public: | |
| 394 explicit SetPrefetchForTest(bool prefetch) | |
| 395 : old_prefetch_state_(ResourceDispatcherHost::is_prefetch_enabled()) { | |
| 396 ResourceDispatcherHost::set_is_prefetch_enabled(prefetch); | |
| 397 } | |
| 398 | |
| 399 ~SetPrefetchForTest() { | |
| 400 ResourceDispatcherHost::set_is_prefetch_enabled(old_prefetch_state_); | |
| 401 } | |
| 402 private: | |
| 403 bool old_prefetch_state_; | |
| 404 } set_prefetch_for_test(true); | |
| 405 | |
| 406 // After adding the url to safebrowsing database and getfullhash result, | |
|
lzheng
2011/03/08 18:01:34
nit: We may want to update this comment.
Should w
gavinp
2011/03/08 22:33:04
I fixed the comment.
With regard to testing, we'd
| |
| 407 // we should see the interstitial page. | |
| 408 SBFullHashResult malware_full_hash; | |
| 409 int chunk_id = 0; | |
| 410 GenUrlFullhashResult(malware_url, safe_browsing_util::kMalwareList, | |
| 411 chunk_id, &malware_full_hash); | |
| 412 SetupResponseForUrl(malware_url, malware_full_hash); | |
| 413 ui_test_utils::NavigateToURL(browser(), url); | |
| 414 EXPECT_FALSE(ShowingInterstitialPage()); | |
| 415 } | |
| 416 | |
| 384 } // namespace | 417 } // namespace |
| 385 | 418 |
| 386 class TestSBClient | 419 class TestSBClient |
| 387 : public base::RefCountedThreadSafe<TestSBClient>, | 420 : public base::RefCountedThreadSafe<TestSBClient>, |
| 388 public SafeBrowsingService::Client { | 421 public SafeBrowsingService::Client { |
| 389 public: | 422 public: |
| 390 TestSBClient() : result_(SafeBrowsingService::SAFE), | 423 TestSBClient() : result_(SafeBrowsingService::SAFE), |
| 391 safe_browsing_service_(g_browser_process-> | 424 safe_browsing_service_(g_browser_process-> |
| 392 resource_dispatcher_host()-> | 425 resource_dispatcher_host()-> |
| 393 safe_browsing_service()) { | 426 safe_browsing_service()) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 client->CheckDownloadHash(full_hash); | 589 client->CheckDownloadHash(full_hash); |
| 557 | 590 |
| 558 // There should be a timeout and the hash would be considered as safe. | 591 // There should be a timeout and the hash would be considered as safe. |
| 559 EXPECT_EQ(SafeBrowsingService::SAFE, client->GetResult()); | 592 EXPECT_EQ(SafeBrowsingService::SAFE, client->GetResult()); |
| 560 | 593 |
| 561 // Need to set the timeout back to the default value. | 594 // Need to set the timeout back to the default value. |
| 562 SetDownloadHashCheckTimeout(sb_service, default_hashcheck_timeout); | 595 SetDownloadHashCheckTimeout(sb_service, default_hashcheck_timeout); |
| 563 } | 596 } |
| 564 | 597 |
| 565 } // namespace | 598 } // namespace |
| OLD | NEW |