OLD | NEW |
1 // Copyright (c) 2011 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 // This test is relatively complicated. Here's the summary of what it does: | 5 // This test is relatively complicated. Here's the summary of what it does: |
6 // | 6 // |
7 // - Set up mock D-Bus related objects to mock out D-Bus calls. | 7 // - Set up mock D-Bus related objects to mock out D-Bus calls. |
8 // - Set up a mock proxy resolver to mock out the proxy resolution. | 8 // - Set up a mock proxy resolver to mock out the proxy resolution. |
9 // - Create ProxyResolutionServiceProvider by injecting the mocks | 9 // - Create ProxyResolutionServiceProvider by injecting the mocks |
10 // - Start the service provider. | 10 // - Start the service provider. |
11 // - Request ProxyResolutionServiceProvider to resolve proxy for kSourceURL. | 11 // - Request ProxyResolutionServiceProvider to resolve proxy for kSourceURL. |
12 // - ProxyResolutionServiceProvider will return the result as a signal. | 12 // - ProxyResolutionServiceProvider will return the result as a signal. |
13 // - Confirm that we receive the signal and check the contents of the signal. | 13 // - Confirm that we receive the signal and check the contents of the signal. |
14 | 14 |
15 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" | 15 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" |
16 | 16 |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
21 #include "dbus/message.h" | 21 #include "dbus/message.h" |
22 #include "dbus/mock_bus.h" | 22 #include "dbus/mock_bus.h" |
23 #include "dbus/mock_exported_object.h" | 23 #include "dbus/mock_exported_object.h" |
24 #include "dbus/mock_object_proxy.h" | 24 #include "dbus/mock_object_proxy.h" |
| 25 #include "dbus/object_path.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
28 | 29 |
29 using ::testing::_; | 30 using ::testing::_; |
30 using ::testing::Invoke; | 31 using ::testing::Invoke; |
31 using ::testing::Return; | 32 using ::testing::Return; |
32 using ::testing::Unused; | 33 using ::testing::Unused; |
33 | 34 |
34 namespace chromeos { | 35 namespace chromeos { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 mock_bus_ = new dbus::MockBus(options); | 74 mock_bus_ = new dbus::MockBus(options); |
74 | 75 |
75 // ShutdownAndBlock() will be called in TearDown(). | 76 // ShutdownAndBlock() will be called in TearDown(). |
76 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); | 77 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); |
77 | 78 |
78 // Create a mock exported object that behaves as | 79 // Create a mock exported object that behaves as |
79 // org.chromium.CrosDBusService. | 80 // org.chromium.CrosDBusService. |
80 mock_exported_object_ = | 81 mock_exported_object_ = |
81 new dbus::MockExportedObject(mock_bus_.get(), | 82 new dbus::MockExportedObject(mock_bus_.get(), |
82 kLibCrosServiceName, | 83 kLibCrosServiceName, |
83 kLibCrosServicePath); | 84 dbus::ObjectPath(kLibCrosServicePath)); |
84 | 85 |
85 // |mock_exported_object_|'s ExportMethod() will use | 86 // |mock_exported_object_|'s ExportMethod() will use |
86 // |MockExportedObject(). | 87 // |MockExportedObject(). |
87 EXPECT_CALL( | 88 EXPECT_CALL( |
88 *mock_exported_object_, | 89 *mock_exported_object_, |
89 ExportMethod(_, _, _, _)).WillOnce( | 90 ExportMethod(_, _, _, _)).WillOnce( |
90 Invoke(this, | 91 Invoke(this, |
91 &ProxyResolutionServiceProviderTest::MockExportMethod)); | 92 &ProxyResolutionServiceProviderTest::MockExportMethod)); |
92 // |mock_exported_object_|'s SendSignal() will use | 93 // |mock_exported_object_|'s SendSignal() will use |
93 // |MockSendSignal(). | 94 // |MockSendSignal(). |
94 EXPECT_CALL( | 95 EXPECT_CALL( |
95 *mock_exported_object_, | 96 *mock_exported_object_, |
96 SendSignal(_)).WillOnce( | 97 SendSignal(_)).WillOnce( |
97 Invoke(this, | 98 Invoke(this, |
98 &ProxyResolutionServiceProviderTest::MockSendSignal)); | 99 &ProxyResolutionServiceProviderTest::MockSendSignal)); |
99 | 100 |
100 // Create a mock object proxy, with which we call a method of | 101 // Create a mock object proxy, with which we call a method of |
101 // |mock_exported_object_|. | 102 // |mock_exported_object_|. |
102 mock_object_proxy_ = | 103 mock_object_proxy_ = |
103 new dbus::MockObjectProxy(mock_bus_.get(), | 104 new dbus::MockObjectProxy(mock_bus_.get(), |
104 kLibCrosServiceName, | 105 kLibCrosServiceName, |
105 kLibCrosServicePath); | 106 dbus::ObjectPath(kLibCrosServicePath)); |
106 // |mock_object_proxy_|'s CallMethodAndBlock() will use | 107 // |mock_object_proxy_|'s CallMethodAndBlock() will use |
107 // MockCallMethodAndBlock() to return responses. | 108 // MockCallMethodAndBlock() to return responses. |
108 EXPECT_CALL(*mock_object_proxy_, | 109 EXPECT_CALL(*mock_object_proxy_, |
109 CallMethodAndBlock(_, _)) | 110 CallMethodAndBlock(_, _)) |
110 .WillOnce(Invoke( | 111 .WillOnce(Invoke( |
111 this, | 112 this, |
112 &ProxyResolutionServiceProviderTest::MockCallMethodAndBlock)); | 113 &ProxyResolutionServiceProviderTest::MockCallMethodAndBlock)); |
113 // |mock_object_proxy_|'s ConnectToSignal will use | 114 // |mock_object_proxy_|'s ConnectToSignal will use |
114 // MockConnectToSignal(). | 115 // MockConnectToSignal(). |
115 EXPECT_CALL(*mock_object_proxy_, | 116 EXPECT_CALL(*mock_object_proxy_, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 ASSERT_TRUE(response.get()); | 322 ASSERT_TRUE(response.get()); |
322 dbus::MessageReader reader(response.get()); | 323 dbus::MessageReader reader(response.get()); |
323 ASSERT_FALSE(reader.HasMoreData()); | 324 ASSERT_FALSE(reader.HasMoreData()); |
324 | 325 |
325 // Confirm that the signal is received successfully. | 326 // Confirm that the signal is received successfully. |
326 // The contents of the signal are checked in OnSignalReceived(). | 327 // The contents of the signal are checked in OnSignalReceived(). |
327 ASSERT_TRUE(signal_received_successfully_); | 328 ASSERT_TRUE(signal_received_successfully_); |
328 } | 329 } |
329 | 330 |
330 } // namespace chromeos | 331 } // namespace chromeos |
OLD | NEW |