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

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host_unittest.cc

Issue 2847853003: Remove policy watching from It2MeHost. (Closed)
Patch Set: Fix unit tests Created 3 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "remoting/host/it2me/it2me_native_messaging_host.h" 5 #include "remoting/host/it2me/it2me_native_messaging_host.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return true; 118 return true;
119 } 119 }
120 120
121 void FakePolicyService::RefreshPolicies(const base::Closure& callback) { 121 void FakePolicyService::RefreshPolicies(const base::Closure& callback) {
122 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 122 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
123 } 123 }
124 124
125 class MockIt2MeHost : public It2MeHost { 125 class MockIt2MeHost : public It2MeHost {
126 public: 126 public:
127 MockIt2MeHost(std::unique_ptr<ChromotingHostContext> context, 127 MockIt2MeHost(std::unique_ptr<ChromotingHostContext> context,
128 std::unique_ptr<PolicyWatcher> policy_watcher,
129 base::WeakPtr<It2MeHost::Observer> observer, 128 base::WeakPtr<It2MeHost::Observer> observer,
130 std::unique_ptr<SignalStrategy> signal_strategy, 129 std::unique_ptr<SignalStrategy> signal_strategy,
131 const std::string& username, 130 const std::string& username,
132 const std::string& directory_bot_jid) 131 const std::string& directory_bot_jid)
133 : It2MeHost(std::move(context), 132 : It2MeHost(std::move(context),
134 std::move(policy_watcher),
135 /*confirmation_dialog_factory=*/nullptr, 133 /*confirmation_dialog_factory=*/nullptr,
136 observer, 134 observer,
137 std::move(signal_strategy), 135 std::move(signal_strategy),
138 username, 136 username,
139 directory_bot_jid) {} 137 directory_bot_jid) {}
140 138
141 // It2MeHost overrides 139 // It2MeHost overrides
142 void Connect() override; 140 void Connect() override;
143 void Disconnect() override; 141 void Disconnect() override;
144 void RequestNatPolicy() override; 142 void RequestNatPolicy() override;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 220
223 MockIt2MeHostFactory::~MockIt2MeHostFactory() {} 221 MockIt2MeHostFactory::~MockIt2MeHostFactory() {}
224 222
225 scoped_refptr<It2MeHost> MockIt2MeHostFactory::CreateIt2MeHost( 223 scoped_refptr<It2MeHost> MockIt2MeHostFactory::CreateIt2MeHost(
226 std::unique_ptr<ChromotingHostContext> context, 224 std::unique_ptr<ChromotingHostContext> context,
227 policy::PolicyService* policy_service, 225 policy::PolicyService* policy_service,
228 base::WeakPtr<It2MeHost::Observer> observer, 226 base::WeakPtr<It2MeHost::Observer> observer,
229 std::unique_ptr<SignalStrategy> signal_strategy, 227 std::unique_ptr<SignalStrategy> signal_strategy,
230 const std::string& username, 228 const std::string& username,
231 const std::string& directory_bot_jid) { 229 const std::string& directory_bot_jid) {
232 return new MockIt2MeHost(std::move(context), 230 return new MockIt2MeHost(std::move(context), observer,
233 /*policy_watcher=*/nullptr, observer,
234 std::move(signal_strategy), username, 231 std::move(signal_strategy), username,
235 directory_bot_jid); 232 directory_bot_jid);
236 } 233 }
237 234
238 } // namespace 235 } // namespace
239 236
240 class It2MeNativeMessagingHostTest : public testing::Test { 237 class It2MeNativeMessagingHostTest : public testing::Test {
241 public: 238 public:
242 It2MeNativeMessagingHostTest() {} 239 It2MeNativeMessagingHostTest() {}
243 ~It2MeNativeMessagingHostTest() override {} 240 ~It2MeNativeMessagingHostTest() override {}
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 VerifyCommonProperties(std::move(response), "helloResponse", request_id); 389 VerifyCommonProperties(std::move(response), "helloResponse", request_id);
393 } 390 }
394 391
395 void It2MeNativeMessagingHostTest::VerifyErrorResponse() { 392 void It2MeNativeMessagingHostTest::VerifyErrorResponse() {
396 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 393 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
397 VerifyStringProperty(std::move(response), "type", "error"); 394 VerifyStringProperty(std::move(response), "type", "error");
398 } 395 }
399 396
400 void It2MeNativeMessagingHostTest::VerifyConnectResponses(int request_id) { 397 void It2MeNativeMessagingHostTest::VerifyConnectResponses(int request_id) {
401 bool connect_response_received = false; 398 bool connect_response_received = false;
399 bool nat_policy_received = false;
rkjnsn 2017/05/03 21:31:47 I see this was added to fix the unit test, but I c
Jamie 2017/05/03 23:41:10 The change to the native messaging host means that
rkjnsn 2017/05/04 20:45:45 Ah, I see. Since MockIt2MeHost overrides Connect,
402 bool starting_received = false; 400 bool starting_received = false;
403 bool requestedAccessCode_received = false; 401 bool requestedAccessCode_received = false;
404 bool receivedAccessCode_received = false; 402 bool receivedAccessCode_received = false;
405 bool connecting_received = false; 403 bool connecting_received = false;
406 bool connected_received = false; 404 bool connected_received = false;
407 405
408 // We expect a total of 6 messages: 1 connectResponse and 5 hostStateChanged. 406 // We expect a total of 7 messages: 1 connectResponse, 1 natPolicyChanged,
409 for (int i = 0; i < 6; ++i) { 407 // and 5 hostStateChanged.
408 for (int i = 0; i < 7; ++i) {
410 std::unique_ptr<base::DictionaryValue> response = 409 std::unique_ptr<base::DictionaryValue> response =
411 ReadMessageFromOutputPipe(); 410 ReadMessageFromOutputPipe();
412 ASSERT_TRUE(response); 411 ASSERT_TRUE(response);
413 412
414 std::string type; 413 std::string type;
415 ASSERT_TRUE(response->GetString("type", &type)); 414 ASSERT_TRUE(response->GetString("type", &type));
416 415
417 if (type == "connectResponse") { 416 if (type == "connectResponse") {
418 EXPECT_FALSE(connect_response_received); 417 EXPECT_FALSE(connect_response_received);
419 connect_response_received = true; 418 connect_response_received = true;
420 VerifyId(std::move(response), request_id); 419 VerifyId(std::move(response), request_id);
420 } else if (type == "natPolicyChanged") {
421 EXPECT_FALSE(nat_policy_received);
422 nat_policy_received = true;
421 } else if (type == "hostStateChanged") { 423 } else if (type == "hostStateChanged") {
422 std::string state; 424 std::string state;
423 ASSERT_TRUE(response->GetString("state", &state)); 425 ASSERT_TRUE(response->GetString("state", &state));
424 426
425 std::string value; 427 std::string value;
426 if (state == It2MeNativeMessagingHost::HostStateToString(kStarting)) { 428 if (state == It2MeNativeMessagingHost::HostStateToString(kStarting)) {
427 EXPECT_FALSE(starting_received); 429 EXPECT_FALSE(starting_received);
428 starting_received = true; 430 starting_received = true;
429 } else if (state == It2MeNativeMessagingHost::HostStateToString( 431 } else if (state == It2MeNativeMessagingHost::HostStateToString(
430 kRequestedAccessCode)) { 432 kRequestedAccessCode)) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 EXPECT_TRUE(response); 604 EXPECT_TRUE(response);
603 std::string value; 605 std::string value;
604 EXPECT_FALSE(response->GetString("id", &value)); 606 EXPECT_FALSE(response->GetString("id", &value));
605 607
606 response = ReadMessageFromOutputPipe(); 608 response = ReadMessageFromOutputPipe();
607 EXPECT_TRUE(response); 609 EXPECT_TRUE(response);
608 EXPECT_TRUE(response->GetString("id", &value)); 610 EXPECT_TRUE(response->GetString("id", &value));
609 EXPECT_EQ("42", value); 611 EXPECT_EQ("42", value);
610 } 612 }
611 613
612 TEST_F(It2MeNativeMessagingHostTest, Connect) { 614 TEST_F(It2MeNativeMessagingHostTest, ConnectMultiple) {
613 // A new It2MeHost instance is created for every it2me session. The native 615 // A new It2MeHost instance is created for every it2me session. The native
614 // messaging host, on the other hand, is long lived. This test verifies 616 // messaging host, on the other hand, is long lived. This test verifies
615 // multiple It2Me host startup and shutdowns. 617 // multiple It2Me host startup and shutdowns.
616 for (int i = 0; i < 3; ++i) { 618 for (int i = 0; i < 3; ++i) {
617 TestConnect(); 619 TestConnect();
618 } 620 }
619 } 621 }
620 622
621 // Verify non-Dictionary requests are rejected. 623 // Verify non-Dictionary requests are rejected.
622 TEST_F(It2MeNativeMessagingHostTest, WrongFormat) { 624 TEST_F(It2MeNativeMessagingHostTest, WrongFormat) {
623 base::ListValue message; 625 base::ListValue message;
624 // No "error" response will be sent for non-Dictionary messages. 626 // No "error" response will be sent for non-Dictionary messages.
625 TestBadRequest(message, false); 627 TestBadRequest(message, false);
626 } 628 }
627 629
628 // Verify requests with no type are rejected. 630 // Verify requests with no type are rejected.
629 TEST_F(It2MeNativeMessagingHostTest, MissingType) { 631 TEST_F(It2MeNativeMessagingHostTest, MissingType) {
630 base::DictionaryValue message; 632 base::DictionaryValue message;
631 TestBadRequest(message, true); 633 TestBadRequest(message, true);
632 } 634 }
633 635
634 // Verify rejection if type is unrecognized. 636 // Verify rejection if type is unrecognized.
635 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 637 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
636 base::DictionaryValue message; 638 base::DictionaryValue message;
637 message.SetString("type", "xxx"); 639 message.SetString("type", "xxx");
638 TestBadRequest(message, true); 640 TestBadRequest(message, true);
639 } 641 }
640 642
641 } // namespace remoting 643 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698