cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / ui / panels / panel_browsertest.cc
blobe7e58af631ddd0be0047e7b5ccf243bfb510d845
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/task_management/task_management_browsertest_util.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/browser_iterator.h"
20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
22 #include "chrome/browser/ui/panels/docked_panel_collection.h"
23 #include "chrome/browser/ui/panels/native_panel.h"
24 #include "chrome/browser/ui/panels/panel.h"
25 #include "chrome/browser/ui/panels/panel_manager.h"
26 #include "chrome/browser/ui/panels/test_panel_active_state_observer.h"
27 #include "chrome/browser/web_applications/web_app.h"
28 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/url_constants.h"
30 #include "chrome/grit/generated_resources.h"
31 #include "chrome/test/base/interactive_test_utils.h"
32 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/app_modal/app_modal_dialog.h"
34 #include "components/app_modal/native_app_modal_dialog.h"
35 #include "content/public/browser/native_web_keyboard_event.h"
36 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/web_contents.h"
38 #include "content/public/common/url_constants.h"
39 #include "content/public/test/browser_test_utils.h"
40 #include "extensions/browser/extension_registry.h"
41 #include "extensions/common/constants.h"
42 #include "net/base/net_util.h"
43 #include "net/test/url_request/url_request_mock_http_job.h"
44 #include "testing/gtest/include/gtest/gtest.h"
45 #include "ui/base/hit_test.h"
46 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/events/event_utils.h"
48 #include "ui/gfx/screen.h"
50 using content::WebContents;
52 class PanelBrowserTest : public BasePanelBrowserTest {
53 public:
54 PanelBrowserTest() : BasePanelBrowserTest() {
57 protected:
58 // Helper function for debugging.
59 void PrintAllPanelBounds() {
60 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
61 DLOG(WARNING) << "PanelBounds:";
62 for (size_t i = 0; i < panels.size(); ++i) {
63 DLOG(WARNING) << "#=" << i
64 << ", ptr=" << panels[i]
65 << ", x=" << panels[i]->GetBounds().x()
66 << ", y=" << panels[i]->GetBounds().y()
67 << ", width=" << panels[i]->GetBounds().width()
68 << ", height" << panels[i]->GetBounds().height();
72 std::vector<gfx::Rect> GetAllPanelBounds() {
73 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
74 std::vector<gfx::Rect> bounds;
75 for (size_t i = 0; i < panels.size(); i++)
76 bounds.push_back(panels[i]->GetBounds());
77 return bounds;
80 std::vector<gfx::Rect> AddXDeltaToBounds(const std::vector<gfx::Rect>& bounds,
81 const std::vector<int>& delta_x) {
82 std::vector<gfx::Rect> new_bounds = bounds;
83 for (size_t i = 0; i < bounds.size(); ++i)
84 new_bounds[i].Offset(delta_x[i], 0);
85 return new_bounds;
88 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() {
89 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
90 std::vector<Panel::ExpansionState> expansion_states;
91 for (size_t i = 0; i < panels.size(); i++)
92 expansion_states.push_back(panels[i]->expansion_state());
93 return expansion_states;
96 std::vector<bool> GetAllPanelActiveStates() {
97 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
98 std::vector<bool> active_states;
99 for (size_t i = 0; i < panels.size(); i++)
100 active_states.push_back(panels[i]->IsActive());
101 return active_states;
104 std::vector<bool> ProduceExpectedActiveStates(
105 int expected_active_panel_index) {
106 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
107 std::vector<bool> active_states;
108 for (int i = 0; i < static_cast<int>(panels.size()); i++)
109 active_states.push_back(i == expected_active_panel_index);
110 return active_states;
113 void WaitForPanelActiveStates(const std::vector<bool>& old_states,
114 const std::vector<bool>& new_states) {
115 DCHECK(old_states.size() == new_states.size());
116 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
117 for (size_t i = 0; i < old_states.size(); i++) {
118 if (old_states[i] != new_states[i]){
119 WaitForPanelActiveState(
120 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE);
125 void TestMinimizeRestore() {
126 // This constant is used to generate a point 'sufficiently higher then
127 // top edge of the panel'. On some platforms (Mac) we extend hover area
128 // a bit above the minimized panel as well, so it takes significant
129 // distance to 'move mouse out' of the hover-sensitive area.
130 const int kFarEnoughFromHoverArea = 153;
132 PanelManager* panel_manager = PanelManager::GetInstance();
133 std::vector<Panel*> panels = panel_manager->panels();
134 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds();
135 std::vector<gfx::Rect> expected_bounds = test_begin_bounds;
136 std::vector<Panel::ExpansionState> expected_expansion_states(
137 panels.size(), Panel::EXPANDED);
138 std::vector<NativePanelTesting*> native_panels_testing(panels.size());
139 for (size_t i = 0; i < panels.size(); ++i) {
140 native_panels_testing[i] = CreateNativePanelTesting(panels[i]);
143 // Verify titlebar click does not minimize.
144 for (size_t index = 0; index < panels.size(); ++index) {
145 // Press left mouse button. Verify nothing changed.
146 native_panels_testing[index]->PressLeftMouseButtonTitlebar(
147 panels[index]->GetBounds().origin());
148 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
149 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
151 // Release mouse button. Verify nothing changed.
152 native_panels_testing[index]->ReleaseMouseButtonTitlebar();
153 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
154 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
157 // Minimize all panels for next stage in test.
158 for (size_t index = 0; index < panels.size(); ++index) {
159 panels[index]->Minimize();
160 expected_bounds[index].set_height(panel::kMinimizedPanelHeight);
161 expected_bounds[index].set_y(
162 test_begin_bounds[index].y() +
163 test_begin_bounds[index].height() - panel::kMinimizedPanelHeight);
164 expected_expansion_states[index] = Panel::MINIMIZED;
165 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
166 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
169 // Setup bounds and expansion states for minimized and titlebar-only
170 // states.
171 std::vector<Panel::ExpansionState> titlebar_exposed_states(
172 panels.size(), Panel::TITLE_ONLY);
173 std::vector<gfx::Rect> minimized_bounds = expected_bounds;
174 std::vector<Panel::ExpansionState> minimized_states(
175 panels.size(), Panel::MINIMIZED);
176 std::vector<gfx::Rect> titlebar_exposed_bounds = test_begin_bounds;
177 for (size_t index = 0; index < panels.size(); ++index) {
178 titlebar_exposed_bounds[index].set_height(
179 panels[index]->native_panel()->TitleOnlyHeight());
180 titlebar_exposed_bounds[index].set_y(
181 test_begin_bounds[index].y() +
182 test_begin_bounds[index].height() -
183 panels[index]->native_panel()->TitleOnlyHeight());
186 // Test hover. All panels are currently in minimized state.
187 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
188 for (size_t index = 0; index < panels.size(); ++index) {
189 // Hover mouse on minimized panel.
190 // Verify titlebar is exposed on all panels.
191 gfx::Point hover_point(panels[index]->GetBounds().origin());
192 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
193 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
194 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
196 // Hover mouse above the panel. Verify all panels are minimized.
197 hover_point.set_y(
198 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
199 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
200 EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
201 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
203 // Hover mouse below minimized panel.
204 // Verify titlebar is exposed on all panels.
205 hover_point.set_y(panels[index]->GetBounds().y() +
206 panels[index]->GetBounds().height() + 5);
207 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
208 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
209 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
211 // Hover below titlebar exposed panel. Verify nothing changed.
212 hover_point.set_y(panels[index]->GetBounds().y() +
213 panels[index]->GetBounds().height() + 6);
214 MoveMouse(hover_point);
215 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
216 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
218 // Hover mouse above panel. Verify all panels are minimized.
219 hover_point.set_y(
220 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
221 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
222 EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
223 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
226 // Test restore. All panels are currently in minimized state.
227 for (size_t index = 0; index < panels.size(); ++index) {
228 // Hover on the last panel. This is to test the case of clicking on the
229 // panel when it's in titlebar exposed state.
230 if (index == panels.size() - 1)
231 MoveMouse(minimized_bounds[index].origin());
233 // Click minimized or title bar exposed panel as the case may be.
234 // Verify panel is restored to its original size.
235 native_panels_testing[index]->PressLeftMouseButtonTitlebar(
236 panels[index]->GetBounds().origin());
237 native_panels_testing[index]->ReleaseMouseButtonTitlebar();
238 expected_bounds[index].set_height(
239 test_begin_bounds[index].height());
240 expected_bounds[index].set_y(test_begin_bounds[index].y());
241 expected_expansion_states[index] = Panel::EXPANDED;
242 EXPECT_EQ(expected_bounds, GetAllPanelBounds());
243 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
245 // Hover again on the last panel which is now restored, to reset the
246 // titlebar exposed state.
247 if (index == panels.size() - 1)
248 MoveMouse(minimized_bounds[index].origin());
251 // The below could be separate tests, just adding a TODO here for tracking.
252 // TODO(prasadt): Add test for dragging when in titlebar exposed state.
253 // TODO(prasadt): Add test in presence of auto hiding task bar.
255 for (size_t i = 0; i < panels.size(); ++i)
256 delete native_panels_testing[i];
260 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CheckDockedPanelProperties) {
261 PanelManager* panel_manager = PanelManager::GetInstance();
262 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
264 // Create 3 docked panels that are in expanded, title-only or minimized states
265 // respectively.
266 Panel* panel1 = CreatePanelWithBounds("1", gfx::Rect(0, 0, 100, 100));
267 Panel* panel2 = CreatePanelWithBounds("2", gfx::Rect(0, 0, 100, 100));
268 Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100));
269 panel2->SetExpansionState(Panel::TITLE_ONLY);
270 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
271 panel3->SetExpansionState(Panel::MINIMIZED);
272 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
273 scoped_ptr<NativePanelTesting> panel1_testing(
274 CreateNativePanelTesting(panel1));
275 scoped_ptr<NativePanelTesting> panel2_testing(
276 CreateNativePanelTesting(panel2));
277 scoped_ptr<NativePanelTesting> panel3_testing(
278 CreateNativePanelTesting(panel3));
280 // Ensure that the layout message can get a chance to be processed so that
281 // the button visibility can be updated.
282 base::MessageLoop::current()->RunUntilIdle();
284 EXPECT_EQ(3, panel_manager->num_panels());
285 EXPECT_TRUE(docked_collection->HasPanel(panel1));
286 EXPECT_TRUE(docked_collection->HasPanel(panel2));
287 EXPECT_TRUE(docked_collection->HasPanel(panel3));
289 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
290 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
291 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
293 EXPECT_TRUE(panel1->IsAlwaysOnTop());
294 EXPECT_TRUE(panel2->IsAlwaysOnTop());
295 EXPECT_TRUE(panel3->IsAlwaysOnTop());
297 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON));
298 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON));
299 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON));
301 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
302 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
303 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
305 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON));
306 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON));
307 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON));
309 // Expanded panel cannot be resized at the bottom.
310 EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel1->CanResizeByMouse());
311 EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse());
312 EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse());
314 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
315 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
316 EXPECT_EQ(panel::TOP_ROUNDED, panel3_testing->GetWindowCornerStyle());
318 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel1->attention_mode());
319 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel2->attention_mode());
320 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode());
322 panel_manager->CloseAll();
325 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) {
326 PanelManager* panel_manager = PanelManager::GetInstance();
327 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
329 Panel* panel = CreatePanel("PanelTest");
330 EXPECT_EQ(1, panel_manager->num_panels());
332 gfx::Rect bounds = panel->GetBounds();
333 EXPECT_GT(bounds.x(), 0);
334 EXPECT_GT(bounds.y(), 0);
335 EXPECT_GT(bounds.width(), 0);
336 EXPECT_GT(bounds.height(), 0);
338 EXPECT_EQ(bounds.right(),
339 panel_manager->docked_collection()->StartingRightPosition());
341 CloseWindowAndWait(panel);
343 EXPECT_EQ(0, panel_manager->num_panels());
346 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) {
347 gfx::Rect work_area = PanelManager::GetInstance()->
348 display_settings_provider()->GetPrimaryWorkArea();
349 Panel* panel = CreatePanelWithBounds("BigPanel", work_area);
350 gfx::Rect bounds = panel->GetBounds();
351 EXPECT_EQ(panel->max_size().width(), bounds.width());
352 EXPECT_LT(bounds.width(), work_area.width());
353 EXPECT_EQ(panel->max_size().height(), bounds.height());
354 EXPECT_LT(bounds.height(), work_area.height());
355 panel->Close();
358 class WaitForStableInitialSize : public TestPanelNotificationObserver {
359 public:
360 explicit WaitForStableInitialSize(Panel* panel)
361 : TestPanelNotificationObserver(
362 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
363 content::NotificationService::AllSources()),
364 panel_(panel) {}
365 ~WaitForStableInitialSize() override {}
367 protected:
368 bool AtExpectedState() override {
369 return panel_->GetBounds().height() > panel_->TitleOnlyHeight();
371 Panel* panel_;
374 class WaitForAutoResizeWider : public TestPanelNotificationObserver {
375 public:
376 explicit WaitForAutoResizeWider(Panel* panel)
377 : TestPanelNotificationObserver(
378 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
379 content::NotificationService::AllSources()),
380 panel_(panel),
381 initial_size_(panel->GetBounds().size()) {}
382 ~WaitForAutoResizeWider() override {}
384 protected:
385 bool AtExpectedState() override {
386 return panel_->GetBounds().width() > initial_size_.width();
388 Panel* panel_;
389 gfx::Size initial_size_;
392 class WaitForAutoResizeNarrower : public TestPanelNotificationObserver {
393 public:
394 explicit WaitForAutoResizeNarrower(Panel* panel)
395 : TestPanelNotificationObserver(
396 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
397 content::NotificationService::AllSources()),
398 panel_(panel),
399 initial_size_(panel->GetBounds().size()) {}
400 ~WaitForAutoResizeNarrower() override {}
402 protected:
403 bool AtExpectedState() override {
404 return panel_->GetBounds().width() < initial_size_.width();
406 Panel* panel_;
407 gfx::Size initial_size_;
410 // crbug.com/160504
411 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) {
412 PanelManager* panel_manager = PanelManager::GetInstance();
413 panel_manager->enable_auto_sizing(true);
414 // Bigger space is needed by this test.
415 mock_display_settings_provider()->SetPrimaryDisplay(
416 gfx::Rect(0, 0, 1200, 900), gfx::Rect(0, 0, 1200, 900));
418 // Create a test panel with web contents loaded.
419 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
420 GURL url(ui_test_utils::GetTestUrl(
421 base::FilePath(kTestDir),
422 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
423 params.url = url;
424 Panel* panel = CreatePanelWithParams(params);
426 // Ensure panel has auto resized to original web content size.
427 // The resize will update the docked panel collection.
428 WaitForStableInitialSize initial_resize(panel);
429 initial_resize.Wait();
430 gfx::Rect initial_bounds = panel->GetBounds();
432 // Expand the test page. The resize will update the docked panel collection.
433 WaitForAutoResizeWider enlarge(panel);
434 EXPECT_TRUE(content::ExecuteScript(
435 panel->GetWebContents(), "changeSize(50);"));
436 enlarge.Wait();
437 gfx::Rect bounds_on_grow = panel->GetBounds();
438 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width());
439 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height());
441 // Shrink the test page. The resize will update the docked panel collection.
442 WaitForAutoResizeNarrower shrink(panel);
443 EXPECT_TRUE(content::ExecuteScript(
444 panel->GetWebContents(), "changeSize(-30);"));
445 shrink.Wait();
446 gfx::Rect bounds_on_shrink = panel->GetBounds();
447 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width());
448 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width());
449 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height());
451 // Verify resizing turns off auto-resizing and panel no longer auto-resizes.
452 gfx::Rect previous_bounds = panel->GetBounds();
453 // These should be identical because the panel is expanded.
454 EXPECT_EQ(previous_bounds.size(), panel->GetRestoredBounds().size());
455 gfx::Size new_size(previous_bounds.size());
456 new_size.Enlarge(5, 5);
457 gfx::Rect new_bounds(previous_bounds.origin(), new_size);
458 panel->SetBounds(new_bounds);
459 EXPECT_FALSE(panel->auto_resizable());
460 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
461 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
463 // Turn back on auto-resize and verify that panel auto resizes.
464 content::WindowedNotificationObserver auto_resize_enabled(
465 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
466 content::NotificationService::AllSources());
467 panel->SetAutoResizable(true);
468 auto_resize_enabled.Wait();
469 gfx::Rect bounds_auto_resize_enabled = panel->GetBounds();
470 EXPECT_EQ(bounds_on_shrink.width(), bounds_auto_resize_enabled.width());
471 EXPECT_EQ(bounds_on_shrink.height(), bounds_auto_resize_enabled.height());
473 panel->Close();
476 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ResizePanel) {
477 PanelManager* panel_manager = PanelManager::GetInstance();
478 panel_manager->enable_auto_sizing(true);
480 Panel* panel = CreatePanel("TestPanel");
481 EXPECT_TRUE(panel->auto_resizable());
482 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
484 // Verify resizing turns off auto-resizing and that it works.
485 gfx::Rect original_bounds = panel->GetBounds();
486 // These should be identical because the panel is expanded.
487 EXPECT_EQ(original_bounds.size(), panel->GetRestoredBounds().size());
488 gfx::Size new_size(original_bounds.size());
489 new_size.Enlarge(5, 5);
490 gfx::Rect new_bounds(original_bounds.origin(), new_size);
491 panel->SetBounds(new_bounds);
492 EXPECT_FALSE(panel->auto_resizable());
493 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
494 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
496 // Verify current height unaffected when panel is not expanded.
497 panel->SetExpansionState(Panel::MINIMIZED);
498 int original_height = panel->GetBounds().height();
499 new_size.Enlarge(5, 5);
500 new_bounds.set_size(new_size);
501 panel->SetBounds(new_bounds);
502 EXPECT_EQ(new_bounds.size().width(), panel->GetBounds().width());
503 EXPECT_EQ(original_height, panel->GetBounds().height());
504 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
506 panel->Close();
509 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AnimateBounds) {
510 // Create a detached panel, instead of docked panel because it cannot be
511 // moved to any location.
512 Panel* panel = CreateDetachedPanel("1", gfx::Rect(200, 100, 100, 100));
513 scoped_ptr<NativePanelTesting> panel_testing(
514 CreateNativePanelTesting(panel));
516 // Validates that no animation should be triggered when the panel is being
517 // dragged.
518 gfx::Point mouse_location(panel->GetBounds().origin());
519 panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
520 panel_testing->DragTitlebar(mouse_location + gfx::Vector2d(-100, 5));
521 EXPECT_FALSE(panel_testing->IsAnimatingBounds());
522 panel_testing->FinishDragTitlebar();
524 // Set bounds with animation.
525 gfx::Rect bounds = gfx::Rect(10, 20, 150, 160);
526 panel->SetPanelBounds(bounds);
527 EXPECT_TRUE(panel_testing->IsAnimatingBounds());
528 WaitForBoundsAnimationFinished(panel);
529 EXPECT_FALSE(panel_testing->IsAnimatingBounds());
530 EXPECT_EQ(bounds, panel->GetBounds());
532 // Set bounds without animation.
533 bounds = gfx::Rect(30, 40, 200, 220);
534 panel->SetPanelBoundsInstantly(bounds);
535 EXPECT_FALSE(panel_testing->IsAnimatingBounds());
536 EXPECT_EQ(bounds, panel->GetBounds());
538 panel->Close();
541 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) {
542 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
543 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
544 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
546 panel->SetExpansionState(Panel::MINIMIZED);
547 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
548 gfx::Rect bounds = panel->GetBounds();
549 gfx::Rect restored = panel->GetRestoredBounds();
550 EXPECT_EQ(bounds.x(), restored.x());
551 EXPECT_GT(bounds.y(), restored.y());
552 EXPECT_EQ(bounds.width(), restored.width());
553 EXPECT_LT(bounds.height(), restored.height());
555 panel->SetExpansionState(Panel::TITLE_ONLY);
556 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
557 bounds = panel->GetBounds();
558 restored = panel->GetRestoredBounds();
559 EXPECT_EQ(bounds.x(), restored.x());
560 EXPECT_GT(bounds.y(), restored.y());
561 EXPECT_EQ(bounds.width(), restored.width());
562 EXPECT_LT(bounds.height(), restored.height());
564 panel->SetExpansionState(Panel::MINIMIZED);
565 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
566 bounds = panel->GetBounds();
567 restored = panel->GetRestoredBounds();
568 EXPECT_EQ(bounds.x(), restored.x());
569 EXPECT_GT(bounds.y(), restored.y());
570 EXPECT_EQ(bounds.width(), restored.width());
571 EXPECT_LT(bounds.height(), restored.height());
573 panel->SetExpansionState(Panel::EXPANDED);
574 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
576 // Verify that changing the panel bounds does not affect the restored height.
577 int saved_restored_height = restored.height();
578 panel->SetExpansionState(Panel::MINIMIZED);
579 bounds = gfx::Rect(10, 20, 300, 400);
580 panel->SetPanelBounds(bounds);
581 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
583 panel->SetExpansionState(Panel::TITLE_ONLY);
584 bounds = gfx::Rect(20, 30, 100, 200);
585 panel->SetPanelBounds(bounds);
586 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
588 panel->SetExpansionState(Panel::EXPANDED);
589 bounds = gfx::Rect(40, 60, 300, 400);
590 panel->SetPanelBounds(bounds);
591 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
592 panel->set_full_size(bounds.size());
593 EXPECT_NE(saved_restored_height, panel->GetRestoredBounds().height());
595 panel->Close();
598 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestore) {
599 // Test with one panel.
600 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
601 TestMinimizeRestore();
603 PanelManager::GetInstance()->CloseAll();
606 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreTwoPanels) {
607 // Test with two panels.
608 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
609 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
610 TestMinimizeRestore();
612 PanelManager::GetInstance()->CloseAll();
615 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreThreePanels) {
616 // Test with three panels.
617 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
618 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
619 CreatePanelWithBounds("PanelTest3", gfx::Rect(0, 0, 120, 120));
620 TestMinimizeRestore();
622 PanelManager::GetInstance()->CloseAll();
625 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreButtonClick) {
626 // Test with three panels.
627 Panel* panel1 = CreatePanel("PanelTest1");
628 Panel* panel2 = CreatePanel("PanelTest2");
629 Panel* panel3 = CreatePanel("PanelTest3");
630 EXPECT_FALSE(panel1->IsMinimized());
631 EXPECT_FALSE(panel2->IsMinimized());
632 EXPECT_FALSE(panel3->IsMinimized());
634 // Click restore button on an expanded panel. Expect no change.
635 panel1->OnRestoreButtonClicked(panel::NO_MODIFIER);
636 EXPECT_FALSE(panel1->IsMinimized());
637 EXPECT_FALSE(panel2->IsMinimized());
638 EXPECT_FALSE(panel3->IsMinimized());
640 // Click minimize button on an expanded panel. Only that panel will minimize.
641 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
642 EXPECT_TRUE(panel1->IsMinimized());
643 EXPECT_FALSE(panel2->IsMinimized());
644 EXPECT_FALSE(panel3->IsMinimized());
646 // Click minimize button on a minimized panel. Expect no change.
647 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
648 EXPECT_TRUE(panel1->IsMinimized());
649 EXPECT_FALSE(panel2->IsMinimized());
650 EXPECT_FALSE(panel3->IsMinimized());
652 // Minimize all panels by clicking minimize button on an expanded panel
653 // with the apply-all modifier.
654 panel2->OnMinimizeButtonClicked(panel::APPLY_TO_ALL);
655 EXPECT_TRUE(panel1->IsMinimized());
656 EXPECT_TRUE(panel2->IsMinimized());
657 EXPECT_TRUE(panel3->IsMinimized());
659 // Click restore button on a minimized panel. Only that panel will restore.
660 panel2->OnRestoreButtonClicked(panel::NO_MODIFIER);
661 EXPECT_TRUE(panel1->IsMinimized());
662 EXPECT_FALSE(panel2->IsMinimized());
663 EXPECT_TRUE(panel3->IsMinimized());
665 // Restore all panels by clicking restore button on a minimized panel.
666 panel3->OnRestoreButtonClicked(panel::APPLY_TO_ALL);
667 EXPECT_FALSE(panel1->IsMinimized());
668 EXPECT_FALSE(panel2->IsMinimized());
669 EXPECT_FALSE(panel3->IsMinimized());
672 // http://crbug.com/243891 flaky on Linux
673 #if defined(OS_LINUX)
674 #define MAYBE_RestoreAllWithTitlebarClick DISABLED_RestoreAllWithTitlebarClick
675 #else
676 #define MAYBE_RestoreAllWithTitlebarClick RestoreAllWithTitlebarClick
677 #endif
678 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_RestoreAllWithTitlebarClick) {
679 // Test with three panels.
680 Panel* panel1 = CreatePanel("PanelTest1");
681 Panel* panel2 = CreatePanel("PanelTest2");
682 Panel* panel3 = CreatePanel("PanelTest3");
683 EXPECT_FALSE(panel1->IsMinimized());
684 EXPECT_FALSE(panel2->IsMinimized());
685 EXPECT_FALSE(panel3->IsMinimized());
687 scoped_ptr<NativePanelTesting> test_panel1(
688 CreateNativePanelTesting(panel1));
689 scoped_ptr<NativePanelTesting> test_panel2(
690 CreateNativePanelTesting(panel2));
691 scoped_ptr<NativePanelTesting> test_panel3(
692 CreateNativePanelTesting(panel3));
694 // Click on an expanded panel's titlebar using the apply-all modifier.
695 // Verify expansion state is unchanged.
696 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
697 panel::APPLY_TO_ALL);
698 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
699 EXPECT_FALSE(panel1->IsMinimized());
700 EXPECT_FALSE(panel2->IsMinimized());
701 EXPECT_FALSE(panel3->IsMinimized());
703 // Click on a minimized panel's titlebar using the apply-all modifier.
704 panel1->Minimize();
705 panel2->Minimize();
706 panel3->Minimize();
707 EXPECT_TRUE(panel1->IsMinimized());
708 EXPECT_TRUE(panel2->IsMinimized());
709 EXPECT_TRUE(panel3->IsMinimized());
711 // Nothing changes until mouse is released.
712 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
713 panel::APPLY_TO_ALL);
714 EXPECT_TRUE(panel1->IsMinimized());
715 EXPECT_TRUE(panel2->IsMinimized());
716 EXPECT_TRUE(panel3->IsMinimized());
717 // Verify all panels restored when mouse is released.
718 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
719 EXPECT_FALSE(panel1->IsMinimized());
720 EXPECT_FALSE(panel2->IsMinimized());
721 EXPECT_FALSE(panel3->IsMinimized());
723 // Minimize a single panel. Then click on expanded panel with apply-all
724 // modifier. Verify nothing changes.
725 panel1->Minimize();
726 EXPECT_TRUE(panel1->IsMinimized());
727 EXPECT_FALSE(panel2->IsMinimized());
728 EXPECT_FALSE(panel3->IsMinimized());
730 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
731 panel::APPLY_TO_ALL);
732 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
733 EXPECT_TRUE(panel1->IsMinimized());
734 EXPECT_FALSE(panel2->IsMinimized());
735 EXPECT_FALSE(panel3->IsMinimized());
737 // Minimize another panel. Then click on a minimized panel with apply-all
738 // modifier to restore all panels.
739 panel2->Minimize();
740 EXPECT_TRUE(panel1->IsMinimized());
741 EXPECT_TRUE(panel2->IsMinimized());
742 EXPECT_FALSE(panel3->IsMinimized());
744 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
745 panel::APPLY_TO_ALL);
746 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
747 EXPECT_FALSE(panel1->IsMinimized());
748 EXPECT_FALSE(panel2->IsMinimized());
749 EXPECT_FALSE(panel3->IsMinimized());
751 // Click on the single minimized panel. Verify all are restored.
752 panel1->Minimize();
753 EXPECT_TRUE(panel1->IsMinimized());
754 EXPECT_FALSE(panel2->IsMinimized());
755 EXPECT_FALSE(panel3->IsMinimized());
757 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
758 panel::APPLY_TO_ALL);
759 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
760 EXPECT_FALSE(panel1->IsMinimized());
761 EXPECT_FALSE(panel2->IsMinimized());
762 EXPECT_FALSE(panel3->IsMinimized());
764 // Click on the single expanded panel. Verify nothing changes.
765 panel1->Minimize();
766 panel3->Minimize();
767 EXPECT_TRUE(panel1->IsMinimized());
768 EXPECT_FALSE(panel2->IsMinimized());
769 EXPECT_TRUE(panel3->IsMinimized());
771 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
772 panel::APPLY_TO_ALL);
773 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
774 EXPECT_TRUE(panel1->IsMinimized());
775 EXPECT_FALSE(panel2->IsMinimized());
776 EXPECT_TRUE(panel3->IsMinimized());
778 // Hover over a minimized panel and click on the titlebar while it is in
779 // title-only mode. Should restore all panels.
780 panel2->Minimize();
781 EXPECT_TRUE(panel1->IsMinimized());
782 EXPECT_TRUE(panel2->IsMinimized());
783 EXPECT_TRUE(panel3->IsMinimized());
785 MoveMouseAndWaitForExpansionStateChange(panel2, panel2->GetBounds().origin());
786 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
787 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
788 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state());
790 test_panel3->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(),
791 panel::APPLY_TO_ALL);
792 test_panel3->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
793 EXPECT_FALSE(panel1->IsMinimized());
794 EXPECT_FALSE(panel2->IsMinimized());
795 EXPECT_FALSE(panel3->IsMinimized());
797 // Draw attention to a minimized panel. Click on a minimized panel that is
798 // not drawing attention. Verify restore all applies without affecting
799 // draw attention.
800 panel1->Minimize();
801 panel2->Minimize();
802 panel3->Minimize();
803 EXPECT_TRUE(panel1->IsMinimized());
804 EXPECT_TRUE(panel2->IsMinimized());
805 EXPECT_TRUE(panel3->IsMinimized());
807 panel1->FlashFrame(true);
808 EXPECT_TRUE(panel1->IsDrawingAttention());
810 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
811 panel::APPLY_TO_ALL);
812 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
813 EXPECT_FALSE(panel1->IsMinimized());
814 EXPECT_FALSE(panel2->IsMinimized());
815 EXPECT_FALSE(panel3->IsMinimized());
816 EXPECT_TRUE(panel1->IsDrawingAttention());
818 // Restore all panels by clicking on the minimized panel that is drawing
819 // attention. Verify restore all applies and clears draw attention.
820 panel1->Minimize();
821 panel2->Minimize();
822 panel3->Minimize();
823 EXPECT_TRUE(panel1->IsMinimized());
824 EXPECT_TRUE(panel2->IsMinimized());
825 EXPECT_TRUE(panel3->IsMinimized());
827 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
828 panel::APPLY_TO_ALL);
829 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
830 EXPECT_FALSE(panel1->IsMinimized());
831 EXPECT_FALSE(panel2->IsMinimized());
832 EXPECT_FALSE(panel3->IsMinimized());
833 EXPECT_FALSE(panel1->IsDrawingAttention());
835 PanelManager::GetInstance()->CloseAll();
838 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
839 MinimizeRestoreOnAutoHidingDesktopBar) {
840 PanelManager* panel_manager = PanelManager::GetInstance();
841 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
842 int expected_bottom_on_expanded = docked_collection->work_area().bottom();
843 int expected_bottom_on_title_only = expected_bottom_on_expanded;
844 int expected_bottom_on_minimized = expected_bottom_on_expanded;
846 // Turn on auto-hiding.
847 static const int bottom_bar_thickness = 40;
848 mock_display_settings_provider()->EnableAutoHidingDesktopBar(
849 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
850 true,
851 bottom_bar_thickness);
852 expected_bottom_on_title_only -= bottom_bar_thickness;
854 Panel* panel = CreatePanel("1");
855 int initial_height = panel->GetBounds().height();
857 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
858 EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
860 panel->Minimize();
861 WaitForBoundsAnimationFinished(panel);
862 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
863 EXPECT_EQ(panel::kMinimizedPanelHeight, panel->GetBounds().height());
864 EXPECT_EQ(expected_bottom_on_minimized, panel->GetBounds().bottom());
866 panel->SetExpansionState(Panel::TITLE_ONLY);
867 WaitForBoundsAnimationFinished(panel);
868 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
869 EXPECT_EQ(panel::kTitlebarHeight, panel->GetBounds().height());
870 EXPECT_EQ(expected_bottom_on_title_only, panel->GetBounds().bottom());
872 panel->Restore();
873 WaitForBoundsAnimationFinished(panel);
874 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
875 EXPECT_EQ(initial_height, panel->GetBounds().height());
876 EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
878 panel->Close();
881 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ChangeAutoHideTaskBarThickness) {
882 PanelManager* manager = PanelManager::GetInstance();
883 DockedPanelCollection* docked_collection = manager->docked_collection();
884 int initial_starting_right_position =
885 docked_collection->StartingRightPosition();
887 int bottom_bar_thickness = 20;
888 int right_bar_thickness = 30;
889 mock_display_settings_provider()->EnableAutoHidingDesktopBar(
890 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
891 true,
892 bottom_bar_thickness);
893 mock_display_settings_provider()->EnableAutoHidingDesktopBar(
894 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
895 true,
896 right_bar_thickness);
897 EXPECT_EQ(initial_starting_right_position,
898 docked_collection->StartingRightPosition());
900 Panel* panel = CreatePanel("PanelTest");
901 panel->SetExpansionState(Panel::TITLE_ONLY);
902 WaitForBoundsAnimationFinished(panel);
904 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
905 panel->GetBounds().bottom());
906 EXPECT_EQ(docked_collection->StartingRightPosition(),
907 panel->GetBounds().right());
909 initial_starting_right_position = docked_collection->StartingRightPosition();
910 int bottom_bar_thickness_delta = 10;
911 bottom_bar_thickness += bottom_bar_thickness_delta;
912 int right_bar_thickness_delta = 15;
913 right_bar_thickness += right_bar_thickness_delta;
914 mock_display_settings_provider()->SetDesktopBarThickness(
915 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
916 bottom_bar_thickness);
917 mock_display_settings_provider()->SetDesktopBarThickness(
918 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
919 right_bar_thickness);
920 base::MessageLoopForUI::current()->RunUntilIdle();
921 EXPECT_EQ(initial_starting_right_position,
922 docked_collection->StartingRightPosition());
923 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
924 panel->GetBounds().bottom());
925 EXPECT_EQ(docked_collection->StartingRightPosition(),
926 panel->GetBounds().right());
928 initial_starting_right_position = docked_collection->StartingRightPosition();
929 bottom_bar_thickness_delta = 20;
930 bottom_bar_thickness -= bottom_bar_thickness_delta;
931 right_bar_thickness_delta = 10;
932 right_bar_thickness -= right_bar_thickness_delta;
933 mock_display_settings_provider()->SetDesktopBarThickness(
934 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
935 bottom_bar_thickness);
936 mock_display_settings_provider()->SetDesktopBarThickness(
937 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
938 right_bar_thickness);
939 base::MessageLoopForUI::current()->RunUntilIdle();
940 EXPECT_EQ(docked_collection->StartingRightPosition(),
941 initial_starting_right_position);
942 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
943 panel->GetBounds().bottom());
944 EXPECT_EQ(docked_collection->StartingRightPosition(),
945 panel->GetBounds().right());
947 panel->Close();
950 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivatePanelOrTabbedWindow) {
951 if (!WmSupportWindowActivation()) {
952 LOG(WARNING) << "Skipping test due to WM problems.";
953 return;
956 Panel* panel1 = CreatePanel("Panel1");
957 Panel* panel2 = CreatePanel("Panel2");
959 // Activate main tabbed window.
960 browser()->window()->Activate();
961 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
963 // Activate a panel.
964 panel2->Activate();
965 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
967 // Activate the main tabbed window back.
968 browser()->window()->Activate();
969 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
971 // Activate another panel.
972 panel1->Activate();
973 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
974 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
976 // Switch focus between panels.
977 panel2->Activate();
978 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
979 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
981 PanelManager::GetInstance()->CloseAll();
984 // TODO(jianli): To be enabled for other platforms.
985 #if defined(OS_WIN) || defined(OS_LINUX)
986 #define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
987 #else
988 #define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
989 #endif
990 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
991 if (!WmSupportWindowActivation()) {
992 LOG(WARNING) << "Skipping test due to WM problems.";
993 return;
996 // Create an active panel.
997 Panel* panel = CreatePanel("PanelTest");
998 scoped_ptr<NativePanelTesting> native_panel_testing(
999 CreateNativePanelTesting(panel));
1001 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); // doublecheck active state
1002 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
1004 // Deactivate the panel.
1005 panel->Deactivate();
1006 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
1008 // On GTK there is no way to deactivate a window. So the Deactivate() call
1009 // above does not actually deactivate the window, but simply lowers it.
1010 #if !defined(OS_LINUX)
1011 EXPECT_TRUE(native_panel_testing->VerifyActiveState(false));
1012 #endif
1014 // This test does not reactivate the panel because the panel might not be
1015 // reactivated programmatically once it is deactivated.
1018 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivateDeactivateMultiple) {
1019 if (!WmSupportWindowActivation()) {
1020 LOG(WARNING) << "Skipping test due to WM problems.";
1021 return;
1024 BrowserWindow* tabbed_window = browser()->window();
1026 // Create 4 panels in the following screen layout:
1027 // P3 P2 P1 P0
1028 const int kNumPanels = 4;
1029 for (int i = 0; i < kNumPanels; ++i)
1030 CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100));
1031 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
1033 std::vector<bool> expected_active_states;
1034 std::vector<bool> last_active_states;
1036 // The last created panel, P3, should be active.
1037 expected_active_states = ProduceExpectedActiveStates(3);
1038 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1039 EXPECT_FALSE(tabbed_window->IsActive());
1041 // Activating P1 should cause P3 to lose focus.
1042 panels[1]->Activate();
1043 last_active_states = expected_active_states;
1044 expected_active_states = ProduceExpectedActiveStates(1);
1045 WaitForPanelActiveStates(last_active_states, expected_active_states);
1046 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1048 // Minimizing inactive panel P2 should not affect other panels' active states.
1049 panels[2]->SetExpansionState(Panel::MINIMIZED);
1050 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
1051 EXPECT_FALSE(tabbed_window->IsActive());
1054 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionBasic) {
1055 Panel* panel = CreateInactivePanel("P1");
1056 scoped_ptr<NativePanelTesting> native_panel_testing(
1057 CreateNativePanelTesting(panel));
1059 // Test that the attention is drawn when the expanded panel is not in focus.
1060 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
1061 EXPECT_FALSE(panel->IsActive());
1062 EXPECT_FALSE(panel->IsDrawingAttention());
1063 panel->FlashFrame(true);
1064 EXPECT_TRUE(panel->IsDrawingAttention());
1065 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
1067 // Stop drawing attention.
1068 panel->FlashFrame(false);
1069 EXPECT_FALSE(panel->IsDrawingAttention());
1070 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1072 // Draw attention, then minimize. Titlebar should remain visible.
1073 panel->FlashFrame(true);
1074 EXPECT_TRUE(panel->IsDrawingAttention());
1076 panel->Minimize();
1077 EXPECT_TRUE(panel->IsDrawingAttention());
1078 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
1080 // Stop drawing attention. Titlebar should no longer be visible.
1081 panel->FlashFrame(false);
1082 EXPECT_FALSE(panel->IsDrawingAttention());
1083 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
1085 panel->Close();
1088 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) {
1089 Panel* panel1 = CreateInactivePanel("P1");
1090 Panel* panel2 = CreateInactivePanel("P2");
1092 scoped_ptr<NativePanelTesting> native_panel1_testing(
1093 CreateNativePanelTesting(panel1));
1095 // Test that the attention is drawn and the title-bar is brought up when the
1096 // minimized panel is drawing attention.
1097 panel1->Minimize();
1098 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1099 panel1->FlashFrame(true);
1100 EXPECT_TRUE(panel1->IsDrawingAttention());
1101 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1102 EXPECT_TRUE(native_panel1_testing->VerifyDrawingAttention());
1104 // Test that we cannot bring up other minimized panel if the mouse is over
1105 // the panel that draws attension.
1106 panel2->Minimize();
1107 gfx::Point hover_point(panel1->GetBounds().origin());
1108 MoveMouse(hover_point);
1109 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1110 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1112 // Test that we cannot bring down the panel that is drawing the attention.
1113 hover_point.set_y(hover_point.y() - 200);
1114 MoveMouse(hover_point);
1115 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1117 // Test that the attention is cleared when activated.
1118 panel1->Activate();
1119 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
1120 EXPECT_FALSE(panel1->IsDrawingAttention());
1121 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
1122 EXPECT_FALSE(native_panel1_testing->VerifyDrawingAttention());
1124 PanelManager::GetInstance()->CloseAll();
1127 // Verify that minimized state of a panel is correct after draw attention
1128 // is stopped when there are other minimized panels.
1129 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, StopDrawingAttentionWhileMinimized) {
1130 Panel* panel1 = CreateInactivePanel("P1");
1131 Panel* panel2 = CreateInactivePanel("P2");
1133 panel1->Minimize();
1134 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1135 panel2->Minimize();
1136 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1138 // Verify panel returns to minimized state when no longer drawing attention.
1139 panel1->FlashFrame(true);
1140 EXPECT_TRUE(panel1->IsDrawingAttention());
1141 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1143 panel1->FlashFrame(false);
1144 EXPECT_FALSE(panel1->IsDrawingAttention());
1145 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1147 // Hover over other minimized panel to bring up titlebars.
1148 gfx::Point hover_point(panel2->GetBounds().origin());
1149 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
1150 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1151 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
1153 // Verify panel keeps titlebar visible when no longer drawing attention
1154 // if titlebars are up.
1155 panel1->FlashFrame(true);
1156 EXPECT_TRUE(panel1->IsDrawingAttention());
1157 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1159 panel1->FlashFrame(false);
1160 EXPECT_FALSE(panel1->IsDrawingAttention());
1161 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1163 // Move mouse away. All panels should return to minimized state.
1164 hover_point.set_y(hover_point.y() - 200);
1165 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
1166 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1167 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1169 // Verify minimized panel that is drawing attention stays in title-only mode
1170 // after attention is cleared if mouse is in the titlebar area.
1171 panel1->FlashFrame(true);
1172 EXPECT_TRUE(panel1->IsDrawingAttention());
1173 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1175 gfx::Point hover_point_in_panel(panel1->GetBounds().origin());
1176 MoveMouse(hover_point_in_panel);
1178 panel1->FlashFrame(false);
1179 EXPECT_FALSE(panel1->IsDrawingAttention());
1180 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1181 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1183 // Typical user scenario will detect the mouse in the panel
1184 // after attention is cleared, causing titles to pop up, so
1185 // we simulate that here.
1186 MoveMouseAndWaitForExpansionStateChange(panel2, hover_point_in_panel);
1187 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
1188 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
1190 // Move mouse away and panels should go back to fully minimized state.
1191 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
1192 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1193 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1195 PanelManager::GetInstance()->CloseAll();
1198 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) {
1199 // Create an active panel.
1200 Panel* panel = CreatePanel("P1");
1201 scoped_ptr<NativePanelTesting> native_panel_testing(
1202 CreateNativePanelTesting(panel));
1204 // Test that the attention should not be drawn if the expanded panel is in
1205 // focus.
1206 panel->FlashFrame(true);
1207 EXPECT_FALSE(panel->IsDrawingAttention());
1208 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1210 panel->Close();
1213 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) {
1214 Panel* panel = CreateInactivePanel("P1");
1215 scoped_ptr<NativePanelTesting> native_panel_testing(
1216 CreateNativePanelTesting(panel));
1218 panel->FlashFrame(true);
1219 EXPECT_TRUE(panel->IsDrawingAttention());
1220 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
1222 // Test that the attention is cleared when panel gets focus.
1223 panel->Activate();
1224 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1225 EXPECT_FALSE(panel->IsDrawingAttention());
1226 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1228 panel->Close();
1231 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1232 DrawAttentionMinimizedNotResetOnActivate) {
1233 Panel* panel = CreateInactivePanel("P1");
1235 panel->Minimize();
1236 EXPECT_TRUE(panel->IsMinimized());
1237 panel->FlashFrame(true);
1238 EXPECT_TRUE(panel->IsDrawingAttention());
1240 // Simulate panel being activated while minimized. Cannot call
1241 // Activate() as that expands the panel.
1242 panel->OnActiveStateChanged(true);
1243 EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged.
1245 // Unminimize panel to show that attention would have been cleared
1246 // if panel had not been minimized.
1247 panel->Restore();
1248 EXPECT_FALSE(panel->IsMinimized());
1249 EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged.
1251 panel->OnActiveStateChanged(true);
1252 EXPECT_FALSE(panel->IsDrawingAttention()); // Attention cleared.
1254 panel->Close();
1257 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) {
1258 Panel* panel = CreateInactivePanel("P1");
1259 scoped_ptr<NativePanelTesting> native_panel_testing(
1260 CreateNativePanelTesting(panel));
1262 panel->FlashFrame(true);
1263 EXPECT_TRUE(panel->IsDrawingAttention());
1264 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
1266 // Test that the attention is cleared when panel gets focus.
1267 native_panel_testing->PressLeftMouseButtonTitlebar(
1268 panel->GetBounds().origin());
1269 native_panel_testing->ReleaseMouseButtonTitlebar();
1271 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1272 EXPECT_FALSE(panel->IsDrawingAttention());
1273 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
1275 panel->Close();
1278 // http://crbug.com/175760; several panel tests failing regularly on mac.
1279 #if defined(OS_MACOSX)
1280 #define MAYBE_MinimizeImmediatelyAfterRestore \
1281 DISABLED_MinimizeImmediatelyAfterRestore
1282 #else
1283 #define MAYBE_MinimizeImmediatelyAfterRestore MinimizeImmediatelyAfterRestore
1284 #endif
1285 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1286 MAYBE_MinimizeImmediatelyAfterRestore) {
1287 CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE);
1288 Panel* panel = CreatePanelWithParams(params);
1289 scoped_ptr<NativePanelTesting> native_panel_testing(
1290 CreateNativePanelTesting(panel));
1292 PanelActiveStateObserver signal(panel, false);
1293 panel->Minimize(); // this should deactivate.
1294 signal.Wait();
1295 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
1297 panel->Restore();
1298 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
1300 // Verify that minimizing a panel right after expansion works.
1301 panel->Minimize();
1302 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
1304 panel->Close();
1307 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) {
1308 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
1309 Panel* panel = CreatePanelWithParams(params);
1310 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
1312 PanelActiveStateObserver signal(panel, false);
1313 panel->Minimize();
1314 signal.Wait();
1315 panel->Close();
1318 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateInactiveSwitchToActive) {
1319 Panel* panel = CreateInactivePanel("1");
1321 panel->Activate();
1322 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
1324 panel->Close();
1327 // TODO(dimich): try/enable on other platforms. See bug 103253 for details on
1328 // why this is disabled on windows.
1329 #if defined(OS_MACOSX)
1330 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
1331 MinimizeTwoPanelsWithoutTabbedWindow
1332 #else
1333 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
1334 DISABLED_MinimizeTwoPanelsWithoutTabbedWindow
1335 #endif
1337 // When there are 2 panels and no chrome window, minimizing one panel does
1338 // not expand/focuses another.
1339 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1340 MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) {
1341 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
1342 Panel* panel1 = CreatePanelWithParams(params);
1343 Panel* panel2 = CreatePanelWithParams(params);
1345 // Close main tabbed window.
1346 content::WindowedNotificationObserver signal(
1347 chrome::NOTIFICATION_BROWSER_CLOSED,
1348 content::Source<Browser>(browser()));
1349 chrome::CloseWindow(browser());
1350 signal.Wait();
1352 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
1353 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
1354 panel1->Activate();
1355 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
1357 panel1->SetExpansionState(Panel::MINIMIZED);
1358 base::MessageLoop::current()->RunUntilIdle();
1359 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
1360 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1362 panel2->SetExpansionState(Panel::MINIMIZED);
1363 base::MessageLoop::current()->RunUntilIdle();
1364 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
1365 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
1367 // Verify that panel1 is still minimized and not active.
1368 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
1369 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
1371 // Another check for the same.
1372 EXPECT_FALSE(panel1->IsActive());
1373 EXPECT_FALSE(panel2->IsActive());
1375 panel1->Close();
1376 panel2->Close();
1379 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1380 NonExtensionDomainPanelsCloseOnUninstall) {
1381 // Create a test extension.
1382 base::DictionaryValue empty_value;
1383 scoped_refptr<extensions::Extension> extension =
1384 CreateExtension(FILE_PATH_LITERAL("TestExtension"),
1385 extensions::Manifest::INTERNAL, empty_value);
1386 std::string extension_app_name =
1387 web_app::GenerateApplicationNameFromExtensionId(extension->id());
1389 PanelManager* panel_manager = PanelManager::GetInstance();
1390 EXPECT_EQ(0, panel_manager->num_panels());
1392 // Create a panel with the extension as host.
1393 CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE);
1394 std::string extension_domain_url(extensions::kExtensionScheme);
1395 extension_domain_url += "://";
1396 extension_domain_url += extension->id();
1397 extension_domain_url += "/hello.html";
1398 params.url = GURL(extension_domain_url);
1399 Panel* panel = CreatePanelWithParams(params);
1400 EXPECT_EQ(1, panel_manager->num_panels());
1402 // Create a panel with a non-extension host.
1403 CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE);
1404 params1.url = GURL(url::kAboutBlankURL);
1405 Panel* panel1 = CreatePanelWithParams(params1);
1406 EXPECT_EQ(2, panel_manager->num_panels());
1408 // Create another extension and a panel from that extension.
1409 scoped_refptr<extensions::Extension> extension_other =
1410 CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"),
1411 extensions::Manifest::INTERNAL, empty_value);
1412 std::string extension_app_name_other =
1413 web_app::GenerateApplicationNameFromExtensionId(extension_other->id());
1414 Panel* panel_other = CreatePanel(extension_app_name_other);
1416 content::WindowedNotificationObserver signal(
1417 chrome::NOTIFICATION_PANEL_CLOSED,
1418 content::Source<Panel>(panel));
1419 content::WindowedNotificationObserver signal1(
1420 chrome::NOTIFICATION_PANEL_CLOSED,
1421 content::Source<Panel>(panel1));
1423 // Send unload notification on the first extension.
1424 extensions::ExtensionRegistry* registry =
1425 extensions::ExtensionRegistry::Get(browser()->profile());
1426 registry->RemoveEnabled(extension->id());
1427 registry->TriggerOnUnloaded(
1428 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
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 HTTOPLEFT);
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 accelerator.
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 mock_display_settings_provider()->EnableFullScreenMode(true);
1730 EXPECT_FALSE(panel_testing->IsWindowVisible());
1732 // Panel should become visible when leaving full-screen mode.
1733 mock_display_settings_provider()->EnableFullScreenMode(false);
1734 EXPECT_TRUE(panel_testing->IsWindowVisible());
1736 PanelManager::GetInstance()->CloseAll();
1739 IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
1740 HideDockedPanelCreatedOnFullScreenMode) {
1741 // Enable full-screen mode first.
1742 mock_display_settings_provider()->EnableFullScreenMode(true);
1744 // Create a docked panel without waiting for it to be shown since it is not
1745 // supposed to be shown on full-screen mode.
1746 CreatePanelParams params("1", gfx::Rect(0, 0, 250, 200), SHOW_AS_ACTIVE);
1747 params.wait_for_fully_created = false;
1748 Panel* panel = CreatePanelWithParams(params);
1749 scoped_ptr<NativePanelTesting> panel_testing(
1750 CreateNativePanelTesting(panel));
1752 // Panel should not be shown on full-screen mode.
1753 EXPECT_FALSE(panel_testing->IsWindowVisible());
1755 // Panel should become visible when leaving full-screen mode.
1756 mock_display_settings_provider()->EnableFullScreenMode(false);
1757 EXPECT_TRUE(panel_testing->IsWindowVisible());
1759 PanelManager::GetInstance()->CloseAll();
1762 class PanelExtensionApiTest : public ExtensionApiTest {
1763 protected:
1764 void SetUpCommandLine(base::CommandLine* command_line) override {
1765 ExtensionApiTest::SetUpCommandLine(command_line);
1766 command_line->AppendSwitch(switches::kEnablePanels);
1770 #if defined(OS_LINUX) || (!defined(OS_WIN) && defined(USE_AURA)) || \
1771 defined(OS_MACOSX)
1772 // Focus test fails if there is no window manager on Linux.
1773 // Aura panels have different behavior that do not apply to this test.
1774 #define MAYBE_FocusChangeEventOnMinimize DISABLED_FocusChangeEventOnMinimize
1775 #else
1776 #define MAYBE_FocusChangeEventOnMinimize FocusChangeEventOnMinimize
1777 #endif
1778 IN_PROC_BROWSER_TEST_F(PanelExtensionApiTest,
1779 MAYBE_FocusChangeEventOnMinimize) {
1780 // This is needed so the subsequently created panels can be activated.
1781 // On a Mac, it transforms background-only test process into foreground one.
1782 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1783 ASSERT_TRUE(RunExtensionTest("panels/focus_change_on_minimize")) << message_;
1786 #if defined(ENABLE_TASK_MANAGER)
1788 namespace {
1790 base::string16 GetExpectedPrefix() {
1791 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_EXTENSION_PREFIX,
1792 base::string16());
1795 const std::vector<task_management::WebContentsTag*>& GetTrackedTags() {
1796 return task_management::WebContentsTagsManager::GetInstance()->
1797 tracked_tags();
1800 // Tests that the task manager tags are recorded correctly as a result of
1801 // creating panels.
1802 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, TaskManagementTagsBasic) {
1803 // Browser tests start with a single tab.
1804 EXPECT_EQ(1U, GetTrackedTags().size());
1806 // Create a bunch of panels.
1807 gfx::Rect bounds(300, 200, 250, 200);
1808 CreatePanelParams params("PanelTest1", bounds, SHOW_AS_ACTIVE);
1809 params.url = GURL("about:blank");
1810 CreatePanelWithParams(params);
1811 EXPECT_EQ(2U, GetTrackedTags().size());
1813 params.name = std::string("PanelTest2_Detached");
1814 params.wait_for_fully_created = false;
1815 params.create_mode = PanelManager::CREATE_AS_DETACHED;
1816 CreatePanelWithParams(params);
1817 EXPECT_EQ(3U, GetTrackedTags().size());
1819 params.name = std::string("PanelTest3_Docked");
1820 params.create_mode = PanelManager::CREATE_AS_DOCKED;
1821 CreatePanelWithParams(params);
1822 EXPECT_EQ(4U, GetTrackedTags().size());
1824 params.name = std::string("PanelTest3_Inactive");
1825 params.show_flag = SHOW_AS_INACTIVE;
1826 CreatePanelWithParams(params);
1827 EXPECT_EQ(5U, GetTrackedTags().size());
1829 // Close all panels and make sure the tags are removed.
1830 PanelManager::GetInstance()->CloseAll();
1831 EXPECT_EQ(1U, GetTrackedTags().size());
1834 // Tests that the task manager sees the PanelTasks as a result of creating
1835 // panels, and removes the PanelTasks as a result of closing panels.
1836 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, TaskManagementTasksProvided) {
1837 task_management::MockWebContentsTaskManager task_manager;
1838 // Browser tests start with a single tab.
1839 EXPECT_EQ(1U, GetTrackedTags().size());
1841 // Create a single panel.
1842 gfx::Rect bounds(300, 200, 250, 200);
1843 CreatePanelParams params("PanelTest1", bounds, SHOW_AS_ACTIVE);
1844 params.url = GURL("about:blank");
1845 CreatePanelWithParams(params);
1846 EXPECT_EQ(2U, GetTrackedTags().size());
1848 task_manager.StartObserving();
1850 // The pre-existing tab and panel are provided.
1851 EXPECT_EQ(2U, task_manager.tasks().size());
1853 // Create one more panel.
1854 params.name = std::string("PanelTest2");
1855 CreatePanelWithParams(params);
1856 EXPECT_EQ(3U, GetTrackedTags().size());
1857 ASSERT_EQ(3U, task_manager.tasks().size());
1859 const task_management::Task* task = task_manager.tasks().back();
1860 EXPECT_EQ(task_management::Task::EXTENSION, task->GetType());
1861 const base::string16 title = task->title();
1862 const base::string16 expected_prefix = GetExpectedPrefix();
1863 EXPECT_TRUE(base::StartsWith(title,
1864 expected_prefix,
1865 base::CompareCase::INSENSITIVE_ASCII));
1867 PanelManager::GetInstance()->CloseAll();
1868 EXPECT_EQ(1U, task_manager.tasks().size());
1871 } // namespace
1873 #endif // defined(ENABLE_TASK_MANAGER)