summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/panels/detached_panel_browsertest.cc
blob: e20501f42e877e2fb616db6c6b46262542318664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/message_loop.h"
#include "chrome/browser/ui/panels/base_panel_browser_test.h"
#include "chrome/browser/ui/panels/detached_panel_collection.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"

class DetachedPanelBrowserTest : public BasePanelBrowserTest {
};

// http://crbug.com/143247
#if !defined(OS_WIN)
#define MAYBE_CheckDetachedPanelProperties DISABLED_CheckDetachedPanelProperties
#else
#define MAYBE_CheckDetachedPanelProperties CheckDetachedPanelProperties
#endif
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
                       MAYBE_CheckDetachedPanelProperties) {
  PanelManager* panel_manager = PanelManager::GetInstance();
  DetachedPanelCollection* detached_collection =
      panel_manager->detached_collection();

  // Create an initially detached panel (as opposed to other tests which create
  // a docked panel, then detaches it).
  gfx::Rect bounds(300, 200, 250, 200);
  CreatePanelParams params("1", bounds, SHOW_AS_ACTIVE);
  params.create_mode = PanelManager::CREATE_AS_DETACHED;
  Panel* panel = CreatePanelWithParams(params);
  scoped_ptr<NativePanelTesting> panel_testing(
      CreateNativePanelTesting(panel));

  EXPECT_EQ(1, panel_manager->num_panels());
  EXPECT_TRUE(detached_collection->HasPanel(panel));

  EXPECT_EQ(bounds.x(), panel->GetBounds().x());
  // Ignore checking y position since the detached panel will be placed near
  // the top if the stacking mode is enabled.
  if (!PanelManager::IsPanelStackingEnabled())
    EXPECT_EQ(bounds.y(), panel->GetBounds().y());
  EXPECT_EQ(bounds.width(), panel->GetBounds().width());
  EXPECT_EQ(bounds.height(), panel->GetBounds().height());
  EXPECT_FALSE(panel->IsAlwaysOnTop());

  EXPECT_TRUE(panel_testing->IsButtonVisible(panel::CLOSE_BUTTON));
  EXPECT_TRUE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
  EXPECT_FALSE(panel_testing->IsButtonVisible(panel::RESTORE_BUTTON));

  EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());

  EXPECT_EQ(panel::ALL_ROUNDED, panel_testing->GetWindowCornerStyle());

  Panel::AttentionMode expected_attention_mode =
      static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
                                         Panel::USE_SYSTEM_ATTENTION);
  EXPECT_EQ(expected_attention_mode, panel->attention_mode());

  panel_manager->CloseAll();
}

// http://crbug.com/143247
#if !defined(OS_WIN)
#define MAYBE_DrawAttentionOnActive DISABLED_DrawAttentionOnActive
#else
#define MAYBE_DrawAttentionOnActive DrawAttentionOnActive
#endif
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, MAYBE_DrawAttentionOnActive) {
  // Create a detached panel that is initially active.
  Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
  scoped_ptr<NativePanelTesting> native_panel_testing(
      CreateNativePanelTesting(panel));

  // Test that the attention should not be drawn if the detached panel is in
  // focus.
  WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);  // doublecheck active state
  EXPECT_FALSE(panel->IsDrawingAttention());
  panel->FlashFrame(true);
  EXPECT_FALSE(panel->IsDrawingAttention());
  EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());

  panel->Close();
}

// http://crbug.com/143247
#if !defined(OS_WIN)
#define MAYBE_DrawAttentionOnInactive DISABLED_DrawAttentionOnInactive
#else
#define MAYBE_DrawAttentionOnInactive DrawAttentionOnInactive
#endif
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
                       MAYBE_DrawAttentionOnInactive) {
  // Create two panels so that first panel becomes inactive.
  Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
  CreateDetachedPanel("2", gfx::Rect(100, 100, 250, 200));
  WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);

  scoped_ptr<NativePanelTesting> native_panel_testing(
      CreateNativePanelTesting(panel));

  // Test that the attention is drawn when the detached panel is not in focus.
  EXPECT_FALSE(panel->IsActive());
  EXPECT_FALSE(panel->IsDrawingAttention());
  panel->FlashFrame(true);
  EXPECT_TRUE(panel->IsDrawingAttention());
  EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());

  // Stop drawing attention.
  panel->FlashFrame(false);
  EXPECT_FALSE(panel->IsDrawingAttention());
  EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());

  PanelManager::GetInstance()->CloseAll();
}

// http://crbug.com/143247
#if !defined(OS_WIN)
#define MAYBE_DrawAttentionResetOnActivate DISABLED_DrawAttentionResetOnActivate
#else
#define MAYBE_DrawAttentionResetOnActivate DrawAttentionResetOnActivate
#endif
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
                       MAYBE_DrawAttentionResetOnActivate) {
  // Create 2 panels so we end up with an inactive panel that can
  // be made to draw attention.
  Panel* panel1 = CreateDetachedPanel("test panel1",
                                      gfx::Rect(300, 200, 250, 200));
  Panel* panel2 = CreateDetachedPanel("test panel2",
                                      gfx::Rect(100, 100, 250, 200));
  WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);

  scoped_ptr<NativePanelTesting> native_panel_testing(
      CreateNativePanelTesting(panel1));

  // Test that the attention is drawn when the detached panel is not in focus.
  panel1->FlashFrame(true);
  EXPECT_TRUE(panel1->IsDrawingAttention());
  EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());

  // Test that the attention is cleared when panel gets focus.
  panel1->Activate();
  WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
  EXPECT_FALSE(panel1->IsDrawingAttention());
  EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());

  panel1->Close();
  panel2->Close();
}

// http://crbug.com/143247
#if !defined(OS_WIN)
#define MAYBE_ClickTitlebar DISABLED_ClickTitlebar
#else
#define MAYBE_ClickTitlebar ClickTitlebar
#endif
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, MAYBE_ClickTitlebar) {
  PanelManager* panel_manager = PanelManager::GetInstance();

  Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
  EXPECT_FALSE(panel->IsMinimized());

  // Clicking on an active detached panel's titlebar has no effect, regardless
  // of modifier.
  WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);  // doublecheck active state
  scoped_ptr<NativePanelTesting> test_panel(
      CreateNativePanelTesting(panel));
  test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
  test_panel->ReleaseMouseButtonTitlebar();
  EXPECT_TRUE(panel->IsActive());
  EXPECT_FALSE(panel->IsMinimized());

  test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin(),
                                           panel::APPLY_TO_ALL);
  test_panel->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
  EXPECT_TRUE(panel->IsActive());
  EXPECT_FALSE(panel->IsMinimized());

  // Create a second panel to cause the first to become inactive.
  CreateDetachedPanel("2", gfx::Rect(100, 200, 230, 345));
  WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);

  // Clicking on an inactive detached panel's titlebar activates it.
  test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
  test_panel->ReleaseMouseButtonTitlebar();
  WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
  EXPECT_FALSE(panel->IsMinimized());

  panel_manager->CloseAll();
}

IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
                       UpdateDetachedPanelOnPrimaryDisplayChange) {
  PanelManager* panel_manager = PanelManager::GetInstance();

  // Create a big detached panel on the primary display.
  gfx::Rect initial_bounds(50, 50, 700, 500);
  Panel* panel = CreateDetachedPanel("1", initial_bounds);
  EXPECT_EQ(initial_bounds, panel->GetBounds());

  // Make the primary display smaller.
  // Expect that the panel should be resized to fit within the display.
  gfx::Rect primary_display_area(0, 0, 500, 300);
  gfx::Rect primary_work_area(0, 0, 500, 280);
  mock_display_settings_provider()->SetPrimaryDisplay(
      primary_display_area, primary_work_area);

  gfx::Rect bounds = panel->GetBounds();
  EXPECT_LE(primary_work_area.x(), bounds.x());
  EXPECT_LE(bounds.x(), primary_work_area.right());
  EXPECT_LE(primary_work_area.y(), bounds.y());
  EXPECT_LE(bounds.y(), primary_work_area.bottom());

  panel_manager->CloseAll();
}

IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
                       UpdateDetachedPanelOnSecondaryDisplayChange) {
  PanelManager* panel_manager = PanelManager::GetInstance();

  // Setup 2 displays with secondary display on the right side of primary
  // display.
  gfx::Rect primary_display_area(0, 0, 400, 600);
  gfx::Rect primary_work_area(0, 0, 400, 560);
  mock_display_settings_provider()->SetPrimaryDisplay(
      primary_display_area, primary_work_area);
  gfx::Rect secondary_display_area(400, 0, 400, 500);
  gfx::Rect secondary_work_area(400, 0, 400, 460);
  mock_display_settings_provider()->SetSecondaryDisplay(
      secondary_display_area, secondary_work_area);

  // Create a big detached panel on the seconday display.
  gfx::Rect initial_bounds(450, 50, 350, 400);
  Panel* panel = CreateDetachedPanel("1", initial_bounds);
  EXPECT_EQ(initial_bounds, panel->GetBounds());

  // Move down the secondary display and make it smaller.
  // Expect that the panel should be resized to fit within the display.
  secondary_display_area.SetRect(400, 100, 300, 400);
  secondary_work_area.SetRect(400, 100, 300, 360);
  mock_display_settings_provider()->SetSecondaryDisplay(
      secondary_display_area, secondary_work_area);

  gfx::Rect bounds = panel->GetBounds();
  EXPECT_LE(secondary_work_area.x(), bounds.x());
  EXPECT_LE(bounds.x(), secondary_work_area.right());
  EXPECT_LE(secondary_work_area.y(), bounds.y());
  EXPECT_LE(bounds.y(), secondary_work_area.bottom());

  panel_manager->CloseAll();
}