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

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

Issue 5971008: move base/object_watcher into base/win and add the win namespace. Fixup calle... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 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/object_watcher.cc ('k') | chrome/browser/file_path_watcher/file_path_watcher_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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <process.h> 5 #include <process.h>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/object_watcher.h" 8 #include "base/win/object_watcher.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace base {
12 namespace win {
13
11 namespace { 14 namespace {
12 15
13 class QuitDelegate : public base::ObjectWatcher::Delegate { 16 class QuitDelegate : public base::ObjectWatcher::Delegate {
14 public: 17 public:
15 virtual void OnObjectSignaled(HANDLE object) { 18 virtual void OnObjectSignaled(HANDLE object) {
16 MessageLoop::current()->Quit(); 19 MessageLoop::current()->Quit();
17 } 20 }
18 }; 21 };
19 22
20 class DecrementCountDelegate : public base::ObjectWatcher::Delegate { 23 class DecrementCountDelegate : public base::ObjectWatcher::Delegate {
21 public: 24 public:
22 explicit DecrementCountDelegate(int* counter) : counter_(counter) { 25 explicit DecrementCountDelegate(int* counter) : counter_(counter) {
23 } 26 }
24 virtual void OnObjectSignaled(HANDLE object) { 27 virtual void OnObjectSignaled(HANDLE object) {
25 --(*counter_); 28 --(*counter_);
26 } 29 }
27 private: 30 private:
28 int* counter_; 31 int* counter_;
29 }; 32 };
30 33
31 } // namespace
32
33 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { 34 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) {
34 MessageLoop message_loop(message_loop_type); 35 MessageLoop message_loop(message_loop_type);
35 36
36 base::ObjectWatcher watcher; 37 base::ObjectWatcher watcher;
37 EXPECT_EQ(NULL, watcher.GetWatchedObject()); 38 EXPECT_EQ(NULL, watcher.GetWatchedObject());
38 39
39 // A manual-reset event that is not yet signaled. 40 // A manual-reset event that is not yet signaled.
40 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); 41 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL);
41 42
42 QuitDelegate delegate; 43 QuitDelegate delegate;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 { 110 {
110 MessageLoop message_loop(message_loop_type); 111 MessageLoop message_loop(message_loop_type);
111 112
112 QuitDelegate delegate; 113 QuitDelegate delegate;
113 watcher.StartWatching(event, &delegate); 114 watcher.StartWatching(event, &delegate);
114 } 115 }
115 } 116 }
116 CloseHandle(event); 117 CloseHandle(event);
117 } 118 }
118 119
120 } // namespace
121
119 //----------------------------------------------------------------------------- 122 //-----------------------------------------------------------------------------
120 123
121 TEST(ObjectWatcherTest, BasicSignal) { 124 TEST(ObjectWatcherTest, BasicSignal) {
122 RunTest_BasicSignal(MessageLoop::TYPE_DEFAULT); 125 RunTest_BasicSignal(MessageLoop::TYPE_DEFAULT);
123 RunTest_BasicSignal(MessageLoop::TYPE_IO); 126 RunTest_BasicSignal(MessageLoop::TYPE_IO);
124 RunTest_BasicSignal(MessageLoop::TYPE_UI); 127 RunTest_BasicSignal(MessageLoop::TYPE_UI);
125 } 128 }
126 129
127 TEST(ObjectWatcherTest, BasicCancel) { 130 TEST(ObjectWatcherTest, BasicCancel) {
128 RunTest_BasicCancel(MessageLoop::TYPE_DEFAULT); 131 RunTest_BasicCancel(MessageLoop::TYPE_DEFAULT);
129 RunTest_BasicCancel(MessageLoop::TYPE_IO); 132 RunTest_BasicCancel(MessageLoop::TYPE_IO);
130 RunTest_BasicCancel(MessageLoop::TYPE_UI); 133 RunTest_BasicCancel(MessageLoop::TYPE_UI);
131 } 134 }
132 135
133 TEST(ObjectWatcherTest, CancelAfterSet) { 136 TEST(ObjectWatcherTest, CancelAfterSet) {
134 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); 137 RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT);
135 RunTest_CancelAfterSet(MessageLoop::TYPE_IO); 138 RunTest_CancelAfterSet(MessageLoop::TYPE_IO);
136 RunTest_CancelAfterSet(MessageLoop::TYPE_UI); 139 RunTest_CancelAfterSet(MessageLoop::TYPE_UI);
137 } 140 }
138 141
139 TEST(ObjectWatcherTest, OutlivesMessageLoop) { 142 TEST(ObjectWatcherTest, OutlivesMessageLoop) {
140 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); 143 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT);
141 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); 144 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO);
142 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); 145 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI);
143 } 146 }
147
148 } // namespace win
149 } // namespace base
OLDNEW
« no previous file with comments | « base/win/object_watcher.cc ('k') | chrome/browser/file_path_watcher/file_path_watcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698