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

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

Issue 2508143002: Prerender: add true simultaneous nostate prefetch test. (Closed)
Patch Set: comments Created 4 years, 1 month 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 | « no previous file | chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc » ('j') | 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 <stddef.h> 5 #include <stddef.h>
6 #include <deque> 6 #include <deque>
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <utility> 10 #include <utility>
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 using content::Referrer; 129 using content::Referrer;
130 using content::RenderFrameHost; 130 using content::RenderFrameHost;
131 using content::RenderViewHost; 131 using content::RenderViewHost;
132 using content::RenderWidgetHost; 132 using content::RenderWidgetHost;
133 using content::TestNavigationObserver; 133 using content::TestNavigationObserver;
134 using content::WebContents; 134 using content::WebContents;
135 using content::WebContentsObserver; 135 using content::WebContentsObserver;
136 using net::NetworkChangeNotifier; 136 using net::NetworkChangeNotifier;
137 using prerender::test_utils::RequestCounter; 137 using prerender::test_utils::RequestCounter;
138 using prerender::test_utils::CreateCountingInterceptorOnIO; 138 using prerender::test_utils::CreateCountingInterceptorOnIO;
139 using prerender::test_utils::CreateHangingFirstRequestInterceptorOnIO;
139 using prerender::test_utils::CreateMockInterceptorOnIO; 140 using prerender::test_utils::CreateMockInterceptorOnIO;
140 using prerender::test_utils::TestPrerender; 141 using prerender::test_utils::TestPrerender;
141 using prerender::test_utils::TestPrerenderContents; 142 using prerender::test_utils::TestPrerenderContents;
142 using task_manager::browsertest_util::WaitForTaskManagerRows; 143 using task_manager::browsertest_util::WaitForTaskManagerRows;
143 144
144 // Prerender tests work as follows: 145 // Prerender tests work as follows:
145 // 146 //
146 // A page with a prefetch link to the test page is loaded. Once prerendered, 147 // A page with a prefetch link to the test page is loaded. Once prerendered,
147 // its Javascript function DidPrerenderPass() is called, which returns true if 148 // its Javascript function DidPrerenderPass() is called, which returns true if
148 // the page behaves as expected when prerendered. 149 // the page behaves as expected when prerendered.
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 class RestorePrerenderMode { 482 class RestorePrerenderMode {
482 public: 483 public:
483 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) { 484 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) {
484 } 485 }
485 486
486 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); } 487 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); }
487 private: 488 private:
488 PrerenderManager::PrerenderManagerMode prev_mode_; 489 PrerenderManager::PrerenderManagerMode prev_mode_;
489 }; 490 };
490 491
491 // URLRequestJob (and associated handler) which hangs.
492 class HangingURLRequestJob : public net::URLRequestJob {
493 public:
494 HangingURLRequestJob(net::URLRequest* request,
495 net::NetworkDelegate* network_delegate)
496 : net::URLRequestJob(request, network_delegate) {
497 }
498
499 void Start() override {}
500
501 private:
502 ~HangingURLRequestJob() override {}
503 };
504
505 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor {
506 public:
507 HangingFirstRequestInterceptor(const base::FilePath& file,
508 base::Closure callback)
509 : file_(file),
510 callback_(callback),
511 first_run_(true) {
512 }
513 ~HangingFirstRequestInterceptor() override {}
514
515 net::URLRequestJob* MaybeInterceptRequest(
516 net::URLRequest* request,
517 net::NetworkDelegate* network_delegate) const override {
518 if (first_run_) {
519 first_run_ = false;
520 if (!callback_.is_null()) {
521 BrowserThread::PostTask(
522 BrowserThread::UI, FROM_HERE, callback_);
523 }
524 return new HangingURLRequestJob(request, network_delegate);
525 }
526 return new net::URLRequestMockHTTPJob(
527 request,
528 network_delegate,
529 file_,
530 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
531 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
532 }
533
534 private:
535 base::FilePath file_;
536 base::Closure callback_;
537 mutable bool first_run_;
538 };
539
540 // Makes |url| never respond on the first load, and then with the contents of
541 // |file| afterwards. When the first load has been scheduled, runs |callback| on
542 // the UI thread.
543 void CreateHangingFirstRequestInterceptorOnIO(
544 const GURL& url, const base::FilePath& file, base::Closure callback) {
545 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
546 std::unique_ptr<net::URLRequestInterceptor> never_respond_handler(
547 new HangingFirstRequestInterceptor(file, callback));
548 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
549 url, std::move(never_respond_handler));
550 }
551
552 // A ContentBrowserClient that cancels all prerenderers on OpenURL. 492 // A ContentBrowserClient that cancels all prerenderers on OpenURL.
553 class TestContentBrowserClient : public ChromeContentBrowserClient { 493 class TestContentBrowserClient : public ChromeContentBrowserClient {
554 public: 494 public:
555 TestContentBrowserClient() {} 495 TestContentBrowserClient() {}
556 ~TestContentBrowserClient() override {} 496 ~TestContentBrowserClient() override {}
557 497
558 // ChromeContentBrowserClient: 498 // ChromeContentBrowserClient:
559 bool ShouldAllowOpenURL(content::SiteInstance* site_instance, 499 bool ShouldAllowOpenURL(content::SiteInstance* site_instance,
560 const GURL& url) override { 500 const GURL& url) override {
561 PrerenderManagerFactory::GetForBrowserContext( 501 PrerenderManagerFactory::GetForBrowserContext(
(...skipping 2844 matching lines...) Expand 10 before | Expand all | Expand 10 after
3406 browser()->tab_strip_model()->GetActiveWebContents(); 3346 browser()->tab_strip_model()->GetActiveWebContents();
3407 bool display_test_result = false; 3347 bool display_test_result = false;
3408 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, 3348 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents,
3409 "DidDisplayReallyPass()", 3349 "DidDisplayReallyPass()",
3410 &display_test_result)); 3350 &display_test_result));
3411 ASSERT_TRUE(display_test_result); 3351 ASSERT_TRUE(display_test_result);
3412 } 3352 }
3413 #endif // !defined(DISABLE_NACL) 3353 #endif // !defined(DISABLE_NACL)
3414 3354
3415 } // namespace prerender 3355 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698