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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/win/hwnd_subclass.cc ('k') | ui/gfx/blit.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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.
4
5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/base/win/window_impl.h"
8 #include "ui/base/win/hwnd_subclass.h"
9
10 namespace ui {
11
12 typedef testing::Test HWNDSubclassTest;
13
14 namespace {
15
16 class TestWindow : public ui::WindowImpl {
17 public:
18 TestWindow() : saw_message(false) {}
19 virtual ~TestWindow() {}
20
21 bool saw_message;
22
23 private:
24 // Overridden from ui::WindowImpl:
25 virtual BOOL ProcessWindowMessage(HWND window,
26 UINT message,
27 WPARAM w_param,
28 LPARAM l_param,
29 LRESULT& result,
30 DWORD msg_map_id) OVERRIDE {
31 if (message == WM_NCHITTEST)
32 saw_message = true;
33
34 return FALSE; // Results in DefWindowProc().
35 }
36
37 DISALLOW_COPY_AND_ASSIGN(TestWindow);
38 };
39
40 class TestMessageFilter : public HWNDMessageFilter {
41 public:
42 TestMessageFilter() : consume_messages(false), saw_message(false) {}
43 virtual ~TestMessageFilter() {}
44
45 // Setting to true causes the filter subclass to stop messages from reaching
46 // the subclassed window procedure.
47 bool consume_messages;
48
49 // True if the message filter saw the message.
50 bool saw_message;
51
52 private:
53 // Overridden from HWNDMessageFilter:
54 virtual bool FilterMessage(HWND hwnd,
55 UINT message,
56 WPARAM w_param,
57 LPARAM l_param,
58 LRESULT* l_result) OVERRIDE {
59 if (message == WM_NCHITTEST) {
60 saw_message = true;
61 return consume_messages;
62 }
63 return false;
64 }
65
66 DISALLOW_COPY_AND_ASSIGN(TestMessageFilter);
67 };
68
69 } // namespace
70
71 TEST_F(HWNDSubclassTest, Filtering) {
72 TestWindow window;
73 window.Init(NULL, gfx::Rect(0, 0, 100, 100));
74 EXPECT_TRUE(window.hwnd() != NULL);
75
76 {
77 TestMessageFilter* mf = new TestMessageFilter;
78 HWNDSubclass subclass(window.hwnd());
79 subclass.SetFilter(mf);
80
81 // We are not filtering, so both the filter and the window should receive
82 // this message:
83 ::SendMessage(window.hwnd(), WM_NCHITTEST, 0, 0);
84
85 EXPECT_TRUE(mf->saw_message);
86 EXPECT_TRUE(window.saw_message);
87
88 mf->saw_message = false;
89 window.saw_message = false;
90
91 mf->consume_messages = true;
92
93 // We are now filtering, so only the filter should see this message:
94 ::SendMessage(window.hwnd(), WM_NCHITTEST, 0, 0);
95
96 EXPECT_TRUE(mf->saw_message);
97 EXPECT_FALSE(window.saw_message);
98 }
99 }
100
101 } // namespace ui
OLDNEW
« 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