OLD | NEW |
---|---|
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/message_loop.h" | |
10 #include "base/run_loop.h" | |
9 #include "remoting/host/desktop_resizer.h" | 11 #include "remoting/host/desktop_resizer.h" |
10 #include "remoting/host/resizing_host_observer.h" | 12 #include "remoting/host/resizing_host_observer.h" |
11 #include "remoting/host/screen_resolution.h" | 13 #include "remoting/host/screen_resolution.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/skia/include/core/SkSize.h" | 15 #include "third_party/skia/include/core/SkSize.h" |
14 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
15 | 17 |
16 std::ostream& operator<<(std::ostream& os, const SkISize& size) { | 18 std::ostream& operator<<(std::ostream& os, const SkISize& size) { |
17 return os << size.width() << "x" << size.height(); | 19 return os << size.width() << "x" << size.height(); |
18 } | 20 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 public: | 75 public: |
74 ResizingHostObserverTest() : desktop_resizer_(NULL) { | 76 ResizingHostObserverTest() : desktop_resizer_(NULL) { |
75 } | 77 } |
76 | 78 |
77 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { | 79 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { |
78 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; | 80 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; |
79 desktop_resizer_ = desktop_resizer.get(); | 81 desktop_resizer_ = desktop_resizer.get(); |
80 | 82 |
81 resizing_host_observer_.reset( | 83 resizing_host_observer_.reset( |
82 new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>())); | 84 new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>())); |
85 resizing_host_observer_->SetMinimumResizeIntervalForTesting( | |
86 base::TimeDelta::FromMilliseconds(0)); | |
83 } | 87 } |
84 | 88 |
85 SkISize GetBestSize(const SkISize& client_size) { | 89 SkISize GetBestSize(const SkISize& client_size) { |
86 resizing_host_observer_->SetScreenResolution(ScreenResolution( | 90 resizing_host_observer_->SetScreenResolution(ScreenResolution( |
87 webrtc::DesktopSize(client_size.width(), client_size.height()), | 91 webrtc::DesktopSize(client_size.width(), client_size.height()), |
88 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI))); | 92 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI))); |
89 return desktop_resizer_->GetCurrentSize(); | 93 return desktop_resizer_->GetCurrentSize(); |
90 } | 94 } |
91 | 95 |
92 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, | 96 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, |
93 int number_of_sizes) { | 97 int number_of_sizes) { |
94 for (int i = 0; i < number_of_sizes; ++i) { | 98 for (int i = 0; i < number_of_sizes; ++i) { |
95 SkISize best_size = GetBestSize(client_sizes[i]); | 99 SkISize best_size = GetBestSize(client_sizes[i]); |
96 EXPECT_EQ(expected_sizes[i], best_size) | 100 EXPECT_EQ(expected_sizes[i], best_size) |
97 << "Input size = " << client_sizes[i]; | 101 << "Input size = " << client_sizes[i]; |
98 } | 102 } |
99 } | 103 } |
100 | 104 |
101 private: | 105 protected: |
102 scoped_ptr<ResizingHostObserver> resizing_host_observer_; | 106 scoped_ptr<ResizingHostObserver> resizing_host_observer_; |
103 FakeDesktopResizer* desktop_resizer_; | 107 FakeDesktopResizer* desktop_resizer_; |
104 }; | 108 }; |
105 | 109 |
106 // Check that the host is not resized if GetSupportedSizes returns an empty | 110 // Check that the host is not resized if GetSupportedSizes returns an empty |
107 // list (even if GetCurrentSize is supported). | 111 // list (even if GetCurrentSize is supported). |
108 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { | 112 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { |
109 SkISize initial = { 640, 480 }; | 113 SkISize initial = { 640, 480 }; |
110 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 114 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
111 new FakeDesktopResizer(initial, false, NULL, 0)); | 115 new FakeDesktopResizer(initial, false, NULL, 0)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 new FakeDesktopResizer(SkISize::Make(640, 480), false, | 188 new FakeDesktopResizer(SkISize::Make(640, 480), false, |
185 supported_sizes, arraysize(supported_sizes)); | 189 supported_sizes, arraysize(supported_sizes)); |
186 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); | 190 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); |
187 | 191 |
188 SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; | 192 SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; |
189 SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; | 193 SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; |
190 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 194 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
191 EXPECT_EQ(desktop_resizer->set_size_call_count(), 0); | 195 EXPECT_EQ(desktop_resizer->set_size_call_count(), 0); |
192 } | 196 } |
193 | 197 |
198 // Check that desktop resizes are rate-limited, and that if multiple resize | |
199 // requests are received in the time-out period, the most recent is respected. | |
200 TEST_F(ResizingHostObserverTest, RateLimited) { | |
201 int interval_ms = 10; | |
alexeypa (please no reviews)
2013/06/06 21:45:11
1ms should be good enough. All we need is to cause
Jamie
2013/06/06 22:08:04
There is a small chance that it might take > 1ms b
alexeypa (please no reviews)
2013/06/07 16:23:10
Oh, I see. So the first SetScreenResoultion() reco
| |
202 FakeDesktopResizer* desktop_resizer = | |
203 new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0); | |
204 SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); | |
205 resizing_host_observer_->SetMinimumResizeIntervalForTesting( | |
206 base::TimeDelta::FromMilliseconds(interval_ms)); | |
207 | |
208 base::MessageLoop message_loop; | |
209 base::RunLoop run_loop; | |
210 | |
211 EXPECT_EQ(GetBestSize(SkISize::Make(100, 100)), SkISize::Make(100, 100)); | |
alexeypa (please no reviews)
2013/06/06 21:45:11
If I read this correctly, it does not check whethe
Jamie
2013/06/06 22:08:04
That expectation is at the end of the test, after
| |
212 EXPECT_EQ(GetBestSize(SkISize::Make(200, 200)), SkISize::Make(100, 100)); | |
213 EXPECT_EQ(GetBestSize(SkISize::Make(300, 300)), SkISize::Make(100, 100)); | |
214 | |
215 message_loop.PostDelayedTask( | |
216 FROM_HERE, | |
217 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop)), | |
alexeypa (please no reviews)
2013/06/06 21:45:11
Use |run_loop.QuitClosure()| instead of base::Bind
Jamie
2013/06/06 22:08:04
Done.
| |
218 base::TimeDelta::FromMilliseconds(interval_ms + 1)); | |
219 run_loop.Run(); | |
220 | |
221 EXPECT_EQ(desktop_resizer_->GetCurrentSize(), SkISize::Make(300, 300)); | |
alexeypa (please no reviews)
2013/06/07 16:23:10
This expectation is flaky. Posting QuitClosure() b
| |
222 } | |
223 | |
194 } // namespace remoting | 224 } // namespace remoting |
OLD | NEW |