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

Side by Side Diff: dbus/property_unittest.cc

Issue 523623003: Plug some of the leaks in dbus_unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: run_loop_->Quit() Created 6 years, 3 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
« no previous file with comments | « dbus/object_manager_unittest.cc ('k') | dbus/signal_sender_verification_unittest.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) 2012 The Chromium Authors. All rights reserved. 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 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 "dbus/property.h" 5 #include "dbus/property.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/threading/thread_restrictions.h" 16 #include "base/threading/thread_restrictions.h"
16 #include "dbus/bus.h" 17 #include "dbus/bus.h"
17 #include "dbus/object_path.h" 18 #include "dbus/object_path.h"
18 #include "dbus/object_proxy.h" 19 #include "dbus/object_proxy.h"
19 #include "dbus/test_service.h" 20 #include "dbus/test_service.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace dbus { 23 namespace dbus {
23 24
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Stopping a thread is considered an IO operation, so do this after 99 // Stopping a thread is considered an IO operation, so do this after
99 // allowing IO. 100 // allowing IO.
100 test_service_->Stop(); 101 test_service_->Stop();
101 } 102 }
102 103
103 // Generic callback, bind with a string |id| for passing to 104 // Generic callback, bind with a string |id| for passing to
104 // WaitForCallback() to ensure the callback for the right method is 105 // WaitForCallback() to ensure the callback for the right method is
105 // waited for. 106 // waited for.
106 void PropertyCallback(const std::string& id, bool success) { 107 void PropertyCallback(const std::string& id, bool success) {
107 last_callback_ = id; 108 last_callback_ = id;
108 message_loop_.Quit(); 109 run_loop_->Quit();
109 } 110 }
110 111
111 protected: 112 protected:
112 // Called when a property value is updated. 113 // Called when a property value is updated.
113 void OnPropertyChanged(const std::string& name) { 114 void OnPropertyChanged(const std::string& name) {
114 updated_properties_.push_back(name); 115 updated_properties_.push_back(name);
115 message_loop_.Quit(); 116 run_loop_->Quit();
116 } 117 }
117 118
118 // Waits for the given number of updates. 119 // Waits for the given number of updates.
119 void WaitForUpdates(size_t num_updates) { 120 void WaitForUpdates(size_t num_updates) {
120 while (updated_properties_.size() < num_updates) 121 while (updated_properties_.size() < num_updates) {
121 message_loop_.Run(); 122 run_loop_.reset(new base::RunLoop);
123 run_loop_->Run();
124 }
122 for (size_t i = 0; i < num_updates; ++i) 125 for (size_t i = 0; i < num_updates; ++i)
123 updated_properties_.erase(updated_properties_.begin()); 126 updated_properties_.erase(updated_properties_.begin());
124 } 127 }
125 128
126 // Name, Version, Methods, Objects 129 // Name, Version, Methods, Objects
127 static const int kExpectedSignalUpdates = 5; 130 static const int kExpectedSignalUpdates = 5;
128 131
129 // Waits for initial values to be set. 132 // Waits for initial values to be set.
130 void WaitForGetAll() { 133 void WaitForGetAll() {
131 WaitForUpdates(kExpectedSignalUpdates); 134 WaitForUpdates(kExpectedSignalUpdates);
132 } 135 }
133 136
134 // Waits for the callback. |id| is the string bound to the callback when 137 // Waits for the callback. |id| is the string bound to the callback when
135 // the method call is made that identifies it and distinguishes from any 138 // the method call is made that identifies it and distinguishes from any
136 // other; you can set this to whatever you wish. 139 // other; you can set this to whatever you wish.
137 void WaitForCallback(const std::string& id) { 140 void WaitForCallback(const std::string& id) {
138 while (last_callback_ != id) { 141 while (last_callback_ != id) {
139 message_loop_.Run(); 142 run_loop_.reset(new base::RunLoop);
143 run_loop_->Run();
140 } 144 }
141 } 145 }
142 146
143 base::MessageLoop message_loop_; 147 base::MessageLoop message_loop_;
148 scoped_ptr<base::RunLoop> run_loop_;
144 scoped_ptr<base::Thread> dbus_thread_; 149 scoped_ptr<base::Thread> dbus_thread_;
145 scoped_refptr<Bus> bus_; 150 scoped_refptr<Bus> bus_;
146 ObjectProxy* object_proxy_; 151 ObjectProxy* object_proxy_;
147 scoped_ptr<Properties> properties_; 152 scoped_ptr<Properties> properties_;
148 scoped_ptr<TestService> test_service_; 153 scoped_ptr<TestService> test_service_;
149 // Properties updated. 154 // Properties updated.
150 std::vector<std::string> updated_properties_; 155 std::vector<std::string> updated_properties_;
151 // Last callback received. 156 // Last callback received.
152 std::string last_callback_; 157 std::string last_callback_;
153 }; 158 };
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 "Set")); 271 "Set"));
267 WaitForCallback("Set"); 272 WaitForCallback("Set");
268 273
269 // TestService sends a property update. 274 // TestService sends a property update.
270 WaitForUpdates(1); 275 WaitForUpdates(1);
271 276
272 EXPECT_EQ("NewService", properties_->name.value()); 277 EXPECT_EQ("NewService", properties_->name.value());
273 } 278 }
274 279
275 } // namespace dbus 280 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/object_manager_unittest.cc ('k') | dbus/signal_sender_verification_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698