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

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

Issue 1272833002: Pass error messages from native messaging to web-app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests. Created 5 years, 4 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/log_message_handler.h"
20 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 21 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
21 #include "remoting/host/pin_hash.h" 22 #include "remoting/host/pin_hash.h"
22 #include "remoting/host/setup/mock_oauth_client.h" 23 #include "remoting/host/setup/mock_oauth_client.h"
23 #include "remoting/host/setup/test_util.h" 24 #include "remoting/host/setup/test_util.h"
24 #include "remoting/protocol/pairing_registry.h" 25 #include "remoting/protocol/pairing_registry.h"
25 #include "remoting/protocol/protocol_mock_objects.h" 26 #include "remoting/protocol/protocol_mock_objects.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 using remoting::protocol::MockPairingRegistryDelegate; 29 using remoting::protocol::MockPairingRegistryDelegate;
29 using remoting::protocol::PairingRegistry; 30 using remoting::protocol::PairingRegistry;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 377 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
377 EXPECT_FALSE(response); 378 EXPECT_FALSE(response);
378 379
379 // The It2MeMe2MeNativeMessagingHost dtor closes the handles that are passed 380 // The It2MeMe2MeNativeMessagingHost dtor closes the handles that are passed
380 // to it. So the only handle left to close is |output_read_file_|. 381 // to it. So the only handle left to close is |output_read_file_|.
381 output_read_file_.Close(); 382 output_read_file_.Close();
382 } 383 }
383 384
384 scoped_ptr<base::DictionaryValue> 385 scoped_ptr<base::DictionaryValue>
385 Me2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() { 386 Me2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() {
386 uint32 length; 387 while (true) {
387 int read_result = output_read_file_.ReadAtCurrentPos( 388 uint32 length;
388 reinterpret_cast<char*>(&length), sizeof(length)); 389 int read_result = output_read_file_.ReadAtCurrentPos(
389 if (read_result != sizeof(length)) { 390 reinterpret_cast<char*>(&length), sizeof(length));
390 return nullptr; 391 if (read_result != sizeof(length)) {
392 return nullptr;
393 }
394
395 std::string message_json(length, '\0');
396 read_result = output_read_file_.ReadAtCurrentPos(
397 string_as_array(&message_json), length);
398 if (read_result != static_cast<int>(length)) {
399 return nullptr;
400 }
401
402 scoped_ptr<base::Value> message = base::JSONReader::Read(message_json);
403 if (!message || !message->IsType(base::Value::TYPE_DICTIONARY)) {
404 return nullptr;
405 }
406
407 scoped_ptr<base::DictionaryValue> result = make_scoped_ptr(
408 static_cast<base::DictionaryValue*>(message.release()));
409 std::string type;
410 if (!result->GetString("type", &type) ||
411 type != LogMessageHandler::debug_message_type_name) {
412 return result;
413 }
391 } 414 }
392
393 std::string message_json(length, '\0');
394 read_result = output_read_file_.ReadAtCurrentPos(
395 string_as_array(&message_json), length);
396 if (read_result != static_cast<int>(length)) {
397 return nullptr;
398 }
399
400 scoped_ptr<base::Value> message = base::JSONReader::Read(message_json);
401 if (!message || !message->IsType(base::Value::TYPE_DICTIONARY)) {
402 return nullptr;
403 }
404
405 return make_scoped_ptr(
406 static_cast<base::DictionaryValue*>(message.release()));
407 } 415 }
408 416
409 void Me2MeNativeMessagingHostTest::WriteMessageToInputPipe( 417 void Me2MeNativeMessagingHostTest::WriteMessageToInputPipe(
410 const base::Value& message) { 418 const base::Value& message) {
411 std::string message_json; 419 std::string message_json;
412 base::JSONWriter::Write(message, &message_json); 420 base::JSONWriter::Write(message, &message_json);
413 421
414 uint32 length = message_json.length(); 422 uint32 length = message_json.length();
415 input_write_file_.WriteAtCurrentPos(reinterpret_cast<char*>(&length), 423 input_write_file_.WriteAtCurrentPos(reinterpret_cast<char*>(&length),
416 sizeof(length)); 424 sizeof(length));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 617 }
610 618
611 // Verify rejection if getCredentialsFromAuthCode has no auth code. 619 // Verify rejection if getCredentialsFromAuthCode has no auth code.
612 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) { 620 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) {
613 base::DictionaryValue message; 621 base::DictionaryValue message;
614 message.SetString("type", "getCredentialsFromAuthCode"); 622 message.SetString("type", "getCredentialsFromAuthCode");
615 TestBadRequest(message); 623 TestBadRequest(message);
616 } 624 }
617 625
618 } // namespace remoting 626 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698