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

Side by Side Diff: remoting/host/setup/me2me_native_messaging_host_unittest.cc

Issue 1099553003: Added unit tests for getCredentialsFromAuthCode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated BUILD.gn file Created 5 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/setup/me2me_native_messaging_host.h" 5 #include "remoting/host/setup/me2me_native_messaging_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/stringize_macros.h" 14 #include "base/strings/stringize_macros.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "google_apis/gaia/gaia_oauth_client.h" 16 #include "google_apis/gaia/gaia_oauth_client.h"
17 #include "net/base/file_stream.h" 17 #include "net/base/file_stream.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "remoting/base/auto_thread_task_runner.h" 19 #include "remoting/base/auto_thread_task_runner.h"
20 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 20 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
21 #include "remoting/host/pin_hash.h" 21 #include "remoting/host/pin_hash.h"
22 #include "remoting/host/setup/mock_oauth_client.h"
22 #include "remoting/host/setup/test_util.h" 23 #include "remoting/host/setup/test_util.h"
23 #include "remoting/protocol/pairing_registry.h" 24 #include "remoting/protocol/pairing_registry.h"
24 #include "remoting/protocol/protocol_mock_objects.h" 25 #include "remoting/protocol/protocol_mock_objects.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using remoting::protocol::MockPairingRegistryDelegate; 28 using remoting::protocol::MockPairingRegistryDelegate;
28 using remoting::protocol::PairingRegistry; 29 using remoting::protocol::PairingRegistry;
29 using remoting::protocol::SynchronousPairingRegistry; 30 using remoting::protocol::SynchronousPairingRegistry;
30 31
31 namespace { 32 namespace {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 128
128 void VerifyStartDaemonResponse(scoped_ptr<base::DictionaryValue> response) { 129 void VerifyStartDaemonResponse(scoped_ptr<base::DictionaryValue> response) {
129 ASSERT_TRUE(response); 130 ASSERT_TRUE(response);
130 std::string value; 131 std::string value;
131 EXPECT_TRUE(response->GetString("type", &value)); 132 EXPECT_TRUE(response->GetString("type", &value));
132 EXPECT_EQ("startDaemonResponse", value); 133 EXPECT_EQ("startDaemonResponse", value);
133 EXPECT_TRUE(response->GetString("result", &value)); 134 EXPECT_TRUE(response->GetString("result", &value));
134 EXPECT_EQ("OK", value); 135 EXPECT_EQ("OK", value);
135 } 136 }
136 137
138 void VerifyGetCredentialsFromAuthCodeResponse(
139 scoped_ptr<base::DictionaryValue> response) {
140 ASSERT_TRUE(response);
141 std::string value;
142 EXPECT_TRUE(response->GetString("type", &value));
143 EXPECT_EQ("getCredentialsFromAuthCodeResponse", value);
144 EXPECT_TRUE(response->GetString("userEmail", &value));
145 EXPECT_EQ("fake_user_email", value);
146 EXPECT_TRUE(response->GetString("refreshToken", &value));
147 EXPECT_EQ("fake_refresh_token", value);
148 }
149
137 } // namespace 150 } // namespace
138 151
139 namespace remoting { 152 namespace remoting {
140 153
141 class MockDaemonControllerDelegate : public DaemonController::Delegate { 154 class MockDaemonControllerDelegate : public DaemonController::Delegate {
142 public: 155 public:
143 MockDaemonControllerDelegate(); 156 MockDaemonControllerDelegate();
144 ~MockDaemonControllerDelegate() override; 157 ~MockDaemonControllerDelegate() override;
145 158
146 // DaemonController::Delegate interface. 159 // DaemonController::Delegate interface.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 new DaemonController(make_scoped_ptr(daemon_controller_delegate_))); 319 new DaemonController(make_scoped_ptr(daemon_controller_delegate_)));
307 320
308 scoped_refptr<PairingRegistry> pairing_registry = 321 scoped_refptr<PairingRegistry> pairing_registry =
309 new SynchronousPairingRegistry( 322 new SynchronousPairingRegistry(
310 make_scoped_ptr(new MockPairingRegistryDelegate())); 323 make_scoped_ptr(new MockPairingRegistryDelegate()));
311 324
312 scoped_ptr<extensions::NativeMessagingChannel> channel( 325 scoped_ptr<extensions::NativeMessagingChannel> channel(
313 new PipeMessagingChannel(input_read_file.Pass(), 326 new PipeMessagingChannel(input_read_file.Pass(),
314 output_write_file.Pass())); 327 output_write_file.Pass()));
315 328
316 host_.reset(new Me2MeNativeMessagingHost( 329 scoped_ptr<OAuthClient> oauth_client(
317 false, 0, channel.Pass(), daemon_controller, pairing_registry, nullptr)); 330 new MockOAuthClient("fake_user_email", "fake_refresh_token"));
331
332 host_.reset(new Me2MeNativeMessagingHost(false, 0, channel.Pass(),
333 daemon_controller, pairing_registry,
334 oauth_client.Pass()));
318 host_->Start(base::Bind(&Me2MeNativeMessagingHostTest::StopHost, 335 host_->Start(base::Bind(&Me2MeNativeMessagingHostTest::StopHost,
319 base::Unretained(this))); 336 base::Unretained(this)));
320 337
321 // Notify the test that the host has finished starting up. 338 // Notify the test that the host has finished starting up.
322 test_message_loop_->message_loop_proxy()->PostTask( 339 test_message_loop_->message_loop_proxy()->PostTask(
323 FROM_HERE, test_run_loop_->QuitClosure()); 340 FROM_HERE, test_run_loop_->QuitClosure());
324 } 341 }
325 342
326 void Me2MeNativeMessagingHostTest::StopHost() { 343 void Me2MeNativeMessagingHostTest::StopHost() {
327 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); 344 DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 WriteMessageToInputPipe(message); 484 WriteMessageToInputPipe(message);
468 485
469 config.Clear(); 486 config.Clear();
470 config.SetBoolean("start", true); 487 config.SetBoolean("start", true);
471 message.Set("config", config.DeepCopy()); 488 message.Set("config", config.DeepCopy());
472 message.SetBoolean("consent", true); 489 message.SetBoolean("consent", true);
473 message.SetInteger("id", next_id++); 490 message.SetInteger("id", next_id++);
474 message.SetString("type", "startDaemon"); 491 message.SetString("type", "startDaemon");
475 WriteMessageToInputPipe(message); 492 WriteMessageToInputPipe(message);
476 493
494 message.SetInteger("id", next_id++);
495 message.SetString("type", "getCredentialsFromAuthCode");
496 message.SetString("authorizationCode", "fake_auth_code");
497 WriteMessageToInputPipe(message);
498
477 void (*verify_routines[])(scoped_ptr<base::DictionaryValue>) = { 499 void (*verify_routines[])(scoped_ptr<base::DictionaryValue>) = {
478 &VerifyHelloResponse, 500 &VerifyHelloResponse,
479 &VerifyGetHostNameResponse, 501 &VerifyGetHostNameResponse,
480 &VerifyGetPinHashResponse, 502 &VerifyGetPinHashResponse,
481 &VerifyGenerateKeyPairResponse, 503 &VerifyGenerateKeyPairResponse,
482 &VerifyGetDaemonConfigResponse, 504 &VerifyGetDaemonConfigResponse,
483 &VerifyGetUsageStatsConsentResponse, 505 &VerifyGetUsageStatsConsentResponse,
484 &VerifyStopDaemonResponse, 506 &VerifyStopDaemonResponse,
485 &VerifyGetDaemonStateResponse, 507 &VerifyGetDaemonStateResponse,
486 &VerifyUpdateDaemonConfigResponse, 508 &VerifyUpdateDaemonConfigResponse,
487 &VerifyStartDaemonResponse, 509 &VerifyStartDaemonResponse,
510 &VerifyGetCredentialsFromAuthCodeResponse,
488 }; 511 };
489 ASSERT_EQ(arraysize(verify_routines), static_cast<size_t>(next_id)); 512 ASSERT_EQ(arraysize(verify_routines), static_cast<size_t>(next_id));
490 513
491 // Read all responses from output pipe, and verify them. 514 // Read all responses from output pipe, and verify them.
492 for (int i = 0; i < next_id; ++i) { 515 for (int i = 0; i < next_id; ++i) {
493 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 516 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
494 517
495 // Make sure that id is available and is in the range. 518 // Make sure that id is available and is in the range.
496 int id; 519 int id;
497 ASSERT_TRUE(response->GetInteger("id", &id)); 520 ASSERT_TRUE(response->GetInteger("id", &id));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 601 }
579 602
580 // Verify rejection if startDaemon request has no "consent" parameter. 603 // Verify rejection if startDaemon request has no "consent" parameter.
581 TEST_F(Me2MeNativeMessagingHostTest, StartDaemonNoConsent) { 604 TEST_F(Me2MeNativeMessagingHostTest, StartDaemonNoConsent) {
582 base::DictionaryValue message; 605 base::DictionaryValue message;
583 message.SetString("type", "startDaemon"); 606 message.SetString("type", "startDaemon");
584 message.Set("config", base::DictionaryValue().DeepCopy()); 607 message.Set("config", base::DictionaryValue().DeepCopy());
585 TestBadRequest(message); 608 TestBadRequest(message);
586 } 609 }
587 610
611 // Verify rejection if getCredentialsFromAuthCode has no auth code.
612 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) {
613 base::DictionaryValue message;
614 message.SetString("type", "getCredentialsFromAuthCode");
615 TestBadRequest(message);
616 }
617
588 } // namespace remoting 618 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/setup/me2me_native_messaging_host_main.cc ('k') | remoting/host/setup/mock_oauth_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698