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_ = test_chromoting_client->GetWeakPtr(); | |
55 test_chromoting_client_->AddRemoteConnectionObserver(this); | |
56 | |
57 connection_helper_->Initialize(test_chromoting_client.Pass()); | |
51 if (!connection_helper_->StartConnection()) { | 58 if (!connection_helper_->StartConnection()) { |
52 LOG(ERROR) << "Remote host connection could not be established."; | 59 LOG(ERROR) << "Remote host connection could not be established."; |
53 FAIL(); | 60 FAIL(); |
54 } | 61 } |
55 } | 62 } |
56 | 63 |
57 void AppRemotingConnectedClientFixture::TearDown() { | 64 void AppRemotingConnectedClientFixture::TearDown() { |
65 test_chromoting_client_->RemoveRemoteConnectionObserver(this); | |
Sergey Ulanov
2015/07/23 19:36:55
Before dereferencing a weak pointer you need to ch
liaoyuke
2015/07/24 02:07:28
Done.
| |
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 base::ResetAndReturn(&host_message_received_callback_).Run(message); | |
Sergey Ulanov
2015/07/23 19:36:55
Do we need to reset the callback? Will we ever nee
Sergey Ulanov
2015/07/23 19:36:55
Do you need to very type of the message, in case i
joedow
2015/07/23 20:26:56
To add on to Sergey's comments, you could get seve
liaoyuke
2015/07/24 02:07:28
Done.
liaoyuke
2015/07/24 02:07:28
Acknowledged.
liaoyuke
2015/07/24 02:07:28
Acknowledged.
| |
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(); |
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 |