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

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

Issue 2529653002: Prerender: Test that prefetch flags are set correctly on redirect. (Closed)
Patch Set: tweak comments Created 4 years 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
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 "chrome/browser/prerender/prerender_test_utils.h" 5 #include "chrome/browser/prerender/prerender_test_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 13 matching lines...) Expand all
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "components/prefs/pref_service.h" 26 #include "components/prefs/pref_service.h"
27 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/notification_types.h" 29 #include "content/public/browser/notification_types.h"
30 #include "content/public/browser/render_view_host.h" 30 #include "content/public/browser/render_view_host.h"
31 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
32 #include "content/public/common/url_constants.h" 32 #include "content/public/common/url_constants.h"
33 #include "content/public/test/ppapi_test_utils.h" 33 #include "content/public/test/ppapi_test_utils.h"
34 #include "net/base/load_flags.h"
34 #include "net/test/embedded_test_server/request_handler_util.h" 35 #include "net/test/embedded_test_server/request_handler_util.h"
35 #include "net/url_request/url_request_filter.h" 36 #include "net/url_request/url_request_filter.h"
36 #include "ppapi/shared_impl/ppapi_switches.h" 37 #include "ppapi/shared_impl/ppapi_switches.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
39 40
40 using content::BrowserThread; 41 using content::BrowserThread;
41 using content::RenderViewHost; 42 using content::RenderViewHost;
42 43
43 namespace prerender { 44 namespace prerender {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 content::BrowserThread::UI, FROM_HERE, 98 content::BrowserThread::UI, FROM_HERE,
98 base::Bind(&RequestCounter::RequestStarted, counter_)); 99 base::Bind(&RequestCounter::RequestStarted, counter_));
99 } 100 }
100 101
101 private: 102 private:
102 base::FilePath file_; 103 base::FilePath file_;
103 base::WeakPtr<RequestCounter> counter_; 104 base::WeakPtr<RequestCounter> counter_;
104 mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_; 105 mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_;
105 }; 106 };
106 107
108 // URLRequestInterceptor which asserts that the request is prefetch only. Pings
109 // |counter| after the flag is checked.
110 class PrefetchOnlyInterceptor : public net::URLRequestInterceptor {
111 public:
112 explicit PrefetchOnlyInterceptor(const base::WeakPtr<RequestCounter>& counter)
113 : counter_(counter) {}
114 ~PrefetchOnlyInterceptor() override {}
115
116 net::URLRequestJob* MaybeInterceptRequest(
117 net::URLRequest* request,
118 net::NetworkDelegate* network_delegate) const override {
119 EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH);
120 content::BrowserThread::PostTask(
121 content::BrowserThread::UI, FROM_HERE,
122 base::Bind(&RequestCounter::RequestStarted, counter_));
123 return NULL;
droger 2016/11/23 15:20:10 nullptr
mattcary 2016/11/23 15:28:32 Yikes, how 2010 of me.
124 }
125
126 private:
127 base::WeakPtr<RequestCounter> counter_;
128 };
129
107 // URLRequestJob (and associated handler) which hangs. 130 // URLRequestJob (and associated handler) which hangs.
108 class HangingURLRequestJob : public net::URLRequestJob { 131 class HangingURLRequestJob : public net::URLRequestJob {
109 public: 132 public:
110 HangingURLRequestJob(net::URLRequest* request, 133 HangingURLRequestJob(net::URLRequest* request,
111 net::NetworkDelegate* network_delegate) 134 net::NetworkDelegate* network_delegate)
112 : net::URLRequestJob(request, network_delegate) { 135 : net::URLRequestJob(request, network_delegate) {
113 } 136 }
114 137
115 void Start() override {} 138 void Start() override {}
116 139
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 714
692 void CreateCountingInterceptorOnIO( 715 void CreateCountingInterceptorOnIO(
693 const GURL& url, 716 const GURL& url,
694 const base::FilePath& file, 717 const base::FilePath& file,
695 const base::WeakPtr<RequestCounter>& counter) { 718 const base::WeakPtr<RequestCounter>& counter) {
696 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 719 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
697 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 720 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
698 url, base::MakeUnique<CountingInterceptor>(file, counter)); 721 url, base::MakeUnique<CountingInterceptor>(file, counter));
699 } 722 }
700 723
724 void CreatePrefetchOnlyInterceptorOnIO(
725 const GURL& url,
726 const base::WeakPtr<RequestCounter>& counter) {
727 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
728 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
729 url, base::MakeUnique<PrefetchOnlyInterceptor>(counter));
730 }
731
701 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { 732 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
702 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 733 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
703 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 734 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
704 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( 735 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
705 file, content::BrowserThread::GetBlockingPool())); 736 file, content::BrowserThread::GetBlockingPool()));
706 } 737 }
707 738
708 void CreateHangingFirstRequestInterceptorOnIO( 739 void CreateHangingFirstRequestInterceptorOnIO(
709 const GURL& url, const base::FilePath& file, base::Closure callback) { 740 const GURL& url, const base::FilePath& file, base::Closure callback) {
710 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 741 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
711 std::unique_ptr<net::URLRequestInterceptor> interceptor( 742 std::unique_ptr<net::URLRequestInterceptor> interceptor(
712 new HangingFirstRequestInterceptor(file, callback)); 743 new HangingFirstRequestInterceptor(file, callback));
713 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 744 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
714 url, std::move(interceptor)); 745 url, std::move(interceptor));
715 } 746 }
716 747
717 } // namespace test_utils 748 } // namespace test_utils
718 749
719 } // namespace prerender 750 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698