| Index: remoting/host/resizing_host_observer_unittest.cc
|
| diff --git a/remoting/host/resizing_host_observer_unittest.cc b/remoting/host/resizing_host_observer_unittest.cc
|
| index 4eb7fc64c3b817afccdea85a95cba31275aeee31..a8a0eef1e3b2a6a67dcdcd784588e60409e2a835 100644
|
| --- a/remoting/host/resizing_host_observer_unittest.cc
|
| +++ b/remoting/host/resizing_host_observer_unittest.cc
|
| @@ -13,63 +13,75 @@
|
| #include "remoting/host/resizing_host_observer.h"
|
| #include "remoting/host/screen_resolution.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| -#include "third_party/skia/include/core/SkSize.h"
|
| #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
|
|
|
| -std::ostream& operator<<(std::ostream& os, const SkISize& size) {
|
| - return os << size.width() << "x" << size.height();
|
| +namespace remoting {
|
| +
|
| +std::ostream& operator<<(std::ostream& os, const ScreenResolution& resolution) {
|
| + return os << resolution.dimensions().width() << "x"
|
| + << resolution.dimensions().height() << " @ "
|
| + << resolution.dpi().x() << "x" << resolution.dpi().y();
|
| +}
|
| +
|
| +bool operator==(const ScreenResolution& a, const ScreenResolution& b) {
|
| + return a.Equals(b);
|
| }
|
|
|
| const int kDefaultDPI = 96;
|
|
|
| -namespace remoting {
|
| +ScreenResolution MakeResolution(int width, int height) {
|
| + return ScreenResolution(webrtc::DesktopSize(width, height),
|
| + webrtc::DesktopVector(kDefaultDPI, kDefaultDPI));
|
| +}
|
|
|
| class FakeDesktopResizer : public DesktopResizer {
|
| public:
|
| - FakeDesktopResizer(const SkISize& initial_size, bool exact_size_supported,
|
| - const SkISize* supported_sizes, int num_supported_sizes)
|
| - : initial_size_(initial_size),
|
| - current_size_(initial_size),
|
| + FakeDesktopResizer(const ScreenResolution& initial_resolution,
|
| + bool exact_size_supported,
|
| + const ScreenResolution* supported_resolutions,
|
| + int num_supported_resolutions)
|
| + : initial_resolution_(initial_resolution),
|
| + current_resolution_(initial_resolution),
|
| exact_size_supported_(exact_size_supported),
|
| - set_size_call_count_(0) {
|
| - for (int i = 0; i < num_supported_sizes; ++i) {
|
| - supported_sizes_.push_back(supported_sizes[i]);
|
| + set_resolution_call_count_(0) {
|
| + for (int i = 0; i < num_supported_resolutions; ++i) {
|
| + supported_resolutions_.push_back(supported_resolutions[i]);
|
| }
|
| }
|
|
|
| virtual ~FakeDesktopResizer() {
|
| - EXPECT_EQ(initial_size_, GetCurrentSize());
|
| + EXPECT_EQ(initial_resolution_, GetCurrentResolution());
|
| }
|
|
|
| - int set_size_call_count() { return set_size_call_count_; }
|
| + int set_resolution_call_count() { return set_resolution_call_count_; }
|
|
|
| // remoting::DesktopResizer interface
|
| - virtual SkISize GetCurrentSize() OVERRIDE {
|
| - return current_size_;
|
| + virtual ScreenResolution GetCurrentResolution() OVERRIDE {
|
| + return current_resolution_;
|
| }
|
| - virtual std::list<SkISize> GetSupportedSizes(
|
| - const SkISize& preferred) OVERRIDE {
|
| - std::list<SkISize> result = supported_sizes_;
|
| + virtual std::list<ScreenResolution> GetSupportedResolutions(
|
| + const ScreenResolution& preferred) OVERRIDE {
|
| + std::list<ScreenResolution> result = supported_resolutions_;
|
| if (exact_size_supported_) {
|
| result.push_back(preferred);
|
| }
|
| return result;
|
| }
|
| - virtual void SetSize(const SkISize& size) OVERRIDE {
|
| - current_size_ = size;
|
| - ++set_size_call_count_;
|
| + virtual void SetResolution(const ScreenResolution& resolution) OVERRIDE {
|
| + current_resolution_ = resolution;
|
| + ++set_resolution_call_count_;
|
| }
|
| - virtual void RestoreSize(const SkISize& size) OVERRIDE {
|
| - current_size_ = size;
|
| + virtual void RestoreResolution(const ScreenResolution& resolution) OVERRIDE {
|
| + current_resolution_ = resolution;
|
| }
|
|
|
| private:
|
| - SkISize initial_size_;
|
| - SkISize current_size_;
|
| + ScreenResolution initial_resolution_;
|
| + ScreenResolution current_resolution_;
|
| bool exact_size_supported_;
|
| - std::list<SkISize> supported_sizes_;
|
| + std::list<ScreenResolution> supported_resolutions_;
|
|
|
| - int set_size_call_count_;
|
| + int set_resolution_call_count_;
|
| };
|
|
|
| class ResizingHostObserverTest : public testing::Test {
|
| @@ -97,19 +109,18 @@ class ResizingHostObserverTest : public testing::Test {
|
| base::Unretained(this)));
|
| }
|
|
|
| - SkISize GetBestSize(const SkISize& client_size) {
|
| - resizing_host_observer_->SetScreenResolution(ScreenResolution(
|
| - webrtc::DesktopSize(client_size.width(), client_size.height()),
|
| - webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)));
|
| - return desktop_resizer_->GetCurrentSize();
|
| + ScreenResolution GetBestResolution(const ScreenResolution& client_size) {
|
| + resizing_host_observer_->SetScreenResolution(client_size);
|
| + return desktop_resizer_->GetCurrentResolution();
|
| }
|
|
|
| - void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes,
|
| + void VerifySizes(const ScreenResolution* client_sizes,
|
| + const ScreenResolution* expected_sizes,
|
| int number_of_sizes) {
|
| for (int i = 0; i < number_of_sizes; ++i) {
|
| - SkISize best_size = GetBestSize(client_sizes[i]);
|
| + ScreenResolution best_size = GetBestResolution(client_sizes[i]);
|
| EXPECT_EQ(expected_sizes[i], best_size)
|
| - << "Input size = " << client_sizes[i];
|
| + << "Input resolution = " << client_sizes[i];
|
| }
|
| }
|
|
|
| @@ -127,40 +138,46 @@ class ResizingHostObserverTest : public testing::Test {
|
| // Check that the host is not resized if GetSupportedSizes returns an empty
|
| // list (even if GetCurrentSize is supported).
|
| TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) {
|
| - SkISize initial = { 640, 480 };
|
| + ScreenResolution initial = MakeResolution(640, 480);
|
| scoped_ptr<FakeDesktopResizer> desktop_resizer(
|
| new FakeDesktopResizer(initial, false, NULL, 0));
|
| SetDesktopResizer(desktop_resizer.Pass());
|
|
|
| - SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } };
|
| - SkISize expected_sizes[] = { initial, initial };
|
| + ScreenResolution client_sizes[] = { MakeResolution(200, 100),
|
| + MakeResolution(100, 200) };
|
| + ScreenResolution expected_sizes[] = { initial, initial };
|
| VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
|
| }
|
|
|
| // Check that if the implementation supports exact size matching, it is used.
|
| TEST_F(ResizingHostObserverTest, SelectExactSize) {
|
| scoped_ptr<FakeDesktopResizer> desktop_resizer(
|
| - new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0));
|
| + new FakeDesktopResizer(MakeResolution(640, 480), true, NULL, 0));
|
| SetDesktopResizer(desktop_resizer.Pass());
|
|
|
| - SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 },
|
| - { 480, 640 }, { 1280, 1024 } };
|
| + ScreenResolution client_sizes[] = { MakeResolution(200, 100),
|
| + MakeResolution(100, 200),
|
| + MakeResolution(640, 480),
|
| + MakeResolution(480, 640),
|
| + MakeResolution(1280, 1024) };
|
| VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
|
| }
|
|
|
| // Check that if the implementation supports a size that is no larger than
|
| // the requested size, then the largest such size is used.
|
| TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) {
|
| - SkISize supported_sizes[] = {
|
| - SkISize::Make(639, 479), SkISize::Make(640, 480) };
|
| + ScreenResolution supported_sizes[] = { MakeResolution(639, 479),
|
| + MakeResolution(640, 480) };
|
| scoped_ptr<FakeDesktopResizer> desktop_resizer(
|
| - new FakeDesktopResizer(SkISize::Make(640, 480), false,
|
| + new FakeDesktopResizer(MakeResolution(640, 480), false,
|
| supported_sizes, arraysize(supported_sizes)));
|
| SetDesktopResizer(desktop_resizer.Pass());
|
|
|
| - SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 },
|
| - { 999, 999 } };
|
| - SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1],
|
| + ScreenResolution client_sizes[] = { MakeResolution(639, 479),
|
| + MakeResolution(640, 480),
|
| + MakeResolution(641, 481),
|
| + MakeResolution(999, 999) };
|
| + ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1],
|
| supported_sizes[1], supported_sizes[1] };
|
| VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
|
| }
|
| @@ -168,14 +185,17 @@ TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) {
|
| // Check that if the implementation supports only sizes that are larger than
|
| // the requested size, then the one that requires the least down-scaling.
|
| TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) {
|
| - SkISize supported_sizes[] = { { 100, 100 }, { 200, 100 } };
|
| + ScreenResolution supported_sizes[] = { MakeResolution(100, 100),
|
| + MakeResolution(200, 100) };
|
| scoped_ptr<FakeDesktopResizer> desktop_resizer(
|
| - new FakeDesktopResizer(SkISize::Make(200, 100), false,
|
| + new FakeDesktopResizer(MakeResolution(200, 100), false,
|
| supported_sizes, arraysize(supported_sizes)));
|
| SetDesktopResizer(desktop_resizer.Pass());
|
|
|
| - SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } };
|
| - SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
|
| + ScreenResolution client_sizes[] = { MakeResolution(1, 1),
|
| + MakeResolution(99, 99),
|
| + MakeResolution(199, 99) };
|
| + ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0],
|
| supported_sizes[1] };
|
| VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
|
| }
|
| @@ -183,15 +203,19 @@ TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) {
|
| // Check that if the implementation supports two sizes that have the same
|
| // resultant scale factor, then the widest one is selected.
|
| TEST_F(ResizingHostObserverTest, SelectWidest) {
|
| - SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } };
|
| + ScreenResolution supported_sizes[] = { MakeResolution(640, 480),
|
| + MakeResolution(480, 640) };
|
| scoped_ptr<FakeDesktopResizer> desktop_resizer(
|
| - new FakeDesktopResizer(SkISize::Make(480, 640), false,
|
| + new FakeDesktopResizer(MakeResolution(480, 640), false,
|
| supported_sizes, arraysize(supported_sizes)));
|
| SetDesktopResizer(desktop_resizer.Pass());
|
|
|
| - SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 },
|
| - { 640, 640 }, { 1000, 1000 } };
|
| - SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
|
| + ScreenResolution client_sizes[] = { MakeResolution(100, 100),
|
| + MakeResolution(480, 480),
|
| + MakeResolution(500, 500),
|
| + MakeResolution(640, 640),
|
| + MakeResolution(1000, 1000) };
|
| + ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0],
|
| supported_sizes[0], supported_sizes[0],
|
| supported_sizes[0] };
|
| VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
|
| @@ -200,23 +224,28 @@ TEST_F(ResizingHostObserverTest, SelectWidest) {
|
| // Check that if the best match for the client size doesn't change, then we
|
| // don't call SetSize.
|
| TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) {
|
| - SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } };
|
| + ScreenResolution supported_sizes[] = { MakeResolution(640, 480),
|
| + MakeResolution(480, 640) };
|
| FakeDesktopResizer* desktop_resizer =
|
| - new FakeDesktopResizer(SkISize::Make(640, 480), false,
|
| + new FakeDesktopResizer(MakeResolution(640, 480), false,
|
| supported_sizes, arraysize(supported_sizes));
|
| SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer));
|
|
|
| - SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } };
|
| - SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } };
|
| + ScreenResolution client_sizes[] = { MakeResolution(640, 640),
|
| + MakeResolution(1024, 768),
|
| + MakeResolution(640, 480) };
|
| + ScreenResolution expected_sizes[] = { MakeResolution(640, 480),
|
| + MakeResolution(640, 480),
|
| + MakeResolution(640, 480) };
|
| VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
|
| - EXPECT_EQ(desktop_resizer->set_size_call_count(), 0);
|
| + EXPECT_EQ(desktop_resizer->set_resolution_call_count(), 0);
|
| }
|
|
|
| // Check that desktop resizes are rate-limited, and that if multiple resize
|
| // requests are received in the time-out period, the most recent is respected.
|
| TEST_F(ResizingHostObserverTest, RateLimited) {
|
| FakeDesktopResizer* desktop_resizer =
|
| - new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0);
|
| + new FakeDesktopResizer(MakeResolution(640, 480), true, NULL, 0);
|
| SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer));
|
| resizing_host_observer_->SetNowFunctionForTesting(
|
| base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this)));
|
| @@ -224,11 +253,14 @@ TEST_F(ResizingHostObserverTest, RateLimited) {
|
| base::MessageLoop message_loop;
|
| base::RunLoop run_loop;
|
|
|
| - EXPECT_EQ(GetBestSize(SkISize::Make(100, 100)), SkISize::Make(100, 100));
|
| + EXPECT_EQ(GetBestResolution(MakeResolution(100, 100)),
|
| + MakeResolution(100, 100));
|
| now_ += base::TimeDelta::FromMilliseconds(900);
|
| - EXPECT_EQ(GetBestSize(SkISize::Make(200, 200)), SkISize::Make(100, 100));
|
| + EXPECT_EQ(GetBestResolution(MakeResolution(200, 200)),
|
| + MakeResolution(100, 100));
|
| now_ += base::TimeDelta::FromMilliseconds(99);
|
| - EXPECT_EQ(GetBestSize(SkISize::Make(300, 300)), SkISize::Make(100, 100));
|
| + EXPECT_EQ(GetBestResolution(MakeResolution(300, 300)),
|
| + MakeResolution(100, 100));
|
| now_ += base::TimeDelta::FromMilliseconds(1);
|
|
|
| // Due to the kMinimumResizeIntervalMs constant in resizing_host_observer.cc,
|
| @@ -243,7 +275,7 @@ TEST_F(ResizingHostObserverTest, RateLimited) {
|
| run_loop.Run();
|
|
|
| // If the QuitClosure fired before the final resize, it's a test failure.
|
| - EXPECT_EQ(desktop_resizer_->GetCurrentSize(), SkISize::Make(300, 300));
|
| + EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300));
|
| }
|
|
|
| } // namespace remoting
|
|
|