ash_test_base.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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)#ifndef ASH_TEST_ASH_TEST_BASE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_TEST_ASH_TEST_BASE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/message_loop/message_loop.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/threading/thread.h" 13a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "content/public/test/test_browser_thread_bundle.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/wm/public/window_types.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/win/scoped_ole_initializer.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace gfx { 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class Rect; 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace aura { 27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class RootWindow; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Window; 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WindowDelegate; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test { 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class EventGenerator; 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace test 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace aura 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DisplayManager; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test { 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class AshTestHelper; 424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class TestScreenshotDelegate; 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TestSystemTrayDelegate; 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestMetroViewerProcessHost; 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AshTestBase : public testing::Test { 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AshTestBase(); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~AshTestBase(); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // testing::Test: 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TearDown() OVERRIDE; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the display configuration as given in |display_specs|. 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateDisplay(const std::string& display_specs); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns a root Window. Usually this is the active root Window, but that 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // method can return NULL sometimes, and in those cases, we fall back on the 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // primary root Window. 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* CurrentContext(); 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Versions of the functions in aura::test:: that go through our shell 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // StackingController instead of taking a parent. 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithId(int id); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithBounds(const gfx::Rect& bounds); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShell(SkColor color, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds); 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithDelegate( 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::WindowDelegate* delegate, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* CreateTestWindowInShellWithDelegateAndType( 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::WindowDelegate* delegate, 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::wm::WindowType type, 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Attach |window| to the current shell's root window. 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ParentWindowInPrimaryRootWindow(aura::Window* window); 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the EventGenerator that uses screen coordinates and works 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // across multiple displays. It createse a new generator if it 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // hasn't been created yet. 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::test::EventGenerator& GetEventGenerator(); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 92bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch enum UserSessionBlockReason { 93bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch FIRST_BLOCK_REASON, 94bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch BLOCKED_BY_LOCK_SCREEN = FIRST_BLOCK_REASON, 95bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch BLOCKED_BY_LOGIN_SCREEN, 96bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch BLOCKED_BY_USER_ADDING_SCREEN, 97bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch NUMBER_OF_BLOCK_REASONS 98bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch }; 99bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 100c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Proxy to AshTestHelper::SupportsMultipleDisplays(). 1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static bool SupportsMultipleDisplays(); 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 103c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Proxy to AshTestHelper::SupportsHostWindowResize(). 104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static bool SupportsHostWindowResize(); 105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 106bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch void set_start_session(bool start_session) { start_session_ = start_session; } 107bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AshTestHelper* ash_test_helper() { return ash_test_helper_.get(); } 109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RunAllPendingInMessageLoop(); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestScreenshotDelegate* GetScreenshotDelegate(); 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestSystemTrayDelegate* GetSystemTrayDelegate(); 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Utility methods to emulate user logged in or not, session started or not 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and user able to lock screen or not cases. 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetSessionStarted(bool session_started); 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetUserLoggedIn(bool user_logged_in); 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetCanLockScreen(bool can_lock_screen); 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetShouldLockScreenBeforeSuspending(bool should_lock); 121bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void SetUserAddingScreenRunning(bool user_adding_screen_running); 122bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 123bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // Methods to emulate blocking and unblocking user session with given 124bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // |block_reason|. 125bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void BlockUserSession(UserSessionBlockReason block_reason); 126bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void UnblockUserSession(); 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool setup_called_; 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool teardown_called_; 131bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // |SetUp()| doesn't activate session if this is set to false. 132bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool start_session_; 13323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<AshTestHelper> ash_test_helper_; 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<aura::test::EventGenerator> event_generator_; 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Note that the order is important here as ipc_thread_ should be destroyed 13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // after metro_viewer_host_->channel_. 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<base::Thread> ipc_thread_; 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::ScopedOleInitializer ole_initializer_; 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AshTestBase); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 147bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass NoSessionAshTestBase : public AshTestBase { 148bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch public: 149bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NoSessionAshTestBase() { 150bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch set_start_session(false); 151bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch } 152bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch virtual ~NoSessionAshTestBase() {} 153bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 154bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch private: 155bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch DISALLOW_COPY_AND_ASSIGN(NoSessionAshTestBase); 156bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch}; 157bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace test 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // ASH_TEST_ASH_TEST_BASE_H_ 162