Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Unified Diff: ui/base/win/hwnd_subclass_unittest.cc

Issue 10256008: Adds a class that makes it easy to subclass a HWND and filter messages sent to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/win/hwnd_subclass.cc ('k') | ui/gfx/blit.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/win/hwnd_subclass_unittest.cc
===================================================================
--- ui/base/win/hwnd_subclass_unittest.cc (revision 0)
+++ ui/base/win/hwnd_subclass_unittest.cc (revision 0)
@@ -0,0 +1,101 @@
+// 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/base/win/hwnd_subclass.h"
+
+namespace ui {
+
+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 HWNDMessageFilter {
+ public:
+ TestMessageFilter() : 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 HWNDMessageFilter:
+ 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, Filtering) {
+ TestWindow window;
+ window.Init(NULL, gfx::Rect(0, 0, 100, 100));
+ EXPECT_TRUE(window.hwnd() != NULL);
+
+ {
+ TestMessageFilter* mf = new TestMessageFilter;
+ HWNDSubclass subclass(window.hwnd());
+ subclass.SetFilter(mf);
+
+ // 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 ui
Property changes on: ui\base\win\hwnd_subclass_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « ui/base/win/hwnd_subclass.cc ('k') | ui/gfx/blit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698