| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/public/browser/render_widget_host_view.h" | 9 #include "content/public/browser/render_widget_host_view.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
| 12 #include "content/public/test/browser_test.h" | 12 #include "content/public/test/browser_test.h" |
| 13 #include "headless/lib/browser/headless_web_contents_impl.h" | 13 #include "headless/lib/browser/headless_web_contents_impl.h" |
| 14 #include "headless/public/devtools/domains/dom.h" | 14 #include "headless/public/devtools/domains/dom.h" |
| 15 #include "headless/public/devtools/domains/emulation.h" | 15 #include "headless/public/devtools/domains/emulation.h" |
| 16 #include "headless/public/devtools/domains/inspector.h" | 16 #include "headless/public/devtools/domains/inspector.h" |
| 17 #include "headless/public/devtools/domains/network.h" | 17 #include "headless/public/devtools/domains/network.h" |
| 18 #include "headless/public/devtools/domains/page.h" | 18 #include "headless/public/devtools/domains/page.h" |
| 19 #include "headless/public/devtools/domains/runtime.h" | 19 #include "headless/public/devtools/domains/runtime.h" |
| 20 #include "headless/public/devtools/domains/target.h" | 20 #include "headless/public/devtools/domains/target.h" |
| 21 #include "headless/public/headless_browser.h" | 21 #include "headless/public/headless_browser.h" |
| 22 #include "headless/public/headless_devtools_client.h" | 22 #include "headless/public/headless_devtools_client.h" |
| 23 #include "headless/public/headless_devtools_target.h" | 23 #include "headless/public/headless_devtools_target.h" |
| 24 #include "headless/test/headless_browser_test.h" | 24 #include "headless/test/headless_browser_test.h" |
| 25 #include "headless/test/test_protocol_handler.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 28 | 29 |
| 29 #define EXPECT_SIZE_EQ(expected, actual) \ | 30 #define EXPECT_SIZE_EQ(expected, actual) \ |
| 30 do { \ | 31 do { \ |
| 31 EXPECT_EQ((expected).width(), (actual).width()); \ | 32 EXPECT_EQ((expected).width(), (actual).width()); \ |
| 32 EXPECT_EQ((expected).height(), (actual).height()); \ | 33 EXPECT_EQ((expected).height(), (actual).height()); \ |
| 33 } while (false) | 34 } while (false) |
| 34 | 35 |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 } | 879 } |
| 879 | 880 |
| 880 std::map<std::string, std::string> request_id_to_path_; | 881 std::map<std::string, std::string> request_id_to_path_; |
| 881 std::vector<std::string> requests_to_be_sent_; | 882 std::vector<std::string> requests_to_be_sent_; |
| 882 std::vector<std::string> responses_received_; | 883 std::vector<std::string> responses_received_; |
| 883 std::vector<std::string> failures_; | 884 std::vector<std::string> failures_; |
| 884 }; | 885 }; |
| 885 | 886 |
| 886 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessDevToolsNetworkBlockedUrlTest); | 887 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessDevToolsNetworkBlockedUrlTest); |
| 887 | 888 |
| 889 namespace { |
| 890 // Keep in sync with X_DevTools_Emulate_Network_Conditions_Client_Id defined in |
| 891 // HTTPNames.json5. |
| 892 const char kDevToolsEmulateNetworkConditionsClientId[] = |
| 893 "X-DevTools-Emulate-Network-Conditions-Client-Id"; |
| 894 } // namespace |
| 895 |
| 896 class DevToolsHeaderStrippingTest : public HeadlessAsyncDevTooledBrowserTest, |
| 897 public page::Observer, |
| 898 public network::Observer { |
| 899 void RunDevTooledTest() override { |
| 900 EXPECT_TRUE(embedded_test_server()->Start()); |
| 901 base::RunLoop run_loop; |
| 902 devtools_client_->GetPage()->AddObserver(this); |
| 903 devtools_client_->GetPage()->Enable(); |
| 904 // Enable network domain in order to get DevTools to add the header. |
| 905 devtools_client_->GetNetwork()->AddObserver(this); |
| 906 devtools_client_->GetNetwork()->Enable(run_loop.QuitClosure()); |
| 907 base::MessageLoop::ScopedNestableTaskAllower nest_loop( |
| 908 base::MessageLoop::current()); |
| 909 run_loop.Run(); |
| 910 devtools_client_->GetPage()->Navigate( |
| 911 "http://not-an-actual-domain.tld/hello.html"); |
| 912 } |
| 913 |
| 914 ProtocolHandlerMap GetProtocolHandlers() override { |
| 915 const std::string kResponseBody = "<p>HTTP response body</p>"; |
| 916 ProtocolHandlerMap protocol_handlers; |
| 917 protocol_handlers[url::kHttpScheme] = |
| 918 base::MakeUnique<TestProtocolHandler>(kResponseBody); |
| 919 test_handler_ = static_cast<TestProtocolHandler*>( |
| 920 protocol_handlers[url::kHttpScheme].get()); |
| 921 return protocol_handlers; |
| 922 } |
| 923 |
| 924 void OnLoadEventFired(const page::LoadEventFiredParams&) override { |
| 925 EXPECT_FALSE(test_handler_->last_http_request_headers().IsEmpty()); |
| 926 EXPECT_FALSE(test_handler_->last_http_request_headers().HasHeader( |
| 927 kDevToolsEmulateNetworkConditionsClientId)); |
| 928 FinishAsynchronousTest(); |
| 929 } |
| 930 |
| 931 TestProtocolHandler* test_handler_; // NOT OWNED |
| 932 }; |
| 933 |
| 934 HEADLESS_ASYNC_DEVTOOLED_TEST_F(DevToolsHeaderStrippingTest); |
| 935 |
| 888 } // namespace headless | 936 } // namespace headless |
| OLD | NEW |