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 virtual void OnConnect(int connection_id) override {} |
74 | 74 |
75 virtual void OnHttpRequest(int connection_id, | 75 virtual 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 virtual void OnWebSocketRequest( |
93 int connection_id, | 93 int connection_id, |
94 const net::HttpServerRequestInfo& info) OVERRIDE {} | 94 const net::HttpServerRequestInfo& info) override {} |
95 virtual void OnWebSocketMessage(int connection_id, | 95 virtual void OnWebSocketMessage(int connection_id, |
96 const std::string& data) OVERRIDE {} | 96 const std::string& data) override {} |
97 virtual void OnClose(int connection_id) OVERRIDE {} | 97 virtual void OnClose(int connection_id) override {} |
98 | 98 |
99 protected: | 99 protected: |
100 enum ServerResponse { | 100 enum ServerResponse { |
101 kSendHello = 0, | 101 kSendHello = 0, |
102 kSend404, | 102 kSend404, |
103 kClose, | 103 kClose, |
104 }; | 104 }; |
105 | 105 |
106 base::Thread io_thread_; | 106 base::Thread io_thread_; |
107 ServerResponse response_; | 107 ServerResponse response_; |
(...skipping 23 matching lines...) Expand all Loading... |
131 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); | 131 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); |
132 ASSERT_STREQ("stuff", response.c_str()); | 132 ASSERT_STREQ("stuff", response.c_str()); |
133 } | 133 } |
134 | 134 |
135 TEST_F(FetchUrlTest, NoServer) { | 135 TEST_F(FetchUrlTest, NoServer) { |
136 std::string response("stuff"); | 136 std::string response("stuff"); |
137 ASSERT_FALSE( | 137 ASSERT_FALSE( |
138 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); | 138 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); |
139 ASSERT_STREQ("stuff", response.c_str()); | 139 ASSERT_STREQ("stuff", response.c_str()); |
140 } | 140 } |
OLD | NEW |