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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 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/instant/instant_overlay_model.h" 7 #include "chrome/browser/instant/instant_overlay_model.h"
8 #include "chrome/browser/instant/instant_service_factory.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 12 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" 13 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h"
13 #include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" 14 #include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h"
14 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
15 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 18 #include "content/public/browser/web_contents_view.h"
18 #import "testing/gtest_mac.h" 19 #import "testing/gtest_mac.h"
19 20
20 class OverlayableContentsControllerTest : public InProcessBrowserTest, 21 class OverlayableContentsControllerTest : public InProcessBrowserTest,
21 public content::NotificationObserver { 22 public content::NotificationObserver {
22 public: 23 public:
23 OverlayableContentsControllerTest() : instant_overlay_model_(NULL), 24 OverlayableContentsControllerTest() : 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());
31 30
32 controller_.reset([[OverlayableContentsController alloc] 31 controller_.reset([[OverlayableContentsController alloc]
33 initWithBrowser:browser() 32 initWithBrowser:browser()
34 windowController:nil]); 33 windowController:nil]);
35 [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)]; 34 [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)];
36 instant_overlay_model_.AddObserver([controller_ instantOverlayController]); 35
36 instant_overlay_model_.reset(new InstantOverlayModel(
37 InstantServiceFactory::GetForProfile(browser()->profile())));
38 instant_overlay_model_->AddObserver([controller_ instantOverlayController]);
37 } 39 }
38 40
39 virtual void CleanUpOnMainThread() OVERRIDE { 41 virtual void CleanUpOnMainThread() OVERRIDE {
40 instant_overlay_model_.RemoveObserver( 42 instant_overlay_model_->RemoveObserver(
41 [controller_ instantOverlayController]); 43 [controller_ instantOverlayController]);
42 instant_overlay_model_.SetOverlayContents(NULL);
43 controller_.reset(); 44 controller_.reset();
44 web_contents_.reset(); 45 web_contents_.reset();
45 } 46 }
46 47
47 void VerifyOverlayFrame(CGFloat expected_height, 48 void VerifyOverlayFrame(CGFloat expected_height,
48 InstantSizeUnits units) { 49 InstantSizeUnits units) {
49 NSRect container_bounds = [[controller_ view] bounds]; 50 NSRect container_bounds = [[controller_ view] bounds];
50 NSRect overlay_frame = 51 NSRect overlay_frame =
51 [web_contents_->GetView()->GetNativeView() frame]; 52 [web_contents_->GetView()->GetNativeView() frame];
52 53
(...skipping 12 matching lines...) Expand all
65 } 66 }
66 67
67 virtual void Observe(int type, 68 virtual void Observe(int type,
68 const content::NotificationSource& source, 69 const content::NotificationSource& source,
69 const content::NotificationDetails& details) OVERRIDE { 70 const content::NotificationDetails& details) OVERRIDE {
70 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) 71 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED)
71 ++visibility_changed_count_; 72 ++visibility_changed_count_;
72 } 73 }
73 74
74 protected: 75 protected:
75 InstantOverlayModel instant_overlay_model_; 76 scoped_ptr<InstantOverlayModel> instant_overlay_model_;
76 scoped_ptr<content::WebContents> web_contents_; 77 scoped_ptr<content::WebContents> web_contents_;
77 scoped_nsobject<OverlayableContentsController> controller_; 78 scoped_nsobject<OverlayableContentsController> controller_;
78 content::NotificationRegistrar registrar_; 79 content::NotificationRegistrar registrar_;
79 int visibility_changed_count_; 80 int visibility_changed_count_;
80 }; 81 };
81 82
82 // Verify that the view is correctly laid out when size is specified in percent. 83 // Verify that the view is correctly laid out when size is specified in percent.
83 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePerecent) { 84 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePerecent) {
84 chrome::search::Mode mode;
85 mode.mode = chrome::search::Mode::MODE_NTP;
86 CGFloat expected_height = 30; 85 CGFloat expected_height = 30;
87 InstantSizeUnits units = INSTANT_SIZE_PERCENT; 86 InstantSizeUnits units = INSTANT_SIZE_PERCENT;
88 instant_overlay_model_.SetOverlayState(mode, expected_height, units); 87 instant_overlay_model_->SetOverlayState(web_contents_.get(),
88 expected_height, units);
89 89
90 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], 90 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview],
91 [controller_ view]); 91 [controller_ view]);
92 VerifyOverlayFrame(expected_height, units); 92 VerifyOverlayFrame(expected_height, units);
93 93
94 // Resize the view and verify that the overlay is also resized. 94 // Resize the view and verify that the overlay is also resized.
95 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; 95 [[controller_ view] setFrameSize:NSMakeSize(300, 400)];
96 VerifyOverlayFrame(expected_height, units); 96 VerifyOverlayFrame(expected_height, units);
97 } 97 }
98 98
99 // Verify that the view is correctly laid out when size is specified in pixels. 99 // Verify that the view is correctly laid out when size is specified in pixels.
100 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePixels) { 100 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePixels) {
101 chrome::search::Mode mode;
102 mode.mode = chrome::search::Mode::MODE_NTP;
103 CGFloat expected_height = 30; 101 CGFloat expected_height = 30;
104 InstantSizeUnits units = INSTANT_SIZE_PIXELS; 102 InstantSizeUnits units = INSTANT_SIZE_PIXELS;
105 instant_overlay_model_.SetOverlayState(mode, expected_height, units); 103 instant_overlay_model_->SetOverlayState(web_contents_.get(),
104 expected_height, units);
106 105
107 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], 106 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview],
108 [controller_ view]); 107 [controller_ view]);
109 VerifyOverlayFrame(expected_height, units); 108 // TODO(sail): Remove the "- 1" when the overlay no longer has a separator.
109 VerifyOverlayFrame(expected_height - 1, units);
110 110
111 // Resize the view and verify that the overlay is also resized. 111 // Resize the view and verify that the overlay is also resized.
112 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; 112 [[controller_ view] setFrameSize:NSMakeSize(300, 400)];
113 VerifyOverlayFrame(expected_height, units); 113 // TODO(sail): Remove the "- 1" when the overlay no longer has a separator.
114 VerifyOverlayFrame(expected_height - 1, units);
114 } 115 }
115 116
116 // Verify that a shadow is not shown when the overlay covers the entire page 117 // Verify that a shadow is not shown when the overlay covers the entire page.
117 // or when the overlay is in NTP mode. 118 // or when the overlay is not showing.
118 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) { 119 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) {
119 chrome::search::Mode mode; 120 instant_overlay_model_->SetOverlayState(web_contents_.get(),
120 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; 121 100, INSTANT_SIZE_PERCENT);
121 instant_overlay_model_.SetOverlayState(mode, 100, INSTANT_SIZE_PERCENT);
122 EXPECT_FALSE([controller_ dropShadowView]); 122 EXPECT_FALSE([controller_ dropShadowView]);
123 EXPECT_FALSE([controller_ drawDropShadow]); 123 EXPECT_FALSE([controller_ drawDropShadow]);
124 124
125 mode.mode = chrome::search::Mode::MODE_NTP; 125 instant_overlay_model_->SetOverlayState(web_contents_.get(),
126 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); 126 10, INSTANT_SIZE_PERCENT);
127 EXPECT_TRUE([controller_ dropShadowView]);
128 EXPECT_TRUE([controller_ drawDropShadow]);
129
130 instant_overlay_model_->SetOverlayState(NULL, 0, INSTANT_SIZE_PIXELS);
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 instant_overlay_model_->SetOverlayState(web_contents_.get(),
134 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; 138 10, INSTANT_SIZE_PERCENT);
135 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT);
136 EXPECT_TRUE([controller_ dropShadowView]); 139 EXPECT_TRUE([controller_ dropShadowView]);
137 EXPECT_TRUE([controller_ drawDropShadow]); 140 EXPECT_TRUE([controller_ drawDropShadow]);
138 EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]); 141 EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]);
139 142
140 NSRect dropShadowFrame = [[controller_ dropShadowView] frame]; 143 NSRect dropShadowFrame = [[controller_ dropShadowView] frame];
141 NSRect controllerBounds = [[controller_ view] bounds]; 144 NSRect controllerBounds = [[controller_ view] bounds];
142 EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame)); 145 EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame));
143 EXPECT_EQ([OverlayDropShadowView preferredHeight], 146 EXPECT_EQ([OverlayDropShadowView preferredHeight],
144 NSHeight(dropShadowFrame)); 147 NSHeight(dropShadowFrame));
145 } 148 }
146 149
147 // Verify that the shadow is hidden when hiding the overlay. 150 // Verify that the shadow is hidden when hiding the overlay.
148 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) { 151 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) {
149 chrome::search::Mode mode; 152 instant_overlay_model_->SetOverlayState(web_contents_.get(),
150 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; 153 10, INSTANT_SIZE_PERCENT);
151 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT);
152 EXPECT_TRUE([controller_ dropShadowView]); 154 EXPECT_TRUE([controller_ dropShadowView]);
153 155
154 [controller_ onActivateTabWithContents:web_contents_.get()]; 156 [controller_ onActivateTabWithContents:web_contents_.get()];
155 EXPECT_FALSE([controller_ dropShadowView]); 157 EXPECT_FALSE([controller_ dropShadowView]);
156 } 158 }
157 159
158 // Verify that the web contents is not hidden when just the height changes. 160 // Verify that the web contents is not hidden when just the height changes.
159 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HeightChangeNoHide) { 161 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HeightChangeNoHide) {
160 chrome::search::Mode mode; 162 instant_overlay_model_->SetOverlayState(web_contents_.get(),
161 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; 163 10, INSTANT_SIZE_PERCENT);
162 instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT);
163 164
164 registrar_.Add(this, 165 registrar_.Add(this,
165 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, 166 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
166 content::Source<content::WebContents>(web_contents_.get())); 167 content::Source<content::WebContents>(web_contents_.get()));
167 EXPECT_EQ(0, visibility_changed_count_); 168 EXPECT_EQ(0, visibility_changed_count_);
168 instant_overlay_model_.SetOverlayState(mode, 11, INSTANT_SIZE_PERCENT); 169
170 instant_overlay_model_->SetOverlayState(web_contents_.get(),
171 11, INSTANT_SIZE_PERCENT);
169 EXPECT_EQ(1, visibility_changed_count_); 172 EXPECT_EQ(1, visibility_changed_count_);
170 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698