OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | |
26 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "third_party/cros_system_api/dbus/service_constants.h" | 27 #include "third_party/cros_system_api/dbus/service_constants.h" |
29 | 28 |
30 using ::testing::_; | 29 using ::testing::_; |
31 using ::testing::Invoke; | 30 using ::testing::Invoke; |
32 using ::testing::Return; | 31 using ::testing::Return; |
33 using ::testing::Unused; | 32 using ::testing::Unused; |
34 | 33 |
35 namespace chromeos { | 34 namespace chromeos { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 mock_bus_ = new dbus::MockBus(options); | 73 mock_bus_ = new dbus::MockBus(options); |
75 | 74 |
76 // ShutdownAndBlock() will be called in TearDown(). | 75 // ShutdownAndBlock() will be called in TearDown(). |
77 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); | 76 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); |
78 | 77 |
79 // Create a mock exported object that behaves as | 78 // Create a mock exported object that behaves as |
80 // org.chromium.CrosDBusService. | 79 // org.chromium.CrosDBusService. |
81 mock_exported_object_ = | 80 mock_exported_object_ = |
82 new dbus::MockExportedObject(mock_bus_.get(), | 81 new dbus::MockExportedObject(mock_bus_.get(), |
83 kLibCrosServiceName, | 82 kLibCrosServiceName, |
84 dbus::ObjectPath(kLibCrosServicePath)); | 83 kLibCrosServicePath); |
85 | 84 |
86 // |mock_exported_object_|'s ExportMethod() will use | 85 // |mock_exported_object_|'s ExportMethod() will use |
87 // |MockExportedObject(). | 86 // |MockExportedObject(). |
88 EXPECT_CALL( | 87 EXPECT_CALL( |
89 *mock_exported_object_, | 88 *mock_exported_object_, |
90 ExportMethod(_, _, _, _)).WillOnce( | 89 ExportMethod(_, _, _, _)).WillOnce( |
91 Invoke(this, | 90 Invoke(this, |
92 &ProxyResolutionServiceProviderTest::MockExportMethod)); | 91 &ProxyResolutionServiceProviderTest::MockExportMethod)); |
93 // |mock_exported_object_|'s SendSignal() will use | 92 // |mock_exported_object_|'s SendSignal() will use |
94 // |MockSendSignal(). | 93 // |MockSendSignal(). |
95 EXPECT_CALL( | 94 EXPECT_CALL( |
96 *mock_exported_object_, | 95 *mock_exported_object_, |
97 SendSignal(_)).WillOnce( | 96 SendSignal(_)).WillOnce( |
98 Invoke(this, | 97 Invoke(this, |
99 &ProxyResolutionServiceProviderTest::MockSendSignal)); | 98 &ProxyResolutionServiceProviderTest::MockSendSignal)); |
100 | 99 |
101 // Create a mock object proxy, with which we call a method of | 100 // Create a mock object proxy, with which we call a method of |
102 // |mock_exported_object_|. | 101 // |mock_exported_object_|. |
103 mock_object_proxy_ = | 102 mock_object_proxy_ = |
104 new dbus::MockObjectProxy(mock_bus_.get(), | 103 new dbus::MockObjectProxy(mock_bus_.get(), |
105 kLibCrosServiceName, | 104 kLibCrosServiceName, |
106 dbus::ObjectPath(kLibCrosServicePath)); | 105 kLibCrosServicePath); |
107 // |mock_object_proxy_|'s CallMethodAndBlock() will use | 106 // |mock_object_proxy_|'s CallMethodAndBlock() will use |
108 // MockCallMethodAndBlock() to return responses. | 107 // MockCallMethodAndBlock() to return responses. |
109 EXPECT_CALL(*mock_object_proxy_, | 108 EXPECT_CALL(*mock_object_proxy_, |
110 CallMethodAndBlock(_, _)) | 109 CallMethodAndBlock(_, _)) |
111 .WillOnce(Invoke( | 110 .WillOnce(Invoke( |
112 this, | 111 this, |
113 &ProxyResolutionServiceProviderTest::MockCallMethodAndBlock)); | 112 &ProxyResolutionServiceProviderTest::MockCallMethodAndBlock)); |
114 // |mock_object_proxy_|'s ConnectToSignal will use | 113 // |mock_object_proxy_|'s ConnectToSignal will use |
115 // MockConnectToSignal(). | 114 // MockConnectToSignal(). |
116 EXPECT_CALL(*mock_object_proxy_, | 115 EXPECT_CALL(*mock_object_proxy_, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 ASSERT_TRUE(response.get()); | 321 ASSERT_TRUE(response.get()); |
323 dbus::MessageReader reader(response.get()); | 322 dbus::MessageReader reader(response.get()); |
324 ASSERT_FALSE(reader.HasMoreData()); | 323 ASSERT_FALSE(reader.HasMoreData()); |
325 | 324 |
326 // Confirm that the signal is received successfully. | 325 // Confirm that the signal is received successfully. |
327 // The contents of the signal are checked in OnSignalReceived(). | 326 // The contents of the signal are checked in OnSignalReceived(). |
328 ASSERT_TRUE(signal_received_successfully_); | 327 ASSERT_TRUE(signal_received_successfully_); |
329 } | 328 } |
330 | 329 |
331 } // namespace chromeos | 330 } // namespace chromeos |
OLD | NEW |