| 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 "content/browser/devtools/devtools_http_handler.h" | 5 #include "content/browser/devtools/devtools_http_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 content::TestBrowserThreadBundle thread_bundle_; | 130 content::TestBrowserThreadBundle thread_bundle_; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 TEST_F(DevToolsHttpHandlerTest, TestStartStop) { | 133 TEST_F(DevToolsHttpHandlerTest, TestStartStop) { |
| 134 base::RunLoop run_loop, run_loop_2; | 134 base::RunLoop run_loop, run_loop_2; |
| 135 std::unique_ptr<DevToolsSocketFactory> factory( | 135 std::unique_ptr<DevToolsSocketFactory> factory( |
| 136 new DummyServerSocketFactory(run_loop.QuitClosure(), | 136 new DummyServerSocketFactory(run_loop.QuitClosure(), |
| 137 run_loop_2.QuitClosure())); | 137 run_loop_2.QuitClosure())); |
| 138 DevToolsAgentHost::StartRemoteDebuggingServer( | 138 DevToolsAgentHost::StartRemoteDebuggingServer( |
| 139 std::move(factory), std::string(), base::FilePath(), base::FilePath(), | 139 std::move(factory), std::string(), base::FilePath(), base::FilePath(), |
| 140 std::string(), std::string()); | 140 std::string(), std::string(), std::string()); |
| 141 // Our dummy socket factory will post a quit message once the server will | 141 // Our dummy socket factory will post a quit message once the server will |
| 142 // become ready. | 142 // become ready. |
| 143 run_loop.Run(); | 143 run_loop.Run(); |
| 144 DevToolsAgentHost::StopRemoteDebuggingServer(); | 144 DevToolsAgentHost::StopRemoteDebuggingServer(); |
| 145 // Make sure the handler actually stops. | 145 // Make sure the handler actually stops. |
| 146 run_loop_2.Run(); | 146 run_loop_2.Run(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 TEST_F(DevToolsHttpHandlerTest, TestServerSocketFailed) { | 149 TEST_F(DevToolsHttpHandlerTest, TestServerSocketFailed) { |
| 150 base::RunLoop run_loop, run_loop_2; | 150 base::RunLoop run_loop, run_loop_2; |
| 151 std::unique_ptr<DevToolsSocketFactory> factory( | 151 std::unique_ptr<DevToolsSocketFactory> factory( |
| 152 new FailingServerSocketFactory(run_loop.QuitClosure(), | 152 new FailingServerSocketFactory(run_loop.QuitClosure(), |
| 153 run_loop_2.QuitClosure())); | 153 run_loop_2.QuitClosure())); |
| 154 DevToolsAgentHost::StartRemoteDebuggingServer( | 154 DevToolsAgentHost::StartRemoteDebuggingServer( |
| 155 std::move(factory), std::string(), base::FilePath(), base::FilePath(), | 155 std::move(factory), std::string(), base::FilePath(), base::FilePath(), |
| 156 std::string(), std::string()); | 156 std::string(), std::string(), std::string()); |
| 157 // Our dummy socket factory will post a quit message once the server will | 157 // Our dummy socket factory will post a quit message once the server will |
| 158 // become ready. | 158 // become ready. |
| 159 run_loop.Run(); | 159 run_loop.Run(); |
| 160 for (int i = 0; i < 5; i++) { | 160 for (int i = 0; i < 5; i++) { |
| 161 RunAllPendingInMessageLoop(BrowserThread::UI); | 161 RunAllPendingInMessageLoop(BrowserThread::UI); |
| 162 RunAllPendingInMessageLoop(BrowserThread::FILE); | 162 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 163 } | 163 } |
| 164 DevToolsAgentHost::StopRemoteDebuggingServer(); | 164 DevToolsAgentHost::StopRemoteDebuggingServer(); |
| 165 // Make sure the handler actually stops. | 165 // Make sure the handler actually stops. |
| 166 run_loop_2.Run(); | 166 run_loop_2.Run(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 | 169 |
| 170 TEST_F(DevToolsHttpHandlerTest, TestDevToolsActivePort) { | 170 TEST_F(DevToolsHttpHandlerTest, TestDevToolsActivePort) { |
| 171 base::RunLoop run_loop, run_loop_2; | 171 base::RunLoop run_loop, run_loop_2; |
| 172 base::ScopedTempDir temp_dir; | 172 base::ScopedTempDir temp_dir; |
| 173 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | 173 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 174 std::unique_ptr<DevToolsSocketFactory> factory( | 174 std::unique_ptr<DevToolsSocketFactory> factory( |
| 175 new DummyServerSocketFactory(run_loop.QuitClosure(), | 175 new DummyServerSocketFactory(run_loop.QuitClosure(), |
| 176 run_loop_2.QuitClosure())); | 176 run_loop_2.QuitClosure())); |
| 177 | 177 |
| 178 DevToolsAgentHost::StartRemoteDebuggingServer( | 178 DevToolsAgentHost::StartRemoteDebuggingServer( |
| 179 std::move(factory), std::string(), temp_dir.GetPath(), base::FilePath(), | 179 std::move(factory), std::string(), temp_dir.GetPath(), base::FilePath(), |
| 180 std::string(), std::string()); | 180 std::string(), std::string(), std::string()); |
| 181 // Our dummy socket factory will post a quit message once the server will | 181 // Our dummy socket factory will post a quit message once the server will |
| 182 // become ready. | 182 // become ready. |
| 183 run_loop.Run(); | 183 run_loop.Run(); |
| 184 DevToolsAgentHost::StopRemoteDebuggingServer(); | 184 DevToolsAgentHost::StopRemoteDebuggingServer(); |
| 185 // Make sure the handler actually stops. | 185 // Make sure the handler actually stops. |
| 186 run_loop_2.Run(); | 186 run_loop_2.Run(); |
| 187 | 187 |
| 188 // Now make sure the DevToolsActivePort was written into the | 188 // Now make sure the DevToolsActivePort was written into the |
| 189 // temporary directory and its contents are as expected. | 189 // temporary directory and its contents are as expected. |
| 190 base::FilePath active_port_file = | 190 base::FilePath active_port_file = |
| 191 temp_dir.GetPath().Append(kDevToolsActivePortFileName); | 191 temp_dir.GetPath().Append(kDevToolsActivePortFileName); |
| 192 EXPECT_TRUE(base::PathExists(active_port_file)); | 192 EXPECT_TRUE(base::PathExists(active_port_file)); |
| 193 std::string file_contents; | 193 std::string file_contents; |
| 194 EXPECT_TRUE(base::ReadFileToString(active_port_file, &file_contents)); | 194 EXPECT_TRUE(base::ReadFileToString(active_port_file, &file_contents)); |
| 195 int port = 0; | 195 int port = 0; |
| 196 EXPECT_TRUE(base::StringToInt(file_contents, &port)); | 196 EXPECT_TRUE(base::StringToInt(file_contents, &port)); |
| 197 EXPECT_EQ(static_cast<int>(kDummyPort), port); | 197 EXPECT_EQ(static_cast<int>(kDummyPort), port); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace content | 200 } // namespace content |
| OLD | NEW |