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

Side by Side Diff: chrome/browser/io_thread_browsertest.cc

Issue 2945083002: Remove memory cache from system URLRequestContext. (Closed)
Patch Set: Remove change from another CL Created 3 years, 6 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/io_thread.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 void WaitForCompletion() { run_loop_.Run(); } 54 void WaitForCompletion() { run_loop_.Run(); }
55 55
56 private: 56 private:
57 base::RunLoop run_loop_; 57 base::RunLoop run_loop_;
58 58
59 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherDelegate); 59 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherDelegate);
60 }; 60 };
61 61
62 class IOThreadPacTest : public InProcessBrowserTest { 62 class IOThreadBrowserTest : public InProcessBrowserTest {
63 public: 63 public:
64 IOThreadPacTest() {} 64 IOThreadBrowserTest() {}
65 ~IOThreadPacTest() override {} 65 ~IOThreadBrowserTest() override {}
66 66
67 void SetUp() override { 67 void SetUp() override {
68 // Must start listening (And get a port for the proxy) before calling 68 // Must start listening (And get a port for the proxy) before calling
69 // SetUp(). 69 // SetUp(). Use two phase EmbeddedTestServer setup for proxy tests.
70 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); 70 ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
71 InProcessBrowserTest::SetUp(); 71 InProcessBrowserTest::SetUp();
72 } 72 }
73 73
74 void SetUpOnMainThread() override { 74 void SetUpOnMainThread() override {
75 embedded_test_server()->StartAcceptingConnections(); 75 embedded_test_server()->StartAcceptingConnections();
76 76
77 InProcessBrowserTest::SetUpOnMainThread(); 77 InProcessBrowserTest::SetUpOnMainThread();
78 } 78 }
79 79
80 void TearDown() override { 80 void TearDown() override {
81 // Need to stop this before |connection_listener_| is destroyed. 81 // Need to stop this before |connection_listener_| is destroyed.
82 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); 82 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
83 InProcessBrowserTest::TearDown(); 83 InProcessBrowserTest::TearDown();
84 } 84 }
85 }; 85 };
86 86
87 class IOThreadPacTestWithHangingRequest : public IOThreadPacTest { 87 // Make sure that the system URLRequestContext does not cache responses. Main
88 // reason for this test is that caching requires memory, so this guards against
89 // accidentally hooking up a cache.
90 IN_PROC_BROWSER_TEST_F(IOThreadBrowserTest, NoCache) {
91 GURL cacheable_url = embedded_test_server()->GetURL("/cachetime");
92 // Request a cacheable resource. Request should succeed.
93 TestURLFetcherDelegate fetcher_delegate;
94 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
95 cacheable_url, net::URLFetcher::GET, &fetcher_delegate);
96 fetcher->SetRequestContext(
97 g_browser_process->io_thread()->system_url_request_context_getter());
98 fetcher->Start();
99 fetcher_delegate.WaitForCompletion();
100 EXPECT_EQ(200, fetcher->GetResponseCode());
101
102 // Shut down server and re-request resource. Request should fail.
103 TestURLFetcherDelegate failed_fetcher_delegate;
104 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
105 fetcher = net::URLFetcher::Create(cacheable_url, net::URLFetcher::GET,
106 &failed_fetcher_delegate);
107 fetcher->SetRequestContext(
108 g_browser_process->io_thread()->system_url_request_context_getter());
109 fetcher->Start();
110 failed_fetcher_delegate.WaitForCompletion();
111 EXPECT_FALSE(fetcher->GetStatus().is_success());
112 EXPECT_EQ(net::ERR_CONNECTION_REFUSED, fetcher->GetStatus().error());
113 }
114
115 class IOThreadBrowserTestWithHangingPacRequest : public IOThreadBrowserTest {
88 public: 116 public:
89 IOThreadPacTestWithHangingRequest() {} 117 IOThreadBrowserTestWithHangingPacRequest() {}
90 ~IOThreadPacTestWithHangingRequest() override {} 118 ~IOThreadBrowserTestWithHangingPacRequest() override {}
91 119
92 void SetUpOnMainThread() override { 120 void SetUpOnMainThread() override {
93 // This must be created after the main message loop has been set up. 121 // This must be created after the main message loop has been set up.
94 // Waits for one connection. Additional connections are fine. 122 // Waits for one connection. Additional connections are fine.
95 connection_listener_ = 123 connection_listener_ =
96 base::MakeUnique<net::test_server::SimpleConnectionListener>( 124 base::MakeUnique<net::test_server::SimpleConnectionListener>(
97 1, net::test_server::SimpleConnectionListener:: 125 1, net::test_server::SimpleConnectionListener::
98 ALLOW_ADDITIONAL_CONNECTIONS); 126 ALLOW_ADDITIONAL_CONNECTIONS);
99 127
100 embedded_test_server()->SetConnectionListener(connection_listener_.get()); 128 embedded_test_server()->SetConnectionListener(connection_listener_.get());
101 129
102 IOThreadPacTest::SetUpOnMainThread(); 130 IOThreadBrowserTest::SetUpOnMainThread();
103 } 131 }
104 132
105 void SetUpCommandLine(base::CommandLine* command_line) override { 133 void SetUpCommandLine(base::CommandLine* command_line) override {
106 command_line->AppendSwitchASCII( 134 command_line->AppendSwitchASCII(
107 switches::kProxyPacUrl, embedded_test_server()->GetURL("/hung").spec()); 135 switches::kProxyPacUrl, embedded_test_server()->GetURL("/hung").spec());
108 } 136 }
109 137
110 protected: 138 protected:
111 std::unique_ptr<net::test_server::SimpleConnectionListener> 139 std::unique_ptr<net::test_server::SimpleConnectionListener>
112 connection_listener_; 140 connection_listener_;
113 }; 141 };
114 142
115 // Make sure that the SystemURLRequestContext is shut down correctly when 143 // Make sure that the SystemURLRequestContext is shut down correctly when
116 // there's an in-progress PAC script fetch. 144 // there's an in-progress PAC script fetch.
117 IN_PROC_BROWSER_TEST_F(IOThreadPacTestWithHangingRequest, Shutdown) { 145 IN_PROC_BROWSER_TEST_F(IOThreadBrowserTestWithHangingPacRequest, Shutdown) {
118 // Request that should hang while trying to request the PAC script. 146 // Request that should hang while trying to request the PAC script.
119 // Enough requests are created on startup that this probably isn't needed, but 147 // Enough requests are created on startup that this probably isn't needed, but
120 // best to be safe. 148 // best to be safe.
121 HangingURLFetcherDelegate hanging_fetcher_delegate; 149 HangingURLFetcherDelegate hanging_fetcher_delegate;
122 std::unique_ptr<net::URLFetcher> hanging_fetcher = net::URLFetcher::Create( 150 std::unique_ptr<net::URLFetcher> hanging_fetcher = net::URLFetcher::Create(
123 GURL("http://blah/"), net::URLFetcher::GET, &hanging_fetcher_delegate); 151 GURL("http://blah/"), net::URLFetcher::GET, &hanging_fetcher_delegate);
124 hanging_fetcher->SetRequestContext( 152 hanging_fetcher->SetRequestContext(
125 g_browser_process->io_thread()->system_url_request_context_getter()); 153 g_browser_process->io_thread()->system_url_request_context_getter());
126 hanging_fetcher->Start(); 154 hanging_fetcher->Start();
127 155
128 connection_listener_->WaitForConnections(); 156 connection_listener_->WaitForConnections();
129 } 157 }
130 158
131 class IOThreadPacTestWithFileURL : public IOThreadPacTest { 159 class IOThreadBrowserTestWithPacFileURL : public IOThreadBrowserTest {
132 public: 160 public:
133 IOThreadPacTestWithFileURL() { EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); } 161 IOThreadBrowserTestWithPacFileURL() {
162 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
163 }
134 164
135 ~IOThreadPacTestWithFileURL() override {} 165 ~IOThreadBrowserTestWithPacFileURL() override {}
136 166
137 void SetUpCommandLine(base::CommandLine* command_line) override { 167 void SetUpCommandLine(base::CommandLine* command_line) override {
138 base::FilePath pac_file_path; 168 base::FilePath pac_file_path;
139 ASSERT_TRUE( 169 ASSERT_TRUE(
140 base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &pac_file_path)); 170 base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &pac_file_path));
141 171
142 std::string pac_script = base::StringPrintf( 172 std::string pac_script = base::StringPrintf(
143 "function FindProxyForURL(url, host){ return 'PROXY %s;'; }", 173 "function FindProxyForURL(url, host){ return 'PROXY %s;'; }",
144 net::HostPortPair::FromURL(embedded_test_server()->base_url()) 174 net::HostPortPair::FromURL(embedded_test_server()->base_url())
145 .ToString() 175 .ToString()
146 .c_str()); 176 .c_str());
147 ASSERT_EQ( 177 ASSERT_EQ(
148 static_cast<int>(pac_script.size()), 178 static_cast<int>(pac_script.size()),
149 base::WriteFile(pac_file_path, pac_script.c_str(), pac_script.size())); 179 base::WriteFile(pac_file_path, pac_script.c_str(), pac_script.size()));
150 180
151 command_line->AppendSwitchASCII( 181 command_line->AppendSwitchASCII(
152 switches::kProxyPacUrl, net::FilePathToFileURL(pac_file_path).spec()); 182 switches::kProxyPacUrl, net::FilePathToFileURL(pac_file_path).spec());
153 } 183 }
154 184
155 protected: 185 protected:
156 base::ScopedTempDir temp_dir_; 186 base::ScopedTempDir temp_dir_;
157 }; 187 };
158 188
159 // Make sure the system URLRequestContext can hadle fetching PAC scripts from 189 // Make sure the system URLRequestContext can hadle fetching PAC scripts from
160 // file URLs. 190 // file URLs.
161 IN_PROC_BROWSER_TEST_F(IOThreadPacTestWithFileURL, FilePac) { 191 IN_PROC_BROWSER_TEST_F(IOThreadBrowserTestWithPacFileURL, FilePac) {
162 TestURLFetcherDelegate fetcher_delegate; 192 TestURLFetcherDelegate fetcher_delegate;
163 std::unique_ptr<net::URLFetcher> fetcher = 193 std::unique_ptr<net::URLFetcher> fetcher =
164 net::URLFetcher::Create(GURL("http://foo:12345/echoheader?Foo"), 194 net::URLFetcher::Create(GURL("http://foo:12345/echoheader?Foo"),
165 net::URLFetcher::GET, &fetcher_delegate); 195 net::URLFetcher::GET, &fetcher_delegate);
166 fetcher->AddExtraRequestHeader("Foo: Bar"); 196 fetcher->AddExtraRequestHeader("Foo: Bar");
167 fetcher->SetRequestContext( 197 fetcher->SetRequestContext(
168 g_browser_process->io_thread()->system_url_request_context_getter()); 198 g_browser_process->io_thread()->system_url_request_context_getter());
169 fetcher->Start(); 199 fetcher->Start();
170 fetcher_delegate.WaitForCompletion(); 200 fetcher_delegate.WaitForCompletion();
171 EXPECT_EQ(200, fetcher->GetResponseCode()); 201 EXPECT_EQ(200, fetcher->GetResponseCode());
172 std::string response; 202 std::string response;
173 ASSERT_TRUE(fetcher->GetResponseAsString(&response)); 203 ASSERT_TRUE(fetcher->GetResponseAsString(&response));
174 EXPECT_EQ("Bar", response); 204 EXPECT_EQ("Bar", response);
175 } 205 }
176 206
177 } // namespace 207 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698