Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5ce66bc175db89a8777d0d25685c7411fa06193c |
| --- /dev/null |
| +++ b/remoting/host/resizing_host_observer_unittest.cc |
| @@ -0,0 +1,151 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/resizing_host_observer.h" |
| +#include "remoting/host/desktop_resizer.h" |
| + |
| +#include <list> |
| + |
| +#include "base/compiler_specific.h" |
| +#include "base/logging.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkSize.h" |
| + |
| +std::ostream& operator<<(std::ostream& os, const SkISize& size) { |
|
Wez
2012/09/20 21:35:15
nit: Wrap this in an anonymous namespace.
Jamie
2012/09/20 22:59:59
Done.
Jamie
2012/09/25 19:50:24
Undone. It seems that gtest can't see the definiti
|
| + return os << size.width() << "x" << size.height(); |
| +} |
| + |
| +namespace remoting { |
| + |
| +class MockDesktopResizer : public DesktopResizer { |
| + public: |
| + MockDesktopResizer(const SkISize& initial_size, bool exact_size_supported, |
| + const SkISize* supported_sizes, int num_supported_sizes) |
| + : initial_size_(initial_size), |
| + current_size_(initial_size), |
| + exact_size_supported_(exact_size_supported) { |
| + for (int i = 0; i < num_supported_sizes; ++i) { |
| + supported_sizes_.push_back(supported_sizes[i]); |
| + } |
| + } |
| + |
| + const SkISize& initial_size() { return initial_size_; } |
| + |
| + // remoting::DesktopResizer interface |
| + virtual SkISize GetCurrentSize() OVERRIDE { |
| + return current_size_; |
| + } |
| + virtual std::list<SkISize> GetSupportedSizes( |
| + const SkISize& preferred) OVERRIDE { |
| + std::list<SkISize> result = supported_sizes_; |
| + if (exact_size_supported_) { |
| + result.push_back(preferred); |
| + } |
| + return result; |
| + } |
| + virtual void SetSize(const SkISize& size) OVERRIDE { |
| + current_size_ = size; |
| + } |
| + |
| + private: |
| + SkISize initial_size_; |
| + SkISize current_size_; |
| + bool exact_size_supported_; |
| + std::list<SkISize> supported_sizes_; |
| +}; |
| + |
| +class ResizingHostObserverTest : public testing::Test { |
| + public: |
| + void SetDesktopResizer(MockDesktopResizer* desktop_resizer) { |
| + CHECK(!desktop_resizer_.get()) << "Call SetDeskopResizer once per test"; |
| + resizing_host_observer_.reset(new ResizingHostObserver(desktop_resizer)); |
| + desktop_resizer_.reset(desktop_resizer); |
| + resizing_host_observer_->OnClientAuthenticated(""); |
| + } |
| + |
| + SkISize GetBestSize(const SkISize& client_size) { |
| + resizing_host_observer_->OnClientDimensionsChanged("", client_size); |
| + return desktop_resizer_->GetCurrentSize(); |
| + } |
| + |
| + void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, |
| + int number_of_sizes) { |
| + for (int i = 0; i < number_of_sizes; ++i) { |
| + SkISize best_size = GetBestSize(client_sizes[i]); |
| + EXPECT_EQ(expected_sizes[i], best_size) |
| + << "Input size = " << client_sizes[i]; |
| + } |
| + } |
| + |
| + // testing::Test interface |
| + virtual void TearDown() OVERRIDE { |
| + resizing_host_observer_->OnClientDisconnected(""); |
| + EXPECT_EQ(desktop_resizer_->initial_size(), |
| + desktop_resizer_->GetCurrentSize()); |
| + } |
| + |
| + private: |
| + scoped_ptr<ResizingHostObserver> resizing_host_observer_; |
| + scoped_ptr<MockDesktopResizer> desktop_resizer_; |
| +}; |
| + |
| +// Check that if the implementation supports exact size matching, it is used. |
|
Wez
2012/09/20 21:35:15
nit: This test is no different from including all
Jamie
2012/09/20 22:59:59
It's different insofar as the same DesktopResizer
|
| +TEST_F(ResizingHostObserverTest, SelectExactSize) { |
| + SetDesktopResizer( |
| + new MockDesktopResizer(SkISize::Make(640, 480), true, NULL, 0)); |
| + SkISize client_sizes[] = { SkISize::Make(200, 100), SkISize::Make(100, 200), |
|
Wez
2012/09/20 21:35:15
nit: The members of SkISize are public, so I think
Jamie
2012/09/20 22:59:59
Sweet!
|
| + SkISize::Make(640, 480), SkISize::Make(480, 640), |
| + SkISize::Make(1280, 1024) }; |
| + VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); |
| +} |
| + |
| +// Check that if the implementation supports a size that is no larger than |
|
Wez
2012/09/20 21:35:15
nit: ... supports sizes smaller than ...
Jamie
2012/09/20 22:59:59
The distinction between "no larger" and "smaller"
|
| +// 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) }; |
| + SetDesktopResizer( |
| + new MockDesktopResizer(SkISize::Make(640, 480), false, |
| + supported_sizes, arraysize(supported_sizes))); |
| + SkISize client_sizes[] = { SkISize::Make(639, 479), SkISize::Make(640, 480), |
| + SkISize::Make(641, 481), SkISize::Make(999, 999) }; |
| + SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1], |
| + supported_sizes[1], supported_sizes[1] }; |
| + VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
| +} |
| + |
| +// Check that if the implementation supports only sizes that are larger than |
| +// the requested size, then the one that maximizes the resultant scale factor |
|
Wez
2012/09/20 21:35:15
nit: ... the one closest to the requested size is
Jamie
2012/09/20 22:59:59
Done.
|
| +// is used. |
| +TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { |
| + SkISize supported_sizes[] = { |
| + SkISize::Make(100, 100), SkISize::Make(200, 100) }; |
| + SetDesktopResizer( |
| + new MockDesktopResizer(SkISize::Make(200, 100), false, |
| + supported_sizes, arraysize(supported_sizes))); |
| + SkISize client_sizes[] = { SkISize::Make(1, 1), SkISize::Make(99, 99), |
| + SkISize::Make(199, 99) }; |
| + SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], |
| + supported_sizes[1] }; |
| + VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
| +} |
| + |
| +// 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[] = { |
| + SkISize::Make(640, 480), SkISize::Make(480, 640) }; |
| + SetDesktopResizer( |
| + new MockDesktopResizer(SkISize::Make(480, 640), false, |
| + supported_sizes, arraysize(supported_sizes))); |
| + SkISize client_sizes[] = { SkISize::Make(100, 100), SkISize::Make(480, 480), |
| + SkISize::Make(500, 500), SkISize::Make(640, 640), |
| + SkISize::Make(1000, 1000) }; |
| + SkISize 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)); |
| +} |
| + |
| +} // namespace remoting |