| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/io_thread.h" | 17 #include "chrome/browser/io_thread.h" |
| 17 #include "chrome/browser/net/chrome_net_log.h" | 18 #include "chrome/browser/net/chrome_net_log.h" |
| 18 #include "chrome/browser/prerender/prerender_manager.h" | 19 #include "chrome/browser/prerender/prerender_manager.h" |
| 19 #include "chrome/browser/prerender/prerender_manager_factory.h" | 20 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" | 24 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
| 26 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_ui_message_handler.h" | 30 #include "content/public/browser/web_ui_message_handler.h" |
| 29 #include "net/base/address_list.h" | 31 #include "net/base/address_list.h" |
| 30 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 31 #include "net/base/net_log.h" | 33 #include "net/base/net_log.h" |
| 32 #include "net/base/net_log_logger.h" | 34 #include "net/base/net_log_logger.h" |
| 33 #include "net/dns/host_cache.h" | 35 #include "net/dns/host_cache.h" |
| 34 #include "net/dns/host_resolver.h" | 36 #include "net/dns/host_resolver.h" |
| 35 #include "net/dns/mock_host_resolver.h" | 37 #include "net/dns/mock_host_resolver.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // message to the Javascript test harness. | 122 // message to the Javascript test harness. |
| 121 void CreateIncognitoBrowser(const base::ListValue* list_value); | 123 void CreateIncognitoBrowser(const base::ListValue* list_value); |
| 122 | 124 |
| 123 // Closes an incognito browser created with CreateIncognitoBrowser. | 125 // Closes an incognito browser created with CreateIncognitoBrowser. |
| 124 void CloseIncognitoBrowser(const base::ListValue* list_value); | 126 void CloseIncognitoBrowser(const base::ListValue* list_value); |
| 125 | 127 |
| 126 // Creates a simple log with a NetLogLogger, and returns it to the | 128 // Creates a simple log with a NetLogLogger, and returns it to the |
| 127 // Javascript callback. | 129 // Javascript callback. |
| 128 void GetNetLogLoggerLog(const base::ListValue* list_value); | 130 void GetNetLogLoggerLog(const base::ListValue* list_value); |
| 129 | 131 |
| 132 // Changes the data reduction proxy mode. A boolean is assumed to exist at |
| 133 // index 0 which enables the proxy is set to true. |
| 134 void EnableDataReductionProxy(const base::ListValue* list_value); |
| 135 |
| 130 Browser* browser() { return net_internals_test_->browser(); } | 136 Browser* browser() { return net_internals_test_->browser(); } |
| 131 | 137 |
| 132 NetInternalsTest* net_internals_test_; | 138 NetInternalsTest* net_internals_test_; |
| 133 Browser* incognito_browser_; | 139 Browser* incognito_browser_; |
| 134 | 140 |
| 135 DISALLOW_COPY_AND_ASSIGN(MessageHandler); | 141 DISALLOW_COPY_AND_ASSIGN(MessageHandler); |
| 136 }; | 142 }; |
| 137 | 143 |
| 138 NetInternalsTest::MessageHandler::MessageHandler( | 144 NetInternalsTest::MessageHandler::MessageHandler( |
| 139 NetInternalsTest* net_internals_test) | 145 NetInternalsTest* net_internals_test) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 160 web_ui()->RegisterMessageCallback("createIncognitoBrowser", | 166 web_ui()->RegisterMessageCallback("createIncognitoBrowser", |
| 161 base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser, | 167 base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser, |
| 162 base::Unretained(this))); | 168 base::Unretained(this))); |
| 163 web_ui()->RegisterMessageCallback("closeIncognitoBrowser", | 169 web_ui()->RegisterMessageCallback("closeIncognitoBrowser", |
| 164 base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser, | 170 base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser, |
| 165 base::Unretained(this))); | 171 base::Unretained(this))); |
| 166 web_ui()->RegisterMessageCallback("getNetLogLoggerLog", | 172 web_ui()->RegisterMessageCallback("getNetLogLoggerLog", |
| 167 base::Bind( | 173 base::Bind( |
| 168 &NetInternalsTest::MessageHandler::GetNetLogLoggerLog, | 174 &NetInternalsTest::MessageHandler::GetNetLogLoggerLog, |
| 169 base::Unretained(this))); | 175 base::Unretained(this))); |
| 176 web_ui()->RegisterMessageCallback("enableDataReductionProxy", |
| 177 base::Bind( |
| 178 &NetInternalsTest::MessageHandler::EnableDataReductionProxy, |
| 179 base::Unretained(this))); |
| 170 } | 180 } |
| 171 | 181 |
| 172 void NetInternalsTest::MessageHandler::RunJavascriptCallback( | 182 void NetInternalsTest::MessageHandler::RunJavascriptCallback( |
| 173 base::Value* value) { | 183 base::Value* value) { |
| 174 web_ui()->CallJavascriptFunction("NetInternalsTest.callback", *value); | 184 web_ui()->CallJavascriptFunction("NetInternalsTest.callback", *value); |
| 175 } | 185 } |
| 176 | 186 |
| 177 void NetInternalsTest::MessageHandler::GetTestServerURL( | 187 void NetInternalsTest::MessageHandler::GetTestServerURL( |
| 178 const base::ListValue* list_value) { | 188 const base::ListValue* list_value) { |
| 179 ASSERT_TRUE(net_internals_test_->StartTestServer()); | 189 ASSERT_TRUE(net_internals_test_->StartTestServer()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 295 |
| 286 std::string log_contents; | 296 std::string log_contents; |
| 287 ASSERT_TRUE(base::ReadFileToString(temp_file, &log_contents)); | 297 ASSERT_TRUE(base::ReadFileToString(temp_file, &log_contents)); |
| 288 ASSERT_GT(log_contents.length(), 0u); | 298 ASSERT_GT(log_contents.length(), 0u); |
| 289 | 299 |
| 290 scoped_ptr<base::Value> log_contents_value( | 300 scoped_ptr<base::Value> log_contents_value( |
| 291 new base::StringValue(log_contents)); | 301 new base::StringValue(log_contents)); |
| 292 RunJavascriptCallback(log_contents_value.get()); | 302 RunJavascriptCallback(log_contents_value.get()); |
| 293 } | 303 } |
| 294 | 304 |
| 305 void NetInternalsTest::MessageHandler::EnableDataReductionProxy( |
| 306 const base::ListValue* list_value) { |
| 307 bool enable; |
| 308 ASSERT_TRUE(list_value->GetBoolean(0, &enable)); |
| 309 browser()->profile()->GetPrefs()->SetBoolean( |
| 310 data_reduction_proxy::prefs::kDataReductionProxyEnabled, enable); |
| 311 } |
| 312 |
| 295 //////////////////////////////////////////////////////////////////////////////// | 313 //////////////////////////////////////////////////////////////////////////////// |
| 296 // NetInternalsTest | 314 // NetInternalsTest |
| 297 //////////////////////////////////////////////////////////////////////////////// | 315 //////////////////////////////////////////////////////////////////////////////// |
| 298 | 316 |
| 299 NetInternalsTest::NetInternalsTest() | 317 NetInternalsTest::NetInternalsTest() |
| 300 : test_server_started_(false) { | 318 : test_server_started_(false) { |
| 301 message_handler_.reset(new MessageHandler(this)); | 319 message_handler_.reset(new MessageHandler(this)); |
| 302 } | 320 } |
| 303 | 321 |
| 304 NetInternalsTest::~NetInternalsTest() { | 322 NetInternalsTest::~NetInternalsTest() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 if (test_server_started_) | 368 if (test_server_started_) |
| 351 return true; | 369 return true; |
| 352 test_server_started_ = test_server()->Start(); | 370 test_server_started_ = test_server()->Start(); |
| 353 | 371 |
| 354 // Sample domain for SDCH-view test. Dictionaries for localhost/127.0.0.1 | 372 // Sample domain for SDCH-view test. Dictionaries for localhost/127.0.0.1 |
| 355 // are forbidden. | 373 // are forbidden. |
| 356 host_resolver()->AddRule("testdomain.com", "127.0.0.1"); | 374 host_resolver()->AddRule("testdomain.com", "127.0.0.1"); |
| 357 host_resolver()->AddRule("sub.testdomain.com", "127.0.0.1"); | 375 host_resolver()->AddRule("sub.testdomain.com", "127.0.0.1"); |
| 358 return test_server_started_; | 376 return test_server_started_; |
| 359 } | 377 } |
| OLD | NEW |