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 "ui/views/widget/native_widget_win.h"
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/win/scoped_ole_initializer.h"
16 class NativeWidgetWinTest
: public testing::Test
{
18 NativeWidgetWinTest() {}
19 ~NativeWidgetWinTest() {}
21 virtual void TearDown() {
22 // Flush the message loop because we have pending release tasks
23 // and these tasks if un-executed would upset Valgrind.
27 // Create a simple widget win. The caller is responsible for taking ownership
28 // of the returned value.
29 NativeWidgetWin
* CreateNativeWidgetWin();
31 void RunPendingMessages() {
32 message_loop_
.RunUntilIdle();
36 base::MessageLoopForUI message_loop_
;
37 ui::ScopedOleInitializer ole_initializer_
;
39 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWinTest
);
42 NativeWidgetWin
* NativeWidgetWinTest::CreateNativeWidgetWin() {
43 scoped_ptr
<Widget
> widget(new Widget
);
44 Widget::InitParams
params(Widget::InitParams::TYPE_POPUP
);
45 params
.ownership
= views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
46 params
.bounds
= gfx::Rect(50, 50, 650, 650);
48 return static_cast<NativeWidgetWin
*>(widget
.release()->native_widget());
51 TEST_F(NativeWidgetWinTest
, ZoomWindow
) {
52 scoped_ptr
<NativeWidgetWin
> window(CreateNativeWidgetWin());
53 ShowWindow(window
->GetNativeView(), SW_HIDE
);
54 EXPECT_FALSE(window
->IsActive());
55 ShowWindow(window
->GetNativeView(), SW_MAXIMIZE
);
56 EXPECT_TRUE(IsZoomed(window
->GetNativeView()));
60 TEST_F(NativeWidgetWinTest
, SetBoundsForZoomedWindow
) {
61 scoped_ptr
<NativeWidgetWin
> window(CreateNativeWidgetWin());
62 ShowWindow(window
->GetNativeView(), SW_MAXIMIZE
);
63 EXPECT_TRUE(IsZoomed(window
->GetNativeView()));
65 // Create another window, so that it will be active.
66 scoped_ptr
<NativeWidgetWin
> window2(CreateNativeWidgetWin());
67 ShowWindow(window2
->GetNativeView(), SW_MAXIMIZE
);
68 EXPECT_TRUE(window2
->IsActive());
69 EXPECT_FALSE(window
->IsActive());
71 // Verify that setting the bounds of a zoomed window will unzoom it and not
72 // cause it to be activated.
73 window
->SetBounds(gfx::Rect(50, 50, 650, 650));
74 EXPECT_FALSE(IsZoomed(window
->GetNativeView()));
75 EXPECT_FALSE(window
->IsActive());