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

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

Issue 10918224: Cross-platform plumbing for resize-to-client (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments, plus disable resize-to-client if overridden by user. Created 8 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "remoting/host/resizing_host_observer.h"
6 #include "remoting/host/desktop_resizer.h"
7
8 #include <list>
9
10 #include "base/compiler_specific.h"
11 #include "base/logging.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkSize.h"
14
15 namespace {
16 std::ostream& operator<<(std::ostream& os, const SkISize& size) {
17 return os << size.width() << "x" << size.height();
18 }
19 } // namespace
20
21 namespace remoting {
22
23 class MockDesktopResizer : public DesktopResizer {
24 public:
25 MockDesktopResizer(const SkISize& initial_size, bool exact_size_supported,
26 const SkISize* supported_sizes, int num_supported_sizes)
27 : initial_size_(initial_size),
28 current_size_(initial_size),
29 exact_size_supported_(exact_size_supported) {
30 for (int i = 0; i < num_supported_sizes; ++i) {
31 supported_sizes_.push_back(supported_sizes[i]);
32 }
33 }
34
35 const SkISize& initial_size() { return initial_size_; }
36
37 // remoting::DesktopResizer interface
38 virtual SkISize GetCurrentSize() OVERRIDE {
39 return current_size_;
40 }
41 virtual std::list<SkISize> GetSupportedSizes(
42 const SkISize& preferred) OVERRIDE {
43 std::list<SkISize> result = supported_sizes_;
44 if (exact_size_supported_) {
45 result.push_back(preferred);
46 }
47 return result;
48 }
49 virtual void SetSize(const SkISize& size) OVERRIDE {
50 current_size_ = size;
51 }
52 virtual void RestoreSize(const SkISize& size) OVERRIDE {
53 current_size_ = size;
54 }
55
56 private:
57 SkISize initial_size_;
58 SkISize current_size_;
59 bool exact_size_supported_;
60 std::list<SkISize> supported_sizes_;
61 };
62
63 class ResizingHostObserverTest : public testing::Test {
64 public:
65 void SetDesktopResizer(MockDesktopResizer* desktop_resizer) {
66 CHECK(!desktop_resizer_.get()) << "Call SetDeskopResizer once per test";
67 resizing_host_observer_.reset(new ResizingHostObserver(desktop_resizer,
68 NULL));
69 desktop_resizer_.reset(desktop_resizer);
70 resizing_host_observer_->OnClientAuthenticated("");
71 }
72
73 SkISize GetBestSize(const SkISize& client_size) {
74 resizing_host_observer_->OnClientDimensionsChanged("", client_size);
75 return desktop_resizer_->GetCurrentSize();
76 }
77
78 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes,
79 int number_of_sizes) {
80 for (int i = 0; i < number_of_sizes; ++i) {
81 SkISize best_size = GetBestSize(client_sizes[i]);
82 EXPECT_EQ(expected_sizes[i], best_size)
83 << "Input size = " << client_sizes[i];
84 }
85 }
86
87 void Reconnect() {
88 resizing_host_observer_->OnClientDisconnected("");
89 resizing_host_observer_->OnClientAuthenticated("");
90 }
91
92 // testing::Test interface
93 virtual void TearDown() OVERRIDE {
94 resizing_host_observer_->OnClientDisconnected("");
95 EXPECT_EQ(desktop_resizer_->initial_size(),
96 desktop_resizer_->GetCurrentSize());
97 }
98
99 private:
100 scoped_ptr<ResizingHostObserver> resizing_host_observer_;
101 scoped_ptr<MockDesktopResizer> desktop_resizer_;
102 };
103
104 // Check that if the implementation supports exact size matching, it is used.
105 TEST_F(ResizingHostObserverTest, SelectExactSize) {
106 SetDesktopResizer(
107 new MockDesktopResizer(SkISize::Make(640, 480), true, NULL, 0));
108 SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 },
109 { 480, 640 }, { 1280, 1024 } };
110 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
111 }
112
113 // Check that if the implementation supports a size that is no larger than
114 // the requested size, then the largest such size is used.
115 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) {
116 SkISize supported_sizes[] = {
117 SkISize::Make(639, 479), SkISize::Make(640, 480) };
118 SetDesktopResizer(
119 new MockDesktopResizer(SkISize::Make(640, 480), false,
120 supported_sizes, arraysize(supported_sizes)));
121 SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 },
122 { 999, 999 } };
123 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1],
124 supported_sizes[1], supported_sizes[1] };
125 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
126 }
127
128 // Check that if the implementation supports only sizes that are larger than
129 // the requested size, then the one that requires the least down-scaling.
130 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) {
131 SkISize supported_sizes[] = {
132 SkISize::Make(100, 100), SkISize::Make(200, 100) };
133 SetDesktopResizer(
134 new MockDesktopResizer(SkISize::Make(200, 100), false,
135 supported_sizes, arraysize(supported_sizes)));
136 SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } };
137 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
138 supported_sizes[1] };
139 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
140 }
141
142 // Check that if the implementation supports two sizes that have the same
143 // resultant scale factor, then the widest one is selected.
144 TEST_F(ResizingHostObserverTest, SelectWidest) {
145 SkISize supported_sizes[] = {
146 SkISize::Make(640, 480), SkISize::Make(480, 640) };
147 SetDesktopResizer(
148 new MockDesktopResizer(SkISize::Make(480, 640), false,
149 supported_sizes, arraysize(supported_sizes)));
150 SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 },
151 { 640, 640 }, { 1000, 1000 } };
152 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
153 supported_sizes[0], supported_sizes[0],
154 supported_sizes[0] };
155 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
156 }
157
158 // Check that resize-to-client is disabled if the size is changed explicitly.
159 TEST_F(ResizingHostObserverTest, ManualResize) {
160 MockDesktopResizer* desktop_resizer =
161 new MockDesktopResizer(SkISize::Make(640, 480), true, NULL, 0);
162 SetDesktopResizer(desktop_resizer);
163 SkISize client_sizes[] = { { 1, 1 }, { 2, 2 } , { 3, 3 } };
164 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
165 SkISize explicit_size = SkISize::Make(640, 480);
166 desktop_resizer->SetSize(explicit_size);
167 SkISize expected_sizes[] = { explicit_size, explicit_size, explicit_size };
168 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
169 // Make sure this behaviour doesn't persist across reconnect.
170 Reconnect();
171 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
172 }
173
174 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698