OLD | NEW |
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 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
11 #include "chrome/browser/ui/browser_tabstrip.h" | |
12 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
18 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
19 #include "ipc/ipc_message.h" | |
20 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
21 | 18 |
22 using ::testing::NiceMock; | 19 using ::testing::NiceMock; |
23 | 20 |
24 namespace { | 21 namespace { |
25 | 22 |
26 class ConstrainedWindowDelegateMock : public ConstrainedWindowMacDelegate2 { | 23 class ConstrainedWindowDelegateMock : public ConstrainedWindowMacDelegate2 { |
27 public: | 24 public: |
28 MOCK_METHOD1(OnConstrainedWindowClosed, void(ConstrainedWindowMac2*)); | 25 MOCK_METHOD1(OnConstrainedWindowClosed, void(ConstrainedWindowMac2*)); |
29 }; | 26 }; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 ConstrainedWindowMac2 dialog(&delegate, tab0_, sheet_); | 76 ConstrainedWindowMac2 dialog(&delegate, tab0_, sheet_); |
80 EXPECT_EQ(0.0, [sheet_ alphaValue]); | 77 EXPECT_EQ(0.0, [sheet_ alphaValue]); |
81 | 78 |
82 // Switch to inactive tab. | 79 // Switch to inactive tab. |
83 browser()->tab_strip_model()->ActivateTabAt(0, true); | 80 browser()->tab_strip_model()->ActivateTabAt(0, true); |
84 EXPECT_EQ(1.0, [sheet_ alphaValue]); | 81 EXPECT_EQ(1.0, [sheet_ alphaValue]); |
85 | 82 |
86 dialog.CloseConstrainedWindow(); | 83 dialog.CloseConstrainedWindow(); |
87 } | 84 } |
88 | 85 |
89 // If a tab has never been shown then the associated tab view for the web | |
90 // content will not be created. Verify that adding a constrained window to such | |
91 // a tab works correctly. | |
92 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInUninitializedTab) { | |
93 scoped_ptr<content::WebContents> web_contents(content::WebContents::Create( | |
94 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL)); | |
95 bool was_blocked = false; | |
96 chrome::AddWebContents(browser(), NULL, web_contents.release(), | |
97 NEW_BACKGROUND_TAB, gfx::Rect(), false, &was_blocked); | |
98 content::WebContents* tab2 = | |
99 browser()->tab_strip_model()->GetWebContentsAt(2); | |
100 ASSERT_TRUE(tab2); | |
101 EXPECT_FALSE([tab2->GetNativeView() superview]); | |
102 | |
103 // Show dialog and verify that it's not visible yet. | |
104 NiceMock<ConstrainedWindowDelegateMock> delegate; | |
105 ConstrainedWindowMac2 dialog(&delegate, tab2, sheet_); | |
106 EXPECT_FALSE([sheet_ isVisible]); | |
107 | |
108 // Activate the tab and verify that the constrained window is shown. | |
109 browser()->tab_strip_model()->ActivateTabAt(2, true); | |
110 EXPECT_TRUE([tab2->GetNativeView() superview]); | |
111 EXPECT_TRUE([sheet_ isVisible]); | |
112 EXPECT_EQ(1.0, [sheet_ alphaValue]); | |
113 | |
114 dialog.CloseConstrainedWindow(); | |
115 } | |
116 | |
117 // Test that adding a sheet disables tab dragging. | 86 // Test that adding a sheet disables tab dragging. |
118 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { | 87 IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) { |
119 NiceMock<ConstrainedWindowDelegateMock> delegate; | 88 NiceMock<ConstrainedWindowDelegateMock> delegate; |
120 ConstrainedWindowMac2 dialog(&delegate, tab1_, sheet_); | 89 ConstrainedWindowMac2 dialog(&delegate, tab1_, sheet_); |
121 | 90 |
122 // Verify that the dialog disables dragging. | 91 // Verify that the dialog disables dragging. |
123 EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]); | 92 EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]); |
124 EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]); | 93 EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]); |
125 | 94 |
126 dialog.CloseConstrainedWindow(); | 95 dialog.CloseConstrainedWindow(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); | 127 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
159 | 128 |
160 // Dialog will delete it self when closed. | 129 // Dialog will delete it self when closed. |
161 NiceMock<ConstrainedWindowDelegateMock> delegate; | 130 NiceMock<ConstrainedWindowDelegateMock> delegate; |
162 ConstrainedWindowMac2 dialog(&delegate, tab1_, sheet_); | 131 ConstrainedWindowMac2 dialog(&delegate, tab1_, sheet_); |
163 | 132 |
164 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); | 133 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
165 | 134 |
166 dialog.CloseConstrainedWindow(); | 135 dialog.CloseConstrainedWindow(); |
167 } | 136 } |
OLD | NEW |