| Index: ui/views/widget/hwnd_subclass_unittest.cc
|
| ===================================================================
|
| --- ui/views/widget/hwnd_subclass_unittest.cc (revision 0)
|
| +++ ui/views/widget/hwnd_subclass_unittest.cc (revision 0)
|
| @@ -0,0 +1,121 @@
|
| +// Copyright (c) 2012 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 "base/basictypes.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/win/window_impl.h"
|
| +#include "ui/views/widget/hwnd_subclass.h"
|
| +
|
| +namespace views {
|
| +
|
| +typedef testing::Test HWNDSubclassTest;
|
| +
|
| +namespace {
|
| +
|
| +class TestWindow : public ui::WindowImpl {
|
| + public:
|
| + TestWindow() : saw_message(false) {}
|
| + virtual ~TestWindow() {}
|
| +
|
| + bool saw_message;
|
| +
|
| + private:
|
| + // Overridden from ui::WindowImpl:
|
| + virtual BOOL ProcessWindowMessage(HWND window,
|
| + UINT message,
|
| + WPARAM w_param,
|
| + LPARAM l_param,
|
| + LRESULT& result,
|
| + DWORD msg_map_id) OVERRIDE {
|
| + if (message == WM_NCHITTEST)
|
| + saw_message = true;
|
| +
|
| + return FALSE; // Results in DefWindowProc().
|
| + }
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestWindow);
|
| +};
|
| +
|
| +class TestMessageFilter : public HWNDSubclass {
|
| + public:
|
| + TestMessageFilter(HWND target)
|
| + : HWNDSubclass(target),
|
| + consume_messages(false),
|
| + saw_message(false) {}
|
| + virtual ~TestMessageFilter() {}
|
| +
|
| + // Setting to true causes the filter subclass to stop messages from reaching
|
| + // the subclassed window procedure.
|
| + bool consume_messages;
|
| +
|
| + // True if the message filter saw the message.
|
| + bool saw_message;
|
| +
|
| + private:
|
| + // Overridden from HWNDSubclass:
|
| + virtual bool FilterMessage(HWND hwnd,
|
| + UINT message,
|
| + WPARAM w_param,
|
| + LPARAM l_param,
|
| + LRESULT* l_result) OVERRIDE {
|
| + if (message == WM_NCHITTEST) {
|
| + saw_message = true;
|
| + return consume_messages;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestMessageFilter);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(HWNDSubclassTest, Installation) {
|
| + TestWindow window;
|
| + window.Init(NULL, gfx::Rect(0, 0, 100, 100));
|
| + EXPECT_TRUE(window.hwnd() != NULL);
|
| +
|
| + EXPECT_EQ(HWNDSubclass::GetCurrentWndProc(window.hwnd()),
|
| + HWNDSubclass::GetClassWndProc(window.hwnd()));
|
| +
|
| + {
|
| + views::HWNDSubclass subclasser(window.hwnd());
|
| +
|
| + EXPECT_NE(HWNDSubclass::GetCurrentWndProc(window.hwnd()),
|
| + HWNDSubclass::GetClassWndProc(window.hwnd()));
|
| + }
|
| +
|
| + EXPECT_EQ(HWNDSubclass::GetCurrentWndProc(window.hwnd()),
|
| + HWNDSubclass::GetClassWndProc(window.hwnd()));
|
| +}
|
| +
|
| +TEST_F(HWNDSubclassTest, Filtering) {
|
| + TestWindow window;
|
| + window.Init(NULL, gfx::Rect(0, 0, 100, 100));
|
| + EXPECT_TRUE(window.hwnd() != NULL);
|
| +
|
| + {
|
| + TestMessageFilter mf(window.hwnd());
|
| +
|
| + // We are not filtering, so both the filter and the window should receive
|
| + // this message:
|
| + ::SendMessage(window.hwnd(), WM_NCHITTEST, 0, 0);
|
| +
|
| + EXPECT_TRUE(mf.saw_message);
|
| + EXPECT_TRUE(window.saw_message);
|
| +
|
| + mf.saw_message = false;
|
| + window.saw_message = false;
|
| +
|
| + mf.consume_messages = true;
|
| +
|
| + // We are now filtering, so only the filter should see this message:
|
| + ::SendMessage(window.hwnd(), WM_NCHITTEST, 0, 0);
|
| +
|
| + EXPECT_TRUE(mf.saw_message);
|
| + EXPECT_FALSE(window.saw_message);
|
| + }
|
| +}
|
| +
|
| +} // namespace views
|
|
|
| Property changes on: ui\views\widget\hwnd_subclass_unittest.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|