OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "views/widget/native_widget_win.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/message_loop.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace views { | |
13 namespace { | |
14 | |
15 class NativeWidgetWinTest : public testing::Test { | |
16 public: | |
17 NativeWidgetWinTest() { | |
18 OleInitialize(NULL); | |
19 } | |
20 | |
21 ~NativeWidgetWinTest() { | |
22 OleUninitialize(); | |
23 } | |
24 | |
25 virtual void TearDown() { | |
26 // Flush the message loop because we have pending release tasks | |
27 // and these tasks if un-executed would upset Valgrind. | |
28 RunPendingMessages(); | |
29 } | |
30 | |
31 // Create a simple widget win. The caller is responsible for taking ownership | |
32 // of the returned value. | |
33 NativeWidgetWin* CreateNativeWidgetWin(); | |
34 | |
35 void RunPendingMessages() { | |
36 message_loop_.RunAllPending(); | |
37 } | |
38 | |
39 private: | |
40 MessageLoopForUI message_loop_; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWinTest); | |
43 }; | |
44 | |
45 NativeWidgetWin* NativeWidgetWinTest::CreateNativeWidgetWin() { | |
46 scoped_ptr<Widget> widget(new Widget); | |
47 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | |
48 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
49 params.bounds = gfx::Rect(50, 50, 650, 650); | |
50 widget->Init(params); | |
51 return static_cast<NativeWidgetWin*>(widget.release()->native_widget()); | |
52 } | |
53 | |
54 TEST_F(NativeWidgetWinTest, ZoomWindow) { | |
55 scoped_ptr<NativeWidgetWin> window(CreateNativeWidgetWin()); | |
56 window->ShowWindow(SW_HIDE); | |
57 EXPECT_FALSE(window->IsActive()); | |
58 window->ShowWindow(SW_MAXIMIZE); | |
59 EXPECT_TRUE(window->IsZoomed()); | |
60 window->CloseNow(); | |
61 } | |
62 | |
63 TEST_F(NativeWidgetWinTest, SetBoundsForZoomedWindow) { | |
64 scoped_ptr<NativeWidgetWin> window(CreateNativeWidgetWin()); | |
65 window->ShowWindow(SW_MAXIMIZE); | |
66 EXPECT_TRUE(window->IsZoomed()); | |
67 | |
68 // Create another window, so that it will be active. | |
69 scoped_ptr<NativeWidgetWin> window2(CreateNativeWidgetWin()); | |
70 window2->ShowWindow(SW_MAXIMIZE); | |
71 EXPECT_TRUE(window2->IsActive()); | |
72 EXPECT_FALSE(window->IsActive()); | |
73 | |
74 // Verify that setting the bounds of a zoomed window will unzoom it and not | |
75 // cause it to be activated. | |
76 window->SetBounds(gfx::Rect(50, 50, 650, 650)); | |
77 EXPECT_FALSE(window->IsZoomed()); | |
78 EXPECT_FALSE(window->IsActive()); | |
79 | |
80 // Cleanup. | |
81 window->CloseNow(); | |
82 window2->CloseNow(); | |
83 } | |
84 | |
85 } // namespace | |
86 } // namespace views | |
OLD | NEW |