OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/message_loop.h" | |
6 #include "base/run_loop.h" | |
7 #include "content/browser/browser_thread_impl.h" | |
8 #include "content/public/browser/devtools_http_handler.h" | |
9 #include "content/public/browser/devtools_http_handler_delegate.h" | |
10 #include "net/base/stream_listen_socket.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace content { | |
14 namespace { | |
15 | |
16 using net::StreamListenSocket; | |
17 | |
18 class DummyListenSocket : public StreamListenSocket, | |
19 public StreamListenSocket::Delegate { | |
20 public: | |
21 DummyListenSocket() | |
22 : ALLOW_THIS_IN_INITIALIZER_LIST(StreamListenSocket(0, this)) {} | |
23 | |
24 // StreamListenSocket::Delegate "implementation" | |
25 virtual void DidAccept(StreamListenSocket* server, | |
26 StreamListenSocket* connection) OVERRIDE {} | |
27 virtual void DidRead(StreamListenSocket* connection, | |
28 const char* data, | |
29 int len) OVERRIDE {} | |
30 virtual void DidClose(StreamListenSocket* sock) OVERRIDE {} | |
31 protected: | |
32 virtual ~DummyListenSocket() {} | |
33 virtual void Accept() OVERRIDE {} | |
34 }; | |
35 | |
36 class DummyListenSocketFactory : public net::StreamListenSocketFactory { | |
37 public: | |
38 DummyListenSocketFactory( | |
39 base::Closure quit_closure_1, base::Closure quit_closure_2) | |
40 : quit_closure_1_(quit_closure_1), quit_closure_2_(quit_closure_2) {} | |
41 virtual ~DummyListenSocketFactory() { | |
42 BrowserThread::PostTask( | |
43 BrowserThread::UI, FROM_HERE, quit_closure_2_); | |
44 } | |
45 | |
46 virtual scoped_refptr<StreamListenSocket> CreateAndListen( | |
47 StreamListenSocket::Delegate* delegate) const OVERRIDE { | |
48 BrowserThread::PostTask( | |
49 BrowserThread::UI, FROM_HERE, quit_closure_1_); | |
50 return new DummyListenSocket(); | |
51 } | |
52 private: | |
53 base::Closure quit_closure_1_; | |
54 base::Closure quit_closure_2_; | |
55 }; | |
56 | |
57 class DummyDelegate : public DevToolsHttpHandlerDelegate { | |
58 public: | |
59 virtual std::string GetDiscoveryPageHTML() OVERRIDE { return ""; } | |
60 virtual bool BundlesFrontendResources() OVERRIDE { return true; } | |
61 virtual FilePath GetDebugFrontendDir() OVERRIDE { return FilePath(); } | |
62 virtual std::string GetPageThumbnailData(const GURL& url) { return ""; } | |
63 virtual RenderViewHost* CreateNewTarget() { return NULL; } | |
64 }; | |
65 | |
66 } | |
67 | |
68 class DevToolsHttpHandlerTest : public testing::Test { | |
69 public: | |
70 DevToolsHttpHandlerTest() | |
71 : ui_thread_(BrowserThread::UI, &message_loop_) { | |
72 } | |
73 protected: | |
74 virtual void SetUp() { | |
75 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE)); | |
76 file_thread_->Start(); | |
77 } | |
78 virtual void TearDown() { | |
79 file_thread_->Stop(); | |
80 } | |
81 private: | |
82 MessageLoopForIO message_loop_; | |
83 BrowserThreadImpl ui_thread_; | |
84 scoped_ptr<BrowserThreadImpl> file_thread_; | |
85 }; | |
86 | |
87 TEST_F(DevToolsHttpHandlerTest, TestStartStop) { | |
88 base::RunLoop run_loop, run_loop_2; | |
89 content::DevToolsHttpHandler* devtools_http_handler_ = | |
90 content::DevToolsHttpHandler::Start( | |
91 new DummyListenSocketFactory( | |
92 run_loop.QuitClosure(), run_loop_2.QuitClosure()), | |
93 "", | |
94 new DummyDelegate()); | |
95 // Our dummy socket factory will post a quit message once the server will | |
96 // become ready. | |
97 run_loop.Run(); | |
98 devtools_http_handler_->Stop(); | |
99 // Make sure the handler actually stops. | |
100 run_loop_2.Run(); | |
101 } | |
102 | |
103 } // namespace content | |
OLD | NEW |