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

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

Issue 12545026: ResizingHostObserver is created by the desktop environment together with other stubs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 <list> 5 #include <list>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "remoting/host/desktop_resizer.h" 9 #include "remoting/host/desktop_resizer.h"
10 #include "remoting/host/host_status_monitor_fake.h"
11 #include "remoting/host/resizing_host_observer.h" 10 #include "remoting/host/resizing_host_observer.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkSize.h" 12 #include "third_party/skia/include/core/SkSize.h"
14 13
15 std::ostream& operator<<(std::ostream& os, const SkISize& size) { 14 std::ostream& operator<<(std::ostream& os, const SkISize& size) {
16 return os << size.width() << "x" << size.height(); 15 return os << size.width() << "x" << size.height();
17 } 16 }
18 17
19 namespace remoting { 18 namespace remoting {
20 19
21 class FakeDesktopResizer : public DesktopResizer { 20 class FakeDesktopResizer : public DesktopResizer {
22 public: 21 public:
23 FakeDesktopResizer(const SkISize& initial_size, bool exact_size_supported, 22 FakeDesktopResizer(const SkISize& initial_size, bool exact_size_supported,
24 const SkISize* supported_sizes, int num_supported_sizes) 23 const SkISize* supported_sizes, int num_supported_sizes)
25 : initial_size_(initial_size), 24 : initial_size_(initial_size),
26 current_size_(initial_size), 25 current_size_(initial_size),
27 exact_size_supported_(exact_size_supported), 26 exact_size_supported_(exact_size_supported),
28 set_size_call_count_(0) { 27 set_size_call_count_(0) {
29 for (int i = 0; i < num_supported_sizes; ++i) { 28 for (int i = 0; i < num_supported_sizes; ++i) {
30 supported_sizes_.push_back(supported_sizes[i]); 29 supported_sizes_.push_back(supported_sizes[i]);
31 } 30 }
32 } 31 }
33 32
34 const SkISize& initial_size() { return initial_size_; } 33 ~FakeDesktopResizer() {
34 EXPECT_EQ(initial_size_, GetCurrentSize());
35 }
36
35 int set_size_call_count() { return set_size_call_count_; } 37 int set_size_call_count() { return set_size_call_count_; }
36 38
37 // remoting::DesktopResizer interface 39 // remoting::DesktopResizer interface
38 virtual SkISize GetCurrentSize() OVERRIDE { 40 virtual SkISize GetCurrentSize() OVERRIDE {
39 return current_size_; 41 return current_size_;
40 } 42 }
41 virtual std::list<SkISize> GetSupportedSizes( 43 virtual std::list<SkISize> GetSupportedSizes(
42 const SkISize& preferred) OVERRIDE { 44 const SkISize& preferred) OVERRIDE {
43 std::list<SkISize> result = supported_sizes_; 45 std::list<SkISize> result = supported_sizes_;
44 if (exact_size_supported_) { 46 if (exact_size_supported_) {
(...skipping 13 matching lines...) Expand all
58 SkISize initial_size_; 60 SkISize initial_size_;
59 SkISize current_size_; 61 SkISize current_size_;
60 bool exact_size_supported_; 62 bool exact_size_supported_;
61 std::list<SkISize> supported_sizes_; 63 std::list<SkISize> supported_sizes_;
62 64
63 int set_size_call_count_; 65 int set_size_call_count_;
64 }; 66 };
65 67
66 class ResizingHostObserverTest : public testing::Test { 68 class ResizingHostObserverTest : public testing::Test {
67 public: 69 public:
68 void SetDesktopResizer(FakeDesktopResizer* desktop_resizer) { 70 ResizingHostObserverTest() : desktop_resizer_(NULL) {
69 CHECK(!desktop_resizer_.get()) << "Call SetDeskopResizer once per test"; 71 }
72
73 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) {
74 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test";
75 desktop_resizer_ = desktop_resizer.get();
76
70 resizing_host_observer_.reset( 77 resizing_host_observer_.reset(
71 new ResizingHostObserver(desktop_resizer, 78 new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>()));
72 host_status_monitor_.AsWeakPtr()));
73 desktop_resizer_.reset(desktop_resizer);
74 resizing_host_observer_->OnClientAuthenticated("");
75 } 79 }
76 80
77 SkISize GetBestSize(const SkISize& client_size) { 81 SkISize GetBestSize(const SkISize& client_size) {
78 resizing_host_observer_->OnClientResolutionChanged( 82 resizing_host_observer_->OnClientResolutionChanged(SkIPoint(), client_size);
79 "", client_size, SkIPoint());
80 return desktop_resizer_->GetCurrentSize(); 83 return desktop_resizer_->GetCurrentSize();
81 } 84 }
82 85
83 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, 86 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes,
84 int number_of_sizes) { 87 int number_of_sizes) {
85 for (int i = 0; i < number_of_sizes; ++i) { 88 for (int i = 0; i < number_of_sizes; ++i) {
86 SkISize best_size = GetBestSize(client_sizes[i]); 89 SkISize best_size = GetBestSize(client_sizes[i]);
87 EXPECT_EQ(expected_sizes[i], best_size) 90 EXPECT_EQ(expected_sizes[i], best_size)
88 << "Input size = " << client_sizes[i]; 91 << "Input size = " << client_sizes[i];
89 } 92 }
90 } 93 }
91 94
92 void Reconnect() {
93 resizing_host_observer_->OnClientDisconnected("");
94 resizing_host_observer_->OnClientAuthenticated("");
95 }
96
97 // testing::Test interface
98 virtual void TearDown() OVERRIDE {
99 resizing_host_observer_->OnClientDisconnected("");
100 EXPECT_EQ(desktop_resizer_->initial_size(),
101 desktop_resizer_->GetCurrentSize());
102 }
103
104 private: 95 private:
105 scoped_ptr<ResizingHostObserver> resizing_host_observer_; 96 scoped_ptr<ResizingHostObserver> resizing_host_observer_;
106 scoped_ptr<FakeDesktopResizer> desktop_resizer_; 97 FakeDesktopResizer* desktop_resizer_;
107 HostStatusMonitorFake host_status_monitor_;
108 }; 98 };
109 99
110 // Check that the host is not resized if GetSupportedSizes returns an empty 100 // Check that the host is not resized if GetSupportedSizes returns an empty
111 // list (even if GetCurrentSize is supported). 101 // list (even if GetCurrentSize is supported).
112 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { 102 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) {
113 SkISize initial = { 640, 480 }; 103 SkISize initial = { 640, 480 };
114 SetDesktopResizer( 104 scoped_ptr<FakeDesktopResizer> desktop_resizer(
115 new FakeDesktopResizer(initial, false, NULL, 0)); 105 new FakeDesktopResizer(initial, false, NULL, 0));
106 SetDesktopResizer(desktop_resizer.Pass());
107
116 SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } }; 108 SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } };
117 SkISize expected_sizes[] = { initial, initial }; 109 SkISize expected_sizes[] = { initial, initial };
118 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 110 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
119 } 111 }
120 112
121 // Check that if the implementation supports exact size matching, it is used. 113 // Check that if the implementation supports exact size matching, it is used.
122 TEST_F(ResizingHostObserverTest, SelectExactSize) { 114 TEST_F(ResizingHostObserverTest, SelectExactSize) {
123 SetDesktopResizer( 115 scoped_ptr<FakeDesktopResizer> desktop_resizer(
124 new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0)); 116 new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0));
117 SetDesktopResizer(desktop_resizer.Pass());
118
125 SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 }, 119 SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 },
126 { 480, 640 }, { 1280, 1024 } }; 120 { 480, 640 }, { 1280, 1024 } };
127 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); 121 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
128 } 122 }
129 123
130 // Check that if the implementation supports a size that is no larger than 124 // Check that if the implementation supports a size that is no larger than
131 // the requested size, then the largest such size is used. 125 // the requested size, then the largest such size is used.
132 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { 126 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) {
133 SkISize supported_sizes[] = { 127 SkISize supported_sizes[] = {
134 SkISize::Make(639, 479), SkISize::Make(640, 480) }; 128 SkISize::Make(639, 479), SkISize::Make(640, 480) };
135 SetDesktopResizer( 129 scoped_ptr<FakeDesktopResizer> desktop_resizer(
136 new FakeDesktopResizer(SkISize::Make(640, 480), false, 130 new FakeDesktopResizer(SkISize::Make(640, 480), false,
137 supported_sizes, arraysize(supported_sizes))); 131 supported_sizes, arraysize(supported_sizes)));
132 SetDesktopResizer(desktop_resizer.Pass());
133
138 SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 }, 134 SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 },
139 { 999, 999 } }; 135 { 999, 999 } };
140 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1], 136 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1],
141 supported_sizes[1], supported_sizes[1] }; 137 supported_sizes[1], supported_sizes[1] };
142 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 138 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
143 } 139 }
144 140
145 // Check that if the implementation supports only sizes that are larger than 141 // Check that if the implementation supports only sizes that are larger than
146 // the requested size, then the one that requires the least down-scaling. 142 // the requested size, then the one that requires the least down-scaling.
147 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { 143 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) {
148 SkISize supported_sizes[] = { { 100, 100 }, { 200, 100 } }; 144 SkISize supported_sizes[] = { { 100, 100 }, { 200, 100 } };
149 SetDesktopResizer( 145 scoped_ptr<FakeDesktopResizer> desktop_resizer(
150 new FakeDesktopResizer(SkISize::Make(200, 100), false, 146 new FakeDesktopResizer(SkISize::Make(200, 100), false,
151 supported_sizes, arraysize(supported_sizes))); 147 supported_sizes, arraysize(supported_sizes)));
148 SetDesktopResizer(desktop_resizer.Pass());
149
152 SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } }; 150 SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } };
153 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], 151 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
154 supported_sizes[1] }; 152 supported_sizes[1] };
155 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 153 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
156 } 154 }
157 155
158 // Check that if the implementation supports two sizes that have the same 156 // Check that if the implementation supports two sizes that have the same
159 // resultant scale factor, then the widest one is selected. 157 // resultant scale factor, then the widest one is selected.
160 TEST_F(ResizingHostObserverTest, SelectWidest) { 158 TEST_F(ResizingHostObserverTest, SelectWidest) {
161 SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; 159 SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } };
162 SetDesktopResizer( 160 scoped_ptr<FakeDesktopResizer> desktop_resizer(
163 new FakeDesktopResizer(SkISize::Make(480, 640), false, 161 new FakeDesktopResizer(SkISize::Make(480, 640), false,
164 supported_sizes, arraysize(supported_sizes))); 162 supported_sizes, arraysize(supported_sizes)));
163 SetDesktopResizer(desktop_resizer.Pass());
164
165 SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 }, 165 SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 },
166 { 640, 640 }, { 1000, 1000 } }; 166 { 640, 640 }, { 1000, 1000 } };
167 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], 167 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
168 supported_sizes[0], supported_sizes[0], 168 supported_sizes[0], supported_sizes[0],
169 supported_sizes[0] }; 169 supported_sizes[0] };
170 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 170 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
171 } 171 }
172 172
173 // Check that if the best match for the client size doesn't change, then we 173 // Check that if the best match for the client size doesn't change, then we
174 // don't call SetSize. 174 // don't call SetSize.
175 TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { 175 TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) {
176 SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; 176 SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } };
177 FakeDesktopResizer* desktop_resizer = 177 FakeDesktopResizer* desktop_resizer =
178 new FakeDesktopResizer(SkISize::Make(640, 480), false, 178 new FakeDesktopResizer(SkISize::Make(640, 480), false,
179 supported_sizes, arraysize(supported_sizes)); 179 supported_sizes, arraysize(supported_sizes));
180 SetDesktopResizer(desktop_resizer); 180 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer));
181
181 SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; 182 SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } };
182 SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; 183 SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } };
183 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 184 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
184 EXPECT_EQ(desktop_resizer->set_size_call_count(), 0); 185 EXPECT_EQ(desktop_resizer->set_size_call_count(), 0);
185 } 186 }
186 187
187 } // namespace remoting 188 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698