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

Side by Side Diff: dbus/bus_unittest.cc

Issue 12039033: DBus: Fixes a flaky test case. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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
« no previous file with comments | « no previous file | no next file » | 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/bus.h" 5 #include "dbus/bus.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // This should not. 101 // This should not.
102 dbus::ExportedObject* object_proxy3 = 102 dbus::ExportedObject* object_proxy3 =
103 bus->GetExportedObject( 103 bus->GetExportedObject(
104 dbus::ObjectPath("/org/chromium/DifferentTestObject")); 104 dbus::ObjectPath("/org/chromium/DifferentTestObject"));
105 ASSERT_TRUE(object_proxy3); 105 ASSERT_TRUE(object_proxy3);
106 EXPECT_NE(object_proxy1, object_proxy3); 106 EXPECT_NE(object_proxy1, object_proxy3);
107 107
108 bus->ShutdownAndBlock(); 108 bus->ShutdownAndBlock();
109 } 109 }
110 110
111 // http://crbug.com/137846 111 TEST(BusTest, UnregisterExportedObject) {
112 TEST(BusTest, DISABLED_UnregisterExportedObject) {
113 // Start the D-Bus thread. 112 // Start the D-Bus thread.
114 base::Thread::Options thread_options; 113 base::Thread::Options thread_options;
115 thread_options.message_loop_type = MessageLoop::TYPE_IO; 114 thread_options.message_loop_type = MessageLoop::TYPE_IO;
116 base::Thread dbus_thread("D-Bus thread"); 115 base::Thread dbus_thread("D-Bus thread");
117 dbus_thread.StartWithOptions(thread_options); 116 dbus_thread.StartWithOptions(thread_options);
118 117
119 // Create the bus. 118 // Create the bus.
120 dbus::Bus::Options options; 119 dbus::Bus::Options options;
121 options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy(); 120 options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy();
122 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); 121 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
123 ASSERT_FALSE(bus->shutdown_completed()); 122 ASSERT_FALSE(bus->shutdown_completed());
124 123
125 dbus::ExportedObject* object_proxy1 = 124 dbus::ExportedObject* object_proxy1 =
126 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); 125 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject"));
127 ASSERT_TRUE(object_proxy1); 126 ASSERT_TRUE(object_proxy1);
128 127
128 // Increment the reference count to the object proxy to avoid destroying it
129 // calling UnregisterExportedObject. This ensures the dbus::ExportedObject is
130 // not freed from memory. See http://crbug.com/137846 for details.
131 object_proxy1->AddRef();
132
129 bus->UnregisterExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); 133 bus->UnregisterExportedObject(dbus::ObjectPath("/org/chromium/TestObject"));
130 134
131 // This should return a new object. 135 // This should return a new object because the object_proxy1 is still in
136 // alloc'ed memory.
132 dbus::ExportedObject* object_proxy2 = 137 dbus::ExportedObject* object_proxy2 =
133 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); 138 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject"));
134 ASSERT_TRUE(object_proxy2); 139 ASSERT_TRUE(object_proxy2);
135 EXPECT_NE(object_proxy1, object_proxy2); 140 EXPECT_NE(object_proxy1, object_proxy2);
136 141
142 // Release the incremented reference.
143 object_proxy1->Release();
144
137 // Shut down synchronously. 145 // Shut down synchronously.
138 bus->ShutdownOnDBusThreadAndBlock(); 146 bus->ShutdownOnDBusThreadAndBlock();
139 EXPECT_TRUE(bus->shutdown_completed()); 147 EXPECT_TRUE(bus->shutdown_completed());
140 dbus_thread.Stop(); 148 dbus_thread.Stop();
141 } 149 }
142 150
143 TEST(BusTest, ShutdownAndBlock) { 151 TEST(BusTest, ShutdownAndBlock) {
144 dbus::Bus::Options options; 152 dbus::Bus::Options options;
145 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); 153 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
146 ASSERT_FALSE(bus->shutdown_completed()); 154 ASSERT_FALSE(bus->shutdown_completed());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); 190 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1));
183 // Can add the same function with different data. 191 // Can add the same function with different data.
184 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); 192 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2));
185 193
186 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); 194 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1));
187 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); 195 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1));
188 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); 196 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2));
189 197
190 bus->ShutdownAndBlock(); 198 bus->ShutdownAndBlock();
191 } 199 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698