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

Side by Side Diff: base/win/message_window_unittest.cc

Issue 17615003: ProcessSingleton now uses base::win::MessageWindow to create a message-only window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback. Created 7 years, 5 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 | « base/win/message_window.cc ('k') | chrome/browser/chrome_process_finder_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/guid.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "base/win/message_window.h" 8 #include "base/win/message_window.h"
8 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace base { 12 namespace base {
12 13
13 namespace { 14 namespace {
14 15
15 bool HandleMessage( 16 bool HandleMessage(
16 UINT message, WPARAM wparam, LPARAM lparam, LRESULT* result) { 17 UINT message, WPARAM wparam, LPARAM lparam, LRESULT* result) {
17 // Return |wparam| as the result of WM_USER message. 18 // Return |wparam| as the result of WM_USER message.
18 if (message == WM_USER) { 19 if (message == WM_USER) {
19 *result = wparam; 20 *result = wparam;
20 return true; 21 return true;
21 } 22 }
22 23
23 return false; 24 return false;
24 } 25 }
25 26
26 } // namespace 27 } // namespace
27 28
28 // Checks that a window can be created. 29 // Checks that a window can be created.
29 TEST(MessageWindowTest, Create) { 30 TEST(MessageWindowTest, Create) {
30 win::MessageWindow window; 31 win::MessageWindow window;
31 EXPECT_TRUE(window.Create(base::Bind(&HandleMessage))); 32 EXPECT_TRUE(window.Create(base::Bind(&HandleMessage)));
32 } 33 }
33 34
35 // Checks that a named window can be created.
34 TEST(MessageWindowTest, CreateNamed) { 36 TEST(MessageWindowTest, CreateNamed) {
35 win::MessageWindow window; 37 win::MessageWindow window;
36 EXPECT_TRUE(window.CreateNamed(base::Bind(&HandleMessage), 38 EXPECT_TRUE(window.CreateNamed(base::Bind(&HandleMessage),
37 UTF8ToUTF16("test_message_window"))); 39 UTF8ToUTF16("test_message_window")));
38 } 40 }
39 41
40 // Verifies that the created window can receive messages. 42 // Verifies that the created window can receive messages.
41 TEST(MessageWindowTest, SendMessage) { 43 TEST(MessageWindowTest, SendMessage) {
42 win::MessageWindow window; 44 win::MessageWindow window;
43 EXPECT_TRUE(window.Create(base::Bind(&HandleMessage))); 45 EXPECT_TRUE(window.Create(base::Bind(&HandleMessage)));
44 46
45 EXPECT_EQ(SendMessage(window.hwnd(), WM_USER, 100, 0), 100); 47 EXPECT_EQ(SendMessage(window.hwnd(), WM_USER, 100, 0), 100);
46 } 48 }
47 49
50 // Verifies that a named window can be found by name.
51 TEST(MessageWindowTest, FindWindow) {
52 string16 name = UTF8ToUTF16(base::GenerateGUID());
53 win::MessageWindow window;
54 EXPECT_TRUE(window.CreateNamed(base::Bind(&HandleMessage), name));
55
56 HWND hwnd = win::MessageWindow::FindWindow(name);
57 EXPECT_TRUE(hwnd != NULL);
58 EXPECT_EQ(SendMessage(hwnd, WM_USER, 200, 0), 200);
59 }
60
48 } // namespace base 61 } // namespace base
OLDNEW
« no previous file with comments | « base/win/message_window.cc ('k') | chrome/browser/chrome_process_finder_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698