OLD | NEW |
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/ui/webui/net_internals/net_internals_ui_browsertest.h" | 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_ui_message_handler.h" | 28 #include "content/public/browser/web_ui_message_handler.h" |
29 #include "net/base/address_list.h" | 29 #include "net/base/address_list.h" |
30 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
31 #include "net/base/net_log.h" | 31 #include "net/base/net_log.h" |
32 #include "net/base/net_log_logger.h" | 32 #include "net/base/net_log_logger.h" |
33 #include "net/dns/host_cache.h" | 33 #include "net/dns/host_cache.h" |
34 #include "net/dns/host_resolver.h" | 34 #include "net/dns/host_resolver.h" |
35 #include "net/dns/mock_host_resolver.h" | 35 #include "net/dns/mock_host_resolver.h" |
36 #include "net/http/http_network_session.h" | 36 #include "net/http/http_network_session.h" |
37 #include "net/http/http_pipelined_host_capability.h" | |
38 #include "net/http/http_transaction_factory.h" | 37 #include "net/http/http_transaction_factory.h" |
39 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
40 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
42 #include "url/gurl.h" | 41 #include "url/gurl.h" |
43 | 42 |
44 using content::BrowserThread; | 43 using content::BrowserThread; |
45 using content::WebUIMessageHandler; | 44 using content::WebUIMessageHandler; |
46 | 45 |
47 namespace { | 46 namespace { |
(...skipping 23 matching lines...) Expand all Loading... |
71 ASSERT_TRUE(ip_literal.empty()); | 70 ASSERT_TRUE(ip_literal.empty()); |
72 } | 71 } |
73 | 72 |
74 // Add entry to the cache. | 73 // Add entry to the cache. |
75 cache->Set(net::HostCache::Key(hostname, net::ADDRESS_FAMILY_UNSPECIFIED, 0), | 74 cache->Set(net::HostCache::Key(hostname, net::ADDRESS_FAMILY_UNSPECIFIED, 0), |
76 net::HostCache::Entry(net_error, address_list), | 75 net::HostCache::Entry(net_error, address_list), |
77 base::TimeTicks::Now(), | 76 base::TimeTicks::Now(), |
78 ttl); | 77 ttl); |
79 } | 78 } |
80 | 79 |
81 // Called on IO thread. Adds an entry to the list of known HTTP pipelining | |
82 // hosts. | |
83 void AddDummyHttpPipelineFeedbackOnIOThread( | |
84 net::URLRequestContextGetter* context_getter, | |
85 const std::string& hostname, | |
86 int port, | |
87 net::HttpPipelinedHostCapability capability) { | |
88 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
89 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | |
90 net::HttpNetworkSession* http_network_session = | |
91 context->http_transaction_factory()->GetSession(); | |
92 base::WeakPtr<net::HttpServerProperties> http_server_properties = | |
93 http_network_session->http_server_properties(); | |
94 net::HostPortPair origin(hostname, port); | |
95 http_server_properties->SetPipelineCapability(origin, capability); | |
96 } | |
97 | |
98 // Called on IO thread. Adds an entry to the list of known HTTP pipelining | |
99 // hosts. | |
100 void EnableHttpPipeliningOnIOThread( | |
101 net::URLRequestContextGetter* context_getter, bool enable) { | |
102 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
103 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | |
104 net::HttpNetworkSession* http_network_session = | |
105 context->http_transaction_factory()->GetSession(); | |
106 http_network_session->set_http_pipelining_enabled(enable); | |
107 } | |
108 | |
109 } // namespace | 80 } // namespace |
110 | 81 |
111 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
112 // NetInternalsTest::MessageHandler | 83 // NetInternalsTest::MessageHandler |
113 //////////////////////////////////////////////////////////////////////////////// | 84 //////////////////////////////////////////////////////////////////////////////// |
114 | 85 |
115 // Class to handle messages from the renderer needed by certain tests. | 86 // Class to handle messages from the renderer needed by certain tests. |
116 class NetInternalsTest::MessageHandler : public content::WebUIMessageHandler { | 87 class NetInternalsTest::MessageHandler : public content::WebUIMessageHandler { |
117 public: | 88 public: |
118 explicit MessageHandler(NetInternalsTest* net_internals_test); | 89 explicit MessageHandler(NetInternalsTest* net_internals_test); |
(...skipping 26 matching lines...) Expand all Loading... |
145 // there, and that the background tab exists at slot 1. | 116 // there, and that the background tab exists at slot 1. |
146 void NavigateToPrerender(const base::ListValue* list_value); | 117 void NavigateToPrerender(const base::ListValue* list_value); |
147 | 118 |
148 // Creates an incognito browser. Once creation is complete, passes a | 119 // Creates an incognito browser. Once creation is complete, passes a |
149 // message to the Javascript test harness. | 120 // message to the Javascript test harness. |
150 void CreateIncognitoBrowser(const base::ListValue* list_value); | 121 void CreateIncognitoBrowser(const base::ListValue* list_value); |
151 | 122 |
152 // Closes an incognito browser created with CreateIncognitoBrowser. | 123 // Closes an incognito browser created with CreateIncognitoBrowser. |
153 void CloseIncognitoBrowser(const base::ListValue* list_value); | 124 void CloseIncognitoBrowser(const base::ListValue* list_value); |
154 | 125 |
155 // Takes in a boolean and enables/disabled HTTP pipelining accordingly. | |
156 void EnableHttpPipelining(const base::ListValue* list_value); | |
157 | |
158 // Called on UI thread. Adds an entry to the list of known HTTP pipelining | |
159 // hosts. | |
160 void AddDummyHttpPipelineFeedback(const base::ListValue* list_value); | |
161 | |
162 // Creates a simple log with a NetLogLogger, and returns it to the | 126 // Creates a simple log with a NetLogLogger, and returns it to the |
163 // Javascript callback. | 127 // Javascript callback. |
164 void GetNetLogLoggerLog(const base::ListValue* list_value); | 128 void GetNetLogLoggerLog(const base::ListValue* list_value); |
165 | 129 |
166 Browser* browser() { return net_internals_test_->browser(); } | 130 Browser* browser() { return net_internals_test_->browser(); } |
167 | 131 |
168 NetInternalsTest* net_internals_test_; | 132 NetInternalsTest* net_internals_test_; |
169 Browser* incognito_browser_; | 133 Browser* incognito_browser_; |
170 | 134 |
171 DISALLOW_COPY_AND_ASSIGN(MessageHandler); | 135 DISALLOW_COPY_AND_ASSIGN(MessageHandler); |
(...skipping 20 matching lines...) Expand all Loading... |
192 base::Unretained(this))); | 156 base::Unretained(this))); |
193 web_ui()->RegisterMessageCallback("navigateToPrerender", | 157 web_ui()->RegisterMessageCallback("navigateToPrerender", |
194 base::Bind(&NetInternalsTest::MessageHandler::NavigateToPrerender, | 158 base::Bind(&NetInternalsTest::MessageHandler::NavigateToPrerender, |
195 base::Unretained(this))); | 159 base::Unretained(this))); |
196 web_ui()->RegisterMessageCallback("createIncognitoBrowser", | 160 web_ui()->RegisterMessageCallback("createIncognitoBrowser", |
197 base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser, | 161 base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser, |
198 base::Unretained(this))); | 162 base::Unretained(this))); |
199 web_ui()->RegisterMessageCallback("closeIncognitoBrowser", | 163 web_ui()->RegisterMessageCallback("closeIncognitoBrowser", |
200 base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser, | 164 base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser, |
201 base::Unretained(this))); | 165 base::Unretained(this))); |
202 web_ui()->RegisterMessageCallback("enableHttpPipelining", | |
203 base::Bind(&NetInternalsTest::MessageHandler::EnableHttpPipelining, | |
204 base::Unretained(this))); | |
205 web_ui()->RegisterMessageCallback("addDummyHttpPipelineFeedback", | |
206 base::Bind( | |
207 &NetInternalsTest::MessageHandler::AddDummyHttpPipelineFeedback, | |
208 base::Unretained(this))); | |
209 web_ui()->RegisterMessageCallback("getNetLogLoggerLog", | 166 web_ui()->RegisterMessageCallback("getNetLogLoggerLog", |
210 base::Bind( | 167 base::Bind( |
211 &NetInternalsTest::MessageHandler::GetNetLogLoggerLog, | 168 &NetInternalsTest::MessageHandler::GetNetLogLoggerLog, |
212 base::Unretained(this))); | 169 base::Unretained(this))); |
213 } | 170 } |
214 | 171 |
215 void NetInternalsTest::MessageHandler::RunJavascriptCallback( | 172 void NetInternalsTest::MessageHandler::RunJavascriptCallback( |
216 base::Value* value) { | 173 base::Value* value) { |
217 web_ui()->CallJavascriptFunction("NetInternalsTest.callback", *value); | 174 web_ui()->CallJavascriptFunction("NetInternalsTest.callback", *value); |
218 } | 175 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 253 |
297 void NetInternalsTest::MessageHandler::CloseIncognitoBrowser( | 254 void NetInternalsTest::MessageHandler::CloseIncognitoBrowser( |
298 const base::ListValue* list_value) { | 255 const base::ListValue* list_value) { |
299 ASSERT_TRUE(incognito_browser_); | 256 ASSERT_TRUE(incognito_browser_); |
300 incognito_browser_->tab_strip_model()->CloseAllTabs(); | 257 incognito_browser_->tab_strip_model()->CloseAllTabs(); |
301 // Closing all a Browser's tabs will ultimately result in its destruction, | 258 // Closing all a Browser's tabs will ultimately result in its destruction, |
302 // thought it may not have been destroyed yet. | 259 // thought it may not have been destroyed yet. |
303 incognito_browser_ = NULL; | 260 incognito_browser_ = NULL; |
304 } | 261 } |
305 | 262 |
306 void NetInternalsTest::MessageHandler::EnableHttpPipelining( | |
307 const base::ListValue* list_value) { | |
308 bool enable; | |
309 ASSERT_TRUE(list_value->GetBoolean(0, &enable)); | |
310 BrowserThread::PostTask( | |
311 BrowserThread::IO, FROM_HERE, | |
312 base::Bind(&EnableHttpPipeliningOnIOThread, | |
313 make_scoped_refptr(browser()->profile()->GetRequestContext()), | |
314 enable)); | |
315 } | |
316 | |
317 void NetInternalsTest::MessageHandler::AddDummyHttpPipelineFeedback( | |
318 const base::ListValue* list_value) { | |
319 std::string hostname; | |
320 double port; | |
321 std::string raw_capability; | |
322 net::HttpPipelinedHostCapability capability; | |
323 ASSERT_TRUE(list_value->GetString(0, &hostname)); | |
324 ASSERT_TRUE(list_value->GetDouble(1, &port)); | |
325 ASSERT_TRUE(list_value->GetString(2, &raw_capability)); | |
326 if (raw_capability == "capable") { | |
327 capability = net::PIPELINE_CAPABLE; | |
328 } else if (raw_capability == "incapable") { | |
329 capability = net::PIPELINE_INCAPABLE; | |
330 } else { | |
331 FAIL() << "Unexpected capability string: " << raw_capability; | |
332 } | |
333 BrowserThread::PostTask( | |
334 BrowserThread::IO, FROM_HERE, | |
335 base::Bind(&AddDummyHttpPipelineFeedbackOnIOThread, | |
336 make_scoped_refptr(browser()->profile()->GetRequestContext()), | |
337 hostname, | |
338 static_cast<int>(port), | |
339 capability)); | |
340 } | |
341 | |
342 void NetInternalsTest::MessageHandler::GetNetLogLoggerLog( | 263 void NetInternalsTest::MessageHandler::GetNetLogLoggerLog( |
343 const base::ListValue* list_value) { | 264 const base::ListValue* list_value) { |
344 base::ScopedTempDir temp_directory; | 265 base::ScopedTempDir temp_directory; |
345 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 266 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
346 base::FilePath temp_file; | 267 base::FilePath temp_file; |
347 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_directory.path(), | 268 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_directory.path(), |
348 &temp_file)); | 269 &temp_file)); |
349 FILE* temp_file_handle = base::OpenFile(temp_file, "w"); | 270 FILE* temp_file_handle = base::OpenFile(temp_file, "w"); |
350 ASSERT_TRUE(temp_file_handle); | 271 ASSERT_TRUE(temp_file_handle); |
351 | 272 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 GURL url_loader = test_server()->GetURL(replacement_path); | 345 GURL url_loader = test_server()->GetURL(replacement_path); |
425 return url_loader; | 346 return url_loader; |
426 } | 347 } |
427 | 348 |
428 bool NetInternalsTest::StartTestServer() { | 349 bool NetInternalsTest::StartTestServer() { |
429 if (test_server_started_) | 350 if (test_server_started_) |
430 return true; | 351 return true; |
431 test_server_started_ = test_server()->Start(); | 352 test_server_started_ = test_server()->Start(); |
432 return test_server_started_; | 353 return test_server_started_; |
433 } | 354 } |
OLD | NEW |