| OLD | NEW |
| 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 <stdint.h> |
| 6 |
| 5 #include <string> | 7 #include <string> |
| 6 | 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 static std::string EnabledUserId(); | 48 static std::string EnabledUserId(); |
| 47 | 49 |
| 48 MockServiceProcessControl() : connected_(false) { } | 50 MockServiceProcessControl() : connected_(false) { } |
| 49 | 51 |
| 50 MOCK_CONST_METHOD0(IsConnected, bool()); | 52 MOCK_CONST_METHOD0(IsConnected, bool()); |
| 51 | 53 |
| 52 MOCK_METHOD2(Launch, void(const base::Closure&, const base::Closure&)); | 54 MOCK_METHOD2(Launch, void(const base::Closure&, const base::Closure&)); |
| 53 MOCK_METHOD0(Disconnect, void()); | 55 MOCK_METHOD0(Disconnect, void()); |
| 54 | 56 |
| 55 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message&)); | 57 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message&)); |
| 56 MOCK_METHOD1(OnChannelConnected, void(int32 peer_pid)); | 58 MOCK_METHOD1(OnChannelConnected, void(int32_t peer_pid)); |
| 57 MOCK_METHOD0(OnChannelError, void()); | 59 MOCK_METHOD0(OnChannelError, void()); |
| 58 | 60 |
| 59 MOCK_METHOD1(Send, bool(IPC::Message*)); | 61 MOCK_METHOD1(Send, bool(IPC::Message*)); |
| 60 | 62 |
| 61 typedef enum { | 63 typedef enum { |
| 62 kServiceStateDisabled, | 64 kServiceStateDisabled, |
| 63 kServiceStateEnabled, | 65 kServiceStateEnabled, |
| 64 kServiceStateNone | 66 kServiceStateNone |
| 65 } ServiceState; | 67 } ServiceState; |
| 66 | 68 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 111 |
| 110 EXPECT_CALL(*this, Send(_)).Times(0); | 112 EXPECT_CALL(*this, Send(_)).Times(0); |
| 111 | 113 |
| 112 if (service_state == kServiceStateEnabled) | 114 if (service_state == kServiceStateEnabled) |
| 113 SetServiceEnabledExpectations(); | 115 SetServiceEnabledExpectations(); |
| 114 else if (service_state == kServiceStateDisabled) | 116 else if (service_state == kServiceStateDisabled) |
| 115 SetServiceDisabledExpectations(); | 117 SetServiceDisabledExpectations(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 void MockServiceProcessControl::SetServiceEnabledExpectations() { | 120 void MockServiceProcessControl::SetServiceEnabledExpectations() { |
| 119 EXPECT_CALL( | 121 EXPECT_CALL(*this, Send(Property(&IPC::Message::type, |
| 120 *this, | 122 static_cast<int32_t>( |
| 121 Send(Property(&IPC::Message::type, | 123 ServiceMsg_GetCloudPrintProxyInfo::ID)))) |
| 122 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) | 124 .Times(1) |
| 123 .Times(1).WillOnce( | 125 .WillOnce(DoAll(DeleteArg<0>(), |
| 124 DoAll( | 126 WithoutArgs(Invoke( |
| 125 DeleteArg<0>(), | 127 this, &MockServiceProcessControl::SendEnabledInfo)))); |
| 126 WithoutArgs( | |
| 127 Invoke(this, &MockServiceProcessControl::SendEnabledInfo)))); | |
| 128 } | 128 } |
| 129 | 129 |
| 130 void MockServiceProcessControl::SetServiceDisabledExpectations() { | 130 void MockServiceProcessControl::SetServiceDisabledExpectations() { |
| 131 EXPECT_CALL( | 131 EXPECT_CALL(*this, Send(Property(&IPC::Message::type, |
| 132 *this, | 132 static_cast<int32_t>( |
| 133 Send(Property(&IPC::Message::type, | 133 ServiceMsg_GetCloudPrintProxyInfo::ID)))) |
| 134 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) | 134 .Times(1) |
| 135 .Times(1).WillOnce( | 135 .WillOnce( |
| 136 DoAll( | 136 DoAll(DeleteArg<0>(), |
| 137 DeleteArg<0>(), | 137 WithoutArgs(Invoke( |
| 138 WithoutArgs( | 138 this, &MockServiceProcessControl::SendDisabledInfo)))); |
| 139 Invoke(this, &MockServiceProcessControl::SendDisabledInfo)))); | |
| 140 } | 139 } |
| 141 | 140 |
| 142 void MockServiceProcessControl::SetWillBeEnabledExpectations() { | 141 void MockServiceProcessControl::SetWillBeEnabledExpectations() { |
| 143 int32 message_id = ServiceMsg_EnableCloudPrintProxyWithRobot::ID; | 142 int32_t message_id = ServiceMsg_EnableCloudPrintProxyWithRobot::ID; |
| 144 EXPECT_CALL( | 143 EXPECT_CALL( |
| 145 *this, | 144 *this, |
| 146 Send(Property(&IPC::Message::type, message_id))) | 145 Send(Property(&IPC::Message::type, message_id))) |
| 147 .Times(1).WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 146 .Times(1).WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 148 } | 147 } |
| 149 | 148 |
| 150 void MockServiceProcessControl::SetWillBeDisabledExpectations() { | 149 void MockServiceProcessControl::SetWillBeDisabledExpectations() { |
| 151 EXPECT_CALL( | 150 EXPECT_CALL(*this, Send(Property(&IPC::Message::type, |
| 152 *this, | 151 static_cast<int32_t>( |
| 153 Send(Property(&IPC::Message::type, | 152 ServiceMsg_DisableCloudPrintProxy::ID)))) |
| 154 static_cast<int32>(ServiceMsg_DisableCloudPrintProxy::ID)))) | 153 .Times(1) |
| 155 .Times(1).WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 154 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 156 } | 155 } |
| 157 | 156 |
| 158 bool MockServiceProcessControl::SendEnabledInfo() { | 157 bool MockServiceProcessControl::SendEnabledInfo() { |
| 159 info_.enabled = true; | 158 info_.enabled = true; |
| 160 info_.email = EnabledUserId(); | 159 info_.email = EnabledUserId(); |
| 161 PostTask(base::Bind(&MockServiceProcessControl::OnCloudPrintProxyInfo, | 160 PostTask(base::Bind(&MockServiceProcessControl::OnCloudPrintProxyInfo, |
| 162 base::Unretained(this), info_)); | 161 base::Unretained(this), info_)); |
| 163 return true; | 162 return true; |
| 164 } | 163 } |
| 165 | 164 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 441 |
| 443 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); | 442 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); |
| 444 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 443 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
| 445 | 444 |
| 446 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); | 445 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); |
| 447 service.EnableForUser(); | 446 service.EnableForUser(); |
| 448 | 447 |
| 449 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), | 448 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), |
| 450 prefs->GetString(prefs::kCloudPrintEmail)); | 449 prefs->GetString(prefs::kCloudPrintEmail)); |
| 451 } | 450 } |
| OLD | NEW |