OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 7 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 8 #include "chrome/browser/ui/panels/native_panel.h" |
| 9 #include "chrome/browser/ui/panels/panel.h" |
| 10 #include "chrome/browser/ui/panels/panel_manager.h" |
| 11 |
| 12 class DetachedPanelBrowserTest : public BasePanelBrowserTest { |
| 13 }; |
| 14 |
| 15 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CheckDetachedPanelProperties) { |
| 16 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 17 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 18 |
| 19 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 20 scoped_ptr<NativePanelTesting> panel_testing( |
| 21 NativePanelTesting::Create(panel->native_panel())); |
| 22 |
| 23 EXPECT_EQ(1, panel_manager->num_panels()); |
| 24 EXPECT_TRUE(detached_strip->HasPanel(panel)); |
| 25 |
| 26 EXPECT_FALSE(panel->always_on_top()); |
| 27 |
| 28 EXPECT_TRUE(panel_testing->IsButtonVisible(panel::CLOSE_BUTTON)); |
| 29 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); |
| 30 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::RESTORE_BUTTON)); |
| 31 |
| 32 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse()); |
| 33 |
| 34 Panel::AttentionMode expected_attention_mode = |
| 35 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | |
| 36 Panel::USE_SYSTEM_ATTENTION); |
| 37 EXPECT_EQ(expected_attention_mode, panel->attention_mode()); |
| 38 |
| 39 panel_manager->CloseAll(); |
| 40 } |
| 41 |
| 42 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnActive) { |
| 43 // Create a detached panel that is initially active. |
| 44 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 45 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 46 NativePanelTesting::Create(panel->native_panel())); |
| 47 |
| 48 // Test that the attention should not be drawn if the detached panel is in |
| 49 // focus. |
| 50 EXPECT_TRUE(panel->IsActive()); |
| 51 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 52 panel->FlashFrame(true); |
| 53 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 54 MessageLoop::current()->RunAllPending(); |
| 55 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 56 |
| 57 panel->Close(); |
| 58 } |
| 59 |
| 60 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnInactive) { |
| 61 // Create an inactive detached panel. |
| 62 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 63 panel->Deactivate(); |
| 64 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); |
| 65 |
| 66 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 67 NativePanelTesting::Create(panel->native_panel())); |
| 68 |
| 69 // Test that the attention is drawn when the detached panel is not in focus. |
| 70 EXPECT_FALSE(panel->IsActive()); |
| 71 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 72 panel->FlashFrame(true); |
| 73 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 74 MessageLoop::current()->RunAllPending(); |
| 75 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); |
| 76 |
| 77 // Stop drawing attention. |
| 78 panel->FlashFrame(false); |
| 79 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 80 MessageLoop::current()->RunAllPending(); |
| 81 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 82 |
| 83 panel->Close(); |
| 84 } |
| 85 |
| 86 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionResetOnActivate) { |
| 87 // Create 2 panels so we end up with an inactive panel that can |
| 88 // be made to draw attention. |
| 89 Panel* panel1 = CreatePanel("test panel1"); |
| 90 Panel* panel2 = CreatePanel("test panel2"); |
| 91 |
| 92 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 93 NativePanelTesting::Create(panel1->native_panel())); |
| 94 |
| 95 // Test that the attention is drawn when the detached panel is not in focus. |
| 96 panel1->FlashFrame(true); |
| 97 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 98 MessageLoop::current()->RunAllPending(); |
| 99 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); |
| 100 |
| 101 // Test that the attention is cleared when panel gets focus. |
| 102 panel1->Activate(); |
| 103 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); |
| 104 EXPECT_FALSE(panel1->IsDrawingAttention()); |
| 105 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 106 |
| 107 panel1->Close(); |
| 108 panel2->Close(); |
| 109 } |
| 110 |
| 111 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, ClickTitlebar) { |
| 112 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 113 |
| 114 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 115 EXPECT_TRUE(panel->IsActive()); |
| 116 EXPECT_FALSE(panel->IsMinimized()); |
| 117 |
| 118 // Clicking on an active detached panel's titlebar has no effect, regardless |
| 119 // of modifier. |
| 120 scoped_ptr<NativePanelTesting> test_panel( |
| 121 NativePanelTesting::Create(panel->native_panel())); |
| 122 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin()); |
| 123 test_panel->ReleaseMouseButtonTitlebar(); |
| 124 EXPECT_TRUE(panel->IsActive()); |
| 125 EXPECT_FALSE(panel->IsMinimized()); |
| 126 |
| 127 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin(), |
| 128 panel::APPLY_TO_ALL); |
| 129 test_panel->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 130 EXPECT_TRUE(panel->IsActive()); |
| 131 EXPECT_FALSE(panel->IsMinimized()); |
| 132 |
| 133 // Create a second panel to cause the first to become inactive. |
| 134 CreateDetachedPanel("2", gfx::Rect(100, 200, 230, 345)); |
| 135 EXPECT_FALSE(panel->IsActive()); |
| 136 |
| 137 // Clicking on an inactive detached panel's titlebar activates it. |
| 138 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin()); |
| 139 test_panel->ReleaseMouseButtonTitlebar(); |
| 140 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 141 EXPECT_FALSE(panel->IsMinimized()); |
| 142 |
| 143 panel_manager->CloseAll(); |
| 144 } |
OLD | NEW |