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 "chrome/browser/ui/panels/display_settings_provider_win.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
11 class DisplaySettingsProviderWinTest
: public testing::Test
{
13 class MockDisplaySettingsProviderWin
: public DisplaySettingsProviderWin
{
15 MockDisplaySettingsProviderWin()
16 : DisplaySettingsProviderWin() {
17 OnDisplaySettingsChanged();
19 virtual ~MockDisplaySettingsProviderWin() { }
20 virtual gfx::Rect
GetPrimaryWorkArea() const {
21 return gfx::Rect(0, 0, 800, 600);
24 // Expose the protected methods from base class for testing purpose.
25 using DisplaySettingsProviderWin::GetDesktopBarThicknessFromBounds
;
26 using DisplaySettingsProviderWin::GetDesktopBarVisibilityFromBounds
;
30 TEST_F(DisplaySettingsProviderWinTest
, GetDesktopBarThicknessFromBounds
) {
31 scoped_ptr
<MockDisplaySettingsProviderWin
> provider(
32 new MockDisplaySettingsProviderWin());
37 thickness
= provider
->GetDesktopBarThicknessFromBounds(
38 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM
,
39 gfx::Rect(0, 560, 800, 40));
40 EXPECT_EQ(40, thickness
);
43 thickness
= provider
->GetDesktopBarThicknessFromBounds(
44 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT
,
45 gfx::Rect(760, 0, 30, 600));
46 EXPECT_EQ(30, thickness
);
49 thickness
= provider
->GetDesktopBarThicknessFromBounds(
50 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT
,
51 gfx::Rect(760, 0, 35, 600));
52 EXPECT_EQ(35, thickness
);
55 TEST_F(DisplaySettingsProviderWinTest
, GetDesktopBarVisibilityFromBounds
) {
56 scoped_ptr
<MockDisplaySettingsProviderWin
> provider(
57 new MockDisplaySettingsProviderWin());
59 DisplaySettingsProvider::DesktopBarVisibility visibility
;
61 // Tests for bottom bar.
62 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
63 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM
,
64 gfx::Rect(0, 560, 800, 40));
65 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_VISIBLE
, visibility
);
66 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
67 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM
,
68 gfx::Rect(0, 598, 800, 40));
69 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_HIDDEN
, visibility
);
70 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
71 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM
,
72 gfx::Rect(0, 580, 800, 40));
73 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_ANIMATING
, visibility
);
75 // Tests for right bar.
76 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
77 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT
,
78 gfx::Rect(760, 0, 40, 600));
79 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_VISIBLE
, visibility
);
80 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
81 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT
,
82 gfx::Rect(798, 0, 40, 600));
83 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_HIDDEN
, visibility
);
84 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
85 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT
,
86 gfx::Rect(780, 0, 40, 600));
87 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_ANIMATING
, visibility
);
89 // Tests for left bar.
90 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
91 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT
,
92 gfx::Rect(0, 0, 40, 600));
93 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_VISIBLE
, visibility
);
94 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
95 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT
,
96 gfx::Rect(-38, 0, 40, 600));
97 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_HIDDEN
, visibility
);
98 visibility
= provider
->GetDesktopBarVisibilityFromBounds(
99 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT
,
100 gfx::Rect(-15, 0, 40, 600));
101 EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_ANIMATING
, visibility
);