| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/common/channel_info.h" | 28 #include "chrome/common/channel_info.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "components/net_log/chrome_net_log.h" | 31 #include "components/net_log/chrome_net_log.h" |
| 32 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 33 #include "content/public/browser/render_frame_host.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/browser/web_ui_message_handler.h" | 35 #include "content/public/browser/web_ui_message_handler.h" |
| 36 #include "net/base/address_list.h" | 36 #include "net/base/address_list.h" |
| 37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 38 #include "net/base/network_change_notifier.h" |
| 38 #include "net/dns/host_cache.h" | 39 #include "net/dns/host_cache.h" |
| 39 #include "net/dns/host_resolver.h" | 40 #include "net/dns/host_resolver.h" |
| 40 #include "net/dns/mock_host_resolver.h" | 41 #include "net/dns/mock_host_resolver.h" |
| 41 #include "net/http/http_network_session.h" | 42 #include "net/http/http_network_session.h" |
| 42 #include "net/http/http_transaction_factory.h" | 43 #include "net/http/http_transaction_factory.h" |
| 43 #include "net/log/net_log.h" | 44 #include "net/log/net_log.h" |
| 44 #include "net/log/net_log_event_type.h" | 45 #include "net/log/net_log_event_type.h" |
| 45 #include "net/log/net_log_source_type.h" | 46 #include "net/log/net_log_source_type.h" |
| 46 #include "net/log/net_log_with_source.h" | 47 #include "net/log/net_log_with_source.h" |
| 47 #include "net/log/write_to_file_net_log_observer.h" | 48 #include "net/log/write_to_file_net_log_observer.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // which must already have been started. | 111 // which must already have been started. |
| 111 void GetTestServerURL(const base::ListValue* list_value); | 112 void GetTestServerURL(const base::ListValue* list_value); |
| 112 | 113 |
| 113 // Called on UI thread. Adds an entry to the cache for the specified | 114 // Called on UI thread. Adds an entry to the cache for the specified |
| 114 // hostname by posting a task to the IO thread. Takes the host name, | 115 // hostname by posting a task to the IO thread. Takes the host name, |
| 115 // ip address, net error code, and expiration time in days from now | 116 // ip address, net error code, and expiration time in days from now |
| 116 // as parameters. If the error code indicates failure, the ip address | 117 // as parameters. If the error code indicates failure, the ip address |
| 117 // must be an empty string. | 118 // must be an empty string. |
| 118 void AddCacheEntry(const base::ListValue* list_value); | 119 void AddCacheEntry(const base::ListValue* list_value); |
| 119 | 120 |
| 121 // Simulates a network change. |
| 122 void ChangeNetwork(const base::ListValue* list_value); |
| 123 |
| 120 // Opens the given URL in a new tab. | 124 // Opens the given URL in a new tab. |
| 121 void LoadPage(const base::ListValue* list_value); | 125 void LoadPage(const base::ListValue* list_value); |
| 122 | 126 |
| 123 // Opens a page in a new tab that prerenders the given URL. | 127 // Opens a page in a new tab that prerenders the given URL. |
| 124 void PrerenderPage(const base::ListValue* list_value); | 128 void PrerenderPage(const base::ListValue* list_value); |
| 125 | 129 |
| 126 // Navigates to the prerender in the background tab. This assumes that | 130 // Navigates to the prerender in the background tab. This assumes that |
| 127 // there is a "Click()" function in the background tab which will navigate | 131 // there is a "Click()" function in the background tab which will navigate |
| 128 // there, and that the background tab exists at slot 1. | 132 // there, and that the background tab exists at slot 1. |
| 129 void NavigateToPrerender(const base::ListValue* list_value); | 133 void NavigateToPrerender(const base::ListValue* list_value); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 157 incognito_browser_(NULL) { | 161 incognito_browser_(NULL) { |
| 158 } | 162 } |
| 159 | 163 |
| 160 void NetInternalsTest::MessageHandler::RegisterMessages() { | 164 void NetInternalsTest::MessageHandler::RegisterMessages() { |
| 161 web_ui()->RegisterMessageCallback("getTestServerURL", | 165 web_ui()->RegisterMessageCallback("getTestServerURL", |
| 162 base::Bind(&NetInternalsTest::MessageHandler::GetTestServerURL, | 166 base::Bind(&NetInternalsTest::MessageHandler::GetTestServerURL, |
| 163 base::Unretained(this))); | 167 base::Unretained(this))); |
| 164 web_ui()->RegisterMessageCallback("addCacheEntry", | 168 web_ui()->RegisterMessageCallback("addCacheEntry", |
| 165 base::Bind(&NetInternalsTest::MessageHandler::AddCacheEntry, | 169 base::Bind(&NetInternalsTest::MessageHandler::AddCacheEntry, |
| 166 base::Unretained(this))); | 170 base::Unretained(this))); |
| 171 web_ui()->RegisterMessageCallback( |
| 172 "changeNetwork", |
| 173 base::Bind(&NetInternalsTest::MessageHandler::ChangeNetwork, |
| 174 base::Unretained(this))); |
| 167 web_ui()->RegisterMessageCallback("loadPage", | 175 web_ui()->RegisterMessageCallback("loadPage", |
| 168 base::Bind(&NetInternalsTest::MessageHandler::LoadPage, | 176 base::Bind(&NetInternalsTest::MessageHandler::LoadPage, |
| 169 base::Unretained(this))); | 177 base::Unretained(this))); |
| 170 web_ui()->RegisterMessageCallback("prerenderPage", | 178 web_ui()->RegisterMessageCallback("prerenderPage", |
| 171 base::Bind(&NetInternalsTest::MessageHandler::PrerenderPage, | 179 base::Bind(&NetInternalsTest::MessageHandler::PrerenderPage, |
| 172 base::Unretained(this))); | 180 base::Unretained(this))); |
| 173 web_ui()->RegisterMessageCallback("navigateToPrerender", | 181 web_ui()->RegisterMessageCallback("navigateToPrerender", |
| 174 base::Bind(&NetInternalsTest::MessageHandler::NavigateToPrerender, | 182 base::Bind(&NetInternalsTest::MessageHandler::NavigateToPrerender, |
| 175 base::Unretained(this))); | 183 base::Unretained(this))); |
| 176 web_ui()->RegisterMessageCallback("createIncognitoBrowser", | 184 web_ui()->RegisterMessageCallback("createIncognitoBrowser", |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 ASSERT_TRUE(browser()); | 225 ASSERT_TRUE(browser()); |
| 218 | 226 |
| 219 BrowserThread::PostTask( | 227 BrowserThread::PostTask( |
| 220 BrowserThread::IO, FROM_HERE, | 228 BrowserThread::IO, FROM_HERE, |
| 221 base::Bind(&AddCacheEntryOnIOThread, | 229 base::Bind(&AddCacheEntryOnIOThread, |
| 222 base::RetainedRef(browser()->profile()->GetRequestContext()), | 230 base::RetainedRef(browser()->profile()->GetRequestContext()), |
| 223 hostname, ip_literal, static_cast<int>(net_error), | 231 hostname, ip_literal, static_cast<int>(net_error), |
| 224 static_cast<int>(expire_days_from_now))); | 232 static_cast<int>(expire_days_from_now))); |
| 225 } | 233 } |
| 226 | 234 |
| 235 void NetInternalsTest::MessageHandler::ChangeNetwork( |
| 236 const base::ListValue* list_value) { |
| 237 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 238 } |
| 239 |
| 227 void NetInternalsTest::MessageHandler::LoadPage( | 240 void NetInternalsTest::MessageHandler::LoadPage( |
| 228 const base::ListValue* list_value) { | 241 const base::ListValue* list_value) { |
| 229 std::string url; | 242 std::string url; |
| 230 ASSERT_TRUE(list_value->GetString(0, &url)); | 243 ASSERT_TRUE(list_value->GetString(0, &url)); |
| 231 LOG(WARNING) << "url: [" << url << "]"; | 244 LOG(WARNING) << "url: [" << url << "]"; |
| 232 ui_test_utils::NavigateToURLWithDisposition( | 245 ui_test_utils::NavigateToURLWithDisposition( |
| 233 browser(), GURL(url), WindowOpenDisposition::NEW_BACKGROUND_TAB, | 246 browser(), GURL(url), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
| 234 ui_test_utils::BROWSER_TEST_NONE); | 247 ui_test_utils::BROWSER_TEST_NONE); |
| 235 } | 248 } |
| 236 | 249 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if (test_server_started_) | 376 if (test_server_started_) |
| 364 return true; | 377 return true; |
| 365 test_server_started_ = embedded_test_server()->Start(); | 378 test_server_started_ = embedded_test_server()->Start(); |
| 366 | 379 |
| 367 // Sample domain for SDCH-view test. Dictionaries for localhost/127.0.0.1 | 380 // Sample domain for SDCH-view test. Dictionaries for localhost/127.0.0.1 |
| 368 // are forbidden. | 381 // are forbidden. |
| 369 host_resolver()->AddRule("testdomain.com", "127.0.0.1"); | 382 host_resolver()->AddRule("testdomain.com", "127.0.0.1"); |
| 370 host_resolver()->AddRule("sub.testdomain.com", "127.0.0.1"); | 383 host_resolver()->AddRule("sub.testdomain.com", "127.0.0.1"); |
| 371 return test_server_started_; | 384 return test_server_started_; |
| 372 } | 385 } |
| OLD | NEW |