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

Side by Side Diff: remoting/host/session_manager_unittest.cc

Issue 2690003: Copy the (early prototype of) remoting in Chrome into the public tree.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/session_manager.cc ('k') | remoting/host/simple_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/message_loop.h"
6 #include "base/task.h"
7 #include "remoting/host/mock_objects.h"
8 #include "remoting/host/session_manager.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using ::testing::_;
13 using ::testing::AtLeast;
14 using ::testing::NotNull;
15 using ::testing::Return;
16
17 namespace remoting {
18
19 static const int kWidth = 640;
20 static const int kHeight = 480;
21 static int kStride[3] = {
22 kWidth * 4,
23 kWidth * 4,
24 kWidth * 4,
25 };
26 static uint8* kData[3] = {
27 reinterpret_cast<uint8*>(0x01),
28 reinterpret_cast<uint8*>(0x02),
29 reinterpret_cast<uint8*>(0x03),
30 };
31 static const chromotocol_pb::PixelFormat kFormat =
32 chromotocol_pb::PixelFormatRgb32;
33
34 class SessionManagerTest : public testing::Test {
35 public:
36 SessionManagerTest() {
37 }
38
39 protected:
40 void Init() {
41 capturer_ = new MockCapturer();
42 encoder_ = new MockEncoder();
43 client_ = new MockClientConnection();
44 record_ = new SessionManager(&message_loop_,
45 &message_loop_,
46 &message_loop_,
47 capturer_,
48 encoder_);
49 }
50
51 scoped_refptr<SessionManager> record_;
52 scoped_refptr<MockClientConnection> client_;
53 MockCapturer* capturer_;
54 MockEncoder* encoder_;
55 MessageLoop message_loop_;
56
57 private:
58 DISALLOW_COPY_AND_ASSIGN(SessionManagerTest);
59 };
60
61 TEST_F(SessionManagerTest, Init) {
62 Init();
63 }
64
65 ACTION(RunSimpleTask) {
66 arg0->Run();
67 delete arg0;
68 }
69
70 ACTION_P2(FinishDecode, header, data) {
71 *arg4 = header;
72 *arg5 = data;
73 *arg6 = true;
74 arg7->Run();
75 delete arg7;
76 }
77
78 ACTION_P(AssignCaptureData, data) {
79 arg0[0] = data[0];
80 arg0[1] = data[1];
81 arg0[2] = data[2];
82 }
83
84 TEST_F(SessionManagerTest, OneRecordCycle) {
85 Init();
86
87 // Set the recording rate to very low to avoid capture twice.
88 record_->SetMaxRate(0.01);
89
90 // Add the mock client connection to the session.
91 EXPECT_CALL(*capturer_, GetWidth()).WillRepeatedly(Return(kWidth));
92 EXPECT_CALL(*capturer_, GetHeight()).WillRepeatedly(Return(kHeight));
93 EXPECT_CALL(*client_, SendInitClientMessage(kWidth, kHeight));
94 record_->AddClient(client_);
95
96 // First the capturer is called.
97 EXPECT_CALL(*capturer_, CaptureDirtyRects(NotNull()))
98 .WillOnce(RunSimpleTask());
99 // TODO(hclam): Return DirtyRects for verification.
100 EXPECT_CALL(*capturer_, GetDirtyRects(NotNull()));
101 EXPECT_CALL(*capturer_, GetData(NotNull()))
102 .WillOnce(AssignCaptureData(kData));
103 EXPECT_CALL(*capturer_, GetDataStride(NotNull()))
104 .WillOnce(AssignCaptureData(kStride));
105 EXPECT_CALL(*capturer_, GetPixelFormat())
106 .WillOnce(Return(kFormat));
107
108 // Expect the encoder be called.
109 chromotocol_pb::UpdateStreamPacketHeader header;
110 scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(0);
111 EXPECT_CALL(*encoder_, SetSize(kWidth, kHeight));
112 EXPECT_CALL(*encoder_, SetPixelFormat(kFormat));
113 // TODO(hclam): Expect the content of the dirty rects.
114 EXPECT_CALL(*encoder_,
115 Encode(_, NotNull(), NotNull(), false, NotNull(),
116 NotNull(), NotNull(), NotNull()))
117 .WillOnce(FinishDecode(header, buffer));
118
119 // Expect the client be notified.
120 EXPECT_CALL(*client_, SendBeginUpdateStreamMessage());
121 EXPECT_CALL(*client_, SendUpdateStreamPacketMessage(NotNull(), buffer));
122 EXPECT_CALL(*client_, SendEndUpdateStreamMessage());
123 EXPECT_CALL(*client_, GetPendingUpdateStreamMessages())
124 .Times(AtLeast(0))
125 .WillRepeatedly(Return(0));
126
127
128 // Start the recording.
129 record_->Start();
130
131 // Make sure all tasks are completed.
132 message_loop_.RunAllPending();
133 }
134
135 // TODO(hclam): Add test for double buffering.
136 // TODO(hclam): Add test for multiple captures.
137 // TODO(hclam): Add test for interruption.
138
139 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/session_manager.cc ('k') | remoting/host/simple_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698