Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / panels / panel_browsertest.cc
blob2c0ffc7843b7c52e8df46feb06f1350175cc5012
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.
5 #include "base/bind.h"
6 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/devtools/devtools_window.h"
11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/net/url_request_mock_util.h"
13 #include "chrome/browser/prefs/browser_prefs.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
16 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_iterator.h"
21 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
23 #include "chrome/browser/ui/panels/docked_panel_collection.h"
24 #include "chrome/browser/ui/panels/native_panel.h"
25 #include "chrome/browser/ui/panels/panel.h"
26 #include "chrome/browser/ui/panels/panel_manager.h"
27 #include "chrome/browser/ui/panels/test_panel_active_state_observer.h"
28 #include "chrome/browser/web_applications/web_app.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/interactive_test_utils.h"
33 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/native_web_keyboard_event.h"
35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/web_contents.h"
37 #include "content/public/common/url_constants.h"
38 #include "content/public/test/browser_test_utils.h"
39 #include "content/test/net/url_request_mock_http_job.h"
40 #include "extensions/common/constants.h"
41 #include "net/base/net_util.h"
42 #include "testing/gtest/include/gtest/gtest.h"
43 #include "ui/events/event_utils.h"
44 #include "ui/gfx/screen.h"
46 using content::WebContents;
48 class PanelBrowserTest : public BasePanelBrowserTest {
49 public:
50 PanelBrowserTest() : BasePanelBrowserTest() {
53 protected:
54 // Helper function for debugging.
55 void PrintAllPanelBounds() {
56 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
57 DLOG(WARNING) << "PanelBounds:";
58 for (size_t i = 0; i < panels.size(); ++i) {
59 DLOG(WARNING) << "#=" << i
60 << ", ptr=" << panels[i]
61 << ", x=" << panels[i]->GetBounds().x()
62 << ", y=" << panels[i]->GetBounds().y()
63 << ", width=" << panels[i]->GetBounds().width()
64 << ", height" << panels[i]->GetBounds().height();
68 std::vector<gfx::Rect> GetAllPanelBounds() {
69 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
70 std::vector<gfx::Rect> bounds;
71 for (size_t i = 0; i < panels.size(); i++)
72 bounds.push_back(panels[i]->GetBounds());
73 return bounds;
76 std::vector<gfx::Rect> AddXDeltaToBounds(const std::vector<gfx::Rect>& bounds,
77 const std::vector<int>& delta_x) {
78 std::vector<gfx::Rect> new_bounds = bounds;
79 for (size_t i = 0; i < bounds.size(); ++i)
80 new_bounds[i].Offset(delta_x[i], 0);
81 return new_bounds;
84 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() {
85 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
86 std::vector<Panel::ExpansionState> expansion_states;
87 for (size_t i = 0; i < panels.size(); i++)
88 expansion_states.push_back(panels[i]->expansion_state());
89 return expansion_states;
92 std::vector<bool> GetAllPanelActiveStates() {
93 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
94 std::vector<bool> active_states;
95 for (size_t i = 0; i < panels.size(); i++)
96 active_states.push_back(panels[i]->IsActive());
97 return active_states;
100 std::vector<bool> ProduceExpectedActiveStates(
101 int expected_active_panel_index) {
102 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
103 std::vector<bool> active_states;
104 for (int i = 0; i < static_cast<int>(panels.size()); i++)
105 active_states.push_back(i == expected_active_panel_index);
106 return active_states;
109 void WaitForPanelActiveStates(const std::vector<bool>& old_states,
110 const std::vector<bool>& new_states) {
111 DCHECK(old_states.size() == new_states.size());
112 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
113 for (size_t i = 0; i < old_states.size(); i++) {
114 if (old_states[i] != new_states[i]){
115 WaitForPanelActiveState(
116 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE);
121 void TestMinimizeRestore() {
122 // This constant is used to generate a point 'sufficiently higher then
123 // top edge of the panel'. On some platforms (Mac) we extend hover area
124 // a bit above the minimized panel as well, so it takes significant
125 // distance to 'move mouse out' of the hover-sensitive area.
126 const int kFarEnoughFromHoverArea = 153;
128 PanelManager* panel_manager = PanelManager::GetInstance();
129 std::vector<Panel*> panels = panel_manager->panels();
130 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds();
131 std::vector<gfx::Rect> expected_bounds = test_begin_bounds;
132 std::vector<Panel::ExpansionState> expected_expansion_states(
133 panels.size(), Panel::EXPANDED);
134 std::vector<NativePanelTesting*> native_panels_testing(panels.size());
135 for (size_t i = 0; i < panels.size(); ++i) {
136 native_panels_testing[i] = CreateNativePanelTesting(panels[i]);
139 // Verify titlebar click does not minimize.
140 for (size_t index = 0; index < panels.size(); ++index) {
141 // Press left mouse button. Verify nothing changed.
142 native_panels_testing[index]->PressLeftMouseButtonTitlebar(
143 panels[index]->GetBounds().origin());
144 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
145 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
147 // Release mouse button. Verify nothing changed.
148 native_panels_testing[index]->ReleaseMouseButtonTitlebar();
149 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
150 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
153 // Minimize all panels for next stage in test.
154 for (size_t index = 0; index < panels.size(); ++index) {
155 panels[index]->Minimize();
156 expected_bounds[index].set_height(panel::kMinimizedPanelHeight);
157 expected_bounds[index].set_y(
158 test_begin_bounds[index].y() +
159 test_begin_bounds[index].height() - panel::kMinimizedPanelHeight);
160 expected_expansion_states[index] = Panel::MINIMIZED;
161 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
162 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
165 // Setup bounds and expansion states for minimized and titlebar-only
166 // states.
167 std::vector<Panel::ExpansionState> titlebar_exposed_states(
168 panels.size(), Panel::TITLE_ONLY);
169 std::vector<gfx::Rect> minimized_bounds = expected_bounds;
170 std::vector<Panel::ExpansionState> minimized_states(
171 panels.size(), Panel::MINIMIZED);
172 std::vector<gfx::Rect> titlebar_exposed_bounds = test_begin_bounds;
173 for (size_t index = 0; index < panels.size(); ++index) {
174 titlebar_exposed_bounds[index].set_height(
175 panels[index]->native_panel()->TitleOnlyHeight());
176 titlebar_exposed_bounds[index].set_y(
177 test_begin_bounds[index].y() +
178 test_begin_bounds[index].height() -
179 panels[index]->native_panel()->TitleOnlyHeight());
182 // Test hover. All panels are currently in minimized state.
183 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
184 for (size_t index = 0; index < panels.size(); ++index) {
185 // Hover mouse on minimized panel.
186 // Verify titlebar is exposed on all panels.
187 gfx::Point hover_point(panels[index]->GetBounds().origin());
188 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
189 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
190 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
192 // Hover mouse above the panel. Verify all panels are minimized.
193 hover_point.set_y(
194 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
195 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
196 EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
197 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
199 // Hover mouse below minimized panel.
200 // Verify titlebar is exposed on all panels.
201 hover_point.set_y(panels[index]->GetBounds().y() +
202 panels[index]->GetBounds().height() + 5);
203 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
204 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
205 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
207 // Hover below titlebar exposed panel. Verify nothing changed.
208 hover_point.set_y(panels[index]->GetBounds().y() +
209 panels[index]->GetBounds().height() + 6);
210 MoveMouse(hover_point);
211 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
212 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
214 // Hover mouse above panel. Verify all panels are minimized.
215 hover_point.set_y(
216 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
217 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
218 EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
219 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
222 // Test restore. All panels are currently in minimized state.
223 for (size_t index = 0; index < panels.size(); ++index) {
224 // Hover on the last panel. This is to test the case of clicking on the
225 // panel when it's in titlebar exposed state.
226 if (index == panels.size() - 1)
227 MoveMouse(minimized_bounds[index].origin());
229 // Click minimized or title bar exposed panel as the case may be.
230 // Verify panel is restored to its original size.
231 native_panels_testing[index]->PressLeftMouseButtonTitlebar(
232 panels[index]->GetBounds().origin());
233 native_panels_testing[index]->ReleaseMouseButtonTitlebar();
234 expected_bounds[index].set_height(
235 test_begin_bounds[index].height());
236 expected_bounds[index].set_y(test_begin_bounds[index].y());
237 expected_expansion_states[index] = Panel::EXPANDED;
238 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
239 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
241 // Hover again on the last panel which is now restored, to reset the
242 // titlebar exposed state.
243 if (index == panels.size() - 1)
244 MoveMouse(minimized_bounds[index].origin());
247 // The below could be separate tests, just adding a TODO here for tracking.
248 // TODO(prasadt): Add test for dragging when in titlebar exposed state.
249 // TODO(prasadt): Add test in presence of auto hiding task bar.
251 for (size_t i = 0; i < panels.size(); ++i)
252 delete native_panels_testing[i];
256 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CheckDockedPanelProperties) {
257 PanelManager* panel_manager = PanelManager::GetInstance();
258 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
260 // Create 3 docked panels that are in expanded, title-only or minimized states
261 // respectively.
262 Panel* panel1 = CreatePanelWithBounds("1", gfx::Rect(0, 0, 100, 100));
263 Panel* panel2 = CreatePanelWithBounds("2", gfx::Rect(0, 0, 100, 100));
264 Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100));
265 panel2->SetExpansionState(Panel::TITLE_ONLY);
266 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
267 panel3->SetExpansionState(Panel::MINIMIZED);
268 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
269 scoped_ptr<NativePanelTesting> panel1_testing(
270 CreateNativePanelTesting(panel1));
271 scoped_ptr<NativePanelTesting> panel2_testing(
272 CreateNativePanelTesting(panel2));
273 scoped_ptr<NativePanelTesting> panel3_testing(
274 CreateNativePanelTesting(panel3));
276 // Ensure that the layout message can get a chance to be processed so that
277 // the button visibility can be updated.
278 base::MessageLoop::current()->RunUntilIdle();
280 EXPECT_EQ(3, panel_manager->num_panels());
281 EXPECT_TRUE(docked_collection->HasPanel(panel1));
282 EXPECT_TRUE(docked_collection->HasPanel(panel2));
283 EXPECT_TRUE(docked_collection->HasPanel(panel3));
285 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
286 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
287 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
289 EXPECT_TRUE(panel1->IsAlwaysOnTop());
290 EXPECT_TRUE(panel2->IsAlwaysOnTop());
291 EXPECT_TRUE(panel3->IsAlwaysOnTop());
293 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON));
294 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON));
295 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON));
297 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
298 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
299 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
301 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON));
302 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON));
303 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON));
305 // Expanded panel cannot be resized at the bottom.
306 EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel1->CanResizeByMouse());
307 EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse());
308 EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse());
310 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
311 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
312 EXPECT_EQ(panel::TOP_ROUNDED, panel3_testing->GetWindowCornerStyle());
314 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel1->attention_mode());
315 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel2->attention_mode());
316 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode());
318 panel_manager->CloseAll();
321 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
322 PanelManager* panel_manager = PanelManager::GetInstance();
323 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
325 Panel* panel = CreatePanel("PanelTest");
326 EXPECT_EQ(1, panel_manager->num_panels());
328 gfx::Rect bounds = panel->GetBounds();
329 EXPECT_GT(bounds.x(), 0);
330 EXPECT_GT(bounds.y(), 0);
331 EXPECT_GT(bounds.width(), 0);
332 EXPECT_GT(bounds.height(), 0);
334 EXPECT_EQ(bounds.right(),
335 panel_manager->docked_collection()->StartingRightPosition());
337 CloseWindowAndWait(panel);
339 EXPECT_EQ(0, panel_manager->num_panels());
342 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) {
343 gfx::Rect work_area = PanelManager::GetInstance()->
344 display_settings_provider()->GetPrimaryWorkArea();
345 Panel* panel = CreatePanelWithBounds("BigPanel", work_area);
346 gfx::Rect bounds = panel->GetBounds();
347 EXPECT_EQ(panel->max_size().width(), bounds.width());
348 EXPECT_LT(bounds.width(), work_area.width());
349 EXPECT_EQ(panel->max_size().height(), bounds.height());
350 EXPECT_LT(bounds.height(), work_area.height());
351 panel->Close();
354 class WaitForStableInitialSize : public TestPanelNotificationObserver {
355 public:
356 explicit WaitForStableInitialSize(Panel* panel)
357 : TestPanelNotificationObserver(
358 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
359 content::NotificationService::AllSources()),
360 panel_(panel) {}
361 virtual ~WaitForStableInitialSize() {}
363 protected:
364 virtual bool AtExpectedState() OVERRIDE {
365 return panel_->GetBounds().height() > panel_->TitleOnlyHeight();
367 Panel* panel_;
370 class WaitForAutoResizeWider : public TestPanelNotificationObserver {
371 public:
372 explicit WaitForAutoResizeWider(Panel* panel)
373 : TestPanelNotificationObserver(
374 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
375 content::NotificationService::AllSources()),
376 panel_(panel),
377 initial_size_(panel->GetBounds().size()) {}
378 virtual ~WaitForAutoResizeWider() {}
380 protected:
381 virtual bool AtExpectedState() OVERRIDE {
382 return panel_->GetBounds().width() > initial_size_.width();
384 Panel* panel_;
385 gfx::Size initial_size_;
388 class WaitForAutoResizeNarrower : public TestPanelNotificationObserver {
389 public:
390 explicit WaitForAutoResizeNarrower(Panel* panel)
391 : TestPanelNotificationObserver(
392 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
393 content::NotificationService::AllSources()),
394 panel_(panel),
395 initial_size_(panel->GetBounds().size()) {}
396 virtual ~WaitForAutoResizeNarrower() {}
398 protected:
399 virtual bool AtExpectedState() OVERRIDE {
400 return panel_->GetBounds().width() < initial_size_.width();
402 Panel* panel_;
403 gfx::Size initial_size_;
406 // crbug.com/160504
407 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) {
408 PanelManager* panel_manager = PanelManager::GetInstance();
409 panel_manager->enable_auto_sizing(true);
410 // Bigger space is needed by this test.
411 mock_display_settings_provider()->SetPrimaryDisplay(
412 gfx::Rect(0, 0, 1200, 900), gfx::Rect(0, 0, 1200, 900));
414 // Create a test panel with web contents loaded.
415 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
416 GURL url(ui_test_utils::GetTestUrl(
417 base::FilePath(kTestDir),
418 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
419 params.url = url;
420 Panel* panel = CreatePanelWithParams(params);
422 // Ensure panel has auto resized to original web content size.
423 // The resize will update the docked panel collection.
424 WaitForStableInitialSize initial_resize(panel);
425 initial_resize.Wait();
426 gfx::Rect initial_bounds = panel->GetBounds();
428 // Expand the test page. The resize will update the docked panel collection.
429 WaitForAutoResizeWider enlarge(panel);
430 EXPECT_TRUE(content::ExecuteScript(
431 panel->GetWebContents(), "changeSize(50);"));
432 enlarge.Wait();
433 gfx::Rect bounds_on_grow = panel->GetBounds();
434 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width());
435 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height());
437 // Shrink the test page. The resize will update the docked panel collection.
438 WaitForAutoResizeNarrower shrink(panel);
439 EXPECT_TRUE(content::ExecuteScript(
440 panel->GetWebContents(), "changeSize(-30);"));
441 shrink.Wait();
442 gfx::Rect bounds_on_shrink = panel->GetBounds();
443 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width());
444 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width());
445 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height());
447 // Verify resizing turns off auto-resizing and panel no longer auto-resizes.
448 gfx::Rect previous_bounds = panel->GetBounds();
449 // These should be identical because the panel is expanded.
450 EXPECT_EQ(previous_bounds.size(), panel->GetRestoredBounds().size());
451 gfx::Size new_size(previous_bounds.size());
452 new_size.Enlarge(5, 5);
453 gfx::Rect new_bounds(previous_bounds.origin(), new_size);
454 panel->SetBounds(new_bounds);
455 EXPECT_FALSE(panel->auto_resizable());
456 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
457 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
459 // Turn back on auto-resize and verify that panel auto resizes.
460 content::WindowedNotificationObserver auto_resize_enabled(
461 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
462 content::NotificationService::AllSources());
463 panel->SetAutoResizable(true);
464 auto_resize_enabled.Wait();
465 gfx::Rect bounds_auto_resize_enabled = panel->GetBounds();
466 EXPECT_EQ(bounds_on_shrink.width(), bounds_auto_resize_enabled.width());
467 EXPECT_EQ(bounds_on_shrink.height(), bounds_auto_resize_enabled.height());
469 panel->Close();
472 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ResizePanel) {
473 PanelManager* panel_manager = PanelManager::GetInstance();
474 panel_manager->enable_auto_sizing(true);
476 Panel* panel = CreatePanel("TestPanel");
477 EXPECT_TRUE(panel->auto_resizable());
478 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
480 // Verify resizing turns off auto-resizing and that it works.
481 gfx::Rect original_bounds = panel->GetBounds();
482 // These should be identical because the panel is expanded.
483 EXPECT_EQ(original_bounds.size(), panel->GetRestoredBounds().size());
484 gfx::Size new_size(original_bounds.size());
485 new_size.Enlarge(5, 5);
486 gfx::Rect new_bounds(original_bounds.origin(), new_size);
487 panel->SetBounds(new_bounds);
488 EXPECT_FALSE(panel->auto_resizable());
489 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
490 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
492 // Verify current height unaffected when panel is not expanded.
493 panel->SetExpansionState(Panel::MINIMIZED);
494 int original_height = panel->GetBounds().height();
495 new_size.Enlarge(5, 5);
496 new_bounds.set_size(new_size);
497 panel->SetBounds(new_bounds);
498 EXPECT_EQ(new_bounds.size().width(), panel->GetBounds().width());
499 EXPECT_EQ(original_height, panel->GetBounds().height());
500 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
502 panel->Close();
505 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AnimateBounds) {
506 // Create a detached panel, instead of docked panel because it cannot be
507 // moved to any location.
508 Panel* panel = CreateDetachedPanel("1", gfx::Rect(200, 100, 100, 100));
509 scoped_ptr<NativePanelTesting> panel_testing(
510 CreateNativePanelTesting(panel));
512 // Validates that no animation should be triggered when the panel is being
513 // dragged.
514 gfx::Point mouse_location(panel->GetBounds().origin());
515 panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
516 panel_testing->DragTitlebar(mouse_location + gfx::Vector2d(-100, 5));
517 EXPECT_FALSE(panel_testing->IsAnimatingBounds());
518 panel_testing->FinishDragTitlebar();
520 // Set bounds with animation.
521 gfx::Rect bounds = gfx::Rect(10, 20, 150, 160);
522 panel->SetPanelBounds(bounds);
523 // There is no animation on Linux, by design.
524 #if !defined(OS_LINUX)
525 EXPECT_TRUE(panel_testing->IsAnimatingBounds());
526 WaitForBoundsAnimationFinished(panel);
527 #endif
528 EXPECT_FALSE(panel_testing->IsAnimatingBounds());
529 EXPECT_EQ(bounds, panel->GetBounds());
531 // Set bounds without animation.
532 bounds = gfx::Rect(30, 40, 200, 220);
533 panel->SetPanelBoundsInstantly(bounds);
534 EXPECT_FALSE(panel_testing->IsAnimatingBounds());
535 EXPECT_EQ(bounds, panel->GetBounds());
537 panel->Close();
540 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) {
541 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
542 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
543 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
545 panel->SetExpansionState(Panel::MINIMIZED);
546 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
547 gfx::Rect bounds = panel->GetBounds();
548 gfx::Rect restored = panel->GetRestoredBounds();
549 EXPECT_EQ(bounds.x(), restored.x());
550 EXPECT_GT(bounds.y(), restored.y());
551 EXPECT_EQ(bounds.width(), restored.width());
552 EXPECT_LT(bounds.height(), restored.height());
554 panel->SetExpansionState(Panel::TITLE_ONLY);
555 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
556 bounds = panel->GetBounds();
557 restored = panel->GetRestoredBounds();
558 EXPECT_EQ(bounds.x(), restored.x());
559 EXPECT_GT(bounds.y(), restored.y());
560 EXPECT_EQ(bounds.width(), restored.width());
561 EXPECT_LT(bounds.height(), restored.height());
563 panel->SetExpansionState(Panel::MINIMIZED);
564 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
565 bounds = panel->GetBounds();
566 restored = panel->GetRestoredBounds();
567 EXPECT_EQ(bounds.x(), restored.x());
568 EXPECT_GT(bounds.y(), restored.y());
569 EXPECT_EQ(bounds.width(), restored.width());
570 EXPECT_LT(bounds.height(), restored.height());
572 panel->SetExpansionState(Panel::EXPANDED);
573 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
575 // Verify that changing the panel bounds does not affect the restored height.
576 int saved_restored_height = restored.height();
577 panel->SetExpansionState(Panel::MINIMIZED);
578 bounds = gfx::Rect(10, 20, 300, 400);
579 panel->SetPanelBounds(bounds);
580 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
582 panel->SetExpansionState(Panel::TITLE_ONLY);
583 bounds = gfx::Rect(20, 30, 100, 200);
584 panel->SetPanelBounds(bounds);
585 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
587 panel->SetExpansionState(Panel::EXPANDED);
588 bounds = gfx::Rect(40, 60, 300, 400);
589 panel->SetPanelBounds(bounds);
590 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
591 panel->set_full_size(bounds.size());
592 EXPECT_NE(saved_restored_height, panel->GetRestoredBounds().height());
594 panel->Close();
597 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestore) {
598 // Test with one panel.
599 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
600 TestMinimizeRestore();
602 PanelManager::GetInstance()->CloseAll();
605 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreTwoPanels) {
606 // Test with two panels.
607 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
608 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
609 TestMinimizeRestore();
611 PanelManager::GetInstance()->CloseAll();
614 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreThreePanels) {
615 // Test with three panels.
616 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
617 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
618 CreatePanelWithBounds("PanelTest3", gfx::Rect(0, 0, 120, 120));
619 TestMinimizeRestore();
621 PanelManager::GetInstance()->CloseAll();
624 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreButtonClick) {
625 // Test with three panels.
626 Panel* panel1 = CreatePanel("PanelTest1");
627 Panel* panel2 = CreatePanel("PanelTest2");
628 Panel* panel3 = CreatePanel("PanelTest3");
629 EXPECT_FALSE(panel1->IsMinimized());
630 EXPECT_FALSE(panel2->IsMinimized());
631 EXPECT_FALSE(panel3->IsMinimized());
633 // Click restore button on an expanded panel. Expect no change.
634 panel1->OnRestoreButtonClicked(panel::NO_MODIFIER);
635 EXPECT_FALSE(panel1->IsMinimized());
636 EXPECT_FALSE(panel2->IsMinimized());
637 EXPECT_FALSE(panel3->IsMinimized());
639 // Click minimize button on an expanded panel. Only that panel will minimize.
640 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
641 EXPECT_TRUE(panel1->IsMinimized());
642 EXPECT_FALSE(panel2->IsMinimized());
643 EXPECT_FALSE(panel3->IsMinimized());
645 // Click minimize button on a minimized panel. Expect no change.
646 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
647 EXPECT_TRUE(panel1->IsMinimized());
648 EXPECT_FALSE(panel2->IsMinimized());
649 EXPECT_FALSE(panel3->IsMinimized());
651 // Minimize all panels by clicking minimize button on an expanded panel
652 // with the apply-all modifier.
653 panel2->OnMinimizeButtonClicked(panel::APPLY_TO_ALL);
654 EXPECT_TRUE(panel1->IsMinimized());
655 EXPECT_TRUE(panel2->IsMinimized());
656 EXPECT_TRUE(panel3->IsMinimized());
658 // Click restore button on a minimized panel. Only that panel will restore.
659 panel2->OnRestoreButtonClicked(panel::NO_MODIFIER);
660 EXPECT_TRUE(panel1->IsMinimized());
661 EXPECT_FALSE(panel2->IsMinimized());
662 EXPECT_TRUE(panel3->IsMinimized());
664 // Restore all panels by clicking restore button on a minimized panel.
665 panel3->OnRestoreButtonClicked(panel::APPLY_TO_ALL);
666 EXPECT_FALSE(panel1->IsMinimized());
667 EXPECT_FALSE(panel2->IsMinimized());
668 EXPECT_FALSE(panel3->IsMinimized());
671 // http://crbug.com/243891 flaky on Linux
672 #if defined(OS_LINUX)
673 #define MAYBE_RestoreAllWithTitlebarClick DISABLED_RestoreAllWithTitlebarClick
674 #else
675 #define MAYBE_RestoreAllWithTitlebarClick RestoreAllWithTitlebarClick
676 #endif
677 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_RestoreAllWithTitlebarClick) {
678 // Test with three panels.
679 Panel* panel1 = CreatePanel("PanelTest1");
680 Panel* panel2 = CreatePanel("PanelTest2");
681 Panel* panel3 = CreatePanel("PanelTest3");
682 EXPECT_FALSE(panel1->IsMinimized());
683 EXPECT_FALSE(panel2->IsMinimized());
684 EXPECT_FALSE(panel3->IsMinimized());
686 scoped_ptr<NativePanelTesting> test_panel1(
687 CreateNativePanelTesting(panel1));
688 scoped_ptr<NativePanelTesting> test_panel2(
689 CreateNativePanelTesting(panel2));
690 scoped_ptr<NativePanelTesting> test_panel3(
691 CreateNativePanelTesting(panel3));
693 // Click on an expanded panel's titlebar using the apply-all modifier.
694 // Verify expansion state is unchanged.
695 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
696 panel::APPLY_TO_ALL);
697 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
698 EXPECT_FALSE(panel1->IsMinimized());
699 EXPECT_FALSE(panel2->IsMinimized());
700 EXPECT_FALSE(panel3->IsMinimized());
702 // Click on a minimized panel's titlebar using the apply-all modifier.
703 panel1->Minimize();
704 panel2->Minimize();
705 panel3->Minimize();
706 EXPECT_TRUE(panel1->IsMinimized());
707 EXPECT_TRUE(panel2->IsMinimized());
708 EXPECT_TRUE(panel3->IsMinimized());
710 // Nothing changes until mouse is released.
711 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
712 panel::APPLY_TO_ALL);
713 EXPECT_TRUE(panel1->IsMinimized());
714 EXPECT_TRUE(panel2->IsMinimized());
715 EXPECT_TRUE(panel3->IsMinimized());
716 // Verify all panels restored when mouse is released.
717 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
718 EXPECT_FALSE(panel1->IsMinimized());
719 EXPECT_FALSE(panel2->IsMinimized());
720 EXPECT_FALSE(panel3->IsMinimized());
722 // Minimize a single panel. Then click on expanded panel with apply-all
723 // modifier. Verify nothing changes.
724 panel1->Minimize();
725 EXPECT_TRUE(panel1->IsMinimized());
726 EXPECT_FALSE(panel2->IsMinimized());
727 EXPECT_FALSE(panel3->IsMinimized());
729 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
730 panel::APPLY_TO_ALL);
731 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
732 EXPECT_TRUE(panel1->IsMinimized());
733 EXPECT_FALSE(panel2->IsMinimized());
734 EXPECT_FALSE(panel3->IsMinimized());
736 // Minimize another panel. Then click on a minimized panel with apply-all
737 // modifier to restore all panels.
738 panel2->Minimize();
739 EXPECT_TRUE(panel1->IsMinimized());
740 EXPECT_TRUE(panel2->IsMinimized());
741 EXPECT_FALSE(panel3->IsMinimized());
743 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
744 panel::APPLY_TO_ALL);
745 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
746 EXPECT_FALSE(panel1->IsMinimized());
747 EXPECT_FALSE(panel2->IsMinimized());
748 EXPECT_FALSE(panel3->IsMinimized());
750 // Click on the single minimized panel. Verify all are restored.
751 panel1->Minimize();
752 EXPECT_TRUE(panel1->IsMinimized());
753 EXPECT_FALSE(panel2->IsMinimized());
754 EXPECT_FALSE(panel3->IsMinimized());
756 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
757 panel::APPLY_TO_ALL);
758 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
759 EXPECT_FALSE(panel1->IsMinimized());
760 EXPECT_FALSE(panel2->IsMinimized());
761 EXPECT_FALSE(panel3->IsMinimized());
763 // Click on the single expanded panel. Verify nothing changes.
764 panel1->Minimize();
765 panel3->Minimize();
766 EXPECT_TRUE(panel1->IsMinimized());
767 EXPECT_FALSE(panel2->IsMinimized());
768 EXPECT_TRUE(panel3->IsMinimized());
770 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
771 panel::APPLY_TO_ALL);
772 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
773 EXPECT_TRUE(panel1->IsMinimized());
774 EXPECT_FALSE(panel2->IsMinimized());
775 EXPECT_TRUE(panel3->IsMinimized());
777 // Hover over a minimized panel and click on the titlebar while it is in
778 // title-only mode. Should restore all panels.
779 panel2->Minimize();
780 EXPECT_TRUE(panel1->IsMinimized());
781 EXPECT_TRUE(panel2->IsMinimized());
782 EXPECT_TRUE(panel3->IsMinimized());
784 MoveMouseAndWaitForExpansionStateChange(panel2, panel2->GetBounds().origin());
785 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
786 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
787 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state());
789 test_panel3->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(),
790 panel::APPLY_TO_ALL);
791 test_panel3->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
792 EXPECT_FALSE(panel1->IsMinimized());
793 EXPECT_FALSE(panel2->IsMinimized());
794 EXPECT_FALSE(panel3->IsMinimized());
796 // Draw attention to a minimized panel. Click on a minimized panel that is
797 // not drawing attention. Verify restore all applies without affecting
798 // draw attention.
799 panel1->Minimize();
800 panel2->Minimize();
801 panel3->Minimize();
802 EXPECT_TRUE(panel1->IsMinimized());
803 EXPECT_TRUE(panel2->IsMinimized());
804 EXPECT_TRUE(panel3->IsMinimized());
806 panel1->FlashFrame(true);
807 EXPECT_TRUE(panel1->IsDrawingAttention());
809 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
810 panel::APPLY_TO_ALL);
811 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
812 EXPECT_FALSE(panel1->IsMinimized());
813 EXPECT_FALSE(panel2->IsMinimized());
814 EXPECT_FALSE(panel3->IsMinimized());
815 EXPECT_TRUE(panel1->IsDrawingAttention());
817 // Restore all panels by clicking on the minimized panel that is drawing
818 // attention. Verify restore all applies and clears draw attention.
819 panel1->Minimize();
820 panel2->Minimize();
821 panel3->Minimize();
822 EXPECT_TRUE(panel1->IsMinimized());
823 EXPECT_TRUE(panel2->IsMinimized());
824 EXPECT_TRUE(panel3->IsMinimized());
826 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
827 panel::APPLY_TO_ALL);
828 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
829 EXPECT_FALSE(panel1->IsMinimized());
830 EXPECT_FALSE(panel2->IsMinimized());
831 EXPECT_FALSE(panel3->IsMinimized());
832 EXPECT_FALSE(panel1->IsDrawingAttention());
834 PanelManager::GetInstance()->CloseAll();
837 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
838 MinimizeRestoreOnAutoHidingDesktopBar) {
839 PanelManager* panel_manager = PanelManager::GetInstance();
840 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
841 int expected_bottom_on_expanded = docked_collection->work_area().bottom();
842 int expected_bottom_on_title_only = expected_bottom_on_expanded;
843 int expected_bottom_on_minimized = expected_bottom_on_expanded;
845 // Turn on auto-hiding.
846 static const int bottom_bar_thickness = 40;
847 mock_display_settings_provider()->EnableAutoHidingDesktopBar(
848 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
849 true,
850 bottom_bar_thickness);
851 expected_bottom_on_title_only -= bottom_bar_thickness;
853 Panel* panel = CreatePanel("1");
854 int initial_height = panel->GetBounds().height();
856 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
857 EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
859 panel->Minimize();
860 WaitForBoundsAnimationFinished(panel);
861 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
862 EXPECT_EQ(panel::kMinimizedPanelHeight, panel->GetBounds().height());
863 EXPECT_EQ(expected_bottom_on_minimized, panel->GetBounds().bottom());
865 panel->SetExpansionState(Panel::TITLE_ONLY);
866 WaitForBoundsAnimationFinished(panel);
867 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
868 EXPECT_EQ(panel::kTitlebarHeight, panel->GetBounds().height());
869 EXPECT_EQ(expected_bottom_on_title_only, panel->GetBounds().bottom());
871 panel->Restore();
872 WaitForBoundsAnimationFinished(panel);
873 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
874 EXPECT_EQ(initial_height, panel->GetBounds().height());
875 EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
877 panel->Close();
880 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ChangeAutoHideTaskBarThickness) {
881 PanelManager* manager = PanelManager::GetInstance();
882 DockedPanelCollection* docked_collection = manager->docked_collection();
883 int initial_starting_right_position =
884 docked_collection->StartingRightPosition();
886 int bottom_bar_thickness = 20;
887 int right_bar_thickness = 30;
888 mock_display_settings_provider()->EnableAutoHidingDesktopBar(
889 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
890 true,
891 bottom_bar_thickness);
892 mock_display_settings_provider()->EnableAutoHidingDesktopBar(
893 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
894 true,
895 right_bar_thickness);
896 EXPECT_EQ(initial_starting_right_position,
897 docked_collection->StartingRightPosition());
899 Panel* panel = CreatePanel("PanelTest");
900 panel->SetExpansionState(Panel::TITLE_ONLY);
901 WaitForBoundsAnimationFinished(panel);
903 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
904 panel->GetBounds().bottom());
905 EXPECT_EQ(docked_collection->StartingRightPosition(),
906 panel->GetBounds().right());
908 initial_starting_right_position = docked_collection->StartingRightPosition();
909 int bottom_bar_thickness_delta = 10;
910 bottom_bar_thickness += bottom_bar_thickness_delta;
911 int right_bar_thickness_delta = 15;
912 right_bar_thickness += right_bar_thickness_delta;
913 mock_display_settings_provider()->SetDesktopBarThickness(
914 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
915 bottom_bar_thickness);
916 mock_display_settings_provider()->SetDesktopBarThickness(
917 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
918 right_bar_thickness);
919 base::MessageLoopForUI::current()->RunUntilIdle();
920 EXPECT_EQ(initial_starting_right_position,
921 docked_collection->StartingRightPosition());
922 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
923 panel->GetBounds().bottom());
924 EXPECT_EQ(docked_collection->StartingRightPosition(),
925 panel->GetBounds().right());
927 initial_starting_right_position = docked_collection->StartingRightPosition();
928 bottom_bar_thickness_delta = 20;
929 bottom_bar_thickness -= bottom_bar_thickness_delta;
930 right_bar_thickness_delta = 10;
931 right_bar_thickness -= right_bar_thickness_delta;
932 mock_display_settings_provider()->SetDesktopBarThickness(
933 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
934 bottom_bar_thickness);
935 mock_display_settings_provider()->SetDesktopBarThickness(
936 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
937 right_bar_thickness);
938 base::MessageLoopForUI::current()->RunUntilIdle();
939 EXPECT_EQ(docked_collection->StartingRightPosition(),
940 initial_starting_right_position);
941 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
942 panel->GetBounds().bottom());
943 EXPECT_EQ(docked_collection->StartingRightPosition(),
944 panel->GetBounds().right());
946 panel->Close();
949 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivatePanelOrTabbedWindow) {
950 if (!WmSupportWindowActivation()) {
951 LOG(WARNING) << "Skipping test due to WM problems.";
952 return;
955 Panel* panel1 = CreatePanel("Panel1");
956 Panel* panel2 = CreatePanel("Panel2");
958 // Activate main tabbed window.
959 browser()->window()->Activate();
960 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
962 // Activate a panel.
963 panel2->Activate();
964 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
966 // Activate the main tabbed window back.
967 browser()->window()->Activate();
968 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
970 // Activate another panel.
971 panel1->Activate();
972 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
973 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
975 // Switch focus between panels.
976 panel2->Activate();
977 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
978 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
980 PanelManager::GetInstance()->CloseAll();
983 // TODO(jianli): To be enabled for other platforms.
984 #if defined(OS_WIN) || defined(OS_LINUX)
985 #define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
986 #else
987 #define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
988 #endif
989 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
990 if (!WmSupportWindowActivation()) {
991 LOG(WARNING) << "Skipping test due to WM problems.";
992 return;
995 // Create an active panel.
996 Panel* panel = CreatePanel("PanelTest");
997 scoped_ptr<NativePanelTesting> native_panel_testing(
998 CreateNativePanelTesting(panel));
1000 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); // doublecheck active state
1001 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
1003 // Deactivate the panel.
1004 panel->Deactivate();
1005 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
1007 // On GTK there is no way to deactivate a window. So the Deactivate() call
1008 // above does not actually deactivate the window, but simply lowers it.
1009 #if !defined(OS_LINUX)
1010 EXPECT_TRUE(native_panel_testing->VerifyActiveState(false));
1011 #endif
1013 // This test does not reactivate the panel because the panel might not be
1014 // reactivated programmatically once it is deactivated.
1017 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivateDeactivateMultiple) {
1018 if (!WmSupportWindowActivation()) {
1019 LOG(WARNING) << "Skipping test due to WM problems.";
1020 return;
1023 BrowserWindow* tabbed_window = browser()->window();
1025 // Create 4 panels in the following screen layout:
1026 // P3 P2 P1 P0
1027 const int kNumPanels = 4;
1028 for (int i = 0; i < kNumPanels; ++i)
1029 CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100));
1030 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
1032 std::vector<bool> expected_active_states;
1033 std::vector<bool> last_active_states;
1035 // The last created panel, P3, should be active.
1036 expected_active_states = ProduceExpectedActiveStates(3);
1037 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1038 EXPECT_FALSE(tabbed_window->IsActive());
1040 // Activating P1 should cause P3 to lose focus.
1041 panels[1]->Activate();
1042 last_active_states = expected_active_states;
1043 expected_active_states = ProduceExpectedActiveStates(1);
1044 WaitForPanelActiveStates(last_active_states, expected_active_states);
1045 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1047 // Minimizing inactive panel P2 should not affect other panels' active states.
1048 panels[2]->SetExpansionState(Panel::MINIMIZED);
1049 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1050 EXPECT_FALSE(tabbed_window->IsActive());
1053 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionBasic) {
1054 Panel* panel = CreateInactivePanel("P1");
1055 scoped_ptr<NativePanelTesting> native_panel_testing(
1056 CreateNativePanelTesting(panel));
1058 // Test that the attention is drawn when the expanded panel is not in focus.
1059 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
1060 EXPECT_FALSE(panel->IsActive());
1061 EXPECT_FALSE(panel->IsDrawingAttention());
1062 panel->FlashFrame(true);
1063 EXPECT_TRUE(panel->IsDrawingAttention());
1064 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
1066 // Stop drawing attention.
1067 panel->FlashFrame(false);
1068 EXPECT_FALSE(panel->IsDrawingAttention());
1069 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1071 // Draw attention, then minimize. Titlebar should remain visible.
1072 panel->FlashFrame(true);
1073 EXPECT_TRUE(panel->IsDrawingAttention());
1075 panel->Minimize();
1076 EXPECT_TRUE(panel->IsDrawingAttention());
1077 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
1079 // Stop drawing attention. Titlebar should no longer be visible.
1080 panel->FlashFrame(false);
1081 EXPECT_FALSE(panel->IsDrawingAttention());
1082 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
1084 panel->Close();
1087 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) {
1088 Panel* panel1 = CreateInactivePanel("P1");
1089 Panel* panel2 = CreateInactivePanel("P2");
1091 scoped_ptr<NativePanelTesting> native_panel1_testing(
1092 CreateNativePanelTesting(panel1));
1094 // Test that the attention is drawn and the title-bar is brought up when the
1095 // minimized panel is drawing attention.
1096 panel1->Minimize();
1097 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1098 panel1->FlashFrame(true);
1099 EXPECT_TRUE(panel1->IsDrawingAttention());
1100 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1101 EXPECT_TRUE(native_panel1_testing->VerifyDrawingAttention());
1103 // Test that we cannot bring up other minimized panel if the mouse is over
1104 // the panel that draws attension.
1105 panel2->Minimize();
1106 gfx::Point hover_point(panel1->GetBounds().origin());
1107 MoveMouse(hover_point);
1108 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1109 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1111 // Test that we cannot bring down the panel that is drawing the attention.
1112 hover_point.set_y(hover_point.y() - 200);
1113 MoveMouse(hover_point);
1114 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1116 // Test that the attention is cleared when activated.
1117 panel1->Activate();
1118 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
1119 EXPECT_FALSE(panel1->IsDrawingAttention());
1120 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
1121 EXPECT_FALSE(native_panel1_testing->VerifyDrawingAttention());
1123 PanelManager::GetInstance()->CloseAll();
1126 // Verify that minimized state of a panel is correct after draw attention
1127 // is stopped when there are other minimized panels.
1128 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, StopDrawingAttentionWhileMinimized) {
1129 Panel* panel1 = CreateInactivePanel("P1");
1130 Panel* panel2 = CreateInactivePanel("P2");
1132 panel1->Minimize();
1133 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1134 panel2->Minimize();
1135 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1137 // Verify panel returns to minimized state when no longer drawing attention.
1138 panel1->FlashFrame(true);
1139 EXPECT_TRUE(panel1->IsDrawingAttention());
1140 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1142 panel1->FlashFrame(false);
1143 EXPECT_FALSE(panel1->IsDrawingAttention());
1144 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1146 // Hover over other minimized panel to bring up titlebars.
1147 gfx::Point hover_point(panel2->GetBounds().origin());
1148 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
1149 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1150 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
1152 // Verify panel keeps titlebar visible when no longer drawing attention
1153 // if titlebars are up.
1154 panel1->FlashFrame(true);
1155 EXPECT_TRUE(panel1->IsDrawingAttention());
1156 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1158 panel1->FlashFrame(false);
1159 EXPECT_FALSE(panel1->IsDrawingAttention());
1160 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1162 // Move mouse away. All panels should return to minimized state.
1163 hover_point.set_y(hover_point.y() - 200);
1164 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
1165 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1166 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1168 // Verify minimized panel that is drawing attention stays in title-only mode
1169 // after attention is cleared if mouse is in the titlebar area.
1170 panel1->FlashFrame(true);
1171 EXPECT_TRUE(panel1->IsDrawingAttention());
1172 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1174 gfx::Point hover_point_in_panel(panel1->GetBounds().origin());
1175 MoveMouse(hover_point_in_panel);
1177 panel1->FlashFrame(false);
1178 EXPECT_FALSE(panel1->IsDrawingAttention());
1179 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1180 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1182 // Typical user scenario will detect the mouse in the panel
1183 // after attention is cleared, causing titles to pop up, so
1184 // we simulate that here.
1185 MoveMouseAndWaitForExpansionStateChange(panel2, hover_point_in_panel);
1186 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1187 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
1189 // Move mouse away and panels should go back to fully minimized state.
1190 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
1191 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1192 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1194 PanelManager::GetInstance()->CloseAll();
1197 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) {
1198 // Create an active panel.
1199 Panel* panel = CreatePanel("P1");
1200 scoped_ptr<NativePanelTesting> native_panel_testing(
1201 CreateNativePanelTesting(panel));
1203 // Test that the attention should not be drawn if the expanded panel is in
1204 // focus.
1205 panel->FlashFrame(true);
1206 EXPECT_FALSE(panel->IsDrawingAttention());
1207 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1209 panel->Close();
1212 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) {
1213 Panel* panel = CreateInactivePanel("P1");
1214 scoped_ptr<NativePanelTesting> native_panel_testing(
1215 CreateNativePanelTesting(panel));
1217 panel->FlashFrame(true);
1218 EXPECT_TRUE(panel->IsDrawingAttention());
1219 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
1221 // Test that the attention is cleared when panel gets focus.
1222 panel->Activate();
1223 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1224 EXPECT_FALSE(panel->IsDrawingAttention());
1225 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1227 panel->Close();
1230 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1231 DrawAttentionMinimizedNotResetOnActivate) {
1232 Panel* panel = CreateInactivePanel("P1");
1234 panel->Minimize();
1235 EXPECT_TRUE(panel->IsMinimized());
1236 panel->FlashFrame(true);
1237 EXPECT_TRUE(panel->IsDrawingAttention());
1239 // Simulate panel being activated while minimized. Cannot call
1240 // Activate() as that expands the panel.
1241 panel->OnActiveStateChanged(true);
1242 EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged.
1244 // Unminimize panel to show that attention would have been cleared
1245 // if panel had not been minimized.
1246 panel->Restore();
1247 EXPECT_FALSE(panel->IsMinimized());
1248 EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged.
1250 panel->OnActiveStateChanged(true);
1251 EXPECT_FALSE(panel->IsDrawingAttention()); // Attention cleared.
1253 panel->Close();
1256 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) {
1257 Panel* panel = CreateInactivePanel("P1");
1258 scoped_ptr<NativePanelTesting> native_panel_testing(
1259 CreateNativePanelTesting(panel));
1261 panel->FlashFrame(true);
1262 EXPECT_TRUE(panel->IsDrawingAttention());
1263 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
1265 // Test that the attention is cleared when panel gets focus.
1266 native_panel_testing->PressLeftMouseButtonTitlebar(
1267 panel->GetBounds().origin());
1268 native_panel_testing->ReleaseMouseButtonTitlebar();
1270 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1271 EXPECT_FALSE(panel->IsDrawingAttention());
1272 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1274 panel->Close();
1277 // http://crbug.com/175760; several panel tests failing regularly on mac.
1278 #if defined(OS_MACOSX)
1279 #define MAYBE_MinimizeImmediatelyAfterRestore \
1280 DISABLED_MinimizeImmediatelyAfterRestore
1281 #else
1282 #define MAYBE_MinimizeImmediatelyAfterRestore MinimizeImmediatelyAfterRestore
1283 #endif
1284 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1285 MAYBE_MinimizeImmediatelyAfterRestore) {
1286 CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE);
1287 Panel* panel = CreatePanelWithParams(params);
1288 scoped_ptr<NativePanelTesting> native_panel_testing(
1289 CreateNativePanelTesting(panel));
1291 PanelActiveStateObserver signal(panel, false);
1292 panel->Minimize(); // this should deactivate.
1293 signal.Wait();
1294 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
1296 panel->Restore();
1297 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
1299 // Verify that minimizing a panel right after expansion works.
1300 panel->Minimize();
1301 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
1303 panel->Close();
1306 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) {
1307 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
1308 Panel* panel = CreatePanelWithParams(params);
1309 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
1311 PanelActiveStateObserver signal(panel, false);
1312 panel->Minimize();
1313 signal.Wait();
1314 panel->Close();
1317 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateInactiveSwitchToActive) {
1318 Panel* panel = CreateInactivePanel("1");
1320 panel->Activate();
1321 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1323 panel->Close();
1326 // TODO(dimich): try/enable on other platforms. See bug 103253 for details on
1327 // why this is disabled on windows.
1328 #if defined(OS_MACOSX)
1329 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
1330 MinimizeTwoPanelsWithoutTabbedWindow
1331 #else
1332 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
1333 DISABLED_MinimizeTwoPanelsWithoutTabbedWindow
1334 #endif
1336 // When there are 2 panels and no chrome window, minimizing one panel does
1337 // not expand/focuses another.
1338 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1339 MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) {
1340 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
1341 Panel* panel1 = CreatePanelWithParams(params);
1342 Panel* panel2 = CreatePanelWithParams(params);
1344 // Close main tabbed window.
1345 content::WindowedNotificationObserver signal(
1346 chrome::NOTIFICATION_BROWSER_CLOSED,
1347 content::Source<Browser>(browser()));
1348 chrome::CloseWindow(browser());
1349 signal.Wait();
1351 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
1352 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
1353 panel1->Activate();
1354 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
1356 panel1->SetExpansionState(Panel::MINIMIZED);
1357 base::MessageLoop::current()->RunUntilIdle();
1358 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
1359 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1361 panel2->SetExpansionState(Panel::MINIMIZED);
1362 base::MessageLoop::current()->RunUntilIdle();
1363 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
1364 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1366 // Verify that panel1 is still minimized and not active.
1367 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
1368 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1370 // Another check for the same.
1371 EXPECT_FALSE(panel1->IsActive());
1372 EXPECT_FALSE(panel2->IsActive());
1374 panel1->Close();
1375 panel2->Close();
1378 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1379 NonExtensionDomainPanelsCloseOnUninstall) {
1380 // Create a test extension.
1381 base::DictionaryValue empty_value;
1382 scoped_refptr<extensions::Extension> extension =
1383 CreateExtension(FILE_PATH_LITERAL("TestExtension"),
1384 extensions::Manifest::INTERNAL, empty_value);
1385 std::string extension_app_name =
1386 web_app::GenerateApplicationNameFromExtensionId(extension->id());
1388 PanelManager* panel_manager = PanelManager::GetInstance();
1389 EXPECT_EQ(0, panel_manager->num_panels());
1391 // Create a panel with the extension as host.
1392 CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE);
1393 std::string extension_domain_url(extensions::kExtensionScheme);
1394 extension_domain_url += "://";
1395 extension_domain_url += extension->id();
1396 extension_domain_url += "/hello.html";
1397 params.url = GURL(extension_domain_url);
1398 Panel* panel = CreatePanelWithParams(params);
1399 EXPECT_EQ(1, panel_manager->num_panels());
1401 // Create a panel with a non-extension host.
1402 CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE);
1403 params1.url = GURL(content::kAboutBlankURL);
1404 Panel* panel1 = CreatePanelWithParams(params1);
1405 EXPECT_EQ(2, panel_manager->num_panels());
1407 // Create another extension and a panel from that extension.
1408 scoped_refptr<extensions::Extension> extension_other =
1409 CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"),
1410 extensions::Manifest::INTERNAL, empty_value);
1411 std::string extension_app_name_other =
1412 web_app::GenerateApplicationNameFromExtensionId(extension_other->id());
1413 Panel* panel_other = CreatePanel(extension_app_name_other);
1415 content::WindowedNotificationObserver signal(
1416 chrome::NOTIFICATION_PANEL_CLOSED,
1417 content::Source<Panel>(panel));
1418 content::WindowedNotificationObserver signal1(
1419 chrome::NOTIFICATION_PANEL_CLOSED,
1420 content::Source<Panel>(panel1));
1422 // Send unload notification on the first extension.
1423 extensions::UnloadedExtensionInfo details(
1424 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
1425 content::NotificationService::current()->Notify(
1426 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1427 content::Source<Profile>(browser()->profile()),
1428 content::Details<extensions::UnloadedExtensionInfo>(&details));
1430 // Wait for the panels opened by the first extension to close.
1431 signal.Wait();
1432 signal1.Wait();
1434 // Verify that the panel that's left is the panel from the second extension.
1435 EXPECT_EQ(panel_other, panel_manager->panels()[0]);
1436 panel_other->Close();
1439 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) {
1440 PanelManager* panel_manager = PanelManager::GetInstance();
1441 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
1443 const base::string16 title_first_close = base::UTF8ToUTF16("TitleFirstClose");
1444 const base::string16 title_second_close =
1445 base::UTF8ToUTF16("TitleSecondClose");
1447 // Create a test panel with web contents loaded.
1448 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300),
1449 SHOW_AS_ACTIVE);
1450 params.url = ui_test_utils::GetTestUrl(
1451 base::FilePath(kTestDir),
1452 base::FilePath(FILE_PATH_LITERAL("onbeforeunload.html")));
1453 Panel* panel = CreatePanelWithParams(params);
1454 EXPECT_EQ(1, panel_manager->num_panels());
1456 // Close panel and verify it closes despite having a onbeforeunload handler.
1457 CloseWindowAndWait(panel);
1458 EXPECT_EQ(0, panel_manager->num_panels());
1461 // http://crbug.com/175760; several panel tests failing regularly on mac.
1462 #if defined(OS_MACOSX)
1463 #define MAYBE_SizeClamping DISABLED_SizeClamping
1464 #else
1465 #define MAYBE_SizeClamping SizeClamping
1466 #endif
1467 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_SizeClamping) {
1468 // Using '0' sizes is equivalent of not providing sizes in API and causes
1469 // minimum sizes to be applied to facilitate auto-sizing.
1470 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
1471 Panel* panel = CreatePanelWithParams(params);
1472 EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width());
1473 EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height());
1474 int reasonable_width = panel->min_size().width() + 10;
1475 int reasonable_height = panel->min_size().height() + 20;
1477 panel->Close();
1479 // Using reasonable actual sizes should avoid clamping.
1480 CreatePanelParams params1("Panel1",
1481 gfx::Rect(0, 0,
1482 reasonable_width, reasonable_height),
1483 SHOW_AS_ACTIVE);
1484 panel = CreatePanelWithParams(params1);
1485 EXPECT_EQ(reasonable_width, panel->GetBounds().width());
1486 EXPECT_EQ(reasonable_height, panel->GetBounds().height());
1487 panel->Close();
1489 // Using just one size should auto-compute some reasonable other size.
1490 int given_height = 200;
1491 CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height),
1492 SHOW_AS_ACTIVE);
1493 panel = CreatePanelWithParams(params2);
1494 EXPECT_GT(panel->GetBounds().width(), 0);
1495 EXPECT_EQ(given_height, panel->GetBounds().height());
1496 panel->Close();
1499 // http://crbug.com/175760; several panel tests failing regularly on mac.
1500 // http://crbug.com/179890; TightAutosizeAroundSingleLine broken on Windows by
1501 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1502 DISABLED_TightAutosizeAroundSingleLine) {
1503 PanelManager::GetInstance()->enable_auto_sizing(true);
1504 // Using 0 sizes triggers auto-sizing.
1505 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
1506 params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>");
1507 Panel* panel = CreatePanelWithParams(params);
1509 // Ensure panel has auto resized to original web content size.
1510 WaitForStableInitialSize initial_resize(panel);
1511 initial_resize.Wait();
1513 int initial_width = panel->GetBounds().width();
1514 int initial_height = panel->GetBounds().height();
1516 // Inject some HTML content into the panel.
1517 WaitForAutoResizeWider enlarge(panel);
1518 EXPECT_TRUE(content::ExecuteScript(
1519 panel->GetWebContents(),
1520 "document.body.innerHTML ="
1521 " '<nobr>line of text and a <button>Button</button>';"));
1522 enlarge.Wait();
1524 // The panel should have become larger in both dimensions (the minimums
1525 // has to be set to be smaller then a simple 1-line content, so the autosize
1526 // can work correctly.
1527 EXPECT_GT(panel->GetBounds().width(), initial_width);
1528 EXPECT_GT(panel->GetBounds().height(), initial_height);
1530 panel->Close();
1533 // http://crbug.com/175760; several panel tests failing regularly on mac.
1534 #if defined(OS_MACOSX)
1535 #define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \
1536 DISABLED_DefaultMaxSizeOnDisplaySettingsChange
1537 #else
1538 #define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \
1539 DefaultMaxSizeOnDisplaySettingsChange
1540 #endif
1541 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1542 MAYBE_DefaultMaxSizeOnDisplaySettingsChange) {
1543 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220));
1545 gfx::Size old_max_size = panel->max_size();
1546 gfx::Size old_full_size = panel->full_size();
1548 // Shrink the work area. Expect max size and full size become smaller.
1549 gfx::Rect smaller_work_area(0, 0, 500, 300);
1550 mock_display_settings_provider()->SetPrimaryDisplay(
1551 smaller_work_area, smaller_work_area);
1552 EXPECT_GT(old_max_size.width(), panel->max_size().width());
1553 EXPECT_GT(old_max_size.height(), panel->max_size().height());
1554 EXPECT_GT(smaller_work_area.width(), panel->max_size().width());
1555 EXPECT_GT(smaller_work_area.height(), panel->max_size().height());
1556 EXPECT_GT(old_full_size.width(), panel->full_size().width());
1557 EXPECT_GT(old_full_size.height(), panel->full_size().height());
1558 EXPECT_GE(panel->max_size().width(), panel->full_size().width());
1559 EXPECT_GE(panel->max_size().height(), panel->full_size().height());
1561 panel->Close();
1564 // http://crbug.com/175760; several panel tests failing regularly on mac.
1565 #if defined(OS_MACOSX)
1566 #define MAYBE_CustomMaxSizeOnDisplaySettingsChange \
1567 DISABLED_CustomMaxSizeOnDisplaySettingsChange
1568 #else
1569 #define MAYBE_CustomMaxSizeOnDisplaySettingsChange \
1570 CustomMaxSizeOnDisplaySettingsChange
1571 #endif
1572 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1573 MAYBE_CustomMaxSizeOnDisplaySettingsChange) {
1574 PanelManager* panel_manager = PanelManager::GetInstance();
1575 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220));
1577 // Trigger custom max size by user resizing.
1578 gfx::Size bigger_size = gfx::Size(550, 400);
1579 gfx::Point mouse_location = panel->GetBounds().origin();
1580 panel_manager->StartResizingByMouse(panel,
1581 mouse_location,
1582 panel::RESIZE_TOP_LEFT);
1583 mouse_location.Offset(panel->GetBounds().width() - bigger_size.width(),
1584 panel->GetBounds().height() - bigger_size.height());
1585 panel_manager->ResizeByMouse(mouse_location);
1586 panel_manager->EndResizingByMouse(false);
1588 gfx::Size old_max_size = panel->max_size();
1589 EXPECT_EQ(bigger_size, old_max_size);
1590 gfx::Size old_full_size = panel->full_size();
1591 EXPECT_EQ(bigger_size, old_full_size);
1593 // Shrink the work area. Expect max size and full size become smaller.
1594 gfx::Rect smaller_work_area(0, 0, 500, 300);
1595 mock_display_settings_provider()->SetPrimaryDisplay(
1596 smaller_work_area, smaller_work_area);
1597 EXPECT_GT(old_max_size.width(), panel->max_size().width());
1598 EXPECT_GT(old_max_size.height(), panel->max_size().height());
1599 EXPECT_GE(smaller_work_area.width(), panel->max_size().width());
1600 EXPECT_EQ(smaller_work_area.height(), panel->max_size().height());
1601 EXPECT_GT(old_full_size.width(), panel->full_size().width());
1602 EXPECT_GT(old_full_size.height(), panel->full_size().height());
1603 EXPECT_GE(panel->max_size().width(), panel->full_size().width());
1604 EXPECT_GE(panel->max_size().height(), panel->full_size().height());
1605 EXPECT_EQ(smaller_work_area.height(), panel->full_size().height());
1607 panel->Close();
1610 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevTools) {
1611 // Create a test panel with web contents loaded.
1612 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE);
1613 GURL url(ui_test_utils::GetTestUrl(
1614 base::FilePath(kTestDir),
1615 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
1616 params.url = url;
1617 Panel* panel = CreatePanelWithParams(params);
1619 // Open devtools.
1620 size_t num_browsers = 1;
1621 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
1622 browser()->profile(),
1623 browser()->host_desktop_type()));
1624 content::WindowedNotificationObserver signal(
1625 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
1626 content::NotificationService::AllSources());
1627 EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS));
1628 signal.Wait();
1630 // Check that the new browser window that opened is dev tools window.
1631 ++num_browsers;
1632 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
1633 browser()->profile(),
1634 browser()->host_desktop_type()));
1635 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
1636 if (*iter == browser())
1637 continue;
1638 ASSERT_TRUE((*iter)->is_devtools());
1641 panel->Close();
1644 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevToolsConsole) {
1645 // Create a test panel with web contents loaded.
1646 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE);
1647 GURL url(ui_test_utils::GetTestUrl(
1648 base::FilePath(kTestDir),
1649 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
1650 params.url = url;
1651 Panel* panel = CreatePanelWithParams(params);
1653 // Open devtools console.
1654 size_t num_browsers = 1;
1655 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
1656 browser()->profile(),
1657 browser()->host_desktop_type()));
1658 content::WindowedNotificationObserver signal(
1659 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
1660 content::NotificationService::AllSources());
1661 EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS_CONSOLE));
1662 signal.Wait();
1664 // Check that the new browser window that opened is dev tools window.
1665 ++num_browsers;
1666 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
1667 browser()->profile(),
1668 browser()->host_desktop_type()));
1669 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
1670 if (*iter == browser())
1671 continue;
1672 ASSERT_TRUE((*iter)->is_devtools());
1675 panel->Close();
1678 #if defined(OS_WIN)
1679 #define MAYBE_Accelerator Accelerator
1680 #else
1681 #define MAYBE_Accelerator DISABLED_Accelerator
1682 #endif
1683 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) {
1684 PanelManager* panel_manager = PanelManager::GetInstance();
1686 // Create a test panel with web contents loaded.
1687 CreatePanelParams params("1", gfx::Rect(), SHOW_AS_ACTIVE);
1688 GURL url(ui_test_utils::GetTestUrl(
1689 base::FilePath(kTestDir),
1690 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
1691 params.url = url;
1692 Panel* panel = CreatePanelWithParams(params);
1693 EXPECT_EQ(1, panel_manager->num_panels());
1695 // Close the panel by acclerator.
1696 content::WindowedNotificationObserver signal(
1697 chrome::NOTIFICATION_PANEL_CLOSED,
1698 content::Source<Panel>(panel));
1699 #if defined(USE_AURA)
1700 double now = ui::EventTimeForNow().InSecondsF();
1701 content::NativeWebKeyboardEvent key_event(
1702 ui::ET_KEY_PRESSED,
1703 false,
1704 ui::VKEY_W,
1705 ui::EF_CONTROL_DOWN,
1706 now);
1707 #elif defined(OS_WIN)
1708 ::MSG key_msg = { NULL, WM_KEYDOWN, ui::VKEY_W, 0 };
1709 content::NativeWebKeyboardEvent key_event(key_msg);
1710 key_event.modifiers = content::NativeWebKeyboardEvent::ControlKey;
1711 #else
1712 content::NativeWebKeyboardEvent key_event;
1713 #endif
1714 panel->HandleKeyboardEvent(key_event);
1715 signal.Wait();
1716 EXPECT_EQ(0, panel_manager->num_panels());
1719 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1720 HideDockedPanelCreatedBeforeFullScreenMode) {
1721 // Create a docked panel.
1722 Panel* panel = CreatePanel("PanelTest");
1723 scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
1725 // Panel should be visible at first.
1726 EXPECT_TRUE(panel_testing->IsWindowVisible());
1728 // Panel should become hidden when entering full-screen mode.
1729 // Note that this is not needed on Linux because the full-screen window will
1730 // be always placed above any other windows.
1731 mock_display_settings_provider()->EnableFullScreenMode(true);
1732 #if defined(OS_LINUX)
1733 EXPECT_TRUE(panel_testing->IsWindowVisible());
1734 #else
1735 EXPECT_FALSE(panel_testing->IsWindowVisible());
1736 #endif
1738 // Panel should become visible when leaving full-screen mode.
1739 mock_display_settings_provider()->EnableFullScreenMode(false);
1740 EXPECT_TRUE(panel_testing->IsWindowVisible());
1742 PanelManager::GetInstance()->CloseAll();
1745 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1746 HideDockedPanelCreatedOnFullScreenMode) {
1747 // Enable full-screen mode first.
1748 mock_display_settings_provider()->EnableFullScreenMode(true);
1750 // Create a docked panel without waiting for it to be shown since it is not
1751 // supposed to be shown on full-screen mode.
1752 CreatePanelParams params("1", gfx::Rect(0, 0, 250, 200), SHOW_AS_ACTIVE);
1753 params.wait_for_fully_created = false;
1754 Panel* panel = CreatePanelWithParams(params);
1755 scoped_ptr<NativePanelTesting> panel_testing(
1756 CreateNativePanelTesting(panel));
1758 // Panel should not be shown on full-screen mode.
1759 EXPECT_FALSE(panel_testing->IsWindowVisible());
1761 // Panel should become visible when leaving full-screen mode.
1762 mock_display_settings_provider()->EnableFullScreenMode(false);
1763 EXPECT_TRUE(panel_testing->IsWindowVisible());
1765 PanelManager::GetInstance()->CloseAll();
1768 class PanelExtensionApiTest : public ExtensionApiTest {
1769 protected:
1770 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1771 ExtensionApiTest::SetUpCommandLine(command_line);
1772 command_line->AppendSwitch(switches::kEnablePanels);
1776 #if defined(OS_LINUX) || (!defined(OS_WIN) && defined(USE_AURA)) || \
1777 defined(OS_MACOSX)
1778 // Focus test fails if there is no window manager on Linux.
1779 // Aura panels have different behavior that do not apply to this test.
1780 #define MAYBE_FocusChangeEventOnMinimize DISABLED_FocusChangeEventOnMinimize
1781 #else
1782 #define MAYBE_FocusChangeEventOnMinimize FocusChangeEventOnMinimize
1783 #endif
1784 IN_PROC_BROWSER_TEST_F(PanelExtensionApiTest,
1785 MAYBE_FocusChangeEventOnMinimize) {
1786 // This is needed so the subsequently created panels can be activated.
1787 // On a Mac, it transforms background-only test process into foreground one.
1788 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1789 ASSERT_TRUE(RunExtensionTest("panels/focus_change_on_minimize")) << message_;