Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc

Issue 2615883003: [NoStatePrefetch] Implement FINAL_STATUS_SAFEBROWSING (Closed)
Patch Set: plumb FINAL_STATUS_SAFEBROWSING Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/loader/safe_browsing_resource_throttle.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/string16.h" 6 #include "base/strings/string16.h"
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.h"
8 #include "base/task_scheduler/post_task.h" 8 #include "base/task_scheduler/post_task.h"
9 #include "chrome/browser/history/history_service_factory.h" 9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/history/history_test_utils.h" 10 #include "chrome/browser/history/history_test_utils.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 RequestCounter* counter) { 79 RequestCounter* counter) {
80 base::FilePath url_file = ui_test_utils::GetTestFilePath( 80 base::FilePath url_file = ui_test_utils::GetTestFilePath(
81 base::FilePath(), base::FilePath::FromUTF8Unsafe(path_str)); 81 base::FilePath(), base::FilePath::FromUTF8Unsafe(path_str));
82 content::BrowserThread::PostTask( 82 content::BrowserThread::PostTask(
83 content::BrowserThread::IO, FROM_HERE, 83 content::BrowserThread::IO, FROM_HERE,
84 base::Bind(&prerender::test_utils::CreateCountingInterceptorOnIO, url, 84 base::Bind(&prerender::test_utils::CreateCountingInterceptorOnIO, url,
85 url_file, counter->AsWeakPtr())); 85 url_file, counter->AsWeakPtr()));
86 } 86 }
87 87
88 protected: 88 protected:
89 // Pass FINAL_STATUS_MAX to skip the final status check.
89 std::unique_ptr<TestPrerender> PrefetchFromURL( 90 std::unique_ptr<TestPrerender> PrefetchFromURL(
90 const GURL& target_url, 91 const GURL& target_url,
91 FinalStatus expected_final_status) { 92 FinalStatus expected_final_status) {
92 GURL loader_url = ServeLoaderURL( 93 GURL loader_url = ServeLoaderURL(
93 kPrefetchLoaderPath, "REPLACE_WITH_PREFETCH_URL", target_url, ""); 94 kPrefetchLoaderPath, "REPLACE_WITH_PREFETCH_URL", target_url, "");
94 std::vector<FinalStatus> expected_final_status_queue(1, 95 std::vector<FinalStatus> expected_final_status_queue(1,
95 expected_final_status); 96 expected_final_status);
96 std::vector<std::unique_ptr<TestPrerender>> prerenders = 97 std::vector<std::unique_ptr<TestPrerender>> prerenders =
97 NavigateWithPrerenders(loader_url, expected_final_status_queue); 98 NavigateWithPrerenders(loader_url, expected_final_status_queue);
99 if (expected_final_status == FINAL_STATUS_MAX)
100 prerenders[0]->contents()->set_skip_final_checks(true);
98 prerenders[0]->WaitForStop(); 101 prerenders[0]->WaitForStop();
99 return std::move(prerenders[0]); 102 return std::move(prerenders[0]);
100 } 103 }
101 104
102 std::unique_ptr<TestPrerender> PrefetchFromFile( 105 std::unique_ptr<TestPrerender> PrefetchFromFile(
103 const std::string& html_file, 106 const std::string& html_file,
104 FinalStatus expected_final_status) { 107 FinalStatus expected_final_status) {
105 return PrefetchFromURL(src_server()->GetURL(MakeAbsolute(html_file)), 108 return PrefetchFromURL(src_server()->GetURL(MakeAbsolute(html_file)),
106 expected_final_status); 109 expected_final_status);
107 } 110 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } 463 }
461 464
462 // Checks that the prefetch of png correctly loads the jpeg. 465 // Checks that the prefetch of png correctly loads the jpeg.
463 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Jpeg) { 466 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Jpeg) {
464 RequestCounter counter; 467 RequestCounter counter;
465 CountRequestFor(kPrefetchJpeg, &counter); 468 CountRequestFor(kPrefetchJpeg, &counter);
466 PrefetchFromFile(kPrefetchJpeg, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); 469 PrefetchFromFile(kPrefetchJpeg, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED);
467 counter.WaitForCount(1); 470 counter.WaitForCount(1);
468 } 471 }
469 472
470 // Checks that nothing is prefetched from malware sites. 473 // If the main resource is unsafe, the whole prefetch is cancelled.
471 // TODO(mattcary): disabled as prefetch process teardown is racey with prerender
472 // contents destruction, can fix when prefetch prerenderers are destroyed
473 // deterministically.
474 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, 474 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
475 DISABLED_PrerenderSafeBrowsingTopLevel) { 475 PrerenderSafeBrowsingTopLevel) {
476 GURL url = src_server()->GetURL(MakeAbsolute(kPrefetchPage)); 476 GURL url = src_server()->GetURL(MakeAbsolute(kPrefetchPage));
477 GetFakeSafeBrowsingDatabaseManager()->SetThreatTypeForUrl( 477 GetFakeSafeBrowsingDatabaseManager()->SetThreatTypeForUrl(
478 url, safe_browsing::SB_THREAT_TYPE_URL_MALWARE); 478 url, safe_browsing::SB_THREAT_TYPE_URL_MALWARE);
479 // Prefetch resources are blocked, but the prerender is not killed in any 479
480 // special way. 480 RequestCounter main_counter;
481 // TODO(mattcary): since the prerender will count itself as loaded even if the 481 CountRequestFor(kPrefetchPage, &main_counter);
482 // fetch of the main resource fails, the test doesn't actually confirm what we 482 RequestCounter script_counter;
483 // want it to confirm. This may be fixed by planned changes to the prerender 483 CountRequestFor(kPrefetchScript, &script_counter);
484 // lifecycle. 484
485 std::unique_ptr<TestPrerender> prerender = 485 std::unique_ptr<TestPrerender> prerender =
486 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_SAFE_BROWSING); 486 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_SAFE_BROWSING);
487
488 main_counter.WaitForCount(0);
489 script_counter.WaitForCount(0);
490
491 // Verify that the page load did not happen.
492 prerender->WaitForLoads(0);
493 }
494
495 // If a subresource is unsafe, the corresponding request is cancelled.
496 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
497 PrerenderSafeBrowsingSubresource) {
498 GURL url = src_server()->GetURL(MakeAbsolute(kPrefetchScript));
499 GetFakeSafeBrowsingDatabaseManager()->SetThreatTypeForUrl(
500 url, safe_browsing::SB_THREAT_TYPE_URL_MALWARE);
501
502 RequestCounter main_counter;
503 CountRequestFor(kPrefetchPage, &main_counter);
504 RequestCounter script_counter;
505 CountRequestFor(kPrefetchScript, &script_counter);
506
507 // The final status can be FINAL_STATUS_NOSTATE_PREFETCH_FINISHED or
508 // FINAL_STATUS_SAFE_BROWSING, depending wether the PrerenderContents was
509 // already destroyed when the subresource is loaded.
mattcary 2017/01/06 16:37:20 It seems a shame to not to have a reliable final s
droger 2017/01/06 16:43:42 The easy way to make it reliable would be to call
droger 2017/01/06 17:14:16 Done.
510 std::unique_ptr<TestPrerender> prerender =
511 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_MAX);
512
513 main_counter.WaitForCount(1);
514 script_counter.WaitForCount(0);
487 } 515 }
488 516
489 // Checks that prefetching a page does not add it to browsing history. 517 // Checks that prefetching a page does not add it to browsing history.
490 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, HistoryUntouchedByPrefetch) { 518 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, HistoryUntouchedByPrefetch) {
491 // Initialize. 519 // Initialize.
492 Profile* profile = current_browser()->profile(); 520 Profile* profile = current_browser()->profile();
493 ASSERT_TRUE(profile); 521 ASSERT_TRUE(profile);
494 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( 522 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile(
495 profile, ServiceAccessType::EXPLICIT_ACCESS)); 523 profile, ServiceAccessType::EXPLICIT_ACCESS));
496 524
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 #else 558 #else
531 constexpr net::RequestPriority kExpectedPriority = net::IDLE; 559 constexpr net::RequestPriority kExpectedPriority = net::IDLE;
532 #endif 560 #endif
533 EXPECT_EQ(kExpectedPriority, request->priority()); 561 EXPECT_EQ(kExpectedPriority, request->priority());
534 })); 562 }));
535 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); 563 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED);
536 script_counter.WaitForCount(1); 564 script_counter.WaitForCount(1);
537 } 565 }
538 566
539 } // namespace prerender 567 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/loader/safe_browsing_resource_throttle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698