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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/location.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/thread_task_runner_handle.h" |
10 #include "base/values.h" | 12 #include "base/values.h" |
11 #include "components/devtools_http_handler/devtools_http_handler.h" | 13 #include "components/devtools_http_handler/devtools_http_handler.h" |
12 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 14 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
15 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
16 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
17 #include "net/socket/server_socket.h" | 19 #include "net/socket/server_socket.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 : quit_closure_1_(quit_closure_1), | 62 : quit_closure_1_(quit_closure_1), |
61 quit_closure_2_(quit_closure_2) {} | 63 quit_closure_2_(quit_closure_2) {} |
62 | 64 |
63 ~DummyServerSocketFactory() override { | 65 ~DummyServerSocketFactory() override { |
64 BrowserThread::PostTask( | 66 BrowserThread::PostTask( |
65 BrowserThread::UI, FROM_HERE, quit_closure_2_); | 67 BrowserThread::UI, FROM_HERE, quit_closure_2_); |
66 } | 68 } |
67 | 69 |
68 protected: | 70 protected: |
69 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | 71 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { |
70 base::MessageLoop::current()->PostTask(FROM_HERE, | 72 base::ThreadTaskRunnerHandle::Get()->PostTask( |
71 base::Bind(&QuitFromHandlerThread, quit_closure_1_)); | 73 FROM_HERE, base::Bind(&QuitFromHandlerThread, quit_closure_1_)); |
72 return scoped_ptr<net::ServerSocket>(new DummyServerSocket()); | 74 return scoped_ptr<net::ServerSocket>(new DummyServerSocket()); |
73 } | 75 } |
74 | 76 |
75 base::Closure quit_closure_1_; | 77 base::Closure quit_closure_1_; |
76 base::Closure quit_closure_2_; | 78 base::Closure quit_closure_2_; |
77 }; | 79 }; |
78 | 80 |
79 class FailingServerSocketFactory : public DummyServerSocketFactory { | 81 class FailingServerSocketFactory : public DummyServerSocketFactory { |
80 public: | 82 public: |
81 FailingServerSocketFactory(const base::Closure& quit_closure_1, | 83 FailingServerSocketFactory(const base::Closure& quit_closure_1, |
82 const base::Closure& quit_closure_2) | 84 const base::Closure& quit_closure_2) |
83 : DummyServerSocketFactory(quit_closure_1, quit_closure_2) { | 85 : DummyServerSocketFactory(quit_closure_1, quit_closure_2) { |
84 } | 86 } |
85 | 87 |
86 private: | 88 private: |
87 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | 89 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { |
88 base::MessageLoop::current()->PostTask(FROM_HERE, | 90 base::ThreadTaskRunnerHandle::Get()->PostTask( |
89 base::Bind(&QuitFromHandlerThread, quit_closure_1_)); | 91 FROM_HERE, base::Bind(&QuitFromHandlerThread, quit_closure_1_)); |
90 return scoped_ptr<net::ServerSocket>(); | 92 return scoped_ptr<net::ServerSocket>(); |
91 } | 93 } |
92 }; | 94 }; |
93 | 95 |
94 class DummyDelegate : public DevToolsHttpHandlerDelegate { | 96 class DummyDelegate : public DevToolsHttpHandlerDelegate { |
95 public: | 97 public: |
96 std::string GetDiscoveryPageHTML() override { return std::string(); } | 98 std::string GetDiscoveryPageHTML() override { return std::string(); } |
97 | 99 |
98 std::string GetFrontendResource(const std::string& path) override { | 100 std::string GetFrontendResource(const std::string& path) override { |
99 return std::string(); | 101 return std::string(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 kDevToolsActivePortFileName); | 191 kDevToolsActivePortFileName); |
190 EXPECT_TRUE(base::PathExists(active_port_file)); | 192 EXPECT_TRUE(base::PathExists(active_port_file)); |
191 std::string file_contents; | 193 std::string file_contents; |
192 EXPECT_TRUE(base::ReadFileToString(active_port_file, &file_contents)); | 194 EXPECT_TRUE(base::ReadFileToString(active_port_file, &file_contents)); |
193 int port = 0; | 195 int port = 0; |
194 EXPECT_TRUE(base::StringToInt(file_contents, &port)); | 196 EXPECT_TRUE(base::StringToInt(file_contents, &port)); |
195 EXPECT_EQ(static_cast<int>(kDummyPort), port); | 197 EXPECT_EQ(static_cast<int>(kDummyPort), port); |
196 } | 198 } |
197 | 199 |
198 } // namespace devtools_http_handler | 200 } // namespace devtools_http_handler |
OLD | NEW |