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

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

Issue 15927033: Add host-side rate-limiting to desktop resize events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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/resizing_host_observer.cc ('k') | remoting/webapp/client_plugin_async.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/ref_counted.h"
10 #include "base/message_loop.h"
11 #include "base/run_loop.h"
9 #include "remoting/host/desktop_resizer.h" 12 #include "remoting/host/desktop_resizer.h"
10 #include "remoting/host/resizing_host_observer.h" 13 #include "remoting/host/resizing_host_observer.h"
11 #include "remoting/host/screen_resolution.h" 14 #include "remoting/host/screen_resolution.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkSize.h" 16 #include "third_party/skia/include/core/SkSize.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 17 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
15 18
16 std::ostream& operator<<(std::ostream& os, const SkISize& size) { 19 std::ostream& operator<<(std::ostream& os, const SkISize& size) {
17 return os << size.width() << "x" << size.height(); 20 return os << size.width() << "x" << size.height();
18 } 21 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 SkISize initial_size_; 67 SkISize initial_size_;
65 SkISize current_size_; 68 SkISize current_size_;
66 bool exact_size_supported_; 69 bool exact_size_supported_;
67 std::list<SkISize> supported_sizes_; 70 std::list<SkISize> supported_sizes_;
68 71
69 int set_size_call_count_; 72 int set_size_call_count_;
70 }; 73 };
71 74
72 class ResizingHostObserverTest : public testing::Test { 75 class ResizingHostObserverTest : public testing::Test {
73 public: 76 public:
74 ResizingHostObserverTest() : desktop_resizer_(NULL) { 77 ResizingHostObserverTest()
78 : desktop_resizer_(NULL),
79 now_(base::Time::Now()) {
75 } 80 }
76 81
82 // This needs to be public because the derived test-case class needs to
83 // pass it to Bind, which fails if it's protected.
84 base::Time GetTime() {
85 return now_;
86 }
87
88 protected:
77 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { 89 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) {
78 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; 90 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test";
79 desktop_resizer_ = desktop_resizer.get(); 91 desktop_resizer_ = desktop_resizer.get();
80 92
81 resizing_host_observer_.reset( 93 resizing_host_observer_.reset(
82 new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>())); 94 new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>()));
95 resizing_host_observer_->SetNowFunctionForTesting(
96 base::Bind(&ResizingHostObserverTest::GetTimeAndIncrement,
97 base::Unretained(this)));
83 } 98 }
84 99
85 SkISize GetBestSize(const SkISize& client_size) { 100 SkISize GetBestSize(const SkISize& client_size) {
86 resizing_host_observer_->SetScreenResolution(ScreenResolution( 101 resizing_host_observer_->SetScreenResolution(ScreenResolution(
87 webrtc::DesktopSize(client_size.width(), client_size.height()), 102 webrtc::DesktopSize(client_size.width(), client_size.height()),
88 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI))); 103 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)));
89 return desktop_resizer_->GetCurrentSize(); 104 return desktop_resizer_->GetCurrentSize();
90 } 105 }
91 106
92 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, 107 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes,
93 int number_of_sizes) { 108 int number_of_sizes) {
94 for (int i = 0; i < number_of_sizes; ++i) { 109 for (int i = 0; i < number_of_sizes; ++i) {
95 SkISize best_size = GetBestSize(client_sizes[i]); 110 SkISize best_size = GetBestSize(client_sizes[i]);
96 EXPECT_EQ(expected_sizes[i], best_size) 111 EXPECT_EQ(expected_sizes[i], best_size)
97 << "Input size = " << client_sizes[i]; 112 << "Input size = " << client_sizes[i];
98 } 113 }
99 } 114 }
100 115
101 private: 116 base::Time GetTimeAndIncrement() {
117 base::Time result = now_;
118 now_ += base::TimeDelta::FromSeconds(1);
119 return result;
120 }
121
102 scoped_ptr<ResizingHostObserver> resizing_host_observer_; 122 scoped_ptr<ResizingHostObserver> resizing_host_observer_;
103 FakeDesktopResizer* desktop_resizer_; 123 FakeDesktopResizer* desktop_resizer_;
124 base::Time now_;
104 }; 125 };
105 126
106 // Check that the host is not resized if GetSupportedSizes returns an empty 127 // Check that the host is not resized if GetSupportedSizes returns an empty
107 // list (even if GetCurrentSize is supported). 128 // list (even if GetCurrentSize is supported).
108 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { 129 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) {
109 SkISize initial = { 640, 480 }; 130 SkISize initial = { 640, 480 };
110 scoped_ptr<FakeDesktopResizer> desktop_resizer( 131 scoped_ptr<FakeDesktopResizer> desktop_resizer(
111 new FakeDesktopResizer(initial, false, NULL, 0)); 132 new FakeDesktopResizer(initial, false, NULL, 0));
112 SetDesktopResizer(desktop_resizer.Pass()); 133 SetDesktopResizer(desktop_resizer.Pass());
113 134
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 new FakeDesktopResizer(SkISize::Make(640, 480), false, 205 new FakeDesktopResizer(SkISize::Make(640, 480), false,
185 supported_sizes, arraysize(supported_sizes)); 206 supported_sizes, arraysize(supported_sizes));
186 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); 207 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer));
187 208
188 SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; 209 SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } };
189 SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; 210 SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } };
190 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 211 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
191 EXPECT_EQ(desktop_resizer->set_size_call_count(), 0); 212 EXPECT_EQ(desktop_resizer->set_size_call_count(), 0);
192 } 213 }
193 214
215 // Check that desktop resizes are rate-limited, and that if multiple resize
216 // requests are received in the time-out period, the most recent is respected.
217 TEST_F(ResizingHostObserverTest, RateLimited) {
218 FakeDesktopResizer* desktop_resizer =
219 new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0);
220 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer));
221 resizing_host_observer_->SetNowFunctionForTesting(
222 base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this)));
223
224 base::MessageLoop message_loop;
225 base::RunLoop run_loop;
226
227 EXPECT_EQ(GetBestSize(SkISize::Make(100, 100)), SkISize::Make(100, 100));
228 now_ += base::TimeDelta::FromMilliseconds(900);
229 EXPECT_EQ(GetBestSize(SkISize::Make(200, 200)), SkISize::Make(100, 100));
230 now_ += base::TimeDelta::FromMilliseconds(99);
231 EXPECT_EQ(GetBestSize(SkISize::Make(300, 300)), SkISize::Make(100, 100));
232 now_ += base::TimeDelta::FromMilliseconds(1);
233
234 // Due to the kMinimumResizeIntervalMs constant in resizing_host_observer.cc,
235 // We need to wait a total of 1000ms for the final resize to be processed.
236 // Since it was queued 900 + 99 ms after the first, we need to wait an
237 // additional 1ms. However, since RunLoop is not guaranteed to process tasks
238 // with the same due time in FIFO order, wait an additional 1ms for safety.
239 message_loop.PostDelayedTask(
240 FROM_HERE,
241 run_loop.QuitClosure(),
242 base::TimeDelta::FromMilliseconds(2));
243 run_loop.Run();
244
245 // If the QuitClosure fired before the final resize, it's a test failure.
246 EXPECT_EQ(desktop_resizer_->GetCurrentSize(), SkISize::Make(300, 300));
247 }
248
194 } // namespace remoting 249 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/resizing_host_observer.cc ('k') | remoting/webapp/client_plugin_async.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698