15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/ref_counted.h" 109ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/run_loop.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/host/desktop_resizer.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/host/resizing_host_observer.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/host/screen_resolution.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkSize.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::ostream& operator<<(std::ostream& os, const SkISize& size) { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return os << size.width() << "x" << size.height(); 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kDefaultDPI = 96; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FakeDesktopResizer : public DesktopResizer { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FakeDesktopResizer(const SkISize& initial_size, bool exact_size_supported, 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SkISize* supported_sizes, int num_supported_sizes) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : initial_size_(initial_size), 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_size_(initial_size), 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) exact_size_supported_(exact_size_supported), 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) set_size_call_count_(0) { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < num_supported_sizes; ++i) { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes_.push_back(supported_sizes[i]); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~FakeDesktopResizer() { 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(initial_size_, GetCurrentSize()); 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int set_size_call_count() { return set_size_call_count_; } 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // remoting::DesktopResizer interface 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SkISize GetCurrentSize() OVERRIDE { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return current_size_; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual std::list<SkISize> GetSupportedSizes( 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SkISize& preferred) OVERRIDE { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<SkISize> result = supported_sizes_; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (exact_size_supported_) { 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) result.push_back(preferred); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetSize(const SkISize& size) OVERRIDE { 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_size_ = size; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ++set_size_call_count_; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RestoreSize(const SkISize& size) OVERRIDE { 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_size_ = size; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize initial_size_; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize current_size_; 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool exact_size_supported_; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::list<SkISize> supported_sizes_; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int set_size_call_count_; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResizingHostObserverTest : public testing::Test { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ResizingHostObserverTest() 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) : desktop_resizer_(NULL), 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) now_(base::Time::Now()) { 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This needs to be public because the derived test-case class needs to 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // pass it to Bind, which fails if it's protected. 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Time GetTime() { 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return now_; 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected: 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) desktop_resizer_ = desktop_resizer.get(); 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) resizing_host_observer_.reset( 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new ResizingHostObserver(desktop_resizer.PassAs<DesktopResizer>())); 95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) resizing_host_observer_->SetNowFunctionForTesting( 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Bind(&ResizingHostObserverTest::GetTimeAndIncrement, 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Unretained(this))); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize GetBestSize(const SkISize& client_size) { 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) resizing_host_observer_->SetScreenResolution(ScreenResolution( 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) webrtc::DesktopSize(client_size.width(), client_size.height()), 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) webrtc::DesktopVector(kDefaultDPI, kDefaultDPI))); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return desktop_resizer_->GetCurrentSize(); 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void VerifySizes(const SkISize* client_sizes, const SkISize* expected_sizes, 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int number_of_sizes) { 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < number_of_sizes; ++i) { 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize best_size = GetBestSize(client_sizes[i]); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_sizes[i], best_size) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << "Input size = " << client_sizes[i]; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Time GetTimeAndIncrement() { 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Time result = now_; 118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) now_ += base::TimeDelta::FromSeconds(1); 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return result; 120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<ResizingHostObserver> resizing_host_observer_; 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FakeDesktopResizer* desktop_resizer_; 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Time now_; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that the host is not resized if GetSupportedSizes returns an empty 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// list (even if GetCurrentSize is supported). 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize initial = { 640, 480 }; 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<FakeDesktopResizer> desktop_resizer( 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new FakeDesktopResizer(initial, false, NULL, 0)); 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDesktopResizer(desktop_resizer.Pass()); 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } }; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize expected_sizes[] = { initial, initial }; 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that if the implementation supports exact size matching, it is used. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ResizingHostObserverTest, SelectExactSize) { 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<FakeDesktopResizer> desktop_resizer( 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0)); 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDesktopResizer(desktop_resizer.Pass()); 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize client_sizes[] = { { 200, 100 }, { 100, 200 } , { 640, 480 }, 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 480, 640 }, { 1280, 1024 } }; 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that if the implementation supports a size that is no larger than 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the requested size, then the largest such size is used. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize supported_sizes[] = { 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize::Make(639, 479), SkISize::Make(640, 480) }; 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<FakeDesktopResizer> desktop_resizer( 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new FakeDesktopResizer(SkISize::Make(640, 480), false, 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes, arraysize(supported_sizes))); 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDesktopResizer(desktop_resizer.Pass()); 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize client_sizes[] = { { 639, 479 }, { 640, 480 }, { 641, 481 }, 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 999, 999 } }; 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[1], 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes[1], supported_sizes[1] }; 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that if the implementation supports only sizes that are larger than 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the requested size, then the one that requires the least down-scaling. 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize supported_sizes[] = { { 100, 100 }, { 200, 100 } }; 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<FakeDesktopResizer> desktop_resizer( 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new FakeDesktopResizer(SkISize::Make(200, 100), false, 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes, arraysize(supported_sizes))); 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDesktopResizer(desktop_resizer.Pass()); 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize client_sizes[] = { { 1, 1 }, { 99, 99 }, { 199, 99 } }; 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes[1] }; 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that if the implementation supports two sizes that have the same 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// resultant scale factor, then the widest one is selected. 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ResizingHostObserverTest, SelectWidest) { 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<FakeDesktopResizer> desktop_resizer( 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new FakeDesktopResizer(SkISize::Make(480, 640), false, 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes, arraysize(supported_sizes))); 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDesktopResizer(desktop_resizer.Pass()); 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize client_sizes[] = { { 100, 100 }, { 480, 480 }, { 500, 500 }, 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 640, 640 }, { 1000, 1000 } }; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize expected_sizes[] = { supported_sizes[0], supported_sizes[0], 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes[0], supported_sizes[0], 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes[0] }; 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that if the best match for the client size doesn't change, then we 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// don't call SetSize. 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize supported_sizes[] = { { 640, 480 }, { 480, 640 } }; 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FakeDesktopResizer* desktop_resizer = 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new FakeDesktopResizer(SkISize::Make(640, 480), false, 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) supported_sizes, arraysize(supported_sizes)); 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize client_sizes[] = { { 640, 640 }, { 1024, 768 }, { 640, 480 } }; 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkISize expected_sizes[] = { { 640, 480 }, { 640, 480 }, { 640, 480 } }; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(desktop_resizer->set_size_call_count(), 0); 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Check that desktop resizes are rate-limited, and that if multiple resize 216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// requests are received in the time-out period, the most recent is respected. 217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TEST_F(ResizingHostObserverTest, RateLimited) { 218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FakeDesktopResizer* desktop_resizer = 219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new FakeDesktopResizer(SkISize::Make(640, 480), true, NULL, 0); 220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SetDesktopResizer(scoped_ptr<FakeDesktopResizer>(desktop_resizer)); 221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) resizing_host_observer_->SetNowFunctionForTesting( 222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this))); 223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::MessageLoop message_loop; 225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::RunLoop run_loop; 226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 227868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(GetBestSize(SkISize::Make(100, 100)), SkISize::Make(100, 100)); 228868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) now_ += base::TimeDelta::FromMilliseconds(900); 229868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(GetBestSize(SkISize::Make(200, 200)), SkISize::Make(100, 100)); 230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) now_ += base::TimeDelta::FromMilliseconds(99); 231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(GetBestSize(SkISize::Make(300, 300)), SkISize::Make(100, 100)); 232868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) now_ += base::TimeDelta::FromMilliseconds(1); 233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Due to the kMinimumResizeIntervalMs constant in resizing_host_observer.cc, 235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // We need to wait a total of 1000ms for the final resize to be processed. 236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Since it was queued 900 + 99 ms after the first, we need to wait an 237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // additional 1ms. However, since RunLoop is not guaranteed to process tasks 238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // with the same due time in FIFO order, wait an additional 1ms for safety. 239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) message_loop.PostDelayedTask( 240868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FROM_HERE, 241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) run_loop.QuitClosure(), 242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::TimeDelta::FromMilliseconds(2)); 243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) run_loop.Run(); 244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 245868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // If the QuitClosure fired before the final resize, it's a test failure. 246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_EQ(desktop_resizer_->GetCurrentSize(), SkISize::Make(300, 300)); 247868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 248868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace remoting 250