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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 const std::string& interface_name, | 41 const std::string& interface_name, |
42 PropertyChangedCallback property_changed_callback) | 42 PropertyChangedCallback property_changed_callback) |
43 : PropertySet(object_proxy, interface_name, property_changed_callback) { | 43 : PropertySet(object_proxy, interface_name, property_changed_callback) { |
44 RegisterProperty("Name", &name); | 44 RegisterProperty("Name", &name); |
45 RegisterProperty("Version", &version); | 45 RegisterProperty("Version", &version); |
46 RegisterProperty("Methods", &methods); | 46 RegisterProperty("Methods", &methods); |
47 RegisterProperty("Objects", &objects); | 47 RegisterProperty("Objects", &objects); |
48 } | 48 } |
49 }; | 49 }; |
50 | 50 |
51 virtual PropertySet* CreateProperties( | 51 PropertySet* CreateProperties(ObjectProxy* object_proxy, |
52 ObjectProxy* object_proxy, | 52 const ObjectPath& object_path, |
53 const ObjectPath& object_path, | 53 const std::string& interface_name) override { |
54 const std::string& interface_name) override { | |
55 Properties* properties = new Properties( | 54 Properties* properties = new Properties( |
56 object_proxy, interface_name, | 55 object_proxy, interface_name, |
57 base::Bind(&ObjectManagerTest::OnPropertyChanged, | 56 base::Bind(&ObjectManagerTest::OnPropertyChanged, |
58 base::Unretained(this), object_path)); | 57 base::Unretained(this), object_path)); |
59 return static_cast<PropertySet*>(properties); | 58 return static_cast<PropertySet*>(properties); |
60 } | 59 } |
61 | 60 |
62 virtual void SetUp() { | 61 void SetUp() override { |
63 // Make the main thread not to allow IO. | 62 // Make the main thread not to allow IO. |
64 base::ThreadRestrictions::SetIOAllowed(false); | 63 base::ThreadRestrictions::SetIOAllowed(false); |
65 | 64 |
66 // Start the D-Bus thread. | 65 // Start the D-Bus thread. |
67 dbus_thread_.reset(new base::Thread("D-Bus Thread")); | 66 dbus_thread_.reset(new base::Thread("D-Bus Thread")); |
68 base::Thread::Options thread_options; | 67 base::Thread::Options thread_options; |
69 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 68 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
70 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); | 69 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); |
71 | 70 |
72 // Start the test service, using the D-Bus thread. | 71 // Start the test service, using the D-Bus thread. |
(...skipping 13 matching lines...) Expand all Loading... |
86 ASSERT_TRUE(bus_->HasDBusThread()); | 85 ASSERT_TRUE(bus_->HasDBusThread()); |
87 | 86 |
88 object_manager_ = bus_->GetObjectManager( | 87 object_manager_ = bus_->GetObjectManager( |
89 "org.chromium.TestService", | 88 "org.chromium.TestService", |
90 ObjectPath("/org/chromium/TestService")); | 89 ObjectPath("/org/chromium/TestService")); |
91 object_manager_->RegisterInterface("org.chromium.TestInterface", this); | 90 object_manager_->RegisterInterface("org.chromium.TestInterface", this); |
92 | 91 |
93 WaitForObject(); | 92 WaitForObject(); |
94 } | 93 } |
95 | 94 |
96 virtual void TearDown() { | 95 void TearDown() override { |
97 bus_->ShutdownOnDBusThreadAndBlock(); | 96 bus_->ShutdownOnDBusThreadAndBlock(); |
98 | 97 |
99 // Shut down the service. | 98 // Shut down the service. |
100 test_service_->ShutdownAndBlock(); | 99 test_service_->ShutdownAndBlock(); |
101 | 100 |
102 // Reset to the default. | 101 // Reset to the default. |
103 base::ThreadRestrictions::SetIOAllowed(true); | 102 base::ThreadRestrictions::SetIOAllowed(true); |
104 | 103 |
105 // Stopping a thread is considered an IO operation, so do this after | 104 // Stopping a thread is considered an IO operation, so do this after |
106 // allowing IO. | 105 // allowing IO. |
(...skipping 12 matching lines...) Expand all Loading... |
119 // signal before the timeout. This method immediately fails the test. | 118 // signal before the timeout. This method immediately fails the test. |
120 void PropertiesChangedTestTimeout() { | 119 void PropertiesChangedTestTimeout() { |
121 timeout_expired_ = true; | 120 timeout_expired_ = true; |
122 run_loop_->Quit(); | 121 run_loop_->Quit(); |
123 | 122 |
124 FAIL() << "Never received PropertiesChanged"; | 123 FAIL() << "Never received PropertiesChanged"; |
125 } | 124 } |
126 | 125 |
127 protected: | 126 protected: |
128 // Called when an object is added. | 127 // Called when an object is added. |
129 virtual void ObjectAdded(const ObjectPath& object_path, | 128 void ObjectAdded(const ObjectPath& object_path, |
130 const std::string& interface_name) override { | 129 const std::string& interface_name) override { |
131 added_objects_.push_back(std::make_pair(object_path, interface_name)); | 130 added_objects_.push_back(std::make_pair(object_path, interface_name)); |
132 run_loop_->Quit(); | 131 run_loop_->Quit(); |
133 } | 132 } |
134 | 133 |
135 // Called when an object is removed. | 134 // Called when an object is removed. |
136 virtual void ObjectRemoved(const ObjectPath& object_path, | 135 void ObjectRemoved(const ObjectPath& object_path, |
137 const std::string& interface_name) override { | 136 const std::string& interface_name) override { |
138 removed_objects_.push_back(std::make_pair(object_path, interface_name)); | 137 removed_objects_.push_back(std::make_pair(object_path, interface_name)); |
139 run_loop_->Quit(); | 138 run_loop_->Quit(); |
140 } | 139 } |
141 | 140 |
142 // Called when a property value is updated. | 141 // Called when a property value is updated. |
143 void OnPropertyChanged(const ObjectPath& object_path, | 142 void OnPropertyChanged(const ObjectPath& object_path, |
144 const std::string& name) { | 143 const std::string& name) { |
145 // Store the value of the "Name" property if that's the one that | 144 // Store the value of the "Name" property if that's the one that |
146 // changed. | 145 // changed. |
147 Properties* properties = static_cast<Properties*>( | 146 Properties* properties = static_cast<Properties*>( |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 base::Unretained(this)), | 408 base::Unretained(this)), |
410 base::TimeDelta::FromSeconds(2)); | 409 base::TimeDelta::FromSeconds(2)); |
411 | 410 |
412 while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) { | 411 while (last_name_value_ != "ChangedTestServiceName" && !timeout_expired_) { |
413 run_loop_.reset(new base::RunLoop); | 412 run_loop_.reset(new base::RunLoop); |
414 run_loop_->Run(); | 413 run_loop_->Run(); |
415 } | 414 } |
416 } | 415 } |
417 | 416 |
418 } // namespace dbus | 417 } // namespace dbus |
OLD | NEW |