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#ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_ 6#define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_ 7 8#include <vector> 9 10#include "base/logging.h" 11#include "chrome/browser/ui/window_sizer/window_sizer.h" 12#include "chrome/test/base/test_browser_window.h" 13#include "ui/gfx/rect.h" 14 15// Some standard primary monitor sizes (no task bar). 16static const gfx::Rect p1024x768(0, 0, 1024, 768); 17static const gfx::Rect p1280x1024(0, 0, 1280, 1024); 18static const gfx::Rect p1600x1200(0, 0, 1600, 1200); 19static const gfx::Rect p1680x1050(0, 0, 1680, 1050); 20static const gfx::Rect p1920x1200(0, 0, 1920, 1200); 21 22// Represents a 1024x768 monitor that is the secondary monitor, arranged to 23// the immediate left of the primary 1024x768 monitor. 24static const gfx::Rect left_s1024x768(-1024, 0, 1024, 768); 25 26// Represents a 1024x768 monitor that is the secondary monitor, arranged to 27// the immediate right of the primary 1024x768 monitor. 28static const gfx::Rect right_s1024x768(1024, 0, 1024, 768); 29 30// Represents a 1024x768 monitor that is the secondary monitor, arranged to 31// the immediate top of the primary 1024x768 monitor. 32static const gfx::Rect top_s1024x768(0, -768, 1024, 768); 33 34// Represents a 1024x768 monitor that is the secondary monitor, arranged to 35// the immediate bottom of the primary 1024x768 monitor. 36static const gfx::Rect bottom_s1024x768(0, 768, 1024, 768); 37 38// Represents a 1600x1200 monitor that is the secondary monitor, arranged to 39// the immediate bottom of the primary 1600x1200 monitor. 40static const gfx::Rect bottom_s1600x1200(0, 1200, 1600, 1200); 41 42// The work area for 1024x768 monitors with different taskbar orientations. 43static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734); 44static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734); 45static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768); 46static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768); 47 48extern int kWindowTilePixels; 49 50// Testing implementation of WindowSizer::StateProvider that we use to fake 51// persistent storage and existing windows. 52class TestStateProvider : public WindowSizer::StateProvider { 53 public: 54 TestStateProvider(); 55 virtual ~TestStateProvider() {} 56 57 void SetPersistentState(const gfx::Rect& bounds, 58 const gfx::Rect& work_area, 59 ui::WindowShowState show_state, 60 bool has_persistent_data); 61 void SetLastActiveState(const gfx::Rect& bounds, 62 ui::WindowShowState show_state, 63 bool has_last_active_data); 64 65 // Overridden from WindowSizer::StateProvider: 66 virtual bool GetPersistentState( 67 gfx::Rect* bounds, 68 gfx::Rect* saved_work_area, 69 ui::WindowShowState* show_state) const OVERRIDE; 70 virtual bool GetLastActiveWindowState( 71 gfx::Rect* bounds, 72 ui::WindowShowState* show_state) const OVERRIDE; 73 74 private: 75 gfx::Rect persistent_bounds_; 76 gfx::Rect persistent_work_area_; 77 bool has_persistent_data_; 78 ui::WindowShowState persistent_show_state_; 79 80 gfx::Rect last_active_bounds_; 81 bool has_last_active_data_; 82 ui::WindowShowState last_active_show_state_; 83 84 DISALLOW_COPY_AND_ASSIGN(TestStateProvider); 85}; 86 87// Several convenience functions which allow to set up a state for 88// window sizer test operations with a single call. 89 90enum Source { DEFAULT, LAST_ACTIVE, PERSISTED, BOTH }; 91 92// Sets up the window bounds, monitor bounds, show states and more to get the 93// resulting |out_bounds| and |out_show_state| from the WindowSizer. 94// |source| specifies which type of data gets set for the test: Either the 95// last active window, the persisted value which was stored earlier, both or 96// none. For all these states the |bounds| and |work_area| get used, for the 97// show states either |show_state_persisted| or |show_state_last| will be used. 98void GetWindowBoundsAndShowState(const gfx::Rect& monitor1_bounds, 99 const gfx::Rect& monitor1_work_area, 100 const gfx::Rect& monitor2_bounds, 101 const gfx::Rect& bounds, 102 const gfx::Rect& work_area, 103 ui::WindowShowState show_state_persisted, 104 ui::WindowShowState show_state_last, 105 Source source, 106 const Browser* browser, 107 const gfx::Rect& passed_in, 108 gfx::Rect* out_bounds, 109 ui::WindowShowState* out_show_state); 110 111// Sets up the window bounds, monitor bounds, and work area to get the 112// resulting |out_bounds| from the WindowSizer. 113// |source| specifies which type of data gets set for the test: Either the 114// last active window, the persisted value which was stored earlier, both or 115// none. For all these states the |bounds| and |work_area| get used, for the 116// show states either |show_state_persisted| or |show_state_last| will be used. 117void GetWindowBounds(const gfx::Rect& monitor1_bounds, 118 const gfx::Rect& monitor1_work_area, 119 const gfx::Rect& monitor2_bounds, 120 const gfx::Rect& bounds, 121 const gfx::Rect& work_area, 122 Source source, 123 const Browser* browser, 124 const gfx::Rect& passed_in, 125 gfx::Rect* out_bounds); 126 127// Sets up the window |bounds| and various system states which have an influence 128// on the WindowSizer and then determines the resulting show state from it. 129// |bounds| specifies the |browser| last or persistent bounds depending on 130// |source|. The |display_config| is the primary display configuration used. 131ui::WindowShowState GetWindowShowState( 132 ui::WindowShowState show_state_persisted, 133 ui::WindowShowState show_state_last, 134 Source source, 135 const Browser* browser, 136 const gfx::Rect& bounds, 137 const gfx::Rect& display_config); 138 139#endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_ 140