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_TEST_BASE_TEST_BROWSER_WINDOW_H_
6#define CHROME_TEST_BASE_TEST_BROWSER_WINDOW_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "build/build_config.h"
11#include "chrome/browser/download/test_download_shelf.h"
12#include "chrome/browser/ui/browser.h"
13#include "chrome/browser/ui/browser_window.h"
14#include "chrome/browser/ui/location_bar/location_bar.h"
15
16class LocationBarTesting;
17class OmniboxView;
18
19namespace extensions {
20class Extension;
21}
22
23// An implementation of BrowserWindow used for testing. TestBrowserWindow only
24// contains a valid LocationBar, all other getters return NULL.
25// See BrowserWithTestWindowTest for an example of using this class.
26class TestBrowserWindow : public BrowserWindow {
27 public:
28  TestBrowserWindow();
29  virtual ~TestBrowserWindow();
30
31  // BrowserWindow:
32  virtual void Show() OVERRIDE {}
33  virtual void ShowInactive() OVERRIDE {}
34  virtual void Hide() OVERRIDE {}
35  virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE {}
36  virtual void Close() OVERRIDE {}
37  virtual void Activate() OVERRIDE {}
38  virtual void Deactivate() OVERRIDE {}
39  virtual bool IsActive() const OVERRIDE;
40  virtual void FlashFrame(bool flash) OVERRIDE {}
41  virtual bool IsAlwaysOnTop() const OVERRIDE;
42  virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE {}
43  virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
44  virtual BrowserWindowTesting* GetBrowserWindowTesting() OVERRIDE;
45  virtual StatusBubble* GetStatusBubble() OVERRIDE;
46  virtual void UpdateTitleBar() OVERRIDE {}
47  virtual void BookmarkBarStateChanged(
48      BookmarkBar::AnimateChangeType change_type) OVERRIDE {}
49  virtual void UpdateDevTools() OVERRIDE {}
50  virtual void UpdateLoadingAnimations(bool should_animate) OVERRIDE {}
51  virtual void SetStarredState(bool is_starred) OVERRIDE {}
52  virtual void SetTranslateIconToggled(bool is_lit) OVERRIDE {}
53  virtual void OnActiveTabChanged(content::WebContents* old_contents,
54                                  content::WebContents* new_contents,
55                                  int index,
56                                  int reason) OVERRIDE {}
57  virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE {}
58  virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
59  virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
60  virtual gfx::Rect GetBounds() const OVERRIDE;
61  virtual bool IsMaximized() const OVERRIDE;
62  virtual bool IsMinimized() const OVERRIDE;
63  virtual void Maximize() OVERRIDE {}
64  virtual void Minimize() OVERRIDE {}
65  virtual void Restore() OVERRIDE {}
66  virtual void EnterFullscreen(
67      const GURL& url, FullscreenExitBubbleType type) OVERRIDE {}
68  virtual void ExitFullscreen() OVERRIDE {}
69  virtual void UpdateFullscreenExitBubbleContent(
70      const GURL& url,
71      FullscreenExitBubbleType bubble_type) OVERRIDE {}
72  virtual bool ShouldHideUIForFullscreen() const OVERRIDE;
73  virtual bool IsFullscreen() const OVERRIDE;
74#if defined(OS_WIN)
75  virtual void SetMetroSnapMode(bool enable) OVERRIDE {}
76  virtual bool IsInMetroSnapMode() const;
77#endif
78  virtual bool IsFullscreenBubbleVisible() const OVERRIDE;
79  virtual LocationBar* GetLocationBar() const OVERRIDE;
80  virtual void SetFocusToLocationBar(bool select_all) OVERRIDE {}
81  virtual void UpdateReloadStopState(bool is_loading, bool force) OVERRIDE {}
82  virtual void UpdateToolbar(content::WebContents* contents) OVERRIDE {}
83  virtual void FocusToolbar() OVERRIDE {}
84  virtual void FocusAppMenu() OVERRIDE {}
85  virtual void FocusBookmarksToolbar() OVERRIDE {}
86  virtual void FocusInfobars() OVERRIDE {}
87  virtual void RotatePaneFocus(bool forwards) OVERRIDE {}
88  virtual void ShowAppMenu() OVERRIDE {}
89  virtual bool PreHandleKeyboardEvent(
90      const content::NativeWebKeyboardEvent& event,
91      bool* is_keyboard_shortcut) OVERRIDE;
92  virtual void HandleKeyboardEvent(
93      const content::NativeWebKeyboardEvent& event) OVERRIDE {}
94
95  virtual bool IsBookmarkBarVisible() const OVERRIDE;
96  virtual bool IsBookmarkBarAnimating() const OVERRIDE;
97  virtual bool IsTabStripEditable() const OVERRIDE;
98  virtual bool IsToolbarVisible() const OVERRIDE;
99  virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
100  virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
101                                        Profile* profile) OVERRIDE {}
102  virtual void ShowUpdateChromeDialog() OVERRIDE {}
103  virtual void ShowBookmarkBubble(const GURL& url,
104                                  bool already_bookmarked) OVERRIDE {}
105  virtual void ShowBookmarkAppBubble(
106      const WebApplicationInfo& web_app_info,
107      const std::string& extension_id) OVERRIDE {}
108  virtual void ShowTranslateBubble(
109      content::WebContents* contents,
110      translate::TranslateStep step,
111      translate::TranslateErrors::Type error_type,
112      bool is_user_gesture) OVERRIDE {}
113#if defined(ENABLE_ONE_CLICK_SIGNIN)
114  virtual void ShowOneClickSigninBubble(
115      OneClickSigninBubbleType type,
116      const base::string16& email,
117      const base::string16& error_message,
118      const StartSyncCallback& start_sync_callback) OVERRIDE {}
119#endif
120  virtual bool IsDownloadShelfVisible() const OVERRIDE;
121  virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
122  virtual void ConfirmBrowserCloseWithPendingDownloads(
123      int download_count,
124      Browser::DownloadClosePreventionType dialog_type,
125      bool app_modal,
126      const base::Callback<void(bool)>& callback) OVERRIDE {}
127  virtual void UserChangedTheme() OVERRIDE {}
128  virtual int GetExtraRenderViewHeight() const OVERRIDE;
129  virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE {}
130  virtual void ShowWebsiteSettings(Profile* profile,
131                                   content::WebContents* web_contents,
132                                   const GURL& url,
133                                   const content::SSLStatus& ssl) OVERRIDE {}
134  virtual void Cut() OVERRIDE {}
135  virtual void Copy() OVERRIDE {}
136  virtual void Paste() OVERRIDE {}
137#if defined(OS_MACOSX)
138  virtual void EnterFullscreenWithChrome() OVERRIDE {}
139  virtual void EnterFullscreenWithoutChrome() OVERRIDE {}
140  virtual bool IsFullscreenWithChrome() OVERRIDE;
141  virtual bool IsFullscreenWithoutChrome() OVERRIDE;
142#endif
143
144  virtual WindowOpenDisposition GetDispositionForPopupBounds(
145      const gfx::Rect& bounds) OVERRIDE;
146  virtual FindBar* CreateFindBar() OVERRIDE;
147  virtual web_modal::WebContentsModalDialogHost*
148      GetWebContentsModalDialogHost() OVERRIDE;
149  virtual void ShowAvatarBubble(content::WebContents* web_contents,
150                                const gfx::Rect& rect) OVERRIDE {}
151  virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode,
152      const signin::ManageAccountsParams& manage_accounts_params) OVERRIDE {}
153  virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() OVERRIDE;
154  virtual void ExecuteExtensionCommand(
155      const extensions::Extension* extension,
156      const extensions::Command& command) OVERRIDE;
157
158 protected:
159  virtual void DestroyBrowser() OVERRIDE {}
160
161 private:
162  class TestLocationBar : public LocationBar {
163   public:
164    TestLocationBar() : LocationBar(NULL) {}
165    virtual ~TestLocationBar() {}
166
167    // LocationBar:
168    virtual void ShowFirstRunBubble() OVERRIDE {}
169    virtual GURL GetDestinationURL() const OVERRIDE;
170    virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE;
171    virtual ui::PageTransition GetPageTransition() const OVERRIDE;
172    virtual void AcceptInput() OVERRIDE {}
173    virtual void FocusLocation(bool select_all) OVERRIDE {}
174    virtual void FocusSearch() OVERRIDE {}
175    virtual void UpdateContentSettingsIcons() OVERRIDE {}
176    virtual void UpdateManagePasswordsIconAndBubble() OVERRIDE {}
177    virtual void UpdatePageActions() OVERRIDE {}
178    virtual void InvalidatePageActions() OVERRIDE {}
179    virtual void UpdateBookmarkStarVisibility() OVERRIDE {}
180    virtual bool ShowPageActionPopup(const extensions::Extension* extension,
181                                     bool grant_active_tab) OVERRIDE;
182    virtual void UpdateOpenPDFInReaderPrompt() OVERRIDE {}
183    virtual void UpdateGeneratedCreditCardView() OVERRIDE {}
184    virtual void SaveStateToContents(content::WebContents* contents) OVERRIDE {}
185    virtual void Revert() OVERRIDE {}
186    virtual const OmniboxView* GetOmniboxView() const OVERRIDE;
187    virtual OmniboxView* GetOmniboxView() OVERRIDE;
188    virtual LocationBarTesting* GetLocationBarForTesting() OVERRIDE;
189
190   private:
191    DISALLOW_COPY_AND_ASSIGN(TestLocationBar);
192  };
193
194  TestDownloadShelf download_shelf_;
195  TestLocationBar location_bar_;
196
197  DISALLOW_COPY_AND_ASSIGN(TestBrowserWindow);
198};
199
200namespace chrome {
201
202// Helper that handle the lifetime of TestBrowserWindow instances.
203Browser* CreateBrowserWithTestWindowForParams(Browser::CreateParams* params);
204
205}  // namespace chrome
206
207#endif  // CHROME_TEST_BASE_TEST_BROWSER_WINDOW_H_
208