Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: blimp/net/blimp_connection_unittest.cc

Issue 1551583003: Implementation and fixes for Blimp client/engine E2E communication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dtrainor-linux-cl1528243002
Patch Set: Fixed misplaced EXPORT directive Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/net/blimp_connection.cc ('k') | blimp/net/blimp_message_demultiplexer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <string> 6 #include <string>
7 7
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "blimp/common/proto/blimp_message.pb.h" 10 #include "blimp/common/proto/blimp_message.pb.h"
(...skipping 17 matching lines...) Expand all
28 namespace { 28 namespace {
29 29
30 class BlimpConnectionTest : public testing::Test { 30 class BlimpConnectionTest : public testing::Test {
31 public: 31 public:
32 BlimpConnectionTest() { 32 BlimpConnectionTest() {
33 scoped_ptr<testing::StrictMock<MockPacketWriter>> writer( 33 scoped_ptr<testing::StrictMock<MockPacketWriter>> writer(
34 new testing::StrictMock<MockPacketWriter>); 34 new testing::StrictMock<MockPacketWriter>);
35 writer_ = writer.get(); 35 writer_ = writer.get();
36 connection_.reset(new BlimpConnection(make_scoped_ptr(new MockPacketReader), 36 connection_.reset(new BlimpConnection(make_scoped_ptr(new MockPacketReader),
37 std::move(writer))); 37 std::move(writer)));
38 connection_->SetConnectionErrorObserver(&error_observer_); 38 connection_->AddConnectionErrorObserver(&error_observer1_);
39 connection_->AddConnectionErrorObserver(&error_observer2_);
40 connection_->AddConnectionErrorObserver(&error_observer3_);
41 connection_->RemoveConnectionErrorObserver(&error_observer3_);
39 } 42 }
40 43
41 ~BlimpConnectionTest() override {} 44 ~BlimpConnectionTest() override {}
42 45
43 protected: 46 protected:
44 scoped_ptr<BlimpMessage> CreateInputMessage() { 47 scoped_ptr<BlimpMessage> CreateInputMessage() {
45 scoped_ptr<BlimpMessage> msg(new BlimpMessage); 48 scoped_ptr<BlimpMessage> msg(new BlimpMessage);
46 msg->set_type(BlimpMessage::INPUT); 49 msg->set_type(BlimpMessage::INPUT);
47 return msg; 50 return msg;
48 } 51 }
49 52
50 scoped_ptr<BlimpMessage> CreateControlMessage() { 53 scoped_ptr<BlimpMessage> CreateControlMessage() {
51 scoped_ptr<BlimpMessage> msg(new BlimpMessage); 54 scoped_ptr<BlimpMessage> msg(new BlimpMessage);
52 msg->set_type(BlimpMessage::TAB_CONTROL); 55 msg->set_type(BlimpMessage::TAB_CONTROL);
53 return msg; 56 return msg;
54 } 57 }
55 58
56 base::MessageLoop message_loop_; 59 base::MessageLoop message_loop_;
57 testing::StrictMock<MockPacketWriter>* writer_; 60 testing::StrictMock<MockPacketWriter>* writer_;
58 testing::StrictMock<MockConnectionErrorObserver> error_observer_; 61 testing::StrictMock<MockConnectionErrorObserver> error_observer1_;
62 testing::StrictMock<MockConnectionErrorObserver> error_observer2_;
63
64 // This error observer is Removed() immediately after it's added;
65 // it should never be called.
66 testing::StrictMock<MockConnectionErrorObserver> error_observer3_;
67
59 testing::StrictMock<MockBlimpMessageProcessor> receiver_; 68 testing::StrictMock<MockBlimpMessageProcessor> receiver_;
60 scoped_ptr<BlimpConnection> connection_; 69 scoped_ptr<BlimpConnection> connection_;
61 }; 70 };
62 71
63 // Write completes writing two packets asynchronously. 72 // Write completes writing two packets asynchronously.
64 TEST_F(BlimpConnectionTest, AsyncTwoPacketsWrite) { 73 TEST_F(BlimpConnectionTest, AsyncTwoPacketsWrite) {
65 net::CompletionCallback write_packet_cb; 74 net::CompletionCallback write_packet_cb;
66 75
67 InSequence s; 76 InSequence s;
68 EXPECT_CALL(*writer_, 77 EXPECT_CALL(*writer_,
(...skipping 30 matching lines...) Expand all
99 108
100 InSequence s; 109 InSequence s;
101 EXPECT_CALL(*writer_, 110 EXPECT_CALL(*writer_,
102 WritePacket(BufferEqualsProto(*CreateInputMessage()), _)) 111 WritePacket(BufferEqualsProto(*CreateInputMessage()), _))
103 .WillOnce(SaveArg<1>(&write_packet_cb)) 112 .WillOnce(SaveArg<1>(&write_packet_cb))
104 .RetiresOnSaturation(); 113 .RetiresOnSaturation();
105 EXPECT_CALL(*writer_, 114 EXPECT_CALL(*writer_,
106 WritePacket(BufferEqualsProto(*CreateControlMessage()), _)) 115 WritePacket(BufferEqualsProto(*CreateControlMessage()), _))
107 .WillOnce(SaveArg<1>(&write_packet_cb)) 116 .WillOnce(SaveArg<1>(&write_packet_cb))
108 .RetiresOnSaturation(); 117 .RetiresOnSaturation();
109 EXPECT_CALL(error_observer_, OnConnectionError(net::ERR_FAILED)); 118 EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED));
119 EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED));
110 120
111 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor(); 121 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor();
112 net::TestCompletionCallback complete_cb_1; 122 net::TestCompletionCallback complete_cb_1;
113 sender->ProcessMessage(CreateInputMessage(), 123 sender->ProcessMessage(CreateInputMessage(),
114 complete_cb_1.callback()); 124 complete_cb_1.callback());
115 base::ResetAndReturn(&write_packet_cb).Run(net::OK); 125 base::ResetAndReturn(&write_packet_cb).Run(net::OK);
116 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult()); 126 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult());
117 127
118 net::TestCompletionCallback complete_cb_2; 128 net::TestCompletionCallback complete_cb_2;
119 sender->ProcessMessage(CreateControlMessage(), 129 sender->ProcessMessage(CreateControlMessage(),
120 complete_cb_2.callback()); 130 complete_cb_2.callback());
121 base::ResetAndReturn(&write_packet_cb).Run(net::ERR_FAILED); 131 base::ResetAndReturn(&write_packet_cb).Run(net::ERR_FAILED);
122 EXPECT_EQ(net::ERR_FAILED, complete_cb_2.WaitForResult()); 132 EXPECT_EQ(net::ERR_FAILED, complete_cb_2.WaitForResult());
123 } 133 }
124 134
125 } // namespace 135 } // namespace
126 } // namespace blimp 136 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blimp_connection.cc ('k') | blimp/net/blimp_message_demultiplexer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698