Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #import "base/mac/mac_util.h" 7 #import "base/mac/mac_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
12 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" 19 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
20 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 20 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
21 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" 21 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
22 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 22 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 VIEW_ID_TOOLBAR, 61 VIEW_ID_TOOLBAR,
62 VIEW_ID_BOOKMARK_BAR, 62 VIEW_ID_BOOKMARK_BAR,
63 VIEW_ID_INFO_BAR, 63 VIEW_ID_INFO_BAR,
64 VIEW_ID_FIND_BAR, 64 VIEW_ID_FIND_BAR,
65 VIEW_ID_DOWNLOAD_SHELF, 65 VIEW_ID_DOWNLOAD_SHELF,
66 VIEW_ID_TAB_CONTENT_AREA, 66 VIEW_ID_TAB_CONTENT_AREA,
67 VIEW_ID_FULLSCREEN_FLOATING_BAR, 67 VIEW_ID_FULLSCREEN_FLOATING_BAR,
68 VIEW_ID_COUNT, 68 VIEW_ID_COUNT,
69 }; 69 };
70 70
71 // A very simple info bar implementation used to show an infobar on the browser
72 // window.
73 class DummyInfoBar : public ConfirmInfoBarDelegate {
74 public:
75 explicit DummyInfoBar(InfoBarService* service)
76 : ConfirmInfoBarDelegate(service) {
77 }
78
79 virtual ~DummyInfoBar() {
80 }
81
82 virtual string16 GetMessageText() const OVERRIDE {
83 return string16();
84 }
85
86 private:
87 DISALLOW_COPY_AND_ASSIGN(DummyInfoBar);
88 };
89
90 } // namespace 71 } // namespace
91 72
92 class BrowserWindowControllerTest : public InProcessBrowserTest { 73 class BrowserWindowControllerTest : public InProcessBrowserTest {
93 public: 74 public:
94 BrowserWindowControllerTest() : InProcessBrowserTest() { 75 BrowserWindowControllerTest() : InProcessBrowserTest() {
95 } 76 }
96 77
97 virtual void SetUpOnMainThread() OVERRIDE { 78 virtual void SetUpOnMainThread() OVERRIDE {
98 [[controller() bookmarkBarController] setStateAnimationsEnabled:NO]; 79 [[controller() bookmarkBarController] setStateAnimationsEnabled:NO];
99 [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO]; 80 [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO];
100 } 81 }
101 82
102 BrowserWindowController* controller() const { 83 BrowserWindowController* controller() const {
103 return [BrowserWindowController browserWindowControllerForWindow: 84 return [BrowserWindowController browserWindowControllerForWindow:
104 browser()->window()->GetNativeWindow()]; 85 browser()->window()->GetNativeWindow()];
105 } 86 }
106 87
107 void ShowInfoBar() { 88 static void ShowInfoBar(Browser* browser) {
108 content::WebContents* web_contents = 89 SimpleAlertInfoBarDelegate::Create(
109 browser()->tab_strip_model()->GetActiveWebContents(); 90 InfoBarService::FromWebContents(
110 InfoBarService* service = 91 browser->tab_strip_model()->GetActiveWebContents()),
111 InfoBarService::FromWebContents(web_contents); 92 0, string16(), false);
112 scoped_ptr<InfoBarDelegate> info_bar_delegate(new DummyInfoBar(service));
113 service->AddInfoBar(info_bar_delegate.Pass());
114 } 93 }
115 94
116 NSView* GetViewWithID(ViewID view_id) const { 95 NSView* GetViewWithID(ViewID view_id) const {
117 switch (view_id) { 96 switch (view_id) {
118 case VIEW_ID_FULLSCREEN_FLOATING_BAR: 97 case VIEW_ID_FULLSCREEN_FLOATING_BAR:
119 return [controller() floatingBarBackingView]; 98 return [controller() floatingBarBackingView];
120 case VIEW_ID_TOOLBAR: 99 case VIEW_ID_TOOLBAR:
121 return [[controller() toolbarController] view]; 100 return [[controller() toolbarController] view];
122 case VIEW_ID_BOOKMARK_BAR: 101 case VIEW_ID_BOOKMARK_BAR:
123 return [[controller() bookmarkBarController] view]; 102 return [[controller() bookmarkBarController] view];
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 defaultAlertFrame.size.height); 321 defaultAlertFrame.size.height);
343 322
344 // Close the application window. 323 // Close the application window.
345 popup_browser->tab_strip_model()->CloseSelectedTabs(); 324 popup_browser->tab_strip_model()->CloseSelectedTabs();
346 [popupController close]; 325 [popupController close];
347 } 326 }
348 327
349 // Verify that the info bar tip is hidden when the toolbar is not visible. 328 // Verify that the info bar tip is hidden when the toolbar is not visible.
350 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, 329 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
351 InfoBarTipHiddenForWindowWithoutToolbar) { 330 InfoBarTipHiddenForWindowWithoutToolbar) {
352 ShowInfoBar(); 331 ShowInfoBar(browser());
353 EXPECT_FALSE( 332 EXPECT_FALSE(
354 [[controller() infoBarContainerController] shouldSuppressTopInfoBarTip]); 333 [[controller() infoBarContainerController] shouldSuppressTopInfoBarTip]);
355 334
356 gfx::Rect initial_bounds(0, 0, 400, 400); 335 gfx::Rect initial_bounds(0, 0, 400, 400);
357 OpenAppShortcutWindow(browser()->profile(), GURL("about:blank"), 336 OpenAppShortcutWindow(browser()->profile(), GURL("about:blank"),
358 initial_bounds); 337 initial_bounds);
359 Browser* popup_browser = BrowserList::GetInstance( 338 Browser* popup_browser = BrowserList::GetInstance(
360 chrome::HOST_DESKTOP_TYPE_NATIVE)->GetLastActive(); 339 chrome::HOST_DESKTOP_TYPE_NATIVE)->GetLastActive();
361 NSWindow* popupWindow = popup_browser->window()->GetNativeWindow(); 340 NSWindow* popupWindow = popup_browser->window()->GetNativeWindow();
362 BrowserWindowController* popupController = 341 BrowserWindowController* popupController =
363 [BrowserWindowController browserWindowControllerForWindow:popupWindow]; 342 [BrowserWindowController browserWindowControllerForWindow:popupWindow];
364 EXPECT_FALSE([popupController hasToolbar]); 343 EXPECT_FALSE([popupController hasToolbar]);
365 344
366 // Show infobar for controller. 345 // Show infobar for controller.
367 content::WebContents* web_contents = 346 ShowInfoBar(popup_browser);
368 popup_browser->tab_strip_model()->GetActiveWebContents();
369 InfoBarService* service = InfoBarService::FromWebContents(web_contents);
370 scoped_ptr<InfoBarDelegate> info_bar_delegate(new DummyInfoBar(service));
371 service->AddInfoBar(info_bar_delegate.Pass());
372 EXPECT_TRUE( 347 EXPECT_TRUE(
373 [[popupController infoBarContainerController] 348 [[popupController infoBarContainerController]
374 shouldSuppressTopInfoBarTip]); 349 shouldSuppressTopInfoBarTip]);
375 } 350 }
376 351
377 // Verify that AllowOverlappingViews is set while the history overlay is 352 // Verify that AllowOverlappingViews is set while the history overlay is
378 // visible. 353 // visible.
379 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, 354 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
380 AllowOverlappingViewsHistoryOverlay) { 355 AllowOverlappingViewsHistoryOverlay) {
381 content::WebContentsView* web_contents_view = 356 content::WebContentsView* web_contents_view =
382 browser()->tab_strip_model()->GetActiveWebContents()->GetView(); 357 browser()->tab_strip_model()->GetActiveWebContents()->GetView();
383 EXPECT_TRUE(web_contents_view->GetAllowOverlappingViews()); 358 EXPECT_TRUE(web_contents_view->GetAllowOverlappingViews());
384 359
385 base::scoped_nsobject<HistoryOverlayController> overlay( 360 base::scoped_nsobject<HistoryOverlayController> overlay(
386 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]); 361 [[HistoryOverlayController alloc] initForMode:kHistoryOverlayModeBack]);
387 [overlay showPanelForView:web_contents_view->GetNativeView()]; 362 [overlay showPanelForView:web_contents_view->GetNativeView()];
388 EXPECT_TRUE(web_contents_view->GetAllowOverlappingViews()); 363 EXPECT_TRUE(web_contents_view->GetAllowOverlappingViews());
389 364
390 overlay.reset(); 365 overlay.reset();
391 EXPECT_TRUE(web_contents_view->GetAllowOverlappingViews()); 366 EXPECT_TRUE(web_contents_view->GetAllowOverlappingViews());
392 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698