Chromium Code Reviews| 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. | |
|
bengr
2014/12/02 23:55:32
Please explain the input parameter.
jeremyim
2014/12/03 08:10:37
Done.
| |
| 133 void EnableDataReductionProxy(const base::ListValue* list_value); | |
| 134 | |
| 130 Browser* browser() { return net_internals_test_->browser(); } | 135 Browser* browser() { return net_internals_test_->browser(); } |
| 131 | 136 |
| 132 NetInternalsTest* net_internals_test_; | 137 NetInternalsTest* net_internals_test_; |
| 133 Browser* incognito_browser_; | 138 Browser* incognito_browser_; |
| 134 | 139 |
| 135 DISALLOW_COPY_AND_ASSIGN(MessageHandler); | 140 DISALLOW_COPY_AND_ASSIGN(MessageHandler); |
| 136 }; | 141 }; |
| 137 | 142 |
| 138 NetInternalsTest::MessageHandler::MessageHandler( | 143 NetInternalsTest::MessageHandler::MessageHandler( |
| 139 NetInternalsTest* net_internals_test) | 144 NetInternalsTest* net_internals_test) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 160 web_ui()->RegisterMessageCallback("createIncognitoBrowser", | 165 web_ui()->RegisterMessageCallback("createIncognitoBrowser", |
| 161 base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser, | 166 base::Bind(&NetInternalsTest::MessageHandler::CreateIncognitoBrowser, |
| 162 base::Unretained(this))); | 167 base::Unretained(this))); |
| 163 web_ui()->RegisterMessageCallback("closeIncognitoBrowser", | 168 web_ui()->RegisterMessageCallback("closeIncognitoBrowser", |
| 164 base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser, | 169 base::Bind(&NetInternalsTest::MessageHandler::CloseIncognitoBrowser, |
| 165 base::Unretained(this))); | 170 base::Unretained(this))); |
| 166 web_ui()->RegisterMessageCallback("getNetLogLoggerLog", | 171 web_ui()->RegisterMessageCallback("getNetLogLoggerLog", |
| 167 base::Bind( | 172 base::Bind( |
| 168 &NetInternalsTest::MessageHandler::GetNetLogLoggerLog, | 173 &NetInternalsTest::MessageHandler::GetNetLogLoggerLog, |
| 169 base::Unretained(this))); | 174 base::Unretained(this))); |
| 175 web_ui()->RegisterMessageCallback("enableDataReductionProxy", | |
| 176 base::Bind( | |
| 177 &NetInternalsTest::MessageHandler::EnableDataReductionProxy, | |
| 178 base::Unretained(this))); | |
| 170 } | 179 } |
| 171 | 180 |
| 172 void NetInternalsTest::MessageHandler::RunJavascriptCallback( | 181 void NetInternalsTest::MessageHandler::RunJavascriptCallback( |
| 173 base::Value* value) { | 182 base::Value* value) { |
| 174 web_ui()->CallJavascriptFunction("NetInternalsTest.callback", *value); | 183 web_ui()->CallJavascriptFunction("NetInternalsTest.callback", *value); |
| 175 } | 184 } |
| 176 | 185 |
| 177 void NetInternalsTest::MessageHandler::GetTestServerURL( | 186 void NetInternalsTest::MessageHandler::GetTestServerURL( |
| 178 const base::ListValue* list_value) { | 187 const base::ListValue* list_value) { |
| 179 ASSERT_TRUE(net_internals_test_->StartTestServer()); | 188 ASSERT_TRUE(net_internals_test_->StartTestServer()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 | 294 |
| 286 std::string log_contents; | 295 std::string log_contents; |
| 287 ASSERT_TRUE(base::ReadFileToString(temp_file, &log_contents)); | 296 ASSERT_TRUE(base::ReadFileToString(temp_file, &log_contents)); |
| 288 ASSERT_GT(log_contents.length(), 0u); | 297 ASSERT_GT(log_contents.length(), 0u); |
| 289 | 298 |
| 290 scoped_ptr<base::Value> log_contents_value( | 299 scoped_ptr<base::Value> log_contents_value( |
| 291 new base::StringValue(log_contents)); | 300 new base::StringValue(log_contents)); |
| 292 RunJavascriptCallback(log_contents_value.get()); | 301 RunJavascriptCallback(log_contents_value.get()); |
| 293 } | 302 } |
| 294 | 303 |
| 304 void NetInternalsTest::MessageHandler::EnableDataReductionProxy( | |
| 305 const base::ListValue* list_value) { | |
| 306 bool enable; | |
| 307 ASSERT_TRUE(list_value->GetBoolean(0, &enable)); | |
| 308 browser()->profile()->GetPrefs()->SetBoolean( | |
| 309 data_reduction_proxy::prefs::kDataReductionProxyEnabled, enable); | |
| 310 } | |
| 311 | |
| 295 //////////////////////////////////////////////////////////////////////////////// | 312 //////////////////////////////////////////////////////////////////////////////// |
| 296 // NetInternalsTest | 313 // NetInternalsTest |
| 297 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
| 298 | 315 |
| 299 NetInternalsTest::NetInternalsTest() | 316 NetInternalsTest::NetInternalsTest() |
| 300 : test_server_started_(false) { | 317 : test_server_started_(false) { |
| 301 message_handler_.reset(new MessageHandler(this)); | 318 message_handler_.reset(new MessageHandler(this)); |
| 302 } | 319 } |
| 303 | 320 |
| 304 NetInternalsTest::~NetInternalsTest() { | 321 NetInternalsTest::~NetInternalsTest() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 if (test_server_started_) | 367 if (test_server_started_) |
| 351 return true; | 368 return true; |
| 352 test_server_started_ = test_server()->Start(); | 369 test_server_started_ = test_server()->Start(); |
| 353 | 370 |
| 354 // Sample domain for SDCH-view test. Dictionaries for localhost/127.0.0.1 | 371 // Sample domain for SDCH-view test. Dictionaries for localhost/127.0.0.1 |
| 355 // are forbidden. | 372 // are forbidden. |
| 356 host_resolver()->AddRule("testdomain.com", "127.0.0.1"); | 373 host_resolver()->AddRule("testdomain.com", "127.0.0.1"); |
| 357 host_resolver()->AddRule("sub.testdomain.com", "127.0.0.1"); | 374 host_resolver()->AddRule("sub.testdomain.com", "127.0.0.1"); |
| 358 return test_server_started_; | 375 return test_server_started_; |
| 359 } | 376 } |
| OLD | NEW |