OLD | NEW |
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 message_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 base::RunLoop().Run(); |
122 for (size_t i = 0; i < num_updates; ++i) | 123 for (size_t i = 0; i < num_updates; ++i) |
123 updated_properties_.erase(updated_properties_.begin()); | 124 updated_properties_.erase(updated_properties_.begin()); |
124 } | 125 } |
125 | 126 |
126 // Name, Version, Methods, Objects | 127 // Name, Version, Methods, Objects |
127 static const int kExpectedSignalUpdates = 5; | 128 static const int kExpectedSignalUpdates = 5; |
128 | 129 |
129 // Waits for initial values to be set. | 130 // Waits for initial values to be set. |
130 void WaitForGetAll() { | 131 void WaitForGetAll() { |
131 WaitForUpdates(kExpectedSignalUpdates); | 132 WaitForUpdates(kExpectedSignalUpdates); |
132 } | 133 } |
133 | 134 |
134 // Waits for the callback. |id| is the string bound to the callback when | 135 // 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 | 136 // the method call is made that identifies it and distinguishes from any |
136 // other; you can set this to whatever you wish. | 137 // other; you can set this to whatever you wish. |
137 void WaitForCallback(const std::string& id) { | 138 void WaitForCallback(const std::string& id) { |
138 while (last_callback_ != id) { | 139 while (last_callback_ != id) { |
139 message_loop_.Run(); | 140 base::RunLoop().Run(); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 base::MessageLoop message_loop_; | 144 base::MessageLoop message_loop_; |
144 scoped_ptr<base::Thread> dbus_thread_; | 145 scoped_ptr<base::Thread> dbus_thread_; |
145 scoped_refptr<Bus> bus_; | 146 scoped_refptr<Bus> bus_; |
146 ObjectProxy* object_proxy_; | 147 ObjectProxy* object_proxy_; |
147 scoped_ptr<Properties> properties_; | 148 scoped_ptr<Properties> properties_; |
148 scoped_ptr<TestService> test_service_; | 149 scoped_ptr<TestService> test_service_; |
149 // Properties updated. | 150 // Properties updated. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 "Set")); | 267 "Set")); |
267 WaitForCallback("Set"); | 268 WaitForCallback("Set"); |
268 | 269 |
269 // TestService sends a property update. | 270 // TestService sends a property update. |
270 WaitForUpdates(1); | 271 WaitForUpdates(1); |
271 | 272 |
272 EXPECT_EQ("NewService", properties_->name.value()); | 273 EXPECT_EQ("NewService", properties_->name.value()); |
273 } | 274 } |
274 | 275 |
275 } // namespace dbus | 276 } // namespace dbus |
OLD | NEW |