Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2838293002: Ensure all content_browsertests call the host resolver in SetUpOnMainThread and not after. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 : last_sent_id_(0), 139 : last_sent_id_(0),
140 waiting_for_command_result_id_(0), 140 waiting_for_command_result_id_(0),
141 in_dispatch_(false), 141 in_dispatch_(false),
142 agent_host_can_close_(false) {} 142 agent_host_can_close_(false) {}
143 143
144 void SetUpOnMainThread() override { 144 void SetUpOnMainThread() override {
145 ok_cert_ = 145 ok_cert_ =
146 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 146 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
147 expired_cert_ = net::ImportCertFromFile(net::GetTestCertsDirectory(), 147 expired_cert_ = net::ImportCertFromFile(net::GetTestCertsDirectory(),
148 "expired_cert.pem"); 148 "expired_cert.pem");
149 host_resolver()->AddRule("*", "127.0.0.1");
149 } 150 }
150 151
151 protected: 152 protected:
152 // WebContentsDelegate method: 153 // WebContentsDelegate method:
153 bool DidAddMessageToConsole(WebContents* source, 154 bool DidAddMessageToConsole(WebContents* source,
154 int32_t level, 155 int32_t level,
155 const base::string16& message, 156 const base::string16& message,
156 int32_t line_no, 157 int32_t line_no,
157 const base::string16& source_id) override { 158 const base::string16& source_id) override {
158 console_messages_.push_back(base::UTF16ToUTF8(message)); 159 console_messages_.push_back(base::UTF16ToUTF8(message));
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 EXPECT_TRUE(enough_results); 937 EXPECT_TRUE(enough_results);
937 bool found_frame_notification = false; 938 bool found_frame_notification = false;
938 for (const std::string& notification : notifications_) { 939 for (const std::string& notification : notifications_) {
939 if (notification == "Page.frameStartedLoading") 940 if (notification == "Page.frameStartedLoading")
940 found_frame_notification = true; 941 found_frame_notification = true;
941 } 942 }
942 EXPECT_TRUE(found_frame_notification); 943 EXPECT_TRUE(found_frame_notification);
943 } 944 }
944 945
945 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSiteNoDetach) { 946 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSiteNoDetach) {
946 host_resolver()->AddRule("*", "127.0.0.1");
947 content::SetupCrossSiteRedirector(embedded_test_server()); 947 content::SetupCrossSiteRedirector(embedded_test_server());
948 ASSERT_TRUE(embedded_test_server()->Start()); 948 ASSERT_TRUE(embedded_test_server()->Start());
949 949
950 GURL test_url1 = embedded_test_server()->GetURL( 950 GURL test_url1 = embedded_test_server()->GetURL(
951 "A.com", "/devtools/navigation.html"); 951 "A.com", "/devtools/navigation.html");
952 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url1, 1); 952 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url1, 1);
953 Attach(); 953 Attach();
954 954
955 GURL test_url2 = embedded_test_server()->GetURL( 955 GURL test_url2 = embedded_test_server()->GetURL(
956 "B.com", "/devtools/navigation.html"); 956 "B.com", "/devtools/navigation.html");
(...skipping 12 matching lines...) Expand all
969 969
970 Attach(); 970 Attach();
971 SendCommand("Runtime.enable", nullptr); 971 SendCommand("Runtime.enable", nullptr);
972 972
973 agent_host_->DisconnectWebContents(); 973 agent_host_->DisconnectWebContents();
974 agent_host_->ConnectWebContents(second->web_contents()); 974 agent_host_->ConnectWebContents(second->web_contents());
975 WaitForNotification("Runtime.executionContextsCleared"); 975 WaitForNotification("Runtime.executionContextsCleared");
976 } 976 }
977 977
978 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSitePauseInBeforeUnload) { 978 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSitePauseInBeforeUnload) {
979 host_resolver()->AddRule("*", "127.0.0.1");
980 content::SetupCrossSiteRedirector(embedded_test_server()); 979 content::SetupCrossSiteRedirector(embedded_test_server());
981 ASSERT_TRUE(embedded_test_server()->Start()); 980 ASSERT_TRUE(embedded_test_server()->Start());
982 981
983 NavigateToURLBlockUntilNavigationsComplete(shell(), 982 NavigateToURLBlockUntilNavigationsComplete(shell(),
984 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"), 1); 983 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"), 1);
985 Attach(); 984 Attach();
986 SendCommand("Debugger.enable", nullptr); 985 SendCommand("Debugger.enable", nullptr);
987 986
988 ASSERT_TRUE(content::ExecuteScript( 987 ASSERT_TRUE(content::ExecuteScript(
989 shell(), 988 shell(),
990 "window.onbeforeunload = function() { debugger; return null; }")); 989 "window.onbeforeunload = function() { debugger; return null; }"));
991 990
992 shell()->LoadURL( 991 shell()->LoadURL(
993 embedded_test_server()->GetURL("B.com", "/devtools/navigation.html")); 992 embedded_test_server()->GetURL("B.com", "/devtools/navigation.html"));
994 WaitForNotification("Debugger.paused"); 993 WaitForNotification("Debugger.paused");
995 TestNavigationObserver observer(shell()->web_contents(), 1); 994 TestNavigationObserver observer(shell()->web_contents(), 1);
996 SendCommand("Debugger.resume", nullptr); 995 SendCommand("Debugger.resume", nullptr);
997 observer.Wait(); 996 observer.Wait();
998 } 997 }
999 998
1000 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, InspectDuringFrameSwap) { 999 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, InspectDuringFrameSwap) {
1001 host_resolver()->AddRule("*", "127.0.0.1");
1002 content::SetupCrossSiteRedirector(embedded_test_server()); 1000 content::SetupCrossSiteRedirector(embedded_test_server());
1003 ASSERT_TRUE(embedded_test_server()->Start()); 1001 ASSERT_TRUE(embedded_test_server()->Start());
1004 1002
1005 GURL test_url1 = 1003 GURL test_url1 =
1006 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"); 1004 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html");
1007 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url1, 1); 1005 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url1, 1);
1008 1006
1009 ShellAddedObserver new_shell_observer; 1007 ShellAddedObserver new_shell_observer;
1010 EXPECT_TRUE(ExecuteScript(shell(), "window.open('about:blank','foo');")); 1008 EXPECT_TRUE(ExecuteScript(shell(), "window.open('about:blank','foo');"));
1011 Shell* new_shell = new_shell_observer.GetShell(); 1009 Shell* new_shell = new_shell_observer.GetShell();
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 public: 1262 public:
1265 ~IsolatedDevToolsProtocolTest() override {} 1263 ~IsolatedDevToolsProtocolTest() override {}
1266 1264
1267 void SetUpCommandLine(base::CommandLine* command_line) override { 1265 void SetUpCommandLine(base::CommandLine* command_line) override {
1268 IsolateAllSitesForTesting(command_line); 1266 IsolateAllSitesForTesting(command_line);
1269 } 1267 }
1270 }; 1268 };
1271 1269
1272 IN_PROC_BROWSER_TEST_F(IsolatedDevToolsProtocolTest, 1270 IN_PROC_BROWSER_TEST_F(IsolatedDevToolsProtocolTest,
1273 ControlNavigationsChildFrames) { 1271 ControlNavigationsChildFrames) {
1274 host_resolver()->AddRule("*", "127.0.0.1");
1275 content::SetupCrossSiteRedirector(embedded_test_server()); 1272 content::SetupCrossSiteRedirector(embedded_test_server());
1276 ASSERT_TRUE(embedded_test_server()->Start()); 1273 ASSERT_TRUE(embedded_test_server()->Start());
1277 1274
1278 // Navigate to about:blank first so we can make sure there is a target page we 1275 // Navigate to about:blank first so we can make sure there is a target page we
1279 // can attach to, and have Page.setControlNavigations complete before we start 1276 // can attach to, and have Page.setControlNavigations complete before we start
1280 // the navigations we're interested in. 1277 // the navigations we're interested in.
1281 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); 1278 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
1282 Attach(); 1279 Attach();
1283 1280
1284 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); 1281 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 1665
1669 class SitePerProcessDevToolsProtocolTest : public DevToolsProtocolTest { 1666 class SitePerProcessDevToolsProtocolTest : public DevToolsProtocolTest {
1670 public: 1667 public:
1671 void SetUpCommandLine(base::CommandLine* command_line) override { 1668 void SetUpCommandLine(base::CommandLine* command_line) override {
1672 DevToolsProtocolTest::SetUpCommandLine(command_line); 1669 DevToolsProtocolTest::SetUpCommandLine(command_line);
1673 IsolateAllSitesForTesting(command_line); 1670 IsolateAllSitesForTesting(command_line);
1674 }; 1671 };
1675 1672
1676 void SetUpOnMainThread() override { 1673 void SetUpOnMainThread() override {
1677 DevToolsProtocolTest::SetUpOnMainThread(); 1674 DevToolsProtocolTest::SetUpOnMainThread();
1678 host_resolver()->AddRule("*", "127.0.0.1");
1679 content::SetupCrossSiteRedirector(embedded_test_server()); 1675 content::SetupCrossSiteRedirector(embedded_test_server());
1680 ASSERT_TRUE(embedded_test_server()->Start()); 1676 ASSERT_TRUE(embedded_test_server()->Start());
1681 } 1677 }
1682 }; 1678 };
1683 1679
1684 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsProtocolTest, TargetNoDiscovery) { 1680 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsProtocolTest, TargetNoDiscovery) {
1685 std::string temp; 1681 std::string temp;
1686 std::string target_id; 1682 std::string target_id;
1687 std::unique_ptr<base::DictionaryValue> command_params; 1683 std::unique_ptr<base::DictionaryValue> command_params;
1688 std::unique_ptr<base::DictionaryValue> params; 1684 std::unique_ptr<base::DictionaryValue> params;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 EXPECT_EQ("polyglottal", value); 1796 EXPECT_EQ("polyglottal", value);
1801 found++; 1797 found++;
1802 } else { 1798 } else {
1803 FAIL(); 1799 FAIL();
1804 } 1800 }
1805 } 1801 }
1806 EXPECT_EQ(2u, found); 1802 EXPECT_EQ(2u, found);
1807 } 1803 }
1808 1804
1809 } // namespace content 1805 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698