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

Side by Side Diff: blimp/net/engine_authentication_handler_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: Created 4 years, 12 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
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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/test/test_mock_time_task_runner.h" 9 #include "base/test/test_mock_time_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 23 matching lines...) Expand all
34 : runner_(new base::TestMockTimeTaskRunner), 34 : runner_(new base::TestMockTimeTaskRunner),
35 runner_handle_(runner_), 35 runner_handle_(runner_),
36 auth_handler_(new EngineAuthenticationHandler(&connection_handler_)), 36 auth_handler_(new EngineAuthenticationHandler(&connection_handler_)),
37 connection_(new testing::StrictMock<MockBlimpConnection>()) {} 37 connection_(new testing::StrictMock<MockBlimpConnection>()) {}
38 38
39 ~EngineAuthenticationHandlerTest() override {} 39 ~EngineAuthenticationHandlerTest() override {}
40 40
41 protected: 41 protected:
42 void ExpectOnConnection() { 42 void ExpectOnConnection() {
43 EXPECT_CALL(*connection_, SetConnectionErrorObserver(_)) 43 EXPECT_CALL(*connection_, SetConnectionErrorObserver(_))
44 .Times(2) 44 .WillOnce(SaveArg<0>(&error_observer_));
45 .WillRepeatedly(SaveArg<0>(&error_observer_));
46 EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_)) 45 EXPECT_CALL(*connection_, SetIncomingMessageProcessor(_))
47 .Times(2) 46 .WillOnce(SaveArg<0>(&incoming_message_processor_));
48 .WillRepeatedly(SaveArg<0>(&incoming_message_processor_));
49 } 47 }
50 48
51 scoped_refptr<base::TestMockTimeTaskRunner> runner_; 49 scoped_refptr<base::TestMockTimeTaskRunner> runner_;
52 base::ThreadTaskRunnerHandle runner_handle_; 50 base::ThreadTaskRunnerHandle runner_handle_;
53 testing::StrictMock<MockConnectionHandler> connection_handler_; 51 testing::StrictMock<MockConnectionHandler> connection_handler_;
54 scoped_ptr<EngineAuthenticationHandler> auth_handler_; 52 scoped_ptr<EngineAuthenticationHandler> auth_handler_;
55 scoped_ptr<testing::StrictMock<MockBlimpConnection>> connection_; 53 scoped_ptr<testing::StrictMock<MockBlimpConnection>> connection_;
56 ConnectionErrorObserver* error_observer_ = nullptr; 54 ConnectionErrorObserver* error_observer_ = nullptr;
57 BlimpMessageProcessor* incoming_message_processor_ = nullptr; 55 BlimpMessageProcessor* incoming_message_processor_ = nullptr;
58 }; 56 };
59 57
60 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) { 58 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) {
61 ExpectOnConnection(); 59 ExpectOnConnection();
62 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get()))); 60 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get())));
63 auth_handler_->HandleConnection(std::move(connection_)); 61 auth_handler_->HandleConnection(std::move(connection_));
64 EXPECT_NE(nullptr, error_observer_); 62 EXPECT_NE(nullptr, error_observer_);
65 EXPECT_NE(nullptr, incoming_message_processor_); 63 EXPECT_NE(nullptr, incoming_message_processor_);
66 64
67 scoped_ptr<BlimpMessage> blimp_message = CreateStartConnectionMessage("", 0); 65 scoped_ptr<BlimpMessage> blimp_message = CreateStartConnectionMessage("", 0);
68 net::TestCompletionCallback process_message_cb; 66 net::TestCompletionCallback process_message_cb;
69 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 67 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
70 process_message_cb.callback()); 68 process_message_cb.callback());
71 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 69 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
72 EXPECT_EQ(nullptr, error_observer_);
73 EXPECT_EQ(nullptr, incoming_message_processor_);
74 } 70 }
75 71
76 TEST_F(EngineAuthenticationHandlerTest, WrongMessageReceived) { 72 TEST_F(EngineAuthenticationHandlerTest, WrongMessageReceived) {
77 ExpectOnConnection(); 73 ExpectOnConnection();
78 auth_handler_->HandleConnection(std::move(connection_)); 74 auth_handler_->HandleConnection(std::move(connection_));
79 75
80 InputMessage* input_message; 76 InputMessage* input_message;
81 scoped_ptr<BlimpMessage> blimp_message = CreateBlimpMessage(&input_message); 77 scoped_ptr<BlimpMessage> blimp_message = CreateBlimpMessage(&input_message);
82 net::TestCompletionCallback process_message_cb; 78 net::TestCompletionCallback process_message_cb;
83 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 79 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
84 process_message_cb.callback()); 80 process_message_cb.callback());
85 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 81 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
86 EXPECT_EQ(nullptr, error_observer_);
87 EXPECT_EQ(nullptr, incoming_message_processor_);
88 } 82 }
89 83
90 TEST_F(EngineAuthenticationHandlerTest, ConnectionError) { 84 TEST_F(EngineAuthenticationHandlerTest, ConnectionError) {
91 ExpectOnConnection(); 85 ExpectOnConnection();
92 auth_handler_->HandleConnection(std::move(connection_)); 86 auth_handler_->HandleConnection(std::move(connection_));
93 EXPECT_NE(nullptr, error_observer_); 87 EXPECT_NE(nullptr, error_observer_);
94 EXPECT_NE(nullptr, incoming_message_processor_); 88 EXPECT_NE(nullptr, incoming_message_processor_);
95 error_observer_->OnConnectionError(net::ERR_FAILED); 89 error_observer_->OnConnectionError(net::ERR_FAILED);
96 EXPECT_EQ(nullptr, error_observer_);
97 EXPECT_EQ(nullptr, incoming_message_processor_);
98 } 90 }
99 91
100 TEST_F(EngineAuthenticationHandlerTest, Timeout) { 92 TEST_F(EngineAuthenticationHandlerTest, Timeout) {
101 ExpectOnConnection(); 93 ExpectOnConnection();
102 auth_handler_->HandleConnection(std::move(connection_)); 94 auth_handler_->HandleConnection(std::move(connection_));
103 EXPECT_NE(nullptr, error_observer_); 95 EXPECT_NE(nullptr, error_observer_);
104 EXPECT_NE(nullptr, incoming_message_processor_); 96 EXPECT_NE(nullptr, incoming_message_processor_);
105 97
106 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11)); 98 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11));
107 EXPECT_EQ(nullptr, error_observer_);
108 EXPECT_EQ(nullptr, incoming_message_processor_);
109 } 99 }
110 100
111 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeletedFirst) { 101 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeletedFirst) {
112 ExpectOnConnection(); 102 ExpectOnConnection();
113 auth_handler_->HandleConnection(std::move(connection_)); 103 auth_handler_->HandleConnection(std::move(connection_));
114 auth_handler_.reset(); 104 auth_handler_.reset();
115 105
116 scoped_ptr<BlimpMessage> blimp_message = CreateStartConnectionMessage("", 0); 106 scoped_ptr<BlimpMessage> blimp_message = CreateStartConnectionMessage("", 0);
117 net::TestCompletionCallback process_message_cb; 107 net::TestCompletionCallback process_message_cb;
118 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 108 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
119 process_message_cb.callback()); 109 process_message_cb.callback());
120 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 110 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
121 } 111 }
122 112
123 } // namespace blimp 113 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698