| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/screen_recorder.h" | 5 #include "remoting/host/screen_recorder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "remoting/base/base_mock_objects.h" | 10 #include "remoting/base/base_mock_objects.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 connection_ = new MockConnectionToClient( | 80 connection_ = new MockConnectionToClient( |
| 81 session_, &host_stub_, &event_executor_); | 81 session_, &host_stub_, &event_executor_); |
| 82 connection_->SetEventHandler(&handler_); | 82 connection_->SetEventHandler(&handler_); |
| 83 | 83 |
| 84 record_ = new ScreenRecorder( | 84 record_ = new ScreenRecorder( |
| 85 &message_loop_, &message_loop_, | 85 &message_loop_, &message_loop_, |
| 86 base::MessageLoopProxy::current(), | 86 base::MessageLoopProxy::current(), |
| 87 &capturer_, encoder_); | 87 &capturer_, encoder_); |
| 88 } | 88 } |
| 89 | 89 |
| 90 virtual void TearDown() OVERRIDE { |
| 91 record_ = NULL; |
| 92 connection_ = NULL; |
| 93 // Run message loop before destroying because protocol::Session is |
| 94 // destroyed asynchronously. |
| 95 message_loop_.RunAllPending(); |
| 96 } |
| 97 |
| 90 protected: | 98 protected: |
| 99 MessageLoop message_loop_; |
| 91 scoped_refptr<ScreenRecorder> record_; | 100 scoped_refptr<ScreenRecorder> record_; |
| 92 | 101 |
| 93 MockConnectionToClientEventHandler handler_; | 102 MockConnectionToClientEventHandler handler_; |
| 94 MockHostStub host_stub_; | 103 MockHostStub host_stub_; |
| 95 MockEventExecutor event_executor_; | 104 MockEventExecutor event_executor_; |
| 96 MockSession* session_; // Owned by |connection_|. | 105 MockSession* session_; // Owned by |connection_|. |
| 97 scoped_refptr<MockConnectionToClient> connection_; | 106 scoped_refptr<MockConnectionToClient> connection_; |
| 98 | 107 |
| 99 // The following mock objects are owned by ScreenRecorder. | 108 // The following mock objects are owned by ScreenRecorder. |
| 100 MockCapturer capturer_; | 109 MockCapturer capturer_; |
| 101 MockEncoder* encoder_; | 110 MockEncoder* encoder_; |
| 102 MessageLoop message_loop_; | 111 |
| 103 private: | 112 private: |
| 104 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); | 113 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); |
| 105 }; | 114 }; |
| 106 | 115 |
| 107 // This test mocks capturer, encoder and network layer to simulate one recording | 116 // This test mocks capturer, encoder and network layer to simulate one recording |
| 108 // cycle. When the first encoded packet is submitted to the network | 117 // cycle. When the first encoded packet is submitted to the network |
| 109 // ScreenRecorder is instructed to come to a complete stop. We expect the stop | 118 // ScreenRecorder is instructed to come to a complete stop. We expect the stop |
| 110 // sequence to be executed successfully. | 119 // sequence to be executed successfully. |
| 111 TEST_F(ScreenRecorderTest, StartAndStop) { | 120 TEST_F(ScreenRecorderTest, StartAndStop) { |
| 112 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); | 121 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 record_->Start(); | 161 record_->Start(); |
| 153 message_loop_.Run(); | 162 message_loop_.Run(); |
| 154 } | 163 } |
| 155 | 164 |
| 156 TEST_F(ScreenRecorderTest, StopWithoutStart) { | 165 TEST_F(ScreenRecorderTest, StopWithoutStart) { |
| 157 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); | 166 record_->Stop(base::Bind(&QuitMessageLoop, &message_loop_)); |
| 158 message_loop_.Run(); | 167 message_loop_.Run(); |
| 159 } | 168 } |
| 160 | 169 |
| 161 } // namespace remoting | 170 } // namespace remoting |
| OLD | NEW |