| 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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 base::Time GetTime() { | 101 base::Time GetTime() { |
| 102 return now_; | 102 return now_; |
| 103 } | 103 } |
| 104 | 104 |
| 105 protected: | 105 protected: |
| 106 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { | 106 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { |
| 107 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; | 107 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; |
| 108 desktop_resizer_ = desktop_resizer.get(); | 108 desktop_resizer_ = desktop_resizer.get(); |
| 109 | 109 |
| 110 resizing_host_observer_.reset( | 110 resizing_host_observer_.reset( |
| 111 new ResizingHostObserver(desktop_resizer.Pass())); | 111 new ResizingHostObserver(std::move(desktop_resizer))); |
| 112 resizing_host_observer_->SetNowFunctionForTesting( | 112 resizing_host_observer_->SetNowFunctionForTesting( |
| 113 base::Bind(&ResizingHostObserverTest::GetTimeAndIncrement, | 113 base::Bind(&ResizingHostObserverTest::GetTimeAndIncrement, |
| 114 base::Unretained(this))); | 114 base::Unretained(this))); |
| 115 } | 115 } |
| 116 | 116 |
| 117 ScreenResolution GetBestResolution(const ScreenResolution& client_size) { | 117 ScreenResolution GetBestResolution(const ScreenResolution& client_size) { |
| 118 resizing_host_observer_->SetScreenResolution(client_size); | 118 resizing_host_observer_->SetScreenResolution(client_size); |
| 119 return desktop_resizer_->GetCurrentResolution(); | 119 return desktop_resizer_->GetCurrentResolution(); |
| 120 } | 120 } |
| 121 | 121 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 140 base::Time now_; | 140 base::Time now_; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 // Check that the resolution isn't restored if it wasn't changed by this class. | 143 // Check that the resolution isn't restored if it wasn't changed by this class. |
| 144 TEST_F(ResizingHostObserverTest, NoRestoreResolution) { | 144 TEST_F(ResizingHostObserverTest, NoRestoreResolution) { |
| 145 int restore_resolution_call_count = 0; | 145 int restore_resolution_call_count = 0; |
| 146 ScreenResolution initial = MakeResolution(640, 480); | 146 ScreenResolution initial = MakeResolution(640, 480); |
| 147 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 147 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
| 148 new FakeDesktopResizer(initial, false, nullptr, 0, | 148 new FakeDesktopResizer(initial, false, nullptr, 0, |
| 149 &restore_resolution_call_count)); | 149 &restore_resolution_call_count)); |
| 150 SetDesktopResizer(desktop_resizer.Pass()); | 150 SetDesktopResizer(std::move(desktop_resizer)); |
| 151 VerifySizes(nullptr, nullptr, 0); | 151 VerifySizes(nullptr, nullptr, 0); |
| 152 resizing_host_observer_.reset(); | 152 resizing_host_observer_.reset(); |
| 153 EXPECT_EQ(0, restore_resolution_call_count); | 153 EXPECT_EQ(0, restore_resolution_call_count); |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Check that the host is not resized if GetSupportedSizes returns an empty | 156 // Check that the host is not resized if GetSupportedSizes returns an empty |
| 157 // list (even if GetCurrentSize is supported). | 157 // list (even if GetCurrentSize is supported). |
| 158 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { | 158 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { |
| 159 int restore_resolution_call_count = 0; | 159 int restore_resolution_call_count = 0; |
| 160 ScreenResolution initial = MakeResolution(640, 480); | 160 ScreenResolution initial = MakeResolution(640, 480); |
| 161 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 161 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
| 162 new FakeDesktopResizer(initial, false, nullptr, 0, | 162 new FakeDesktopResizer(initial, false, nullptr, 0, |
| 163 &restore_resolution_call_count)); | 163 &restore_resolution_call_count)); |
| 164 SetDesktopResizer(desktop_resizer.Pass()); | 164 SetDesktopResizer(std::move(desktop_resizer)); |
| 165 | 165 |
| 166 ScreenResolution client_sizes[] = { MakeResolution(200, 100), | 166 ScreenResolution client_sizes[] = { MakeResolution(200, 100), |
| 167 MakeResolution(100, 200) }; | 167 MakeResolution(100, 200) }; |
| 168 ScreenResolution expected_sizes[] = { initial, initial }; | 168 ScreenResolution expected_sizes[] = { initial, initial }; |
| 169 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 169 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
| 170 | 170 |
| 171 resizing_host_observer_.reset(); | 171 resizing_host_observer_.reset(); |
| 172 EXPECT_EQ(0, restore_resolution_call_count); | 172 EXPECT_EQ(0, restore_resolution_call_count); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Check that if the implementation supports exact size matching, it is used. | 175 // Check that if the implementation supports exact size matching, it is used. |
| 176 TEST_F(ResizingHostObserverTest, SelectExactSize) { | 176 TEST_F(ResizingHostObserverTest, SelectExactSize) { |
| 177 int restore_resolution_call_count = 0; | 177 int restore_resolution_call_count = 0; |
| 178 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 178 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
| 179 new FakeDesktopResizer(MakeResolution(640, 480), true, nullptr, 0, | 179 new FakeDesktopResizer(MakeResolution(640, 480), true, nullptr, 0, |
| 180 &restore_resolution_call_count)); | 180 &restore_resolution_call_count)); |
| 181 SetDesktopResizer(desktop_resizer.Pass()); | 181 SetDesktopResizer(std::move(desktop_resizer)); |
| 182 | 182 |
| 183 ScreenResolution client_sizes[] = { MakeResolution(200, 100), | 183 ScreenResolution client_sizes[] = { MakeResolution(200, 100), |
| 184 MakeResolution(100, 200), | 184 MakeResolution(100, 200), |
| 185 MakeResolution(640, 480), | 185 MakeResolution(640, 480), |
| 186 MakeResolution(480, 640), | 186 MakeResolution(480, 640), |
| 187 MakeResolution(1280, 1024) }; | 187 MakeResolution(1280, 1024) }; |
| 188 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); | 188 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); |
| 189 resizing_host_observer_.reset(); | 189 resizing_host_observer_.reset(); |
| 190 EXPECT_EQ(1, restore_resolution_call_count); | 190 EXPECT_EQ(1, restore_resolution_call_count); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Check that if the implementation supports a size that is no larger than | 193 // Check that if the implementation supports a size that is no larger than |
| 194 // the requested size, then the largest such size is used. | 194 // the requested size, then the largest such size is used. |
| 195 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { | 195 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { |
| 196 ScreenResolution supported_sizes[] = { MakeResolution(639, 479), | 196 ScreenResolution supported_sizes[] = { MakeResolution(639, 479), |
| 197 MakeResolution(640, 480) }; | 197 MakeResolution(640, 480) }; |
| 198 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 198 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
| 199 new FakeDesktopResizer(MakeResolution(640, 480), false, | 199 new FakeDesktopResizer(MakeResolution(640, 480), false, |
| 200 supported_sizes, arraysize(supported_sizes), | 200 supported_sizes, arraysize(supported_sizes), |
| 201 nullptr)); | 201 nullptr)); |
| 202 SetDesktopResizer(desktop_resizer.Pass()); | 202 SetDesktopResizer(std::move(desktop_resizer)); |
| 203 | 203 |
| 204 ScreenResolution client_sizes[] = { MakeResolution(639, 479), | 204 ScreenResolution client_sizes[] = { MakeResolution(639, 479), |
| 205 MakeResolution(640, 480), | 205 MakeResolution(640, 480), |
| 206 MakeResolution(641, 481), | 206 MakeResolution(641, 481), |
| 207 MakeResolution(999, 999) }; | 207 MakeResolution(999, 999) }; |
| 208 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1], | 208 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1], |
| 209 supported_sizes[1], supported_sizes[1] }; | 209 supported_sizes[1], supported_sizes[1] }; |
| 210 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 210 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Check that if the implementation supports only sizes that are larger than | 213 // Check that if the implementation supports only sizes that are larger than |
| 214 // the requested size, then the one that requires the least down-scaling. | 214 // the requested size, then the one that requires the least down-scaling. |
| 215 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { | 215 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { |
| 216 ScreenResolution supported_sizes[] = { MakeResolution(100, 100), | 216 ScreenResolution supported_sizes[] = { MakeResolution(100, 100), |
| 217 MakeResolution(200, 100) }; | 217 MakeResolution(200, 100) }; |
| 218 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 218 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
| 219 new FakeDesktopResizer(MakeResolution(200, 100), false, | 219 new FakeDesktopResizer(MakeResolution(200, 100), false, |
| 220 supported_sizes, arraysize(supported_sizes), | 220 supported_sizes, arraysize(supported_sizes), |
| 221 nullptr)); | 221 nullptr)); |
| 222 SetDesktopResizer(desktop_resizer.Pass()); | 222 SetDesktopResizer(std::move(desktop_resizer)); |
| 223 | 223 |
| 224 ScreenResolution client_sizes[] = { MakeResolution(1, 1), | 224 ScreenResolution client_sizes[] = { MakeResolution(1, 1), |
| 225 MakeResolution(99, 99), | 225 MakeResolution(99, 99), |
| 226 MakeResolution(199, 99) }; | 226 MakeResolution(199, 99) }; |
| 227 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], | 227 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], |
| 228 supported_sizes[1] }; | 228 supported_sizes[1] }; |
| 229 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 229 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Check that if the implementation supports two sizes that have the same | 232 // Check that if the implementation supports two sizes that have the same |
| 233 // resultant scale factor, then the widest one is selected. | 233 // resultant scale factor, then the widest one is selected. |
| 234 TEST_F(ResizingHostObserverTest, SelectWidest) { | 234 TEST_F(ResizingHostObserverTest, SelectWidest) { |
| 235 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), | 235 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), |
| 236 MakeResolution(480, 640) }; | 236 MakeResolution(480, 640) }; |
| 237 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 237 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
| 238 new FakeDesktopResizer(MakeResolution(480, 640), false, | 238 new FakeDesktopResizer(MakeResolution(480, 640), false, |
| 239 supported_sizes, arraysize(supported_sizes), | 239 supported_sizes, arraysize(supported_sizes), |
| 240 nullptr)); | 240 nullptr)); |
| 241 SetDesktopResizer(desktop_resizer.Pass()); | 241 SetDesktopResizer(std::move(desktop_resizer)); |
| 242 | 242 |
| 243 ScreenResolution client_sizes[] = { MakeResolution(100, 100), | 243 ScreenResolution client_sizes[] = { MakeResolution(100, 100), |
| 244 MakeResolution(480, 480), | 244 MakeResolution(480, 480), |
| 245 MakeResolution(500, 500), | 245 MakeResolution(500, 500), |
| 246 MakeResolution(640, 640), | 246 MakeResolution(640, 640), |
| 247 MakeResolution(1000, 1000) }; | 247 MakeResolution(1000, 1000) }; |
| 248 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], | 248 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], |
| 249 supported_sizes[0], supported_sizes[0], | 249 supported_sizes[0], supported_sizes[0], |
| 250 supported_sizes[0] }; | 250 supported_sizes[0] }; |
| 251 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 251 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 FROM_HERE, | 300 FROM_HERE, |
| 301 run_loop.QuitClosure(), | 301 run_loop.QuitClosure(), |
| 302 base::TimeDelta::FromMilliseconds(2)); | 302 base::TimeDelta::FromMilliseconds(2)); |
| 303 run_loop.Run(); | 303 run_loop.Run(); |
| 304 | 304 |
| 305 // If the QuitClosure fired before the final resize, it's a test failure. | 305 // If the QuitClosure fired before the final resize, it's a test failure. |
| 306 EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300)); | 306 EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300)); |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace remoting | 309 } // namespace remoting |
| OLD | NEW |