OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/tab_contents/overlayable_contents_controller.h" | 5 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
11 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" | 11 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" |
12 #include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" | 12 #include "chrome/browser/ui/cocoa/tab_contents/overlay_separator_view.h" |
13 #include "chrome/browser/ui/search/instant_overlay_model.h" | 13 #include "chrome/browser/ui/search/instant_overlay_model.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
18 #import "testing/gtest_mac.h" | 18 #import "testing/gtest_mac.h" |
19 | 19 |
20 class OverlayableContentsControllerTest : public InProcessBrowserTest, | 20 class OverlayableContentsControllerTest : public InProcessBrowserTest, |
21 public content::NotificationObserver { | 21 public content::NotificationObserver { |
22 public: | 22 public: |
23 OverlayableContentsControllerTest() : instant_overlay_model_(NULL), | 23 OverlayableContentsControllerTest() : instant_overlay_model_(NULL), |
24 visibility_changed_count_(0) { | 24 visibility_changed_count_(0) { |
25 } | 25 } |
26 | 26 |
27 virtual void SetUpOnMainThread() OVERRIDE { | 27 virtual void SetUpOnMainThread() OVERRIDE { |
28 web_contents_.reset(content::WebContents::Create( | 28 web_contents_.reset(content::WebContents::Create( |
29 content::WebContents::CreateParams(browser()->profile()))); | 29 content::WebContents::CreateParams(browser()->profile()))); |
30 instant_overlay_model_.SetOverlayContents(web_contents_.get()); | 30 instant_overlay_model_.SetOverlayContents(web_contents_.get()); |
31 | 31 |
| 32 BrowserWindowController* window_controller = |
| 33 [BrowserWindowController browserWindowControllerForWindow: |
| 34 browser()->window()->GetNativeWindow()]; |
32 controller_.reset([[OverlayableContentsController alloc] | 35 controller_.reset([[OverlayableContentsController alloc] |
33 initWithBrowser:browser() | 36 initWithBrowser:browser() |
34 windowController:nil]); | 37 windowController:window_controller]); |
35 [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)]; | 38 [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)]; |
36 instant_overlay_model_.AddObserver([controller_ instantOverlayController]); | 39 instant_overlay_model_.AddObserver([controller_ instantOverlayController]); |
37 } | 40 } |
38 | 41 |
39 virtual void CleanUpOnMainThread() OVERRIDE { | 42 virtual void CleanUpOnMainThread() OVERRIDE { |
40 instant_overlay_model_.RemoveObserver( | 43 instant_overlay_model_.RemoveObserver( |
41 [controller_ instantOverlayController]); | 44 [controller_ instantOverlayController]); |
42 instant_overlay_model_.SetOverlayContents(NULL); | 45 instant_overlay_model_.SetOverlayContents(NULL); |
43 controller_.reset(); | 46 controller_.reset(); |
44 web_contents_.reset(); | 47 web_contents_.reset(); |
45 } | 48 } |
46 | 49 |
47 void VerifyOverlayFrame(CGFloat expected_height, | 50 void VerifyOverlayFrame(CGFloat expected_height, |
48 InstantSizeUnits units) { | 51 InstantSizeUnits units) { |
49 NSRect container_bounds = [[controller_ view] bounds]; | 52 NSRect container_bounds = [[controller_ view] bounds]; |
| 53 container_bounds.size.height -= [OverlayTopSeparatorView preferredHeight]; |
50 NSRect overlay_frame = | 54 NSRect overlay_frame = |
51 [web_contents_->GetView()->GetNativeView() frame]; | 55 [web_contents_->GetView()->GetNativeView() frame]; |
52 | 56 |
53 EXPECT_EQ(NSMinX(container_bounds), NSMinX(overlay_frame)); | 57 EXPECT_EQ(NSMinX(container_bounds), NSMinX(overlay_frame)); |
54 EXPECT_EQ(NSWidth(container_bounds), NSWidth(overlay_frame)); | 58 EXPECT_EQ(NSWidth(container_bounds), NSWidth(overlay_frame)); |
55 switch (units) { | 59 switch (units) { |
56 case INSTANT_SIZE_PIXELS: | 60 case INSTANT_SIZE_PIXELS: |
57 EXPECT_EQ(expected_height, NSHeight(overlay_frame)); | 61 EXPECT_EQ(expected_height, NSHeight(overlay_frame)); |
58 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame)); | 62 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame)); |
59 break; | 63 break; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 110 |
107 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], | 111 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], |
108 [controller_ view]); | 112 [controller_ view]); |
109 VerifyOverlayFrame(expected_height, units); | 113 VerifyOverlayFrame(expected_height, units); |
110 | 114 |
111 // Resize the view and verify that the overlay is also resized. | 115 // Resize the view and verify that the overlay is also resized. |
112 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; | 116 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; |
113 VerifyOverlayFrame(expected_height, units); | 117 VerifyOverlayFrame(expected_height, units); |
114 } | 118 } |
115 | 119 |
116 // Verify that a shadow is not shown when the overlay covers the entire page | 120 // Verify that a bottom border is not shown when the overlay covers the entire |
117 // or when the overlay is in NTP mode. | 121 // page or when the overlay is in NTP mode. |
118 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) { | 122 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) { |
119 chrome::search::Mode mode; | 123 chrome::search::Mode mode; |
120 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; | 124 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; |
121 instant_overlay_model_.SetOverlayState(mode, 100, INSTANT_SIZE_PERCENT); | 125 instant_overlay_model_.SetOverlayState(mode, 100, INSTANT_SIZE_PERCENT); |
122 EXPECT_FALSE([controller_ dropShadowView]); | 126 EXPECT_FALSE([controller_ dropShadowView]); |
123 EXPECT_FALSE([controller_ drawDropShadow]); | 127 EXPECT_FALSE([controller_ drawDropShadow]); |
124 | 128 |
125 mode.mode = chrome::search::Mode::MODE_NTP; | 129 mode.mode = chrome::search::Mode::MODE_NTP; |
126 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); | 130 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); |
127 EXPECT_FALSE([controller_ dropShadowView]); | 131 EXPECT_FALSE([controller_ dropShadowView]); |
128 EXPECT_FALSE([controller_ drawDropShadow]); | 132 EXPECT_FALSE([controller_ drawDropShadow]); |
129 } | 133 } |
130 | 134 |
131 // Verify that a shadow is shown when the overlay is in search mode. | 135 // Verify that a shadow is shown when the overlay is in search mode. |
132 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowNTP) { | 136 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowNTP) { |
133 chrome::search::Mode mode; | 137 chrome::search::Mode mode; |
134 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; | 138 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; |
135 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); | 139 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); |
136 EXPECT_TRUE([controller_ dropShadowView]); | 140 EXPECT_TRUE([controller_ dropShadowView]); |
137 EXPECT_TRUE([controller_ drawDropShadow]); | 141 EXPECT_TRUE([controller_ drawDropShadow]); |
138 EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]); | 142 EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]); |
139 | 143 |
140 NSRect dropShadowFrame = [[controller_ dropShadowView] frame]; | 144 NSRect dropShadowFrame = [[controller_ dropShadowView] frame]; |
141 NSRect controllerBounds = [[controller_ view] bounds]; | 145 NSRect controllerBounds = [[controller_ view] bounds]; |
142 EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame)); | 146 EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame)); |
143 EXPECT_EQ([OverlayDropShadowView preferredHeight], | 147 EXPECT_EQ([OverlayBottomSeparatorView preferredHeight], |
144 NSHeight(dropShadowFrame)); | 148 NSHeight(dropShadowFrame)); |
145 } | 149 } |
146 | 150 |
147 // Verify that the shadow is hidden when hiding the overlay. | 151 // Verify that the shadow is hidden when hiding the overlay. |
148 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) { | 152 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) { |
149 chrome::search::Mode mode; | 153 chrome::search::Mode mode; |
150 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; | 154 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; |
151 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); | 155 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); |
152 EXPECT_TRUE([controller_ dropShadowView]); | 156 EXPECT_TRUE([controller_ dropShadowView]); |
153 | 157 |
154 [controller_ onActivateTabWithContents:web_contents_.get()]; | 158 [controller_ onActivateTabWithContents:web_contents_.get()]; |
155 EXPECT_FALSE([controller_ dropShadowView]); | 159 EXPECT_FALSE([controller_ dropShadowView]); |
156 } | 160 } |
157 | 161 |
158 // Verify that the web contents is not hidden when just the height changes. | 162 // Verify that the web contents is not hidden when just the height changes. |
159 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HeightChangeNoHide) { | 163 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HeightChangeNoHide) { |
160 chrome::search::Mode mode; | 164 chrome::search::Mode mode; |
161 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; | 165 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; |
162 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); | 166 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); |
163 | 167 |
164 registrar_.Add(this, | 168 registrar_.Add(this, |
165 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 169 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
166 content::Source<content::WebContents>(web_contents_.get())); | 170 content::Source<content::WebContents>(web_contents_.get())); |
167 EXPECT_EQ(0, visibility_changed_count_); | 171 EXPECT_EQ(0, visibility_changed_count_); |
168 instant_overlay_model_.SetOverlayState(mode, 11, INSTANT_SIZE_PERCENT); | 172 instant_overlay_model_.SetOverlayState(mode, 11, INSTANT_SIZE_PERCENT); |
169 EXPECT_EQ(1, visibility_changed_count_); | 173 EXPECT_EQ(1, visibility_changed_count_); |
170 } | 174 } |
OLD | NEW |