| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "dbus/object_manager.h" | 5 #include "dbus/object_manager.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/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
| 16 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
| 17 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
| 18 #include "dbus/property.h" | 19 #include "dbus/property.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 { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 99 |
| 99 // Shut down the service. | 100 // Shut down the service. |
| 100 test_service_->ShutdownAndBlock(); | 101 test_service_->ShutdownAndBlock(); |
| 101 | 102 |
| 102 // Reset to the default. | 103 // Reset to the default. |
| 103 base::ThreadRestrictions::SetIOAllowed(true); | 104 base::ThreadRestrictions::SetIOAllowed(true); |
| 104 | 105 |
| 105 // Stopping a thread is considered an IO operation, so do this after | 106 // Stopping a thread is considered an IO operation, so do this after |
| 106 // allowing IO. | 107 // allowing IO. |
| 107 test_service_->Stop(); | 108 test_service_->Stop(); |
| 109 |
| 110 base::RunLoop().RunUntilIdle(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void MethodCallback(Response* response) { | 113 void MethodCallback(Response* response) { |
| 111 method_callback_called_ = true; | 114 method_callback_called_ = true; |
| 112 message_loop_.Quit(); | 115 message_loop_.Quit(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 protected: | 118 protected: |
| 116 // Called when an object is added. | 119 // Called when an object is added. |
| 117 virtual void ObjectAdded(const ObjectPath& object_path, | 120 virtual void ObjectAdded(const ObjectPath& object_path, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 updated_properties_.push_back(name); | 136 updated_properties_.push_back(name); |
| 134 message_loop_.Quit(); | 137 message_loop_.Quit(); |
| 135 } | 138 } |
| 136 | 139 |
| 137 static const size_t kExpectedObjects = 1; | 140 static const size_t kExpectedObjects = 1; |
| 138 static const size_t kExpectedProperties = 4; | 141 static const size_t kExpectedProperties = 4; |
| 139 | 142 |
| 140 void WaitForObject() { | 143 void WaitForObject() { |
| 141 while (added_objects_.size() < kExpectedObjects || | 144 while (added_objects_.size() < kExpectedObjects || |
| 142 updated_properties_.size() < kExpectedProperties) | 145 updated_properties_.size() < kExpectedProperties) |
| 143 message_loop_.Run(); | 146 base::RunLoop().Run(); |
| 144 for (size_t i = 0; i < kExpectedObjects; ++i) | 147 for (size_t i = 0; i < kExpectedObjects; ++i) |
| 145 added_objects_.erase(added_objects_.begin()); | 148 added_objects_.erase(added_objects_.begin()); |
| 146 for (size_t i = 0; i < kExpectedProperties; ++i) | 149 for (size_t i = 0; i < kExpectedProperties; ++i) |
| 147 updated_properties_.erase(updated_properties_.begin()); | 150 updated_properties_.erase(updated_properties_.begin()); |
| 148 } | 151 } |
| 149 | 152 |
| 150 void WaitForRemoveObject() { | 153 void WaitForRemoveObject() { |
| 151 while (removed_objects_.size() < kExpectedObjects) | 154 while (removed_objects_.size() < kExpectedObjects) |
| 152 message_loop_.Run(); | 155 base::RunLoop().Run(); |
| 153 for (size_t i = 0; i < kExpectedObjects; ++i) | 156 for (size_t i = 0; i < kExpectedObjects; ++i) |
| 154 removed_objects_.erase(removed_objects_.begin()); | 157 removed_objects_.erase(removed_objects_.begin()); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void WaitForMethodCallback() { | 160 void WaitForMethodCallback() { |
| 158 message_loop_.Run(); | 161 base::RunLoop().Run(); |
| 159 method_callback_called_ = false; | 162 method_callback_called_ = false; |
| 160 } | 163 } |
| 161 | 164 |
| 162 void PerformAction(const std::string& action, const ObjectPath& object_path) { | 165 void PerformAction(const std::string& action, const ObjectPath& object_path) { |
| 163 ObjectProxy* object_proxy = bus_->GetObjectProxy( | 166 ObjectProxy* object_proxy = bus_->GetObjectProxy( |
| 164 "org.chromium.TestService", | 167 "org.chromium.TestService", |
| 165 ObjectPath("/org/chromium/TestObject")); | 168 ObjectPath("/org/chromium/TestObject")); |
| 166 | 169 |
| 167 MethodCall method_call("org.chromium.TestInterface", "PerformAction"); | 170 MethodCall method_call("org.chromium.TestInterface", "PerformAction"); |
| 168 MessageWriter writer(&method_call); | 171 MessageWriter writer(&method_call); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 TEST_F(ObjectManagerTest, OwnershipLostAndRegained) { | 347 TEST_F(ObjectManagerTest, OwnershipLostAndRegained) { |
| 345 PerformAction("Ownership", ObjectPath("/org/chromium/TestService")); | 348 PerformAction("Ownership", ObjectPath("/org/chromium/TestService")); |
| 346 WaitForRemoveObject(); | 349 WaitForRemoveObject(); |
| 347 WaitForObject(); | 350 WaitForObject(); |
| 348 | 351 |
| 349 std::vector<ObjectPath> object_paths = object_manager_->GetObjects(); | 352 std::vector<ObjectPath> object_paths = object_manager_->GetObjects(); |
| 350 ASSERT_EQ(1U, object_paths.size()); | 353 ASSERT_EQ(1U, object_paths.size()); |
| 351 } | 354 } |
| 352 | 355 |
| 353 } // namespace dbus | 356 } // namespace dbus |
| OLD | NEW |