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 // Even though we have added this uri to the safebrowsing database and | |
407 // getfullhash result, we should not see the interstitial page since the | |
408 // only malware was a prefetch target. | |
409 SBFullHashResult malware_full_hash; | |
410 int chunk_id = 0; | |
411 GenUrlFullhashResult(malware_url, safe_browsing_util::kMalwareList, | |
412 chunk_id, &malware_full_hash); | |
413 SetupResponseForUrl(malware_url, malware_full_hash); | |
414 ui_test_utils::NavigateToURL(browser(), url); | |
415 EXPECT_FALSE(ShowingInterstitialPage()); | |
416 | |
417 // However, when we navigate to the malware page, we should still get | |
418 // the interstitial. | |
419 ui_test_utils::WindowedNotificationObserver signal( | |
420 NotificationType::LOAD_STOP, | |
421 Source<NavigationController>( | |
422 &browser()->GetSelectedTabContents()->controller())); | |
423 browser()->OpenURL(malware_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | |
424 signal.Wait(); | |
gavinp
2011/03/08 22:33:04
I use the WindowedNotificationObserver here, inste
| |
425 | |
426 EXPECT_TRUE(ShowingInterstitialPage()); | |
427 } | |
428 | |
384 } // namespace | 429 } // namespace |
385 | 430 |
386 class TestSBClient | 431 class TestSBClient |
387 : public base::RefCountedThreadSafe<TestSBClient>, | 432 : public base::RefCountedThreadSafe<TestSBClient>, |
388 public SafeBrowsingService::Client { | 433 public SafeBrowsingService::Client { |
389 public: | 434 public: |
390 TestSBClient() : result_(SafeBrowsingService::SAFE), | 435 TestSBClient() : result_(SafeBrowsingService::SAFE), |
391 safe_browsing_service_(g_browser_process-> | 436 safe_browsing_service_(g_browser_process-> |
392 resource_dispatcher_host()-> | 437 resource_dispatcher_host()-> |
393 safe_browsing_service()) { | 438 safe_browsing_service()) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 client->CheckDownloadHash(full_hash); | 601 client->CheckDownloadHash(full_hash); |
557 | 602 |
558 // There should be a timeout and the hash would be considered as safe. | 603 // There should be a timeout and the hash would be considered as safe. |
559 EXPECT_EQ(SafeBrowsingService::SAFE, client->GetResult()); | 604 EXPECT_EQ(SafeBrowsingService::SAFE, client->GetResult()); |
560 | 605 |
561 // Need to set the timeout back to the default value. | 606 // Need to set the timeout back to the default value. |
562 SetDownloadHashCheckTimeout(sb_service, default_hashcheck_timeout); | 607 SetDownloadHashCheckTimeout(sb_service, default_hashcheck_timeout); |
563 } | 608 } |
564 | 609 |
565 } // namespace | 610 } // namespace |
OLD | NEW |