OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/task.h" | 6 #include "base/task.h" |
7 #include "remoting/base/mock_objects.h" | 7 #include "remoting/base/mock_objects.h" |
8 #include "remoting/host/mock_objects.h" | 8 #include "remoting/host/mock_objects.h" |
9 #include "remoting/host/session_manager.h" | 9 #include "remoting/host/session_manager.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 MessageLoop message_loop_; | 46 MessageLoop message_loop_; |
47 private: | 47 private: |
48 DISALLOW_COPY_AND_ASSIGN(SessionManagerTest); | 48 DISALLOW_COPY_AND_ASSIGN(SessionManagerTest); |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(SessionManagerTest, Init) { | 51 TEST_F(SessionManagerTest, Init) { |
52 Init(); | 52 Init(); |
53 } | 53 } |
54 | 54 |
55 ACTION_P2(RunCallback, rects, data) { | 55 ACTION_P2(RunCallback, rects, data) { |
56 RectVector& dirty_rects = data->mutable_dirty_rects(); | 56 InvalidRects& dirty_rects = data->mutable_dirty_rects(); |
57 dirty_rects.insert(dirty_rects.end(), rects.begin(), rects.end()); | 57 InvalidRects temp_rects; |
| 58 std::set_union(dirty_rects.begin(), dirty_rects.end(), |
| 59 rects.begin(), rects.end(), |
| 60 std::inserter(temp_rects, temp_rects.begin())); |
| 61 dirty_rects.swap(temp_rects); |
58 arg0->Run(data); | 62 arg0->Run(data); |
59 delete arg0; | 63 delete arg0; |
60 } | 64 } |
61 | 65 |
62 ACTION_P(FinishEncode, msg) { | 66 ACTION_P(FinishEncode, msg) { |
63 Encoder::EncodingState state = (Encoder::EncodingStarting | | 67 Encoder::EncodingState state = (Encoder::EncodingStarting | |
64 Encoder::EncodingInProgress | | 68 Encoder::EncodingInProgress | |
65 Encoder::EncodingEnded); | 69 Encoder::EncodingEnded); |
66 arg2->Run(msg, state); | 70 arg2->Run(msg, state); |
67 } | 71 } |
68 | 72 |
69 ACTION_P(AssignCaptureData, data) { | 73 ACTION_P(AssignCaptureData, data) { |
70 arg0[0] = data[0]; | 74 arg0[0] = data[0]; |
71 arg0[1] = data[1]; | 75 arg0[1] = data[1]; |
72 arg0[2] = data[2]; | 76 arg0[2] = data[2]; |
73 } | 77 } |
74 | 78 |
75 ACTION_P(AssignDirtyRect, rects) { | 79 ACTION_P(AssignDirtyRect, rects) { |
76 *arg0 = *rects; | 80 *arg0 = *rects; |
77 } | 81 } |
78 | 82 |
79 TEST_F(SessionManagerTest, OneRecordCycle) { | 83 TEST_F(SessionManagerTest, OneRecordCycle) { |
80 Init(); | 84 Init(); |
81 | 85 |
82 RectVector update_rects; | 86 InvalidRects update_rects; |
83 update_rects.push_back(gfx::Rect(0, 0, 10, 10)); | 87 update_rects.insert(gfx::Rect(0, 0, 10, 10)); |
84 DataPlanes planes; | 88 DataPlanes planes; |
85 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 89 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
86 planes.data[i] = reinterpret_cast<uint8*>(i); | 90 planes.data[i] = reinterpret_cast<uint8*>(i); |
87 planes.strides[i] = kWidth * 4; | 91 planes.strides[i] = kWidth * 4; |
88 } | 92 } |
89 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, | 93 scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth, |
90 kHeight, kFormat)); | 94 kHeight, kFormat)); |
91 // Set the recording rate to very low to avoid capture twice. | 95 // Set the recording rate to very low to avoid capture twice. |
92 record_->SetMaxRate(0.01); | 96 record_->SetMaxRate(0.01); |
93 | 97 |
94 // Add the mock client connection to the session. | 98 // Add the mock client connection to the session. |
95 EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth)); | 99 EXPECT_CALL(*capturer_, width()).WillRepeatedly(Return(kWidth)); |
96 EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight)); | 100 EXPECT_CALL(*capturer_, height()).WillRepeatedly(Return(kHeight)); |
97 EXPECT_CALL(*client_, SendInitClientMessage(kWidth, kHeight)); | 101 EXPECT_CALL(*client_, SendInitClientMessage(kWidth, kHeight)); |
98 record_->AddClient(client_); | 102 record_->AddClient(client_); |
99 | 103 |
100 // First the capturer is called. | 104 // First the capturer is called. |
101 EXPECT_CALL(*capturer_, InvalidateFullScreen()); | |
102 EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull())) | 105 EXPECT_CALL(*capturer_, CaptureInvalidRects(NotNull())) |
103 .WillOnce(RunCallback(update_rects, data)); | 106 .WillOnce(RunCallback(update_rects, data)); |
104 | 107 |
105 // Expect the encoder be called. | 108 // Expect the encoder be called. |
106 HostMessage* msg = new HostMessage(); | 109 HostMessage* msg = new HostMessage(); |
107 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) | 110 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) |
108 .WillOnce(FinishEncode(msg)); | 111 .WillOnce(FinishEncode(msg)); |
109 | 112 |
110 // Expect the client be notified. | 113 // Expect the client be notified. |
111 EXPECT_CALL(*client_, SendBeginUpdateStreamMessage()); | 114 EXPECT_CALL(*client_, SendBeginUpdateStreamMessage()); |
112 EXPECT_CALL(*client_, SendUpdateStreamPacketMessage(_)); | 115 EXPECT_CALL(*client_, SendUpdateStreamPacketMessage(_)); |
113 EXPECT_CALL(*client_, SendEndUpdateStreamMessage()); | 116 EXPECT_CALL(*client_, SendEndUpdateStreamMessage()); |
114 EXPECT_CALL(*client_, GetPendingUpdateStreamMessages()) | 117 EXPECT_CALL(*client_, GetPendingUpdateStreamMessages()) |
115 .Times(AtLeast(0)) | 118 .Times(AtLeast(0)) |
116 .WillRepeatedly(Return(0)); | 119 .WillRepeatedly(Return(0)); |
117 | 120 |
118 | |
119 // Start the recording. | 121 // Start the recording. |
120 record_->Start(); | 122 record_->Start(); |
121 | 123 |
122 // Make sure all tasks are completed. | 124 // Make sure all tasks are completed. |
123 message_loop_.RunAllPending(); | 125 message_loop_.RunAllPending(); |
124 } | 126 } |
125 | 127 |
126 // TODO(hclam): Add test for double buffering. | 128 // TODO(hclam): Add test for double buffering. |
127 // TODO(hclam): Add test for multiple captures. | 129 // TODO(hclam): Add test for multiple captures. |
128 // TODO(hclam): Add test for interruption. | 130 // TODO(hclam): Add test for interruption. |
129 | 131 |
130 } // namespace remoting | 132 } // namespace remoting |
OLD | NEW |