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

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

Issue 10918224: Cross-platform plumbing for resize-to-client (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed reviewer comments and trybot fixes. Created 8 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/host/resizing_host_observer.h"
6 #include "remoting/host/desktop_resizer.h"
7
8 #include <list>
9
10 #include "base/compiler_specific.h"
11 #include "base/logging.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkSize.h"
14
15 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
16 return os << size.width() << "x" << size.height();
17 }
18
19 namespace remoting {
20
21 class MockDesktopResizer : public DesktopResizer {
22 public:
23 MockDesktopResizer(const SkISize& initial_size, bool exact_size_supported,
24 const SkISize* supported_sizes, int num_supported_sizes)
25 : initial_size_(initial_size),
26 current_size_(initial_size),
27 exact_size_supported_(exact_size_supported) {
28 for (int i = 0; i < num_supported_sizes; ++i) {
29 supported_sizes_.push_back(supported_sizes[i]);
30 }
31 }
32
33 const SkISize& initial_size() { return initial_size_; }
34
35 // remoting::DesktopResizer interface
36 virtual SkISize GetCurrentSize() OVERRIDE {
37 return current_size_;
38 }
39 virtual std::list<SkISize> GetSupportedSizes(
40 const SkISize& preferred) OVERRIDE {
41 std::list<SkISize> result = supported_sizes_;
42 if (exact_size_supported_) {
43 result.push_back(preferred);
44 }
45 return result;
46 }
47 virtual void SetSize(const SkISize& size) OVERRIDE {
48 current_size_ = size;
49 }
50
51 private:
52 SkISize initial_size_;
53 SkISize current_size_;
54 bool exact_size_supported_;
55 std::list<SkISize> supported_sizes_;
56 };
57
58 class ResizingHostObserverTest : public testing::Test {
59 public:
60 void SetDesktopResizer(MockDesktopResizer* desktop_resizer) {
61 CHECK(!desktop_resizer_.get()) << "Call SetDeskopResizer once per test";
62 resizing_host_observer_.reset(new ResizingHostObserver(desktop_resizer));
63 desktop_resizer_.reset(desktop_resizer);
64 resizing_host_observer_->OnClientAuthenticated("");
65 }
66
67 SkISize GetBestSize(const SkISize& client_size) {
68 resizing_host_observer_->OnClientDimensionsChanged("", client_size);
69 return desktop_resizer_->GetCurrentSize();
70 }
71
72 void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes,
73 int number_of_sizes) {
74 for (int i = 0; i < number_of_sizes; ++i) {
75 SkISize best_size = GetBestSize(client_sizes[i]);
76 EXPECT_EQ(expected_sizes[i], best_size)
77 << "Input size = " << client_sizes[i];
78 }
79 }
80
81 // testing::Test interface
82 virtual void TearDown() OVERRIDE {
83 resizing_host_observer_->OnClientDisconnected("");
84 EXPECT_EQ(desktop_resizer_->initial_size(),
85 desktop_resizer_->GetCurrentSize());
86 }
87
88 private:
89 scoped_ptr<ResizingHostObserver> resizing_host_observer_;
90 scoped_ptr<MockDesktopResizer> desktop_resizer_;
91 };
92
93 // 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
94 TEST_F(ResizingHostObserverTest, SelectExactSize) {
95 SetDesktopResizer(
96 new MockDesktopResizer(SkISize::Make(640, 480), true, NULL, 0));
97 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!
98 SkISize::Make(640, 480), SkISize::Make(480, 640),
99 SkISize::Make(1280, 1024) };
100 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
101 }
102
103 // 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"
104 // the requested size, then the largest such size is used.
105 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) {
106 SkISize supported_sizes[] = {
107 SkISize::Make(639, 479), SkISize::Make(640, 480) };
108 SetDesktopResizer(
109 new MockDesktopResizer(SkISize::Make(640, 480), false,
110 supported_sizes, arraysize(supported_sizes)));
111 SkISize client_sizes[] = { SkISize::Make(639, 479), SkISize::Make(640, 480),
112 SkISize::Make(641, 481), SkISize::Make(999, 999) };
113 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1],
114 supported_sizes[1], supported_sizes[1] };
115 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
116 }
117
118 // Check that if the implementation supports only sizes that are larger than
119 // 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.
120 // is used.
121 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) {
122 SkISize supported_sizes[] = {
123 SkISize::Make(100, 100), SkISize::Make(200, 100) };
124 SetDesktopResizer(
125 new MockDesktopResizer(SkISize::Make(200, 100), false,
126 supported_sizes, arraysize(supported_sizes)));
127 SkISize client_sizes[] = { SkISize::Make(1, 1), SkISize::Make(99, 99),
128 SkISize::Make(199, 99) };
129 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
130 supported_sizes[1] };
131 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
132 }
133
134 // Check that if the implementation supports two sizes that have the same
135 // resultant scale factor, then the widest one is selected.
136 TEST_F(ResizingHostObserverTest, SelectWidest) {
137 SkISize supported_sizes[] = {
138 SkISize::Make(640, 480), SkISize::Make(480, 640) };
139 SetDesktopResizer(
140 new MockDesktopResizer(SkISize::Make(480, 640), false,
141 supported_sizes, arraysize(supported_sizes)));
142 SkISize client_sizes[] = { SkISize::Make(100, 100), SkISize::Make(480, 480),
143 SkISize::Make(500, 500), SkISize::Make(640, 640),
144 SkISize::Make(1000, 1000) };
145 SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0],
146 supported_sizes[0], supported_sizes[0],
147 supported_sizes[0] };
148 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
149 }
150
151 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698