Cleanup: Put DBus unit tests in the dbus namespace, so one does not need to write dbus:: everywhere. Remove some other dbus:: usages in the dbus namespace.

Review URL: https://chromiumcodereview.appspot.com/16012018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206010 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 2a57ca64048fe077fdf841cd49e76fa787a6c251
diff --git a/dbus/end_to_end_async_unittest.cc b/dbus/end_to_end_async_unittest.cc
index 210431f..b13f533 100644
--- a/dbus/end_to_end_async_unittest.cc
+++ b/dbus/end_to_end_async_unittest.cc
@@ -20,6 +20,8 @@
 #include "dbus/test_service.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+namespace dbus {
+
 namespace {
 
 // See comments in ObjectProxy::RunResponseCallback() for why the number was
@@ -45,24 +47,24 @@
     ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options));
 
     // Start the test service, using the D-Bus thread.
-    dbus::TestService::Options options;
+    TestService::Options options;
     options.dbus_task_runner = dbus_thread_->message_loop_proxy();
-    test_service_.reset(new dbus::TestService(options));
+    test_service_.reset(new TestService(options));
     ASSERT_TRUE(test_service_->StartService());
     ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted());
     ASSERT_TRUE(test_service_->HasDBusThread());
 
     // Create the client, using the D-Bus thread.
-    dbus::Bus::Options bus_options;
-    bus_options.bus_type = dbus::Bus::SESSION;
-    bus_options.connection_type = dbus::Bus::PRIVATE;
+    Bus::Options bus_options;
+    bus_options.bus_type = Bus::SESSION;
+    bus_options.connection_type = Bus::PRIVATE;
     bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy();
     bus_options.disconnected_callback =
         base::Bind(&EndToEndAsyncTest::OnDisconnected, base::Unretained(this));
-    bus_ = new dbus::Bus(bus_options);
+    bus_ = new Bus(bus_options);
     object_proxy_ = bus_->GetObjectProxy(
         "org.chromium.TestService",
-        dbus::ObjectPath("/org/chromium/TestObject"));
+        ObjectPath("/org/chromium/TestObject"));
     ASSERT_TRUE(bus_->HasDBusThread());
 
     // Connect to the "Test" signal of "org.chromium.TestInterface" from
@@ -93,9 +95,8 @@
     message_loop_.Run();
 
     // Create a second object proxy for the root object.
-    root_object_proxy_ = bus_->GetObjectProxy(
-        "org.chromium.TestService",
-        dbus::ObjectPath("/"));
+    root_object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService",
+                                              ObjectPath("/"));
     ASSERT_TRUE(bus_->HasDBusThread());
 
     // Connect to the "Test" signal of "org.chromium.TestInterface" from
@@ -133,23 +134,23 @@
 
     // Create new bus with invalid address.
     const char kInvalidAddress[] = "";
-    dbus::Bus::Options bus_options;
-    bus_options.bus_type = dbus::Bus::CUSTOM_ADDRESS;
+    Bus::Options bus_options;
+    bus_options.bus_type = Bus::CUSTOM_ADDRESS;
     bus_options.address = kInvalidAddress;
-    bus_options.connection_type = dbus::Bus::PRIVATE;
+    bus_options.connection_type = Bus::PRIVATE;
     bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy();
-    bus_ = new dbus::Bus(bus_options);
+    bus_ = new Bus(bus_options);
     ASSERT_TRUE(bus_->HasDBusThread());
 
     // Create new object proxy.
     object_proxy_ = bus_->GetObjectProxy(
         "org.chromium.TestService",
-        dbus::ObjectPath("/org/chromium/TestObject"));
+        ObjectPath("/org/chromium/TestObject"));
   }
 
   // Calls the method asynchronously. OnResponse() will be called once the
   // response is received.
-  void CallMethod(dbus::MethodCall* method_call,
+  void CallMethod(MethodCall* method_call,
                   int timeout_ms) {
     object_proxy_->CallMethod(method_call,
                               timeout_ms,
@@ -159,7 +160,7 @@
 
   // Calls the method asynchronously. OnResponse() will be called once the
   // response is received without error, otherwise OnError() will be called.
-  void CallMethodWithErrorCallback(dbus::MethodCall* method_call,
+  void CallMethodWithErrorCallback(MethodCall* method_call,
                                    int timeout_ms) {
     object_proxy_->CallMethodWithErrorCallback(
         method_call,
@@ -176,11 +177,11 @@
   }
 
   // Called when the response is received.
-  void OnResponse(dbus::Response* response) {
+  void OnResponse(Response* response) {
     // |response| will be deleted on exit of the function. Copy the
     // payload to |response_strings_|.
     if (response) {
-      dbus::MessageReader reader(response);
+      MessageReader reader(response);
       std::string response_string;
       ASSERT_TRUE(reader.PopString(&response_string));
       response_strings_.push_back(response_string);
@@ -198,7 +199,7 @@
   }
 
   // Called when an error is received.
-  void OnError(dbus::ErrorResponse* error) {
+  void OnError(ErrorResponse* error) {
     // |error| will be deleted on exit of the function. Copy the payload to
     // |error_names_|.
     if (error) {
@@ -212,8 +213,8 @@
 
   // Called when the "Test" signal is received, in the main thread.
   // Copy the string payload to |test_signal_string_|.
-  void OnTestSignal(dbus::Signal* signal) {
-    dbus::MessageReader reader(signal);
+  void OnTestSignal(Signal* signal) {
+    MessageReader reader(signal);
     ASSERT_TRUE(reader.PopString(&test_signal_string_));
     message_loop_.Quit();
   }
@@ -221,15 +222,15 @@
   // Called when the "Test" signal is received, in the main thread, by
   // the root object proxy. Copy the string payload to
   // |root_test_signal_string_|.
-  void OnRootTestSignal(dbus::Signal* signal) {
-    dbus::MessageReader reader(signal);
+  void OnRootTestSignal(Signal* signal) {
+    MessageReader reader(signal);
     ASSERT_TRUE(reader.PopString(&root_test_signal_string_));
     message_loop_.Quit();
   }
 
   // Called when the "Test2" signal is received, in the main thread.
-  void OnTest2Signal(dbus::Signal* signal) {
-    dbus::MessageReader reader(signal);
+  void OnTest2Signal(Signal* signal) {
+    MessageReader reader(signal);
     message_loop_.Quit();
   }
 
@@ -257,10 +258,10 @@
   std::vector<std::string> response_strings_;
   std::vector<std::string> error_names_;
   scoped_ptr<base::Thread> dbus_thread_;
-  scoped_refptr<dbus::Bus> bus_;
-  dbus::ObjectProxy* object_proxy_;
-  dbus::ObjectProxy* root_object_proxy_;
-  scoped_ptr<dbus::TestService> test_service_;
+  scoped_refptr<Bus> bus_;
+  ObjectProxy* object_proxy_;
+  ObjectProxy* root_object_proxy_;
+  scoped_ptr<TestService> test_service_;
   // Text message from "Test" signal.
   std::string test_signal_string_;
   // Text message from "Test" signal delivered to root.
@@ -272,12 +273,12 @@
   const char* kHello = "hello";
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethod(&method_call, timeout_ms);
 
   // Check the response.
@@ -289,12 +290,12 @@
   const char* kHello = "hello";
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethodWithErrorCallback(&method_call, timeout_ms);
 
   // Check the response.
@@ -309,12 +310,12 @@
 
   for (size_t i = 0; i < arraysize(kMessages); ++i) {
     // Create the method call.
-    dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-    dbus::MessageWriter writer(&method_call);
+    MethodCall method_call("org.chromium.TestInterface", "Echo");
+    MessageWriter writer(&method_call);
     writer.AppendString(kMessages[i]);
 
     // Call the method.
-    const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+    const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
     CallMethod(&method_call, timeout_ms);
   }
 
@@ -331,12 +332,12 @@
   const std::string kHugePayload(kHugePayloadSize, 'o');
 
   // Create the method call with a huge payload.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHugePayload);
 
   // Call the method.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethod(&method_call, timeout_ms);
 
   // This caused a DCHECK failure before. Ensure that the issue is fixed.
@@ -351,12 +352,12 @@
   SetUpBrokenBus();
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethod(&method_call, timeout_ms);
   WaitForResponses(1);
 
@@ -371,12 +372,12 @@
   SetUpBrokenBus();
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethodWithErrorCallback(&method_call, timeout_ms);
   WaitForErrors(1);
 
@@ -389,8 +390,8 @@
   const char* kHello = "hello";
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "SlowEcho");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "SlowEcho");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method with timeout of 0ms.
@@ -406,8 +407,8 @@
   const char* kHello = "hello";
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "SlowEcho");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "SlowEcho");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method with timeout of 0ms.
@@ -425,12 +426,12 @@
   const char* kHello = "hello";
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "AsyncEcho");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "AsyncEcho");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethod(&method_call, timeout_ms);
 
   // Check the response.
@@ -439,9 +440,9 @@
 }
 
 TEST_F(EndToEndAsyncTest, NonexistentMethod) {
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Nonexistent");
+  MethodCall method_call("org.chromium.TestInterface", "Nonexistent");
 
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethod(&method_call, timeout_ms);
   WaitForResponses(1);
 
@@ -450,9 +451,9 @@
 }
 
 TEST_F(EndToEndAsyncTest, NonexistentMethodWithErrorCallback) {
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Nonexistent");
+  MethodCall method_call("org.chromium.TestInterface", "Nonexistent");
 
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethodWithErrorCallback(&method_call, timeout_ms);
   WaitForErrors(1);
 
@@ -462,9 +463,9 @@
 }
 
 TEST_F(EndToEndAsyncTest, BrokenMethod) {
-  dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod");
+  MethodCall method_call("org.chromium.TestInterface", "BrokenMethod");
 
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethod(&method_call, timeout_ms);
   WaitForResponses(1);
 
@@ -473,9 +474,9 @@
 }
 
 TEST_F(EndToEndAsyncTest, BrokenMethodWithErrorCallback) {
-  dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod");
+  MethodCall method_call("org.chromium.TestInterface", "BrokenMethod");
 
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethodWithErrorCallback(&method_call, timeout_ms);
   WaitForErrors(1);
 
@@ -486,15 +487,15 @@
 
 TEST_F(EndToEndAsyncTest, InvalidObjectPath) {
   // Trailing '/' is only allowed for the root path.
-  const dbus::ObjectPath invalid_object_path("/org/chromium/TestObject/");
+  const ObjectPath invalid_object_path("/org/chromium/TestObject/");
 
   // Replace object proxy with new one.
   object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService",
                                        invalid_object_path);
 
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
 
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethodWithErrorCallback(&method_call, timeout_ms);
   WaitForErrors(1);
 
@@ -509,11 +510,11 @@
 
   // Replace object proxy with new one.
   object_proxy_ = bus_->GetObjectProxy(
-      invalid_service_name, dbus::ObjectPath("org.chromium.TestObject"));
+      invalid_service_name, ObjectPath("org.chromium.TestObject"));
 
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
 
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   CallMethodWithErrorCallback(&method_call, timeout_ms);
   WaitForErrors(1);
 
@@ -526,15 +527,15 @@
   const char* kHello = "hello";
 
   // Create the method call.
-  dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
-  dbus::MessageWriter writer(&method_call);
+  MethodCall method_call("org.chromium.TestInterface", "Echo");
+  MessageWriter writer(&method_call);
   writer.AppendString(kHello);
 
   // Call the method with an empty callback.
-  const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
+  const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
   object_proxy_->CallMethod(&method_call,
                             timeout_ms,
-                            dbus::ObjectProxy::EmptyResponseCallback());
+                            ObjectProxy::EmptyResponseCallback());
   // Post a delayed task to quit the message loop.
   message_loop_.PostDelayedTask(FROM_HERE,
                                 base::MessageLoop::QuitClosure(),
@@ -580,7 +581,7 @@
 
 TEST_F(EndToEndAsyncTest, DisconnectedSignal) {
   bus_->PostTaskToDBusThread(FROM_HERE,
-                             base::Bind(&dbus::Bus::ClosePrivateConnection,
+                             base::Bind(&Bus::ClosePrivateConnection,
                                         base::Unretained(bus_.get())));
   // OnDisconnected callback quits message loop.
   message_loop_.Run();
@@ -613,8 +614,8 @@
  protected:
   // Called when the "Test" signal is received, in the main thread.
   // Copy the string payload to |additional_test_signal_string_|.
-  void OnAdditionalTestSignal(dbus::Signal* signal) {
-    dbus::MessageReader reader(signal);
+  void OnAdditionalTestSignal(Signal* signal) {
+    MessageReader reader(signal);
     ASSERT_TRUE(reader.PopString(&additional_test_signal_string_));
     message_loop_.Quit();
   }
@@ -642,3 +643,5 @@
   // Verify the signal WAS ALSO received by the additional handler.
   ASSERT_EQ(kMessage, additional_test_signal_string_);
 }
+
+}  // namespace dbus