| 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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 base::RunLoop run_loop; | 33 base::RunLoop run_loop; |
| 34 loop->PostTask(FROM_HERE, run_loop.QuitClosure()); | 34 loop->PostTask(FROM_HERE, run_loop.QuitClosure()); |
| 35 run_loop.Run(); | 35 run_loop.Run(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 class Listener : public WebSocketListener { | 38 class Listener : public WebSocketListener { |
| 39 public: | 39 public: |
| 40 explicit Listener(const std::vector<std::string>& messages) | 40 explicit Listener(const std::vector<std::string>& messages) |
| 41 : messages_(messages) {} | 41 : messages_(messages) {} |
| 42 | 42 |
| 43 virtual ~Listener() { | 43 ~Listener() override { EXPECT_TRUE(messages_.empty()); } |
| 44 EXPECT_TRUE(messages_.empty()); | |
| 45 } | |
| 46 | 44 |
| 47 virtual void OnMessageReceived(const std::string& message) override { | 45 void OnMessageReceived(const std::string& message) override { |
| 48 ASSERT_TRUE(messages_.size()); | 46 ASSERT_TRUE(messages_.size()); |
| 49 EXPECT_EQ(messages_[0], message); | 47 EXPECT_EQ(messages_[0], message); |
| 50 messages_.erase(messages_.begin()); | 48 messages_.erase(messages_.begin()); |
| 51 if (messages_.empty()) | 49 if (messages_.empty()) |
| 52 base::MessageLoop::current()->Quit(); | 50 base::MessageLoop::current()->Quit(); |
| 53 } | 51 } |
| 54 | 52 |
| 55 virtual void OnClose() override { | 53 void OnClose() override { EXPECT_TRUE(false); } |
| 56 EXPECT_TRUE(false); | |
| 57 } | |
| 58 | 54 |
| 59 private: | 55 private: |
| 60 std::vector<std::string> messages_; | 56 std::vector<std::string> messages_; |
| 61 }; | 57 }; |
| 62 | 58 |
| 63 class CloseListener : public WebSocketListener { | 59 class CloseListener : public WebSocketListener { |
| 64 public: | 60 public: |
| 65 explicit CloseListener(base::RunLoop* run_loop) | 61 explicit CloseListener(base::RunLoop* run_loop) |
| 66 : run_loop_(run_loop) {} | 62 : run_loop_(run_loop) {} |
| 67 | 63 |
| 68 virtual ~CloseListener() { | 64 ~CloseListener() override { EXPECT_FALSE(run_loop_); } |
| 69 EXPECT_FALSE(run_loop_); | |
| 70 } | |
| 71 | 65 |
| 72 virtual void OnMessageReceived(const std::string& message) override {} | 66 void OnMessageReceived(const std::string& message) override {} |
| 73 | 67 |
| 74 virtual void OnClose() override { | 68 void OnClose() override { |
| 75 EXPECT_TRUE(run_loop_); | 69 EXPECT_TRUE(run_loop_); |
| 76 if (run_loop_) | 70 if (run_loop_) |
| 77 run_loop_->Quit(); | 71 run_loop_->Quit(); |
| 78 run_loop_ = NULL; | 72 run_loop_ = NULL; |
| 79 } | 73 } |
| 80 | 74 |
| 81 private: | 75 private: |
| 82 base::RunLoop* run_loop_; | 76 base::RunLoop* run_loop_; |
| 83 }; | 77 }; |
| 84 | 78 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 SendReceive(messages); | 200 SendReceive(messages); |
| 207 } | 201 } |
| 208 | 202 |
| 209 TEST_F(WebSocketTest, SendReceiveMultiple) { | 203 TEST_F(WebSocketTest, SendReceiveMultiple) { |
| 210 std::vector<std::string> messages; | 204 std::vector<std::string> messages; |
| 211 messages.push_back("1"); | 205 messages.push_back("1"); |
| 212 messages.push_back("2"); | 206 messages.push_back("2"); |
| 213 messages.push_back("3"); | 207 messages.push_back("3"); |
| 214 SendReceive(messages); | 208 SendReceive(messages); |
| 215 } | 209 } |
| OLD | NEW |