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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 server_url_ = base::StringPrintf("http://127.0.0.1:%d", address.port()); | 63 server_url_ = base::StringPrintf("http://127.0.0.1:%d", address.port()); |
64 event->Signal(); | 64 event->Signal(); |
65 } | 65 } |
66 | 66 |
67 void DestroyServerOnIO(base::WaitableEvent* event) { | 67 void DestroyServerOnIO(base::WaitableEvent* event) { |
68 server_.reset(NULL); | 68 server_.reset(NULL); |
69 event->Signal(); | 69 event->Signal(); |
70 } | 70 } |
71 | 71 |
72 // Overridden from net::HttpServer::Delegate: | 72 // Overridden from net::HttpServer::Delegate: |
73 virtual void OnConnect(int connection_id) override {} | 73 void OnConnect(int connection_id) override {} |
74 | 74 |
75 virtual void OnHttpRequest(int connection_id, | 75 void OnHttpRequest(int connection_id, |
76 const net::HttpServerRequestInfo& info) override { | 76 const net::HttpServerRequestInfo& info) override { |
77 switch (response_) { | 77 switch (response_) { |
78 case kSendHello: | 78 case kSendHello: |
79 server_->Send200(connection_id, "hello", "text/plain"); | 79 server_->Send200(connection_id, "hello", "text/plain"); |
80 break; | 80 break; |
81 case kSend404: | 81 case kSend404: |
82 server_->Send404(connection_id); | 82 server_->Send404(connection_id); |
83 break; | 83 break; |
84 case kClose: | 84 case kClose: |
85 server_->Close(connection_id); | 85 server_->Close(connection_id); |
86 break; | 86 break; |
87 default: | 87 default: |
88 break; | 88 break; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 virtual void OnWebSocketRequest( | 92 void OnWebSocketRequest(int connection_id, |
93 int connection_id, | 93 const net::HttpServerRequestInfo& info) override {} |
94 const net::HttpServerRequestInfo& info) override {} | 94 void OnWebSocketMessage(int connection_id, const std::string& data) override { |
95 virtual void OnWebSocketMessage(int connection_id, | 95 } |
96 const std::string& data) override {} | 96 void OnClose(int connection_id) override {} |
97 virtual void OnClose(int connection_id) override {} | |
98 | 97 |
99 protected: | 98 protected: |
100 enum ServerResponse { | 99 enum ServerResponse { |
101 kSendHello = 0, | 100 kSendHello = 0, |
102 kSend404, | 101 kSend404, |
103 kClose, | 102 kClose, |
104 }; | 103 }; |
105 | 104 |
106 base::Thread io_thread_; | 105 base::Thread io_thread_; |
107 ServerResponse response_; | 106 ServerResponse response_; |
(...skipping 23 matching lines...) Expand all Loading... |
131 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); | 130 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); |
132 ASSERT_STREQ("stuff", response.c_str()); | 131 ASSERT_STREQ("stuff", response.c_str()); |
133 } | 132 } |
134 | 133 |
135 TEST_F(FetchUrlTest, NoServer) { | 134 TEST_F(FetchUrlTest, NoServer) { |
136 std::string response("stuff"); | 135 std::string response("stuff"); |
137 ASSERT_FALSE( | 136 ASSERT_FALSE( |
138 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); | 137 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); |
139 ASSERT_STREQ("stuff", response.c_str()); | 138 ASSERT_STREQ("stuff", response.c_str()); |
140 } | 139 } |
OLD | NEW |