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 "chrome/browser/printing/print_dialog_cloud.h" | 5 #include "chrome/browser/printing/print_dialog_cloud.h" |
6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" | 6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 21 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "content/public/browser/browser_thread.h" | |
26 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
27 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
29 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
32 | 31 |
33 using content::BrowserThread; | 32 using content::BrowserThread; |
34 using content::WebContents; | 33 using content::WebContents; |
35 using content::WebUIMessageHandler; | 34 using content::WebUIMessageHandler; |
36 using testing::A; | 35 using testing::A; |
37 using testing::AtLeast; | 36 using testing::AtLeast; |
38 using testing::Eq; | 37 using testing::Eq; |
39 using testing::HasSubstr; | 38 using testing::HasSubstr; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 MockCloudPrintDataSenderHelper() : CloudPrintDataSenderHelper(NULL) {} | 141 MockCloudPrintDataSenderHelper() : CloudPrintDataSenderHelper(NULL) {} |
143 MOCK_METHOD1(CallJavascriptFunction, void(const std::wstring&)); | 142 MOCK_METHOD1(CallJavascriptFunction, void(const std::wstring&)); |
144 MOCK_METHOD2(CallJavascriptFunction, void(const std::wstring&, | 143 MOCK_METHOD2(CallJavascriptFunction, void(const std::wstring&, |
145 const Value& arg1)); | 144 const Value& arg1)); |
146 MOCK_METHOD3(CallJavascriptFunction, void(const std::wstring&, | 145 MOCK_METHOD3(CallJavascriptFunction, void(const std::wstring&, |
147 const Value& arg1, | 146 const Value& arg1, |
148 const Value& arg2)); | 147 const Value& arg2)); |
149 }; | 148 }; |
150 | 149 |
151 class CloudPrintURLTest : public testing::Test { | 150 class CloudPrintURLTest : public testing::Test { |
| 151 public: |
| 152 CloudPrintURLTest() {} |
| 153 |
152 protected: | 154 protected: |
153 content::TestBrowserThreadBundle thread_bundle_; | 155 virtual void SetUp() { |
154 TestingProfile profile_; | 156 profile_.reset(new TestingProfile()); |
| 157 } |
| 158 |
| 159 scoped_ptr<Profile> profile_; |
155 }; | 160 }; |
156 | 161 |
157 TEST_F(CloudPrintURLTest, CheckDefaultURLs) { | 162 TEST_F(CloudPrintURLTest, CheckDefaultURLs) { |
158 std::string service_url = | 163 std::string service_url = |
159 CloudPrintURL(&profile_). | 164 CloudPrintURL(profile_.get()). |
160 GetCloudPrintServiceURL().spec(); | 165 GetCloudPrintServiceURL().spec(); |
161 EXPECT_THAT(service_url, HasSubstr("www.google.com")); | 166 EXPECT_THAT(service_url, HasSubstr("www.google.com")); |
162 EXPECT_THAT(service_url, HasSubstr("cloudprint")); | 167 EXPECT_THAT(service_url, HasSubstr("cloudprint")); |
163 | 168 |
164 std::string dialog_url = | 169 std::string dialog_url = |
165 CloudPrintURL(&profile_). | 170 CloudPrintURL(profile_.get()). |
166 GetCloudPrintServiceDialogURL().spec(); | 171 GetCloudPrintServiceDialogURL().spec(); |
167 EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); | 172 EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); |
168 EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); | 173 EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); |
169 EXPECT_THAT(dialog_url, HasSubstr("/client/")); | 174 EXPECT_THAT(dialog_url, HasSubstr("/client/")); |
170 EXPECT_THAT(dialog_url, Not(HasSubstr("cloudprint/cloudprint"))); | 175 EXPECT_THAT(dialog_url, Not(HasSubstr("cloudprint/cloudprint"))); |
171 EXPECT_THAT(dialog_url, HasSubstr("/dialog.html")); | 176 EXPECT_THAT(dialog_url, HasSubstr("/dialog.html")); |
172 | 177 |
173 // Repeat to make sure there isn't a transient glitch. | 178 // Repeat to make sure there isn't a transient glitch. |
174 dialog_url = | 179 dialog_url = |
175 CloudPrintURL(&profile_). | 180 CloudPrintURL(profile_.get()). |
176 GetCloudPrintServiceDialogURL().spec(); | 181 GetCloudPrintServiceDialogURL().spec(); |
177 EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); | 182 EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); |
178 EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); | 183 EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); |
179 EXPECT_THAT(dialog_url, HasSubstr("/client/")); | 184 EXPECT_THAT(dialog_url, HasSubstr("/client/")); |
180 EXPECT_THAT(dialog_url, Not(HasSubstr("cloudprint/cloudprint"))); | 185 EXPECT_THAT(dialog_url, Not(HasSubstr("cloudprint/cloudprint"))); |
181 EXPECT_THAT(dialog_url, HasSubstr("/dialog.html")); | 186 EXPECT_THAT(dialog_url, HasSubstr("/dialog.html")); |
182 | 187 |
183 std::string manage_url = | 188 std::string manage_url = |
184 CloudPrintURL(&profile_). | 189 CloudPrintURL(profile_.get()). |
185 GetCloudPrintServiceManageURL().spec(); | 190 GetCloudPrintServiceManageURL().spec(); |
186 EXPECT_THAT(manage_url, HasSubstr("www.google.com")); | 191 EXPECT_THAT(manage_url, HasSubstr("www.google.com")); |
187 EXPECT_THAT(manage_url, HasSubstr("/cloudprint/")); | 192 EXPECT_THAT(manage_url, HasSubstr("/cloudprint/")); |
188 EXPECT_THAT(manage_url, Not(HasSubstr("/client/"))); | 193 EXPECT_THAT(manage_url, Not(HasSubstr("/client/"))); |
189 EXPECT_THAT(manage_url, Not(HasSubstr("cloudprint/cloudprint"))); | 194 EXPECT_THAT(manage_url, Not(HasSubstr("cloudprint/cloudprint"))); |
190 EXPECT_THAT(manage_url, HasSubstr("/manage")); | 195 EXPECT_THAT(manage_url, HasSubstr("/manage")); |
191 | 196 |
192 GURL learn_more_url = CloudPrintURL::GetCloudPrintLearnMoreURL(); | 197 GURL learn_more_url = CloudPrintURL::GetCloudPrintLearnMoreURL(); |
193 std::string learn_more_path = learn_more_url.spec(); | 198 std::string learn_more_path = learn_more_url.spec(); |
194 EXPECT_THAT(learn_more_path, HasSubstr("www.google.com")); | 199 EXPECT_THAT(learn_more_path, HasSubstr("www.google.com")); |
195 EXPECT_THAT(learn_more_path, HasSubstr("/support/")); | 200 EXPECT_THAT(learn_more_path, HasSubstr("/support/")); |
196 EXPECT_THAT(learn_more_path, HasSubstr("/cloudprint")); | 201 EXPECT_THAT(learn_more_path, HasSubstr("/cloudprint")); |
197 EXPECT_TRUE(learn_more_url.has_path()); | 202 EXPECT_TRUE(learn_more_url.has_path()); |
198 EXPECT_FALSE(learn_more_url.has_query()); | 203 EXPECT_FALSE(learn_more_url.has_query()); |
199 | 204 |
200 GURL test_page_url = CloudPrintURL::GetCloudPrintTestPageURL(); | 205 GURL test_page_url = CloudPrintURL::GetCloudPrintTestPageURL(); |
201 std::string test_page_path = test_page_url.spec(); | 206 std::string test_page_path = test_page_url.spec(); |
202 EXPECT_THAT(test_page_path, HasSubstr("www.google.com")); | 207 EXPECT_THAT(test_page_path, HasSubstr("www.google.com")); |
203 EXPECT_THAT(test_page_path, HasSubstr("/landing/")); | 208 EXPECT_THAT(test_page_path, HasSubstr("/landing/")); |
204 EXPECT_THAT(test_page_path, HasSubstr("/cloudprint/")); | 209 EXPECT_THAT(test_page_path, HasSubstr("/cloudprint/")); |
205 EXPECT_TRUE(test_page_url.has_path()); | 210 EXPECT_TRUE(test_page_url.has_path()); |
206 EXPECT_TRUE(test_page_url.has_query()); | 211 EXPECT_TRUE(test_page_url.has_query()); |
207 } | 212 } |
208 | 213 |
209 // Testing for CloudPrintDataSender needs a mock WebUI. | 214 // Testing for CloudPrintDataSender needs a mock WebUI. |
210 class CloudPrintDataSenderTest : public testing::Test { | 215 class CloudPrintDataSenderTest : public testing::Test { |
| 216 public: |
| 217 CloudPrintDataSenderTest() |
| 218 : file_thread_(BrowserThread::FILE, &message_loop_), |
| 219 io_thread_(BrowserThread::IO, &message_loop_) {} |
| 220 |
211 protected: | 221 protected: |
212 virtual void SetUp() { | 222 virtual void SetUp() { |
213 mock_helper_.reset(new MockCloudPrintDataSenderHelper); | 223 mock_helper_.reset(new MockCloudPrintDataSenderHelper); |
214 } | 224 } |
215 | 225 |
216 scoped_refptr<CloudPrintDataSender> CreateSender( | 226 scoped_refptr<CloudPrintDataSender> CreateSender( |
217 const base::RefCountedString* data) { | 227 const base::RefCountedString* data) { |
218 return new CloudPrintDataSender(mock_helper_.get(), | 228 return new CloudPrintDataSender(mock_helper_.get(), |
219 ASCIIToUTF16(kMockJobTitle), | 229 ASCIIToUTF16(kMockJobTitle), |
220 ASCIIToUTF16(kMockPrintTicket), | 230 ASCIIToUTF16(kMockPrintTicket), |
221 std::string("application/pdf"), | 231 std::string("application/pdf"), |
222 data); | 232 data); |
223 } | 233 } |
224 | 234 |
225 scoped_refptr<CloudPrintDataSender> print_data_sender_; | 235 scoped_refptr<CloudPrintDataSender> print_data_sender_; |
226 scoped_ptr<MockCloudPrintDataSenderHelper> mock_helper_; | 236 scoped_ptr<MockCloudPrintDataSenderHelper> mock_helper_; |
227 | 237 |
228 content::TestBrowserThreadBundle thread_bundle_; | 238 base::MessageLoop message_loop_; |
| 239 content::TestBrowserThread file_thread_; |
| 240 content::TestBrowserThread io_thread_; |
229 }; | 241 }; |
230 | 242 |
231 TEST_F(CloudPrintDataSenderTest, CanSend) { | 243 TEST_F(CloudPrintDataSenderTest, CanSend) { |
232 StringValue mock_job_title(kMockJobTitle); | 244 StringValue mock_job_title(kMockJobTitle); |
233 EXPECT_CALL(*mock_helper_, | 245 EXPECT_CALL(*mock_helper_, |
234 CallJavascriptFunction(_, _, StringValueEq(&mock_job_title))). | 246 CallJavascriptFunction(_, _, StringValueEq(&mock_job_title))). |
235 WillOnce(Return()); | 247 WillOnce(Return()); |
236 | 248 |
237 std::string data("test_data"); | 249 std::string data("test_data"); |
238 scoped_refptr<CloudPrintDataSender> print_data_sender( | 250 scoped_refptr<CloudPrintDataSender> print_data_sender( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // CloudPrintWebDialogDelegate, mock CloudPrintDataSender, and a mock | 284 // CloudPrintWebDialogDelegate, mock CloudPrintDataSender, and a mock |
273 // WebUI. | 285 // WebUI. |
274 | 286 |
275 // Testing for CloudPrintWebDialogDelegate needs a mock | 287 // Testing for CloudPrintWebDialogDelegate needs a mock |
276 // CloudPrintFlowHandler. | 288 // CloudPrintFlowHandler. |
277 | 289 |
278 using internal_cloud_print_helpers::MockCloudPrintFlowHandler; | 290 using internal_cloud_print_helpers::MockCloudPrintFlowHandler; |
279 using internal_cloud_print_helpers::CloudPrintWebDialogDelegate; | 291 using internal_cloud_print_helpers::CloudPrintWebDialogDelegate; |
280 | 292 |
281 class CloudPrintWebDialogDelegateTest : public testing::Test { | 293 class CloudPrintWebDialogDelegateTest : public testing::Test { |
| 294 public: |
| 295 CloudPrintWebDialogDelegateTest() |
| 296 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 297 |
282 protected: | 298 protected: |
283 virtual void SetUp() { | 299 virtual void SetUp() { |
284 string16 mock_title; | 300 string16 mock_title; |
285 string16 mock_print_ticket; | 301 string16 mock_print_ticket; |
286 std::string mock_file_type; | 302 std::string mock_file_type; |
287 MockCloudPrintFlowHandler* handler = | 303 MockCloudPrintFlowHandler* handler = |
288 new MockCloudPrintFlowHandler(mock_print_ticket, mock_title, | 304 new MockCloudPrintFlowHandler(mock_print_ticket, mock_title, |
289 mock_file_type, false, base::Closure()); | 305 mock_file_type, false, base::Closure()); |
290 mock_flow_handler_ = handler->AsWeakPtr(); | 306 mock_flow_handler_ = handler->AsWeakPtr(); |
291 EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(_)); | 307 EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(_)); |
292 EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(NULL)); | 308 EXPECT_CALL(*mock_flow_handler_.get(), SetDialogDelegate(NULL)); |
293 delegate_.reset(new CloudPrintWebDialogDelegate(mock_flow_handler_.get(), | 309 delegate_.reset(new CloudPrintWebDialogDelegate(mock_flow_handler_.get(), |
294 std::string())); | 310 std::string())); |
295 } | 311 } |
296 | 312 |
297 virtual void TearDown() { | 313 virtual void TearDown() { |
298 delegate_.reset(); | 314 delegate_.reset(); |
299 if (mock_flow_handler_.get()) | 315 if (mock_flow_handler_.get()) |
300 delete mock_flow_handler_.get(); | 316 delete mock_flow_handler_.get(); |
301 } | 317 } |
302 | 318 |
303 content::TestBrowserThreadBundle thread_bundle_; | 319 base::MessageLoopForUI message_loop_; |
| 320 content::TestBrowserThread ui_thread_; |
304 base::WeakPtr<MockCloudPrintFlowHandler> mock_flow_handler_; | 321 base::WeakPtr<MockCloudPrintFlowHandler> mock_flow_handler_; |
305 scoped_ptr<CloudPrintWebDialogDelegate> delegate_; | 322 scoped_ptr<CloudPrintWebDialogDelegate> delegate_; |
306 }; | 323 }; |
307 | 324 |
308 TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) { | 325 TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) { |
309 EXPECT_THAT(delegate_->GetDialogContentURL().spec(), | 326 EXPECT_THAT(delegate_->GetDialogContentURL().spec(), |
310 StrEq(chrome::kChromeUICloudPrintResourcesURL)); | 327 StrEq(chrome::kChromeUICloudPrintResourcesURL)); |
311 EXPECT_TRUE(delegate_->GetDialogTitle().empty()); | 328 EXPECT_TRUE(delegate_->GetDialogTitle().empty()); |
312 | 329 |
313 bool close_dialog = false; | 330 bool close_dialog = false; |
(...skipping 10 matching lines...) Expand all Loading... |
324 std::vector<WebUIMessageHandler*> handlers; | 341 std::vector<WebUIMessageHandler*> handlers; |
325 delegate_->GetWebUIMessageHandlers(&handlers); | 342 delegate_->GetWebUIMessageHandlers(&handlers); |
326 delegate_.reset(); | 343 delegate_.reset(); |
327 EXPECT_THAT(mock_flow_handler_.get(), NotNull()); | 344 EXPECT_THAT(mock_flow_handler_.get(), NotNull()); |
328 } | 345 } |
329 | 346 |
330 // Testing for ExternalWebDialogUI needs a mock WebContents and mock | 347 // Testing for ExternalWebDialogUI needs a mock WebContents and mock |
331 // CloudPrintWebDialogDelegate (attached to the mock web_contents). | 348 // CloudPrintWebDialogDelegate (attached to the mock web_contents). |
332 | 349 |
333 // Testing for PrintDialogCloud needs a mock Browser. | 350 // Testing for PrintDialogCloud needs a mock Browser. |
OLD | NEW |