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 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return new CloudPrintDataSender(mock_helper_.get(), | 228 return new CloudPrintDataSender(mock_helper_.get(), |
229 ASCIIToUTF16(kMockJobTitle), | 229 ASCIIToUTF16(kMockJobTitle), |
230 ASCIIToUTF16(kMockPrintTicket), | 230 ASCIIToUTF16(kMockPrintTicket), |
231 std::string("application/pdf"), | 231 std::string("application/pdf"), |
232 data); | 232 data); |
233 } | 233 } |
234 | 234 |
235 scoped_refptr<CloudPrintDataSender> print_data_sender_; | 235 scoped_refptr<CloudPrintDataSender> print_data_sender_; |
236 scoped_ptr<MockCloudPrintDataSenderHelper> mock_helper_; | 236 scoped_ptr<MockCloudPrintDataSenderHelper> mock_helper_; |
237 | 237 |
238 MessageLoop message_loop_; | 238 base::MessageLoop message_loop_; |
239 content::TestBrowserThread file_thread_; | 239 content::TestBrowserThread file_thread_; |
240 content::TestBrowserThread io_thread_; | 240 content::TestBrowserThread io_thread_; |
241 }; | 241 }; |
242 | 242 |
243 TEST_F(CloudPrintDataSenderTest, CanSend) { | 243 TEST_F(CloudPrintDataSenderTest, CanSend) { |
244 StringValue mock_job_title(kMockJobTitle); | 244 StringValue mock_job_title(kMockJobTitle); |
245 EXPECT_CALL(*mock_helper_, | 245 EXPECT_CALL(*mock_helper_, |
246 CallJavascriptFunction(_, _, StringValueEq(&mock_job_title))). | 246 CallJavascriptFunction(_, _, StringValueEq(&mock_job_title))). |
247 WillOnce(Return()); | 247 WillOnce(Return()); |
248 | 248 |
249 std::string data("test_data"); | 249 std::string data("test_data"); |
250 scoped_refptr<CloudPrintDataSender> print_data_sender( | 250 scoped_refptr<CloudPrintDataSender> print_data_sender( |
251 CreateSender(base::RefCountedString::TakeString(&data))); | 251 CreateSender(base::RefCountedString::TakeString(&data))); |
252 base::FilePath test_data_file_name = GetTestDataFileName(); | 252 base::FilePath test_data_file_name = GetTestDataFileName(); |
253 BrowserThread::PostTask( | 253 BrowserThread::PostTask( |
254 BrowserThread::IO, FROM_HERE, | 254 BrowserThread::IO, FROM_HERE, |
255 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender)); | 255 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender)); |
256 MessageLoop::current()->RunUntilIdle(); | 256 base::MessageLoop::current()->RunUntilIdle(); |
257 } | 257 } |
258 | 258 |
259 TEST_F(CloudPrintDataSenderTest, NoData) { | 259 TEST_F(CloudPrintDataSenderTest, NoData) { |
260 EXPECT_CALL(*mock_helper_, CallJavascriptFunction(_, _, _)).Times(0); | 260 EXPECT_CALL(*mock_helper_, CallJavascriptFunction(_, _, _)).Times(0); |
261 | 261 |
262 scoped_refptr<CloudPrintDataSender> print_data_sender(CreateSender(NULL)); | 262 scoped_refptr<CloudPrintDataSender> print_data_sender(CreateSender(NULL)); |
263 base::FilePath test_data_file_name = GetTestDataFileName(); | 263 base::FilePath test_data_file_name = GetTestDataFileName(); |
264 BrowserThread::PostTask( | 264 BrowserThread::PostTask( |
265 BrowserThread::IO, FROM_HERE, | 265 BrowserThread::IO, FROM_HERE, |
266 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender)); | 266 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender)); |
267 MessageLoop::current()->RunUntilIdle(); | 267 base::MessageLoop::current()->RunUntilIdle(); |
268 } | 268 } |
269 | 269 |
270 TEST_F(CloudPrintDataSenderTest, EmptyData) { | 270 TEST_F(CloudPrintDataSenderTest, EmptyData) { |
271 EXPECT_CALL(*mock_helper_, CallJavascriptFunction(_, _, _)).Times(0); | 271 EXPECT_CALL(*mock_helper_, CallJavascriptFunction(_, _, _)).Times(0); |
272 | 272 |
273 std::string data; | 273 std::string data; |
274 scoped_refptr<CloudPrintDataSender> print_data_sender( | 274 scoped_refptr<CloudPrintDataSender> print_data_sender( |
275 CreateSender(base::RefCountedString::TakeString(&data))); | 275 CreateSender(base::RefCountedString::TakeString(&data))); |
276 base::FilePath test_data_file_name = GetTestDataFileName(); | 276 base::FilePath test_data_file_name = GetTestDataFileName(); |
277 BrowserThread::PostTask( | 277 BrowserThread::PostTask( |
278 BrowserThread::IO, FROM_HERE, | 278 BrowserThread::IO, FROM_HERE, |
279 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender)); | 279 base::Bind(&CloudPrintDataSender::SendPrintData, print_data_sender)); |
280 MessageLoop::current()->RunUntilIdle(); | 280 base::MessageLoop::current()->RunUntilIdle(); |
281 } | 281 } |
282 | 282 |
283 // Testing for CloudPrintFlowHandler needs a mock | 283 // Testing for CloudPrintFlowHandler needs a mock |
284 // CloudPrintWebDialogDelegate, mock CloudPrintDataSender, and a mock | 284 // CloudPrintWebDialogDelegate, mock CloudPrintDataSender, and a mock |
285 // WebUI. | 285 // WebUI. |
286 | 286 |
287 // Testing for CloudPrintWebDialogDelegate needs a mock | 287 // Testing for CloudPrintWebDialogDelegate needs a mock |
288 // CloudPrintFlowHandler. | 288 // CloudPrintFlowHandler. |
289 | 289 |
290 using internal_cloud_print_helpers::MockCloudPrintFlowHandler; | 290 using internal_cloud_print_helpers::MockCloudPrintFlowHandler; |
(...skipping 18 matching lines...) Expand all Loading... |
309 delegate_.reset(new CloudPrintWebDialogDelegate(mock_flow_handler_.get(), | 309 delegate_.reset(new CloudPrintWebDialogDelegate(mock_flow_handler_.get(), |
310 std::string())); | 310 std::string())); |
311 } | 311 } |
312 | 312 |
313 virtual void TearDown() { | 313 virtual void TearDown() { |
314 delegate_.reset(); | 314 delegate_.reset(); |
315 if (mock_flow_handler_) | 315 if (mock_flow_handler_) |
316 delete mock_flow_handler_.get(); | 316 delete mock_flow_handler_.get(); |
317 } | 317 } |
318 | 318 |
319 MessageLoopForUI message_loop_; | 319 base::MessageLoopForUI message_loop_; |
320 content::TestBrowserThread ui_thread_; | 320 content::TestBrowserThread ui_thread_; |
321 base::WeakPtr<MockCloudPrintFlowHandler> mock_flow_handler_; | 321 base::WeakPtr<MockCloudPrintFlowHandler> mock_flow_handler_; |
322 scoped_ptr<CloudPrintWebDialogDelegate> delegate_; | 322 scoped_ptr<CloudPrintWebDialogDelegate> delegate_; |
323 }; | 323 }; |
324 | 324 |
325 TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) { | 325 TEST_F(CloudPrintWebDialogDelegateTest, BasicChecks) { |
326 EXPECT_THAT(delegate_->GetDialogContentURL().spec(), | 326 EXPECT_THAT(delegate_->GetDialogContentURL().spec(), |
327 StrEq(chrome::kChromeUICloudPrintResourcesURL)); | 327 StrEq(chrome::kChromeUICloudPrintResourcesURL)); |
328 EXPECT_TRUE(delegate_->GetDialogTitle().empty()); | 328 EXPECT_TRUE(delegate_->GetDialogTitle().empty()); |
329 | 329 |
(...skipping 11 matching lines...) Expand all Loading... |
341 std::vector<WebUIMessageHandler*> handlers; | 341 std::vector<WebUIMessageHandler*> handlers; |
342 delegate_->GetWebUIMessageHandlers(&handlers); | 342 delegate_->GetWebUIMessageHandlers(&handlers); |
343 delegate_.reset(); | 343 delegate_.reset(); |
344 EXPECT_THAT(mock_flow_handler_.get(), NotNull()); | 344 EXPECT_THAT(mock_flow_handler_.get(), NotNull()); |
345 } | 345 } |
346 | 346 |
347 // Testing for ExternalWebDialogUI needs a mock WebContents and mock | 347 // Testing for ExternalWebDialogUI needs a mock WebContents and mock |
348 // CloudPrintWebDialogDelegate (attached to the mock web_contents). | 348 // CloudPrintWebDialogDelegate (attached to the mock web_contents). |
349 | 349 |
350 // Testing for PrintDialogCloud needs a mock Browser. | 350 // Testing for PrintDialogCloud needs a mock Browser. |
OLD | NEW |