OLD | NEW |
1 // Copyright (c) 2011 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 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 8 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
9 #include "chrome/browser/service/service_process_control.h" | 9 #include "chrome/browser/service/service_process_control.h" |
10 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" | 10 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "chrome/common/service_messages.h" | 12 #include "chrome/common/service_messages.h" |
13 #include "chrome/test/base/testing_pref_service.h" | 13 #include "chrome/test/base/testing_pref_service.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/test/test_browser_thread.h" | 16 #include "content/test/test_browser_thread.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using ::testing::Assign; | 20 using ::testing::Assign; |
21 using ::testing::AtMost; | 21 using ::testing::AtMost; |
| 22 using ::testing::DeleteArg; |
| 23 using ::testing::DoAll; |
22 using ::testing::Invoke; | 24 using ::testing::Invoke; |
23 using ::testing::Property; | 25 using ::testing::Property; |
| 26 using ::testing::Return; |
24 using ::testing::ReturnPointee; | 27 using ::testing::ReturnPointee; |
25 using ::testing::WithArgs; | 28 using ::testing::WithArgs; |
26 using ::testing::_; | 29 using ::testing::_; |
27 | 30 |
28 class MockServiceProcessControl : public ServiceProcessControl { | 31 class MockServiceProcessControl : public ServiceProcessControl { |
29 public: | 32 public: |
30 static std::string EnabledUserId(); | 33 static std::string EnabledUserId(); |
31 | 34 |
32 MockServiceProcessControl() : connected_(false) { } | 35 MockServiceProcessControl() : connected_(false) { } |
33 | 36 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 else if (service_state == kServiceStateDisabled) | 93 else if (service_state == kServiceStateDisabled) |
91 SetServiceDisabledExpectations(); | 94 SetServiceDisabledExpectations(); |
92 } | 95 } |
93 | 96 |
94 void MockServiceProcessControl::SetServiceEnabledExpectations() { | 97 void MockServiceProcessControl::SetServiceEnabledExpectations() { |
95 EXPECT_CALL( | 98 EXPECT_CALL( |
96 *this, | 99 *this, |
97 Send(Property(&IPC::Message::type, | 100 Send(Property(&IPC::Message::type, |
98 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) | 101 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) |
99 .Times(1).WillOnce( | 102 .Times(1).WillOnce( |
100 WithoutArgs( | 103 DoAll( |
101 Invoke(this, &MockServiceProcessControl::SendEnabledInfo))); | 104 DeleteArg<0>(), |
| 105 WithoutArgs( |
| 106 Invoke(this, &MockServiceProcessControl::SendEnabledInfo)))); |
102 } | 107 } |
103 | 108 |
104 void MockServiceProcessControl::SetServiceDisabledExpectations() { | 109 void MockServiceProcessControl::SetServiceDisabledExpectations() { |
105 EXPECT_CALL( | 110 EXPECT_CALL( |
106 *this, | 111 *this, |
107 Send(Property(&IPC::Message::type, | 112 Send(Property(&IPC::Message::type, |
108 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) | 113 static_cast<int32>(ServiceMsg_GetCloudPrintProxyInfo::ID)))) |
109 .Times(1).WillOnce( | 114 .Times(1).WillOnce( |
110 WithoutArgs( | 115 DoAll( |
111 Invoke(this, &MockServiceProcessControl::SendDisabledInfo))); | 116 DeleteArg<0>(), |
| 117 WithoutArgs( |
| 118 Invoke(this, &MockServiceProcessControl::SendDisabledInfo)))); |
112 } | 119 } |
113 | 120 |
114 void MockServiceProcessControl::SetWillBeEnabledExpectations() { | 121 void MockServiceProcessControl::SetWillBeEnabledExpectations() { |
115 EXPECT_CALL( | 122 EXPECT_CALL( |
116 *this, | 123 *this, |
117 Send(Property(&IPC::Message::type, | 124 Send(Property(&IPC::Message::type, |
118 static_cast<int32>(ServiceMsg_EnableCloudPrintProxy::ID)))) | 125 static_cast<int32>(ServiceMsg_EnableCloudPrintProxy::ID)))) |
119 .Times(1); | 126 .Times(1).WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
120 } | 127 } |
121 | 128 |
122 void MockServiceProcessControl::SetWillBeDisabledExpectations() { | 129 void MockServiceProcessControl::SetWillBeDisabledExpectations() { |
123 EXPECT_CALL( | 130 EXPECT_CALL( |
124 *this, | 131 *this, |
125 Send(Property(&IPC::Message::type, | 132 Send(Property(&IPC::Message::type, |
126 static_cast<int32>(ServiceMsg_DisableCloudPrintProxy::ID)))) | 133 static_cast<int32>(ServiceMsg_DisableCloudPrintProxy::ID)))) |
127 .Times(1); | 134 .Times(1).WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
128 } | 135 } |
129 | 136 |
130 bool MockServiceProcessControl::SendEnabledInfo() { | 137 bool MockServiceProcessControl::SendEnabledInfo() { |
131 info_.enabled = true; | 138 info_.enabled = true; |
132 info_.email = EnabledUserId(); | 139 info_.email = EnabledUserId(); |
133 OnCloudPrintProxyInfo(info_); | 140 OnCloudPrintProxyInfo(info_); |
134 return true; | 141 return true; |
135 } | 142 } |
136 | 143 |
137 bool MockServiceProcessControl::SendDisabledInfo() { | 144 bool MockServiceProcessControl::SendDisabledInfo() { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); | 389 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); |
383 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 390 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
384 | 391 |
385 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); | 392 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); |
386 service.EnableForUser(std::string(), | 393 service.EnableForUser(std::string(), |
387 MockServiceProcessControl::EnabledUserId()); | 394 MockServiceProcessControl::EnabledUserId()); |
388 | 395 |
389 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), | 396 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), |
390 prefs->GetString(prefs::kCloudPrintEmail)); | 397 prefs->GetString(prefs::kCloudPrintEmail)); |
391 } | 398 } |
OLD | NEW |