summaryrefslogtreecommitdiffstats
path: root/ui/views/widget/native_widget_win_unittest.cc
blob: da7e6ae592477afd9aaecf0bf7c404113fab9d7d (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
// Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h"
#include "ui/base/win/window_impl.h"
#include "ui/views/view.h"
#include "ui/views/widget/native_widget.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_test_util.h"

namespace ui {

class NativeWidgetTest : public testing::Test {
 public:
  NativeWidgetTest() {}
  virtual ~NativeWidgetTest() {}

 private:
  DISALLOW_COPY_AND_ASSIGN(NativeWidgetTest);
};

class TestWindowImpl : public WindowImpl {
 public:
  TestWindowImpl() {}
  virtual ~TestWindowImpl() {}

  virtual BOOL ProcessWindowMessage(HWND window,
                                    UINT message,
                                    WPARAM w_param,
                                    LPARAM l_param,
                                    LRESULT& result,
                                    DWORD msg_mad_id = 0) {
    return FALSE;
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(TestWindowImpl);
};

TEST_F(NativeWidgetTest, CreateNativeWidget) {
  scoped_ptr<Widget> widget(internal::CreateWidget());
  EXPECT_TRUE(widget->native_widget()->GetNativeView() != NULL);
}

TEST_F(NativeWidgetTest, GetNativeWidgetForNativeView) {
  scoped_ptr<Widget> widget(internal::CreateWidget());
  NativeWidget* a = widget->native_widget();
  HWND nv = widget->native_widget()->GetNativeView();
  NativeWidget* b = NativeWidget::GetNativeWidgetForNativeView(nv);
  EXPECT_EQ(a, b);
}

// |widget| has the toplevel NativeWidget.
TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) {
  scoped_ptr<Widget> widget(internal::CreateWidget());
  EXPECT_EQ(widget->native_widget(),
            NativeWidget::GetTopLevelNativeWidget(
                widget->native_widget()->GetNativeView()));
}

// |toplevel_widget| has the toplevel NativeWidget.
TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) {
  scoped_ptr<Widget> child_widget(internal::CreateWidget());
  scoped_ptr<Widget> toplevel_widget(internal::CreateWidget());
  SetParent(child_widget->native_widget()->GetNativeView(),
            toplevel_widget->native_widget()->GetNativeView());
  EXPECT_EQ(toplevel_widget->native_widget(),
            NativeWidget::GetTopLevelNativeWidget(
                child_widget->native_widget()->GetNativeView()));
}

// |child_widget| has the toplevel NativeWidget.
TEST_F(NativeWidgetTest, GetTopLevelNativeWidget3) {
  scoped_ptr<Widget> child_widget(internal::CreateWidget());

  TestWindowImpl toplevel;
  toplevel.Init(NULL, gfx::Rect(10, 10, 100, 100));

  SetParent(child_widget->native_widget()->GetNativeView(), toplevel.hwnd());
  EXPECT_EQ(child_widget->native_widget(),
            NativeWidget::GetTopLevelNativeWidget(
                child_widget->native_widget()->GetNativeView()));
}

}  // namespace ui