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

Side by Side Diff: chrome/browser/ui/panels/old_panel_and_desktop_notification_browsertest.cc

Issue 10908153: [Panel refactor] Deprecate old panels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux_chromeos test failure Created 8 years, 3 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
(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 "base/utf_string_conversions.h"
6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/notifications/balloon.h"
8 #include "chrome/browser/notifications/balloon_collection_impl.h"
9 #include "chrome/browser/notifications/desktop_notification_service.h"
10 #include "chrome/browser/notifications/notification.h"
11 #include "chrome/browser/notifications/notification_ui_manager.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/panels/old_base_panel_browser_test.h"
15 #include "chrome/browser/ui/panels/panel.h"
16 #include "chrome/browser/ui/panels/panel_manager.h"
17 #include "chrome/common/pref_names.h"
18 #include "content/public/common/show_desktop_notification_params.h"
19 #include "ui/gfx/screen.h"
20
21 // Desktop notification code subscribes to various panel change notifications
22 // so that it knows when to adjusts balloon positions. In order to give
23 // desktop notification code a chance to process the change notifications,
24 // we call MessageLoopForUI::current()->RunAllPending() after any panel change
25 // has been made.
26 class OldPanelAndDesktopNotificationTest : public OldBasePanelBrowserTest {
27 public:
28 OldPanelAndDesktopNotificationTest() : OldBasePanelBrowserTest() {
29 }
30
31 virtual ~OldPanelAndDesktopNotificationTest() {
32 }
33
34 virtual void SetUpOnMainThread() OVERRIDE {
35 // Do not use our own testing work area since desktop notification code
36 // does not have the hook up for testing work area.
37 disable_display_settings_mock();
38
39 OldBasePanelBrowserTest::SetUpOnMainThread();
40
41 g_browser_process->local_state()->SetInteger(
42 prefs::kDesktopNotificationPosition, BalloonCollection::LOWER_RIGHT);
43 balloons_ = new BalloonCollectionImpl();
44 ui_manager_.reset(NotificationUIManager::Create(
45 g_browser_process->local_state(), balloons_));
46 service_.reset(new DesktopNotificationService(browser()->profile(),
47 ui_manager_.get()));
48 }
49
50 virtual void CleanUpOnMainThread() OVERRIDE {
51 balloons_->RemoveAll();
52 MessageLoopForUI::current()->RunAllPending();
53
54 service_.reset();
55 ui_manager_.reset();
56
57 OldBasePanelBrowserTest::CleanUpOnMainThread();
58 }
59
60 content::ShowDesktopNotificationHostMsgParams StandardTestNotification() {
61 content::ShowDesktopNotificationHostMsgParams params;
62 params.notification_id = 0;
63 params.origin = GURL("http://www.google.com");
64 params.is_html = false;
65 params.icon_url = GURL("/icon.png");
66 params.title = ASCIIToUTF16("Title");
67 params.body = ASCIIToUTF16("Text");
68 params.direction = WebKit::WebTextDirectionDefault;
69 return params;
70 }
71
72 Balloon* CreateBalloon() {
73 content::ShowDesktopNotificationHostMsgParams params =
74 StandardTestNotification();
75 EXPECT_TRUE(service()->ShowDesktopNotification(
76 params, 0, 0, DesktopNotificationService::PageNotification));
77 MessageLoopForUI::current()->RunAllPending();
78 return balloons().front();
79 }
80
81 static int GetBalloonBottomPosition(Balloon* balloon) {
82 #if defined(OS_MACOSX)
83 // The position returned by the notification balloon is based on Mac's
84 // vertically inverted orientation. We need to flip it so that it can
85 // be compared against the position returned by the panel.
86 gfx::Size screen_size = gfx::Screen::GetPrimaryDisplay().size();
87 return screen_size.height() - balloon->GetPosition().y();
88 #else
89 return balloon->GetPosition().y() + balloon->GetViewSize().height();
90 #endif
91 }
92
93 static void DragPanelToMouseLocation(Panel* panel,
94 const gfx::Point& new_mouse_location) {
95 PanelManager* panel_manager = PanelManager::GetInstance();
96 panel_manager->StartDragging(panel, panel->GetBounds().origin());
97 panel_manager->Drag(new_mouse_location);
98 panel_manager->EndDragging(false);
99 }
100
101 static void ResizePanelByMouseWithDelta(Panel* panel,
102 panel::ResizingSides side,
103 const gfx::Point& delta) {
104 PanelManager* panel_manager = PanelManager::GetInstance();
105 gfx::Point mouse_location = panel->GetBounds().origin();
106 panel_manager->StartResizingByMouse(panel, mouse_location, side);
107 panel_manager->ResizeByMouse(mouse_location.Add(delta));
108 panel_manager->EndResizingByMouse(false);
109 }
110
111 DesktopNotificationService* service() const { return service_.get(); }
112 const BalloonCollection::Balloons& balloons() const {
113 return balloons_->GetActiveBalloons();
114 }
115
116 private:
117 BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager.
118 scoped_ptr<NotificationUIManager> ui_manager_;
119 scoped_ptr<DesktopNotificationService> service_;
120 };
121
122 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest, AddAndClosePanel) {
123 Balloon* balloon = CreateBalloon();
124 int original_balloon_bottom = GetBalloonBottomPosition(balloon);
125
126 // Create a docked panel. Expect that the notification balloon moves up to be
127 // above the panel.
128 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
129 MessageLoopForUI::current()->RunAllPending();
130 int balloon_bottom = GetBalloonBottomPosition(balloon);
131 EXPECT_LT(balloon_bottom, panel->GetBounds().y());
132 EXPECT_LT(balloon_bottom, original_balloon_bottom);
133
134 // Close the panel. Expect the notification balloon moves back to its original
135 // position.
136 panel->Close();
137 MessageLoopForUI::current()->RunAllPending();
138 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
139 }
140
141 // http://crbug.com/133612
142 #if defined(OS_LINUX)
143 #define MAYBE_ExpandAndCollapsePanel DISABLED_ExpandAndCollapsePanel
144 #else
145 #define MAYBE_ExpandAndCollapsePanel ExpandAndCollapsePanel
146 #endif
147
148 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest,
149 MAYBE_ExpandAndCollapsePanel) {
150 Balloon* balloon = CreateBalloon();
151
152 // Create a docked panel. Expect that the notification balloon moves up to be
153 // above the panel.
154 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
155 MessageLoopForUI::current()->RunAllPending();
156 int balloon_bottom_on_expanded = GetBalloonBottomPosition(balloon);
157 EXPECT_LT(balloon_bottom_on_expanded, panel->GetBounds().y());
158
159 // Minimize the panel. Expect that the notification balloon moves down, but
160 // still above the minimized panel.
161 panel->Minimize();
162 MessageLoopForUI::current()->RunAllPending();
163 int balloon_bottom_on_minimized = GetBalloonBottomPosition(balloon);
164 EXPECT_LT(balloon_bottom_on_minimized, panel->GetBounds().y());
165 EXPECT_LT(balloon_bottom_on_expanded, balloon_bottom_on_minimized);
166
167 // Bring up the title-bar for the panel by drawing attention. Expect that the
168 // notification balloon moves up a little bit to be still above the title-only
169 // panel.
170 panel->FlashFrame(true);
171 MessageLoopForUI::current()->RunAllPending();
172 int balloon_bottom_on_title_only = GetBalloonBottomPosition(balloon);
173 EXPECT_LT(balloon_bottom_on_title_only, panel->GetBounds().y());
174 EXPECT_LT(balloon_bottom_on_title_only, balloon_bottom_on_minimized);
175 EXPECT_LT(balloon_bottom_on_expanded, balloon_bottom_on_title_only);
176
177 // Expand the panel. Expect that the notification balloon moves up to go back
178 // to the same position when the panel is expanded.
179 panel->Restore();
180 MessageLoopForUI::current()->RunAllPending();
181 EXPECT_EQ(balloon_bottom_on_expanded, GetBalloonBottomPosition(balloon));
182
183 PanelManager::GetInstance()->CloseAll();
184 }
185
186 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest, DragNarrowPanel) {
187 Balloon* balloon = CreateBalloon();
188
189 // Let the panel width be smaller than the balloon width.
190 int panel_width = balloon->GetViewSize().width() - 50;
191
192 // Create 2 docked panels. Expect that the notification balloon moves up to be
193 // above the tall panel.
194 Panel* tall_panel = CreateDockedPanel("1", gfx::Rect(0, 0, panel_width, 300));
195 Panel* short_panel = CreateDockedPanel(
196 "2", gfx::Rect(0, 0, panel_width, 200));
197 MessageLoopForUI::current()->RunAllPending();
198 int balloon_bottom = GetBalloonBottomPosition(balloon);
199 EXPECT_LT(balloon_bottom, tall_panel->GetBounds().y());
200
201 // Swap 2 docked panels by dragging. Expect that the notificaition balloon
202 // remains at the same position.
203 DragPanelToMouseLocation(tall_panel, short_panel->GetBounds().origin());
204 MessageLoopForUI::current()->RunAllPending();
205 EXPECT_EQ(balloon_bottom, GetBalloonBottomPosition(balloon));
206
207 PanelManager::GetInstance()->CloseAll();
208 }
209
210 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest, DragWidePanel) {
211 Balloon* balloon = CreateBalloon();
212
213 // Let the panel width be greater than the balloon width.
214 int panel_width = balloon->GetViewSize().width() + 50;
215
216 // Create 2 docked panels. Expect that the notification balloon moves up to be
217 // above the tall panel.
218 Panel* tall_panel = CreateDockedPanel("1", gfx::Rect(0, 0, panel_width, 300));
219 Panel* short_panel = CreateDockedPanel(
220 "2", gfx::Rect(0, 0, panel_width, 200));
221 MessageLoopForUI::current()->RunAllPending();
222 int balloon_bottom_before_drag = GetBalloonBottomPosition(balloon);
223 EXPECT_LT(balloon_bottom_before_drag, tall_panel->GetBounds().y());
224
225 // Swap 2 docked panels by dragging. Expect that the notificaiton balloon
226 // moves down to be just above the short panel.
227 DragPanelToMouseLocation(tall_panel, short_panel->GetBounds().origin());
228 MessageLoopForUI::current()->RunAllPending();
229 int balloon_bottom_after_drag = GetBalloonBottomPosition(balloon);
230 EXPECT_LT(balloon_bottom_after_drag, short_panel->GetBounds().y());
231 EXPECT_LT(balloon_bottom_before_drag, balloon_bottom_after_drag);
232
233 PanelManager::GetInstance()->CloseAll();
234 }
235
236 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest,
237 DetachAndAttachPanel) {
238 PanelManager* panel_manager = PanelManager::GetInstance();
239 Balloon* balloon = CreateBalloon();
240 int original_balloon_bottom = GetBalloonBottomPosition(balloon);
241
242 // Create a docked panel. Expect that the notification balloon moves up to be
243 // above the panel.
244 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
245 MessageLoopForUI::current()->RunAllPending();
246 int balloon_bottom_after_panel_created = GetBalloonBottomPosition(balloon);
247 EXPECT_LT(balloon_bottom_after_panel_created, panel->GetBounds().y());
248 EXPECT_LT(balloon_bottom_after_panel_created, original_balloon_bottom);
249
250 // Detach the panel. Expect that the notification balloon moves down to its
251 // original position.
252 panel_manager->MovePanelToStrip(
253 panel, PanelStrip::DETACHED, PanelStrip::DEFAULT_POSITION);
254 MessageLoopForUI::current()->RunAllPending();
255 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type());
256 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
257
258 // Reattach the panel. Expect that the notification balloon moves above the
259 // panel.
260 panel_manager->MovePanelToStrip(
261 panel, PanelStrip::DOCKED, PanelStrip::DEFAULT_POSITION);
262 MessageLoopForUI::current()->RunAllPending();
263 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type());
264 EXPECT_EQ(balloon_bottom_after_panel_created,
265 GetBalloonBottomPosition(balloon));
266
267 panel_manager->CloseAll();
268 }
269
270 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest, ResizePanel) {
271 PanelManager* panel_manager = PanelManager::GetInstance();
272 Balloon* balloon = CreateBalloon();
273
274 // Create a docked panel. Expect that the notification balloon moves up to be
275 // above the panel.
276 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
277 MessageLoopForUI::current()->RunAllPending();
278 int balloon_bottom = GetBalloonBottomPosition(balloon);
279 gfx::Rect original_bounds = panel->GetBounds();
280 EXPECT_LT(balloon_bottom, original_bounds.y());
281
282 // Resize the panel to make it taller. Expect that the notification balloon
283 // moves further up by the amount of enlarge offset.
284 gfx::Point resize_delta(50, 100);
285 gfx::Rect new_bounds = original_bounds;
286 new_bounds.set_width(new_bounds.width() + resize_delta.x());
287 new_bounds.set_height(new_bounds.height() + resize_delta.y());
288 panel->SetBounds(new_bounds);
289 MessageLoopForUI::current()->RunAllPending();
290 int balloon_bottom2 = GetBalloonBottomPosition(balloon);
291 EXPECT_EQ(balloon_bottom - resize_delta.y(), balloon_bottom2);
292
293 // Resize the panel to make it shorter. Expect that the notification balloon
294 // moves down by the amount of shrink offset.
295 resize_delta = gfx::Point(0, -60);
296 new_bounds.set_width(new_bounds.width() + resize_delta.x());
297 new_bounds.set_height(new_bounds.height() + resize_delta.y());
298 panel->SetBounds(new_bounds);
299 MessageLoopForUI::current()->RunAllPending();
300 int balloon_bottom3 = GetBalloonBottomPosition(balloon);
301 EXPECT_EQ(balloon_bottom2 - resize_delta.y(), balloon_bottom3);
302
303 panel_manager->CloseAll();
304 }
305
306 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest, ResizePanelByMouse) {
307 Balloon* balloon = CreateBalloon();
308
309 // Create a docked panel. Expect that the notification balloon moves up to be
310 // above the panel.
311 Panel* panel = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 200));
312 MessageLoopForUI::current()->RunAllPending();
313 int balloon_bottom = GetBalloonBottomPosition(balloon);
314 EXPECT_LT(balloon_bottom, panel->GetBounds().y());
315
316 // Resize the panel to make it taller. Expect that the notification balloon
317 // moves further up by the amount of enlarge offset.
318 gfx::Point drag_delta(-50, -100);
319 ResizePanelByMouseWithDelta(panel, panel::RESIZE_TOP_LEFT, drag_delta);
320 MessageLoopForUI::current()->RunAllPending();
321 int balloon_bottom2 = GetBalloonBottomPosition(balloon);
322 EXPECT_EQ(balloon_bottom + drag_delta.y(), balloon_bottom2);
323
324 // Resize the panel to make it shorter. Expect that the notification balloon
325 // moves down by the amount of shrink offset.
326 drag_delta = gfx::Point(0, 60);
327 ResizePanelByMouseWithDelta(panel, panel::RESIZE_TOP, drag_delta);
328 MessageLoopForUI::current()->RunAllPending();
329 int balloon_bottom3 = GetBalloonBottomPosition(balloon);
330 EXPECT_EQ(balloon_bottom2 + drag_delta.y(), balloon_bottom3);
331
332 PanelManager::GetInstance()->CloseAll();
333 }
334
335 // http://crbug.com/133368
336 #if defined(OS_MACOSX)
337 #define MAYBE_InteractWithTwoPanels DISABLED_InteractWithTwoPanels
338 #else
339 #define MAYBE_InteractWithTwoPanels InteractWithTwoPanels
340 #endif
341
342 IN_PROC_BROWSER_TEST_F(OldPanelAndDesktopNotificationTest,
343 MAYBE_InteractWithTwoPanels) {
344 Balloon* balloon = CreateBalloon();
345 int original_balloon_bottom = GetBalloonBottomPosition(balloon);
346
347 // Let the panel width be smaller than the balloon width.
348 int panel_width = balloon->GetViewSize().width() - 50;
349
350 // Create a short panel. Expect that the notification balloon moves up to be
351 // above the short panel.
352 Panel* short_panel = CreateDockedPanel(
353 "1", gfx::Rect(0, 0, panel_width, 150));
354 MessageLoopForUI::current()->RunAllPending();
355 int balloon_bottom_after_short_panel_created =
356 GetBalloonBottomPosition(balloon);
357 EXPECT_LT(balloon_bottom_after_short_panel_created,
358 short_panel->GetBounds().y());
359 EXPECT_LT(balloon_bottom_after_short_panel_created, original_balloon_bottom);
360
361 // Create a tall panel. Expect that the notification balloon moves further up
362 // to be above the tall panel.
363 Panel* tall_panel = CreateDockedPanel("2", gfx::Rect(0, 0, panel_width, 200));
364 MessageLoopForUI::current()->RunAllPending();
365 int balloon_bottom_after_tall_panel_created =
366 GetBalloonBottomPosition(balloon);
367 EXPECT_LT(balloon_bottom_after_tall_panel_created,
368 tall_panel->GetBounds().y());
369 EXPECT_LT(balloon_bottom_after_tall_panel_created,
370 balloon_bottom_after_short_panel_created);
371
372 // Minimize tall panel. Expect that the notification balloon moves down to the
373 // same position when short panel is first created.
374 tall_panel->Minimize();
375 MessageLoopForUI::current()->RunAllPending();
376 int balloon_bottom_after_tall_panel_minimized =
377 GetBalloonBottomPosition(balloon);
378 EXPECT_EQ(balloon_bottom_after_short_panel_created,
379 balloon_bottom_after_tall_panel_minimized);
380
381 // Minimize short panel. Expect that the notification balloon moves further
382 // down.
383 short_panel->Minimize();
384 MessageLoopForUI::current()->RunAllPending();
385 int balloon_bottom_after_both_panels_minimized =
386 GetBalloonBottomPosition(balloon);
387 EXPECT_LT(balloon_bottom_after_both_panels_minimized,
388 short_panel->GetBounds().y());
389 EXPECT_LT(balloon_bottom_after_both_panels_minimized,
390 tall_panel->GetBounds().y());
391 EXPECT_LT(balloon_bottom_after_short_panel_created,
392 balloon_bottom_after_both_panels_minimized);
393 EXPECT_LT(balloon_bottom_after_both_panels_minimized,
394 original_balloon_bottom);
395
396 // Expand short panel. Expect that the notification balloon moves further up
397 // to the same position when short panel is first created.
398 short_panel->Restore();
399 MessageLoopForUI::current()->RunAllPending();
400 int balloon_bottom_after_short_panel_expanded =
401 GetBalloonBottomPosition(balloon);
402 EXPECT_EQ(balloon_bottom_after_short_panel_created,
403 balloon_bottom_after_short_panel_expanded);
404
405 // Close tall panel. Expect that the notification balloon moves down to the
406 // same position when short panel is first created.
407 tall_panel->Close();
408 MessageLoopForUI::current()->RunAllPending();
409 EXPECT_EQ(balloon_bottom_after_short_panel_created,
410 GetBalloonBottomPosition(balloon));
411
412 // Close short panel. Expect that the notification balloo moves back to its
413 // original position.
414 short_panel->Close();
415 MessageLoopForUI::current()->RunAllPending();
416 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
417 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/old_panel.cc ('k') | chrome/browser/ui/panels/old_panel_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698