OLD | NEW |
(Empty) | |
| 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 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" |
| 6 |
| 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 #include "googleurl/src/gurl.h" |
| 14 |
| 15 class ConstrainedWindowMacTest : public InProcessBrowserTest { |
| 16 public: |
| 17 ConstrainedWindowMacTest() : InProcessBrowserTest() { |
| 18 sheet_.reset([[NSWindow alloc] |
| 19 initWithContentRect:NSMakeRect(0, 0, 30, 30) |
| 20 styleMask:NSTitledWindowMask |
| 21 backing:NSBackingStoreBuffered |
| 22 defer:NO]); |
| 23 [sheet_ setReleasedWhenClosed:NO]; |
| 24 } |
| 25 |
| 26 protected: |
| 27 scoped_nsobject<NSWindow> sheet_; |
| 28 }; |
| 29 |
| 30 // Test that a sheet added to a non-active tab is not shown until the |
| 31 // tab is activated. |
| 32 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInNonActiveTab) { |
| 33 AddTabAtIndex(1, GURL("about:blank"), content::PAGE_TRANSITION_LINK); |
| 34 TabContents* tab0 = browser()->tab_strip_model()->GetTabContentsAt(0); |
| 35 TabContents* tab1 = browser()->tab_strip_model()->GetTabContentsAt(1); |
| 36 EXPECT_EQ(tab1, browser()->tab_strip_model()->GetActiveTabContents()); |
| 37 |
| 38 // Show dialog in non active tab. |
| 39 // Dialog will delete it self when closed. |
| 40 ConstrainedWindowMac2* dialog = new ConstrainedWindowMac2(tab0, sheet_); |
| 41 EXPECT_EQ(0.0, [sheet_ alphaValue]); |
| 42 |
| 43 // Switch to non active tab. |
| 44 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 45 EXPECT_EQ(1.0, [sheet_ alphaValue]); |
| 46 |
| 47 dialog->CloseConstrainedWindow(); |
| 48 } |
| 49 |
| 50 // Test that adding a sheet disables tab dragging. |
| 51 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { |
| 52 AddTabAtIndex(1, GURL("about:blank"), content::PAGE_TRANSITION_LINK); |
| 53 TabContents* tab1 = browser()->tab_strip_model()->GetTabContentsAt(1); |
| 54 BrowserWindowController* controller = [BrowserWindowController |
| 55 browserWindowControllerForView:tab1->web_contents()->GetNativeView()]; |
| 56 NSView* tab_view0 = [[controller tabStripController] viewAtIndex:0]; |
| 57 NSView* tab_view1 = [[controller tabStripController] viewAtIndex:1]; |
| 58 |
| 59 // Dialog will delete it self when closed. |
| 60 ConstrainedWindowMac2* dialog = new ConstrainedWindowMac2(tab1, sheet_); |
| 61 |
| 62 // Verify that the dialog disables dragging. |
| 63 ASSERT_TRUE(controller); |
| 64 EXPECT_TRUE([controller isTabDraggable:tab_view0]); |
| 65 EXPECT_FALSE([controller isTabDraggable:tab_view1]); |
| 66 |
| 67 dialog->CloseConstrainedWindow(); |
| 68 } |
OLD | NEW |