| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/renderer/test_runner/web_test_proxy.h" | 5 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
| 6 | 6 |
| 7 #include <cctype> | 7 #include <cctype> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 15 #include "content/shell/renderer/test_runner/TestPlugin.h" | 16 #include "content/shell/renderer/test_runner/TestPlugin.h" |
| 16 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 17 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 17 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" | 18 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" |
| 18 #include "content/shell/renderer/test_runner/accessibility_controller.h" | 19 #include "content/shell/renderer/test_runner/accessibility_controller.h" |
| 19 #include "content/shell/renderer/test_runner/event_sender.h" | 20 #include "content/shell/renderer/test_runner/event_sender.h" |
| 20 #include "content/shell/renderer/test_runner/mock_color_chooser.h" | 21 #include "content/shell/renderer/test_runner/mock_color_chooser.h" |
| 21 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h" | 22 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h" |
| 22 #include "content/shell/renderer/test_runner/mock_web_push_client.h" | 23 #include "content/shell/renderer/test_runner/mock_web_push_client.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 149 } |
| 149 | 150 |
| 150 void BlockRequest(blink::WebURLRequest& request) { | 151 void BlockRequest(blink::WebURLRequest& request) { |
| 151 request.setURL(GURL("255.255.255.255")); | 152 request.setURL(GURL("255.255.255.255")); |
| 152 } | 153 } |
| 153 | 154 |
| 154 bool IsLocalHost(const std::string& host) { | 155 bool IsLocalHost(const std::string& host) { |
| 155 return host == "127.0.0.1" || host == "localhost"; | 156 return host == "127.0.0.1" || host == "localhost"; |
| 156 } | 157 } |
| 157 | 158 |
| 159 bool IsTestHost(const std::string& host) { |
| 160 return EndsWith(host, ".test", false); |
| 161 } |
| 162 |
| 158 bool HostIsUsedBySomeTestsToGenerateError(const std::string& host) { | 163 bool HostIsUsedBySomeTestsToGenerateError(const std::string& host) { |
| 159 return host == "255.255.255.255"; | 164 return host == "255.255.255.255"; |
| 160 } | 165 } |
| 161 | 166 |
| 162 // Used to write a platform neutral file:/// URL by only taking the filename | 167 // Used to write a platform neutral file:/// URL by only taking the filename |
| 163 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). | 168 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). |
| 164 std::string URLSuitableForTestResult(const std::string& url) { | 169 std::string URLSuitableForTestResult(const std::string& url) { |
| 165 if (url.empty() || std::string::npos == url.find("file://")) | 170 if (url.empty() || std::string::npos == url.find("file://")) |
| 166 return url; | 171 return url; |
| 167 | 172 |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 const std::set<std::string>* clearHeaders = | 1080 const std::set<std::string>* clearHeaders = |
| 1076 test_interfaces_->GetTestRunner()->httpHeadersToClear(); | 1081 test_interfaces_->GetTestRunner()->httpHeadersToClear(); |
| 1077 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); | 1082 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); |
| 1078 header != clearHeaders->end(); | 1083 header != clearHeaders->end(); |
| 1079 ++header) | 1084 ++header) |
| 1080 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); | 1085 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); |
| 1081 } | 1086 } |
| 1082 | 1087 |
| 1083 std::string host = url.host(); | 1088 std::string host = url.host(); |
| 1084 if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) { | 1089 if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) { |
| 1085 if (!IsLocalHost(host) && !HostIsUsedBySomeTestsToGenerateError(host) && | 1090 if (!IsLocalHost(host) && !IsTestHost(host) && !HostIsUsedBySomeTestsToGener
ateError(host) && |
| 1086 ((!main_document_url.SchemeIs("http") && | 1091 ((!main_document_url.SchemeIs("http") && |
| 1087 !main_document_url.SchemeIs("https")) || | 1092 !main_document_url.SchemeIs("https")) || |
| 1088 IsLocalHost(main_document_url.host())) && | 1093 IsLocalHost(main_document_url.host())) && |
| 1089 !delegate_->allowExternalPages()) { | 1094 !delegate_->allowExternalPages()) { |
| 1090 delegate_->printMessage(std::string("Blocked access to external URL ") + | 1095 delegate_->printMessage(std::string("Blocked access to external URL ") + |
| 1091 request_url + "\n"); | 1096 request_url + "\n"); |
| 1092 BlockRequest(request); | 1097 BlockRequest(request); |
| 1093 return; | 1098 return; |
| 1094 } | 1099 } |
| 1095 } | 1100 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 if (!push_client_.get()) | 1265 if (!push_client_.get()) |
| 1261 push_client_.reset(new MockWebPushClient); | 1266 push_client_.reset(new MockWebPushClient); |
| 1262 return push_client_.get(); | 1267 return push_client_.get(); |
| 1263 } | 1268 } |
| 1264 | 1269 |
| 1265 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { | 1270 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { |
| 1266 return GetPushClientMock(); | 1271 return GetPushClientMock(); |
| 1267 } | 1272 } |
| 1268 | 1273 |
| 1269 } // namespace content | 1274 } // namespace content |
| OLD | NEW |