Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "remoting/test/app_remoting_connected_client_fixture.h" | 5 #include "remoting/test/app_remoting_connected_client_fixture.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | |
| 7 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "remoting/protocol/host_stub.h" | 14 #include "remoting/protocol/host_stub.h" |
| 14 #include "remoting/test/app_remoting_connection_helper.h" | 15 #include "remoting/test/app_remoting_connection_helper.h" |
| 15 #include "remoting/test/app_remoting_test_driver_environment.h" | 16 #include "remoting/test/app_remoting_test_driver_environment.h" |
| 16 #include "remoting/test/remote_application_details.h" | 17 #include "remoting/test/remote_application_details.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 40 AppRemotingSharedData->GetDetailsFromAppName(GetParam())), | 41 AppRemotingSharedData->GetDetailsFromAppName(GetParam())), |
| 41 timer_(new base::Timer(true, false)) { | 42 timer_(new base::Timer(true, false)) { |
| 42 } | 43 } |
| 43 | 44 |
| 44 AppRemotingConnectedClientFixture::~AppRemotingConnectedClientFixture() { | 45 AppRemotingConnectedClientFixture::~AppRemotingConnectedClientFixture() { |
| 45 } | 46 } |
| 46 | 47 |
| 47 void AppRemotingConnectedClientFixture::SetUp() { | 48 void AppRemotingConnectedClientFixture::SetUp() { |
| 48 connection_helper_.reset( | 49 connection_helper_.reset( |
| 49 new AppRemotingConnectionHelper(application_details_)); | 50 new AppRemotingConnectionHelper(application_details_)); |
| 50 connection_helper_->Initialize(make_scoped_ptr(new TestChromotingClient())); | 51 scoped_ptr<TestChromotingClient> test_chromoting_client( |
| 52 new TestChromotingClient()); | |
| 53 | |
| 54 test_chromoting_client->AddRemoteConnectionObserver(this); | |
| 55 | |
| 56 connection_helper_->Initialize(test_chromoting_client.Pass()); | |
| 51 if (!connection_helper_->StartConnection()) { | 57 if (!connection_helper_->StartConnection()) { |
| 52 LOG(ERROR) << "Remote host connection could not be established."; | 58 LOG(ERROR) << "Remote host connection could not be established."; |
| 53 FAIL(); | 59 FAIL(); |
| 54 } | 60 } |
| 55 } | 61 } |
| 56 | 62 |
| 57 void AppRemotingConnectedClientFixture::TearDown() { | 63 void AppRemotingConnectedClientFixture::TearDown() { |
| 64 connection_helper_->GetTestChromotingClient()->RemoveRemoteConnectionObserver( | |
| 65 this); | |
| 58 connection_helper_.reset(); | 66 connection_helper_.reset(); |
| 59 } | 67 } |
| 60 | 68 |
| 69 void AppRemotingConnectedClientFixture::HostMessageReceived( | |
| 70 const protocol::ExtensionMessage& message) { | |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 72 | |
| 73 if (!host_message_received_callback_.is_null()) { | |
| 74 host_message_received_callback_.Run(message); | |
| 75 } | |
| 76 } | |
| 77 | |
| 61 bool AppRemotingConnectedClientFixture::VerifyResponseForSimpleHostMessage( | 78 bool AppRemotingConnectedClientFixture::VerifyResponseForSimpleHostMessage( |
| 62 const std::string& message_request_title, | 79 const std::string& message_request_title, |
| 63 const std::string& message_response_title, | 80 const std::string& message_response_title, |
| 64 const std::string& message_payload, | 81 const std::string& message_payload, |
| 65 const base::TimeDelta& max_wait_time) { | 82 const base::TimeDelta& max_wait_time) { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 | 84 |
| 68 bool message_received = false; | 85 bool message_received = false; |
| 69 | 86 |
| 70 DCHECK(!run_loop_ || !run_loop_->running()); | 87 DCHECK(!run_loop_ || !run_loop_->running()); |
| 71 run_loop_.reset(new base::RunLoop()); | 88 run_loop_.reset(new base::RunLoop()); |
| 72 | 89 |
| 73 HostMessageReceivedCallback host_message_received_callback_ = | 90 host_message_received_callback_ = |
| 74 base::Bind(&SimpleHostMessageHandler, message_response_title, | 91 base::Bind(&SimpleHostMessageHandler, message_response_title, |
| 75 message_payload, run_loop_->QuitClosure(), &message_received); | 92 message_payload, run_loop_->QuitClosure(), &message_received); |
| 76 connection_helper_->SetHostMessageReceivedCallback( | |
| 77 host_message_received_callback_); | |
| 78 | 93 |
| 79 protocol::ExtensionMessage message; | 94 protocol::ExtensionMessage message; |
| 80 message.set_type(message_request_title); | 95 message.set_type(message_request_title); |
| 81 message.set_data(message_payload); | 96 message.set_data(message_payload); |
| 82 connection_helper_->host_stub()->DeliverClientMessage(message); | 97 connection_helper_->host_stub()->DeliverClientMessage(message); |
| 83 | 98 |
| 84 DCHECK(!timer_->IsRunning()); | 99 DCHECK(!timer_->IsRunning()); |
| 85 timer_->Start(FROM_HERE, max_wait_time, run_loop_->QuitClosure()); | 100 timer_->Start(FROM_HERE, max_wait_time, run_loop_->QuitClosure()); |
| 86 | 101 |
| 87 run_loop_->Run(); | 102 run_loop_->Run(); |
| 88 timer_->Stop(); | 103 timer_->Stop(); |
|
joedow
2015/07/24 13:50:58
Do you want to reset host_message_received_callbac
liaoyuke
2015/07/25 01:43:49
Done.
| |
| 89 | 104 |
| 90 return message_received; | 105 return message_received; |
| 91 } | 106 } |
| 92 | 107 |
| 93 } // namespace test | 108 } // namespace test |
| 94 } // namespace remoting | 109 } // namespace remoting |
| OLD | NEW |