| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 #if defined(ENABLE_PRINT_PREVIEW) | 28 #if defined(ENABLE_PRINT_PREVIEW) |
| 29 #include "chrome/browser/local_discovery/pwg_raster_converter.h" | 29 #include "chrome/browser/local_discovery/pwg_raster_converter.h" |
| 30 #endif // ENABLE_PRINT_PREVIEW | 30 #endif // ENABLE_PRINT_PREVIEW |
| 31 | 31 |
| 32 namespace local_discovery { | 32 namespace local_discovery { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 using testing::NiceMock; |
| 36 using testing::StrictMock; | 37 using testing::StrictMock; |
| 37 using testing::NiceMock; | 38 using testing::TestWithParam; |
| 39 using testing::ValuesIn; |
| 38 | 40 |
| 39 using content::BrowserThread; | 41 using content::BrowserThread; |
| 40 using net::EmbeddedTestServer; | 42 using net::EmbeddedTestServer; |
| 41 | 43 |
| 42 const char kSampleInfoResponse[] = "{" | 44 const char kSampleInfoResponse[] = "{" |
| 43 " \"version\": \"1.0\"," | 45 " \"version\": \"1.0\"," |
| 44 " \"name\": \"Common printer\"," | 46 " \"name\": \"Common printer\"," |
| 45 " \"description\": \"Printer connected through Chrome connector\"," | 47 " \"description\": \"Printer connected through Chrome connector\"," |
| 46 " \"url\": \"https://www.google.com/cloudprint\"," | 48 " \"url\": \"https://www.google.com/cloudprint\"," |
| 47 " \"type\": [" | 49 " \"type\": [" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 "}" | 222 "}" |
| 221 "}"; | 223 "}"; |
| 222 | 224 |
| 223 const char kSampleCJTDuplex[] = | 225 const char kSampleCJTDuplex[] = |
| 224 "{" | 226 "{" |
| 225 "\"version\" : \"1.0\"," | 227 "\"version\" : \"1.0\"," |
| 226 "\"print\": { \"duplex\": {\"type\": \"SHORT_EDGE\"} }" | 228 "\"print\": { \"duplex\": {\"type\": \"SHORT_EDGE\"} }" |
| 227 "}"; | 229 "}"; |
| 228 #endif // ENABLE_PRINT_PREVIEW | 230 #endif // ENABLE_PRINT_PREVIEW |
| 229 | 231 |
| 232 const char* const kTestParams[] = {"8.8.4.4", "2001:4860:4860::8888"}; |
| 233 |
| 230 // Return the representation of the given JSON that would be outputted by | 234 // Return the representation of the given JSON that would be outputted by |
| 231 // JSONWriter. This ensures the same JSON values are represented by the same | 235 // JSONWriter. This ensures the same JSON values are represented by the same |
| 232 // string. | 236 // string. |
| 233 std::string NormalizeJson(const std::string& json) { | 237 std::string NormalizeJson(const std::string& json) { |
| 234 std::string result = json; | 238 std::string result = json; |
| 235 scoped_ptr<base::Value> value = base::JSONReader::Read(result); | 239 scoped_ptr<base::Value> value = base::JSONReader::Read(result); |
| 236 DCHECK(value); | 240 DCHECK(value) << result; |
| 237 base::JSONWriter::Write(*value, &result); | 241 base::JSONWriter::Write(*value, &result); |
| 238 return result; | 242 return result; |
| 239 } | 243 } |
| 240 | 244 |
| 241 class MockTestURLFetcherFactoryDelegate | 245 class MockTestURLFetcherFactoryDelegate |
| 242 : public net::TestURLFetcher::DelegateForTests { | 246 : public net::TestURLFetcher::DelegateForTests { |
| 243 public: | 247 public: |
| 244 // Callback issued correspondingly to the call to the |Start()| method. | 248 // Callback issued correspondingly to the call to the |Start()| method. |
| 245 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); | 249 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); |
| 246 | 250 |
| 247 // Callback issued correspondingly to the call to |AppendChunkToUpload|. | 251 // Callback issued correspondingly to the call to |AppendChunkToUpload|. |
| 248 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. | 252 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. |
| 249 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); | 253 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); |
| 250 | 254 |
| 251 // Callback issued correspondingly to the destructor. | 255 // Callback issued correspondingly to the destructor. |
| 252 MOCK_METHOD1(OnRequestEnd, void(int fetcher_id)); | 256 MOCK_METHOD1(OnRequestEnd, void(int fetcher_id)); |
| 253 }; | 257 }; |
| 254 | 258 |
| 255 class PrivetHTTPTest : public ::testing::Test { | 259 class PrivetHTTPTest : public TestWithParam<const char*> { |
| 256 public: | 260 public: |
| 257 PrivetHTTPTest() { | 261 PrivetHTTPTest() { |
| 258 PrivetURLFetcher::ResetTokenMapForTests(); | 262 PrivetURLFetcher::ResetTokenMapForTests(); |
| 259 | 263 |
| 260 request_context_ = new net::TestURLRequestContextGetter( | 264 request_context_ = new net::TestURLRequestContextGetter( |
| 261 base::ThreadTaskRunnerHandle::Get()); | 265 base::ThreadTaskRunnerHandle::Get()); |
| 262 privet_client_ = | 266 privet_client_ = PrivetV1HTTPClient::CreateDefault( |
| 263 PrivetV1HTTPClient::CreateDefault(make_scoped_ptr<PrivetHTTPClient>( | 267 make_scoped_ptr<PrivetHTTPClient>(new PrivetHTTPClientImpl( |
| 264 new PrivetHTTPClientImpl("sampleDevice._privet._tcp.local", | 268 "sampleDevice._privet._tcp.local", |
| 265 net::HostPortPair("10.0.0.8", 6006), | 269 net::HostPortPair(GetParam(), 6006), request_context_.get()))); |
| 266 request_context_.get()))); | |
| 267 fetcher_factory_.SetDelegateForTests(&fetcher_delegate_); | 270 fetcher_factory_.SetDelegateForTests(&fetcher_delegate_); |
| 268 } | 271 } |
| 269 | 272 |
| 270 virtual ~PrivetHTTPTest() { | 273 GURL GetUrl(const std::string& path) const { |
| 274 std::string host = GetParam(); |
| 275 if (host.find(":") != std::string::npos) |
| 276 host = "[" + host + "]"; |
| 277 return GURL("http://" + host + ":6006" + path); |
| 271 } | 278 } |
| 272 | 279 |
| 273 bool SuccessfulResponseToURL(const GURL& url, | 280 bool SuccessfulResponseToURL(const GURL& url, |
| 274 const std::string& response) { | 281 const std::string& response) { |
| 275 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); | 282 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |
| 276 EXPECT_TRUE(fetcher); | 283 EXPECT_TRUE(fetcher); |
| 277 EXPECT_EQ(url, fetcher->GetOriginalURL()); | 284 EXPECT_EQ(url, fetcher->GetOriginalURL()); |
| 278 | 285 |
| 279 if (!fetcher || url != fetcher->GetOriginalURL()) | 286 if (!fetcher || url != fetcher->GetOriginalURL()) |
| 280 return false; | 287 return false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 protected: | 359 protected: |
| 353 base::MessageLoop loop_; | 360 base::MessageLoop loop_; |
| 354 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 361 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| 355 net::TestURLFetcherFactory fetcher_factory_; | 362 net::TestURLFetcherFactory fetcher_factory_; |
| 356 scoped_ptr<PrivetV1HTTPClient> privet_client_; | 363 scoped_ptr<PrivetV1HTTPClient> privet_client_; |
| 357 NiceMock<MockTestURLFetcherFactoryDelegate> fetcher_delegate_; | 364 NiceMock<MockTestURLFetcherFactoryDelegate> fetcher_delegate_; |
| 358 }; | 365 }; |
| 359 | 366 |
| 360 class MockJSONCallback{ | 367 class MockJSONCallback{ |
| 361 public: | 368 public: |
| 362 MockJSONCallback() {} | |
| 363 ~MockJSONCallback() {} | |
| 364 | |
| 365 void OnPrivetJSONDone(const base::DictionaryValue* value) { | 369 void OnPrivetJSONDone(const base::DictionaryValue* value) { |
| 366 if (!value) { | 370 if (!value) { |
| 367 value_.reset(); | 371 value_.reset(); |
| 368 } else { | 372 } else { |
| 369 value_.reset(value->DeepCopy()); | 373 value_.reset(value->DeepCopy()); |
| 370 } | 374 } |
| 371 | 375 |
| 372 OnPrivetJSONDoneInternal(); | 376 OnPrivetJSONDoneInternal(); |
| 373 } | 377 } |
| 374 | 378 |
| 375 MOCK_METHOD0(OnPrivetJSONDoneInternal, void()); | 379 MOCK_METHOD0(OnPrivetJSONDoneInternal, void()); |
| 376 | 380 |
| 377 const base::DictionaryValue* value() { return value_.get(); } | 381 const base::DictionaryValue* value() { return value_.get(); } |
| 378 PrivetJSONOperation::ResultCallback callback() { | 382 PrivetJSONOperation::ResultCallback callback() { |
| 379 return base::Bind(&MockJSONCallback::OnPrivetJSONDone, | 383 return base::Bind(&MockJSONCallback::OnPrivetJSONDone, |
| 380 base::Unretained(this)); | 384 base::Unretained(this)); |
| 381 } | 385 } |
| 382 protected: | 386 protected: |
| 383 scoped_ptr<base::DictionaryValue> value_; | 387 scoped_ptr<base::DictionaryValue> value_; |
| 384 }; | 388 }; |
| 385 | 389 |
| 386 class MockRegisterDelegate : public PrivetRegisterOperation::Delegate { | 390 class MockRegisterDelegate : public PrivetRegisterOperation::Delegate { |
| 387 public: | 391 public: |
| 388 MockRegisterDelegate() { | |
| 389 } | |
| 390 ~MockRegisterDelegate() { | |
| 391 } | |
| 392 | |
| 393 void OnPrivetRegisterClaimToken( | 392 void OnPrivetRegisterClaimToken( |
| 394 PrivetRegisterOperation* operation, | 393 PrivetRegisterOperation* operation, |
| 395 const std::string& token, | 394 const std::string& token, |
| 396 const GURL& url) override { | 395 const GURL& url) override { |
| 397 OnPrivetRegisterClaimTokenInternal(token, url); | 396 OnPrivetRegisterClaimTokenInternal(token, url); |
| 398 } | 397 } |
| 399 | 398 |
| 400 MOCK_METHOD2(OnPrivetRegisterClaimTokenInternal, void( | 399 MOCK_METHOD2(OnPrivetRegisterClaimTokenInternal, void( |
| 401 const std::string& token, | 400 const std::string& token, |
| 402 const GURL& url)); | 401 const GURL& url)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 421 const std::string& device_id) override { | 420 const std::string& device_id) override { |
| 422 OnPrivetRegisterDoneInternal(device_id); | 421 OnPrivetRegisterDoneInternal(device_id); |
| 423 } | 422 } |
| 424 | 423 |
| 425 MOCK_METHOD1(OnPrivetRegisterDoneInternal, | 424 MOCK_METHOD1(OnPrivetRegisterDoneInternal, |
| 426 void(const std::string& device_id)); | 425 void(const std::string& device_id)); |
| 427 }; | 426 }; |
| 428 | 427 |
| 429 class MockLocalPrintDelegate : public PrivetLocalPrintOperation::Delegate { | 428 class MockLocalPrintDelegate : public PrivetLocalPrintOperation::Delegate { |
| 430 public: | 429 public: |
| 431 MockLocalPrintDelegate() {} | |
| 432 ~MockLocalPrintDelegate() {} | |
| 433 | |
| 434 virtual void OnPrivetPrintingDone( | 430 virtual void OnPrivetPrintingDone( |
| 435 const PrivetLocalPrintOperation* print_operation) { | 431 const PrivetLocalPrintOperation* print_operation) { |
| 436 OnPrivetPrintingDoneInternal(); | 432 OnPrivetPrintingDoneInternal(); |
| 437 } | 433 } |
| 438 | 434 |
| 439 MOCK_METHOD0(OnPrivetPrintingDoneInternal, void()); | 435 MOCK_METHOD0(OnPrivetPrintingDoneInternal, void()); |
| 440 | 436 |
| 441 virtual void OnPrivetPrintingError( | 437 virtual void OnPrivetPrintingError( |
| 442 const PrivetLocalPrintOperation* print_operation, int http_code) { | 438 const PrivetLocalPrintOperation* print_operation, int http_code) { |
| 443 OnPrivetPrintingErrorInternal(http_code); | 439 OnPrivetPrintingErrorInternal(http_code); |
| 444 } | 440 } |
| 445 | 441 |
| 446 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code)); | 442 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code)); |
| 447 }; | 443 }; |
| 448 | 444 |
| 449 class PrivetInfoTest : public PrivetHTTPTest { | 445 class PrivetInfoTest : public PrivetHTTPTest { |
| 450 public: | 446 public: |
| 451 PrivetInfoTest() {} | |
| 452 | |
| 453 ~PrivetInfoTest() override {} | |
| 454 | |
| 455 void SetUp() override { | 447 void SetUp() override { |
| 456 info_operation_ = privet_client_->CreateInfoOperation( | 448 info_operation_ = privet_client_->CreateInfoOperation( |
| 457 info_callback_.callback()); | 449 info_callback_.callback()); |
| 458 } | 450 } |
| 459 | 451 |
| 460 protected: | 452 protected: |
| 461 scoped_ptr<PrivetJSONOperation> info_operation_; | 453 scoped_ptr<PrivetJSONOperation> info_operation_; |
| 462 StrictMock<MockJSONCallback> info_callback_; | 454 StrictMock<MockJSONCallback> info_callback_; |
| 463 }; | 455 }; |
| 464 | 456 |
| 465 TEST_F(PrivetInfoTest, SuccessfulInfo) { | 457 INSTANTIATE_TEST_CASE_P(PrivetTests, PrivetInfoTest, ValuesIn(kTestParams)); |
| 458 |
| 459 TEST_P(PrivetInfoTest, SuccessfulInfo) { |
| 466 info_operation_->Start(); | 460 info_operation_->Start(); |
| 467 | 461 |
| 468 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); | 462 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |
| 469 ASSERT_TRUE(fetcher != NULL); | 463 ASSERT_TRUE(fetcher != NULL); |
| 470 EXPECT_EQ(GURL("http://10.0.0.8:6006/privet/info"), | 464 EXPECT_EQ(GetUrl("/privet/info"), fetcher->GetOriginalURL()); |
| 471 fetcher->GetOriginalURL()); | |
| 472 | 465 |
| 473 fetcher->SetResponseString(kSampleInfoResponse); | 466 fetcher->SetResponseString(kSampleInfoResponse); |
| 474 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 467 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
| 475 net::OK)); | 468 net::OK)); |
| 476 fetcher->set_response_code(200); | 469 fetcher->set_response_code(200); |
| 477 | 470 |
| 478 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 471 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
| 479 fetcher->delegate()->OnURLFetchComplete(fetcher); | 472 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 480 } | 473 } |
| 481 | 474 |
| 482 TEST_F(PrivetInfoTest, InfoFailureHTTP) { | 475 TEST_P(PrivetInfoTest, InfoFailureHTTP) { |
| 483 info_operation_->Start(); | 476 info_operation_->Start(); |
| 484 | 477 |
| 485 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); | 478 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |
| 486 ASSERT_TRUE(fetcher != NULL); | 479 ASSERT_TRUE(fetcher != NULL); |
| 487 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 480 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
| 488 net::OK)); | 481 net::OK)); |
| 489 fetcher->set_response_code(404); | 482 fetcher->set_response_code(404); |
| 490 | 483 |
| 491 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 484 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
| 492 fetcher->delegate()->OnURLFetchComplete(fetcher); | 485 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 493 } | 486 } |
| 494 | 487 |
| 495 class PrivetRegisterTest : public PrivetHTTPTest { | 488 class PrivetRegisterTest : public PrivetHTTPTest { |
| 496 public: | 489 public: |
| 497 PrivetRegisterTest() { | |
| 498 } | |
| 499 ~PrivetRegisterTest() override { | |
| 500 } | |
| 501 | |
| 502 void SetUp() override { | 490 void SetUp() override { |
| 503 info_operation_ = privet_client_->CreateInfoOperation( | 491 info_operation_ = privet_client_->CreateInfoOperation( |
| 504 info_callback_.callback()); | 492 info_callback_.callback()); |
| 505 register_operation_ = | 493 register_operation_ = |
| 506 privet_client_->CreateRegisterOperation("example@google.com", | 494 privet_client_->CreateRegisterOperation("example@google.com", |
| 507 ®ister_delegate_); | 495 ®ister_delegate_); |
| 508 } | 496 } |
| 509 | 497 |
| 510 protected: | 498 protected: |
| 511 bool SuccessfulResponseToURL(const GURL& url, | 499 bool SuccessfulResponseToURL(const GURL& url, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 523 fetcher->delegate()->OnURLFetchComplete(fetcher); | 511 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 524 return true; | 512 return true; |
| 525 } | 513 } |
| 526 | 514 |
| 527 scoped_ptr<PrivetJSONOperation> info_operation_; | 515 scoped_ptr<PrivetJSONOperation> info_operation_; |
| 528 NiceMock<MockJSONCallback> info_callback_; | 516 NiceMock<MockJSONCallback> info_callback_; |
| 529 scoped_ptr<PrivetRegisterOperation> register_operation_; | 517 scoped_ptr<PrivetRegisterOperation> register_operation_; |
| 530 StrictMock<MockRegisterDelegate> register_delegate_; | 518 StrictMock<MockRegisterDelegate> register_delegate_; |
| 531 }; | 519 }; |
| 532 | 520 |
| 533 TEST_F(PrivetRegisterTest, RegisterSuccessSimple) { | 521 TEST_P(PrivetRegisterTest, RegisterSuccessSimple) { |
| 534 register_operation_->Start(); | 522 register_operation_->Start(); |
| 535 | 523 |
| 536 EXPECT_TRUE(SuccessfulResponseToURL( | 524 EXPECT_TRUE( |
| 537 GURL("http://10.0.0.8:6006/privet/info"), | 525 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 538 kSampleInfoResponse)); | |
| 539 | 526 |
| 540 EXPECT_TRUE(SuccessfulResponseToURL( | 527 EXPECT_TRUE( |
| 541 GURL("http://10.0.0.8:6006/privet/register?" | 528 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 542 "action=start&user=example%40google.com"), | 529 "action=start&user=example%40google.com"), |
| 543 kSampleRegisterStartResponse)); | 530 kSampleRegisterStartResponse)); |
| 544 | 531 |
| 545 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal( | 532 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal( |
| 546 "MySampleToken", | 533 "MySampleToken", |
| 547 GURL("https://domain.com/SoMeUrL"))); | 534 GURL("https://domain.com/SoMeUrL"))); |
| 548 | 535 |
| 549 EXPECT_TRUE(SuccessfulResponseToURL( | 536 EXPECT_TRUE(SuccessfulResponseToURL( |
| 550 GURL("http://10.0.0.8:6006/privet/register?" | 537 GetUrl("/privet/register?" |
| 551 "action=getClaimToken&user=example%40google.com"), | 538 "action=getClaimToken&user=example%40google.com"), |
| 552 kSampleRegisterGetClaimTokenResponse)); | 539 kSampleRegisterGetClaimTokenResponse)); |
| 553 | 540 |
| 554 register_operation_->CompleteRegistration(); | 541 register_operation_->CompleteRegistration(); |
| 555 | 542 |
| 556 EXPECT_TRUE(SuccessfulResponseToURL( | 543 EXPECT_TRUE(SuccessfulResponseToURL( |
| 557 GURL("http://10.0.0.8:6006/privet/register?" | 544 GetUrl("/privet/register?" |
| 558 "action=complete&user=example%40google.com"), | 545 "action=complete&user=example%40google.com"), |
| 559 kSampleRegisterCompleteResponse)); | 546 kSampleRegisterCompleteResponse)); |
| 560 | 547 |
| 561 EXPECT_CALL(register_delegate_, OnPrivetRegisterDoneInternal( | 548 EXPECT_CALL(register_delegate_, OnPrivetRegisterDoneInternal( |
| 562 "MyDeviceID")); | 549 "MyDeviceID")); |
| 563 | 550 |
| 564 EXPECT_TRUE(SuccessfulResponseToURL( | 551 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 565 GURL("http://10.0.0.8:6006/privet/info"), | 552 kSampleInfoResponseRegistered)); |
| 566 kSampleInfoResponseRegistered)); | |
| 567 } | 553 } |
| 568 | 554 |
| 569 TEST_F(PrivetRegisterTest, RegisterXSRFFailure) { | 555 TEST_P(PrivetRegisterTest, RegisterXSRFFailure) { |
| 570 register_operation_->Start(); | 556 register_operation_->Start(); |
| 571 | 557 |
| 572 EXPECT_TRUE(SuccessfulResponseToURL( | 558 EXPECT_TRUE( |
| 573 GURL("http://10.0.0.8:6006/privet/info"), | 559 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 574 kSampleInfoResponse)); | 560 |
| 561 EXPECT_TRUE( |
| 562 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 563 "action=start&user=example%40google.com"), |
| 564 kSampleRegisterStartResponse)); |
| 575 | 565 |
| 576 EXPECT_TRUE(SuccessfulResponseToURL( | 566 EXPECT_TRUE(SuccessfulResponseToURL( |
| 577 GURL("http://10.0.0.8:6006/privet/register?" | 567 GetUrl("/privet/register?" |
| 578 "action=start&user=example%40google.com"), | 568 "action=getClaimToken&user=example%40google.com"), |
| 579 kSampleRegisterStartResponse)); | |
| 580 | |
| 581 EXPECT_TRUE(SuccessfulResponseToURL( | |
| 582 GURL("http://10.0.0.8:6006/privet/register?" | |
| 583 "action=getClaimToken&user=example%40google.com"), | |
| 584 kSampleXPrivetErrorResponse)); | 569 kSampleXPrivetErrorResponse)); |
| 585 | 570 |
| 586 EXPECT_TRUE(SuccessfulResponseToURL( | 571 EXPECT_TRUE( |
| 587 GURL("http://10.0.0.8:6006/privet/info"), | 572 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 588 kSampleInfoResponse)); | |
| 589 | 573 |
| 590 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal( | 574 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal( |
| 591 "MySampleToken", GURL("https://domain.com/SoMeUrL"))); | 575 "MySampleToken", GURL("https://domain.com/SoMeUrL"))); |
| 592 | 576 |
| 593 EXPECT_TRUE(SuccessfulResponseToURL( | 577 EXPECT_TRUE(SuccessfulResponseToURL( |
| 594 GURL("http://10.0.0.8:6006/privet/register?" | 578 GetUrl("/privet/register?" |
| 595 "action=getClaimToken&user=example%40google.com"), | 579 "action=getClaimToken&user=example%40google.com"), |
| 596 kSampleRegisterGetClaimTokenResponse)); | 580 kSampleRegisterGetClaimTokenResponse)); |
| 597 } | 581 } |
| 598 | 582 |
| 599 TEST_F(PrivetRegisterTest, TransientFailure) { | 583 TEST_P(PrivetRegisterTest, TransientFailure) { |
| 600 register_operation_->Start(); | 584 register_operation_->Start(); |
| 601 | 585 |
| 602 EXPECT_TRUE(SuccessfulResponseToURL( | 586 EXPECT_TRUE( |
| 603 GURL("http://10.0.0.8:6006/privet/info"), | 587 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 604 kSampleInfoResponse)); | |
| 605 | 588 |
| 606 EXPECT_TRUE(SuccessfulResponseToURL( | 589 EXPECT_TRUE( |
| 607 GURL("http://10.0.0.8:6006/privet/register?" | 590 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 608 "action=start&user=example%40google.com"), | 591 "action=start&user=example%40google.com"), |
| 609 kSampleRegisterErrorTransient)); | 592 kSampleRegisterErrorTransient)); |
| 610 | 593 |
| 611 EXPECT_CALL(fetcher_delegate_, OnRequestStart(0)); | 594 EXPECT_CALL(fetcher_delegate_, OnRequestStart(0)); |
| 612 | 595 |
| 613 RunFor(base::TimeDelta::FromSeconds(2)); | 596 RunFor(base::TimeDelta::FromSeconds(2)); |
| 614 | 597 |
| 615 testing::Mock::VerifyAndClearExpectations(&fetcher_delegate_); | 598 testing::Mock::VerifyAndClearExpectations(&fetcher_delegate_); |
| 616 | 599 |
| 617 EXPECT_TRUE(SuccessfulResponseToURL( | 600 EXPECT_TRUE( |
| 618 GURL("http://10.0.0.8:6006/privet/register?" | 601 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 619 "action=start&user=example%40google.com"), | 602 "action=start&user=example%40google.com"), |
| 620 kSampleRegisterStartResponse)); | 603 kSampleRegisterStartResponse)); |
| 621 } | 604 } |
| 622 | 605 |
| 623 TEST_F(PrivetRegisterTest, PermanentFailure) { | 606 TEST_P(PrivetRegisterTest, PermanentFailure) { |
| 624 register_operation_->Start(); | 607 register_operation_->Start(); |
| 625 | 608 |
| 626 EXPECT_TRUE(SuccessfulResponseToURL( | 609 EXPECT_TRUE( |
| 627 GURL("http://10.0.0.8:6006/privet/info"), | 610 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 628 kSampleInfoResponse)); | |
| 629 | 611 |
| 630 EXPECT_TRUE(SuccessfulResponseToURL( | 612 EXPECT_TRUE( |
| 631 GURL("http://10.0.0.8:6006/privet/register?" | 613 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 632 "action=start&user=example%40google.com"), | 614 "action=start&user=example%40google.com"), |
| 633 kSampleRegisterStartResponse)); | 615 kSampleRegisterStartResponse)); |
| 634 | 616 |
| 635 EXPECT_CALL(register_delegate_, | 617 EXPECT_CALL(register_delegate_, |
| 636 OnPrivetRegisterErrorInternal( | 618 OnPrivetRegisterErrorInternal( |
| 637 "getClaimToken", | 619 "getClaimToken", |
| 638 PrivetRegisterOperation::FAILURE_JSON_ERROR, | 620 PrivetRegisterOperation::FAILURE_JSON_ERROR, |
| 639 200)); | 621 200)); |
| 640 | 622 |
| 641 EXPECT_TRUE(SuccessfulResponseToURL( | 623 EXPECT_TRUE(SuccessfulResponseToURL( |
| 642 GURL("http://10.0.0.8:6006/privet/register?" | 624 GetUrl("/privet/register?" |
| 643 "action=getClaimToken&user=example%40google.com"), | 625 "action=getClaimToken&user=example%40google.com"), |
| 644 kSampleRegisterErrorPermanent)); | 626 kSampleRegisterErrorPermanent)); |
| 645 } | 627 } |
| 646 | 628 |
| 647 TEST_F(PrivetRegisterTest, InfoFailure) { | 629 TEST_P(PrivetRegisterTest, InfoFailure) { |
| 648 register_operation_->Start(); | 630 register_operation_->Start(); |
| 649 | 631 |
| 650 EXPECT_CALL(register_delegate_, | 632 EXPECT_CALL(register_delegate_, |
| 651 OnPrivetRegisterErrorInternal( | 633 OnPrivetRegisterErrorInternal( |
| 652 "start", | 634 "start", |
| 653 PrivetRegisterOperation::FAILURE_TOKEN, | 635 PrivetRegisterOperation::FAILURE_TOKEN, |
| 654 -1)); | 636 -1)); |
| 655 | 637 |
| 656 EXPECT_TRUE(SuccessfulResponseToURL( | 638 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 657 GURL("http://10.0.0.8:6006/privet/info"), | 639 kSampleInfoResponseBadJson)); |
| 658 kSampleInfoResponseBadJson)); | |
| 659 } | 640 } |
| 660 | 641 |
| 661 TEST_F(PrivetRegisterTest, RegisterCancel) { | 642 TEST_P(PrivetRegisterTest, RegisterCancel) { |
| 662 register_operation_->Start(); | 643 register_operation_->Start(); |
| 663 | 644 |
| 664 EXPECT_TRUE(SuccessfulResponseToURL( | 645 EXPECT_TRUE( |
| 665 GURL("http://10.0.0.8:6006/privet/info"), | 646 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 666 kSampleInfoResponse)); | |
| 667 | 647 |
| 668 EXPECT_TRUE(SuccessfulResponseToURL( | 648 EXPECT_TRUE( |
| 669 GURL("http://10.0.0.8:6006/privet/register?" | 649 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 670 "action=start&user=example%40google.com"), | 650 "action=start&user=example%40google.com"), |
| 671 kSampleRegisterStartResponse)); | 651 kSampleRegisterStartResponse)); |
| 672 | 652 |
| 673 register_operation_->Cancel(); | 653 register_operation_->Cancel(); |
| 674 | 654 |
| 675 EXPECT_TRUE(SuccessfulResponseToURL( | 655 EXPECT_TRUE( |
| 676 GURL("http://10.0.0.8:6006/privet/register?" | 656 SuccessfulResponseToURL(GetUrl("/privet/register?" |
| 677 "action=cancel&user=example%40google.com"), | 657 "action=cancel&user=example%40google.com"), |
| 678 kSampleRegisterCancelResponse)); | 658 kSampleRegisterCancelResponse)); |
| 679 | 659 |
| 680 // Must keep mocks alive for 3 seconds so the cancelation object can be | 660 // Must keep mocks alive for 3 seconds so the cancelation object can be |
| 681 // deleted. | 661 // deleted. |
| 682 RunFor(base::TimeDelta::FromSeconds(3)); | 662 RunFor(base::TimeDelta::FromSeconds(3)); |
| 683 } | 663 } |
| 684 | 664 |
| 685 class PrivetCapabilitiesTest : public PrivetHTTPTest { | 665 class PrivetCapabilitiesTest : public PrivetHTTPTest { |
| 686 public: | 666 public: |
| 687 PrivetCapabilitiesTest() {} | |
| 688 | |
| 689 ~PrivetCapabilitiesTest() override {} | |
| 690 | |
| 691 void SetUp() override { | 667 void SetUp() override { |
| 692 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( | 668 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( |
| 693 capabilities_callback_.callback()); | 669 capabilities_callback_.callback()); |
| 694 } | 670 } |
| 695 | 671 |
| 696 protected: | 672 protected: |
| 697 scoped_ptr<PrivetJSONOperation> capabilities_operation_; | 673 scoped_ptr<PrivetJSONOperation> capabilities_operation_; |
| 698 StrictMock<MockJSONCallback> capabilities_callback_; | 674 StrictMock<MockJSONCallback> capabilities_callback_; |
| 699 }; | 675 }; |
| 700 | 676 |
| 701 TEST_F(PrivetCapabilitiesTest, SuccessfulCapabilities) { | 677 INSTANTIATE_TEST_CASE_P(PrivetTests, |
| 678 PrivetCapabilitiesTest, |
| 679 ValuesIn(kTestParams)); |
| 680 |
| 681 TEST_P(PrivetCapabilitiesTest, SuccessfulCapabilities) { |
| 702 capabilities_operation_->Start(); | 682 capabilities_operation_->Start(); |
| 703 | 683 |
| 704 EXPECT_TRUE(SuccessfulResponseToURL( | 684 EXPECT_TRUE( |
| 705 GURL("http://10.0.0.8:6006/privet/info"), | 685 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 706 kSampleInfoResponse)); | |
| 707 | 686 |
| 708 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 687 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
| 709 | 688 |
| 710 EXPECT_TRUE(SuccessfulResponseToURL( | 689 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/capabilities"), |
| 711 GURL("http://10.0.0.8:6006/privet/capabilities"), | 690 kSampleCapabilitiesResponse)); |
| 712 kSampleCapabilitiesResponse)); | |
| 713 | 691 |
| 714 std::string version; | 692 std::string version; |
| 715 EXPECT_TRUE(capabilities_callback_.value()->GetString("version", &version)); | 693 EXPECT_TRUE(capabilities_callback_.value()->GetString("version", &version)); |
| 716 EXPECT_EQ("1.0", version); | 694 EXPECT_EQ("1.0", version); |
| 717 } | 695 } |
| 718 | 696 |
| 719 TEST_F(PrivetCapabilitiesTest, CacheToken) { | 697 TEST_P(PrivetCapabilitiesTest, CacheToken) { |
| 720 capabilities_operation_->Start(); | 698 capabilities_operation_->Start(); |
| 721 | 699 |
| 722 EXPECT_TRUE(SuccessfulResponseToURL( | 700 EXPECT_TRUE( |
| 723 GURL("http://10.0.0.8:6006/privet/info"), | 701 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 724 kSampleInfoResponse)); | |
| 725 | 702 |
| 726 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 703 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
| 727 | 704 |
| 728 EXPECT_TRUE(SuccessfulResponseToURL( | 705 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/capabilities"), |
| 729 GURL("http://10.0.0.8:6006/privet/capabilities"), | 706 kSampleCapabilitiesResponse)); |
| 730 kSampleCapabilitiesResponse)); | |
| 731 | 707 |
| 732 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( | 708 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( |
| 733 capabilities_callback_.callback()); | 709 capabilities_callback_.callback()); |
| 734 | 710 |
| 735 capabilities_operation_->Start(); | 711 capabilities_operation_->Start(); |
| 736 | 712 |
| 737 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 713 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
| 738 | 714 |
| 739 EXPECT_TRUE(SuccessfulResponseToURL( | 715 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/capabilities"), |
| 740 GURL("http://10.0.0.8:6006/privet/capabilities"), | 716 kSampleCapabilitiesResponse)); |
| 741 kSampleCapabilitiesResponse)); | |
| 742 } | 717 } |
| 743 | 718 |
| 744 TEST_F(PrivetCapabilitiesTest, BadToken) { | 719 TEST_P(PrivetCapabilitiesTest, BadToken) { |
| 745 capabilities_operation_->Start(); | 720 capabilities_operation_->Start(); |
| 746 | 721 |
| 747 EXPECT_TRUE(SuccessfulResponseToURL( | 722 EXPECT_TRUE( |
| 748 GURL("http://10.0.0.8:6006/privet/info"), | 723 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 749 kSampleInfoResponse)); | |
| 750 | 724 |
| 751 EXPECT_TRUE(SuccessfulResponseToURL( | 725 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/capabilities"), |
| 752 GURL("http://10.0.0.8:6006/privet/capabilities"), | 726 kSampleXPrivetErrorResponse)); |
| 753 kSampleXPrivetErrorResponse)); | |
| 754 | 727 |
| 755 EXPECT_TRUE(SuccessfulResponseToURL( | 728 EXPECT_TRUE( |
| 756 GURL("http://10.0.0.8:6006/privet/info"), | 729 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 757 kSampleInfoResponse)); | |
| 758 | 730 |
| 759 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 731 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
| 760 | 732 |
| 761 EXPECT_TRUE(SuccessfulResponseToURL( | 733 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/capabilities"), |
| 762 GURL("http://10.0.0.8:6006/privet/capabilities"), | 734 kSampleCapabilitiesResponse)); |
| 763 kSampleCapabilitiesResponse)); | |
| 764 } | 735 } |
| 765 | 736 |
| 766 #if defined(ENABLE_PRINT_PREVIEW) | 737 #if defined(ENABLE_PRINT_PREVIEW) |
| 767 // A note on PWG raster conversion: The PWG raster converter used simply | 738 // A note on PWG raster conversion: The PWG raster converter used simply |
| 768 // converts strings to file paths based on them by appending "test.pdf", since | 739 // converts strings to file paths based on them by appending "test.pdf", since |
| 769 // it's easier to test that way. Instead of using a mock, we simply check if the | 740 // it's easier to test that way. Instead of using a mock, we simply check if the |
| 770 // request is uploading a file that is based on this pattern. | 741 // request is uploading a file that is based on this pattern. |
| 771 class FakePWGRasterConverter : public PWGRasterConverter { | 742 class FakePWGRasterConverter : public PWGRasterConverter { |
| 772 public: | 743 public: |
| 773 FakePWGRasterConverter() { | |
| 774 } | |
| 775 | |
| 776 ~FakePWGRasterConverter() override {} | |
| 777 | |
| 778 void Start(base::RefCountedMemory* data, | 744 void Start(base::RefCountedMemory* data, |
| 779 const printing::PdfRenderSettings& conversion_settings, | 745 const printing::PdfRenderSettings& conversion_settings, |
| 780 const printing::PwgRasterSettings& bitmap_settings, | 746 const printing::PwgRasterSettings& bitmap_settings, |
| 781 const ResultCallback& callback) override { | 747 const ResultCallback& callback) override { |
| 782 bitmap_settings_ = bitmap_settings; | 748 bitmap_settings_ = bitmap_settings; |
| 783 std::string data_str(data->front_as<char>(), data->size()); | 749 std::string data_str(data->front_as<char>(), data->size()); |
| 784 callback.Run(true, base::FilePath().AppendASCII(data_str + "test.pdf")); | 750 callback.Run(true, base::FilePath().AppendASCII(data_str + "test.pdf")); |
| 785 } | 751 } |
| 786 | 752 |
| 787 const printing::PwgRasterSettings& bitmap_settings() { | 753 const printing::PwgRasterSettings& bitmap_settings() { |
| 788 return bitmap_settings_; | 754 return bitmap_settings_; |
| 789 } | 755 } |
| 790 | 756 |
| 791 private: | 757 private: |
| 792 printing::PwgRasterSettings bitmap_settings_; | 758 printing::PwgRasterSettings bitmap_settings_; |
| 793 }; | 759 }; |
| 794 | 760 |
| 795 class PrivetLocalPrintTest : public PrivetHTTPTest { | 761 class PrivetLocalPrintTest : public PrivetHTTPTest { |
| 796 public: | 762 public: |
| 797 PrivetLocalPrintTest() {} | |
| 798 | |
| 799 ~PrivetLocalPrintTest() override {} | |
| 800 | |
| 801 void SetUp() override { | 763 void SetUp() override { |
| 802 PrivetURLFetcher::ResetTokenMapForTests(); | 764 PrivetURLFetcher::ResetTokenMapForTests(); |
| 803 | 765 |
| 804 local_print_operation_ = privet_client_->CreateLocalPrintOperation( | 766 local_print_operation_ = privet_client_->CreateLocalPrintOperation( |
| 805 &local_print_delegate_); | 767 &local_print_delegate_); |
| 806 | 768 |
| 807 scoped_ptr<FakePWGRasterConverter> pwg_converter( | 769 scoped_ptr<FakePWGRasterConverter> pwg_converter( |
| 808 new FakePWGRasterConverter); | 770 new FakePWGRasterConverter); |
| 809 pwg_converter_ = pwg_converter.get(); | 771 pwg_converter_ = pwg_converter.get(); |
| 810 local_print_operation_->SetPWGRasterConverterForTesting( | 772 local_print_operation_->SetPWGRasterConverterForTesting( |
| 811 pwg_converter.Pass()); | 773 pwg_converter.Pass()); |
| 812 } | 774 } |
| 813 | 775 |
| 814 scoped_refptr<base::RefCountedBytes> RefCountedBytesFromString( | 776 scoped_refptr<base::RefCountedBytes> RefCountedBytesFromString( |
| 815 std::string str) { | 777 std::string str) { |
| 816 std::vector<unsigned char> str_vec; | 778 std::vector<unsigned char> str_vec; |
| 817 str_vec.insert(str_vec.begin(), str.begin(), str.end()); | 779 str_vec.insert(str_vec.begin(), str.begin(), str.end()); |
| 818 return scoped_refptr<base::RefCountedBytes>( | 780 return scoped_refptr<base::RefCountedBytes>( |
| 819 base::RefCountedBytes::TakeVector(&str_vec)); | 781 base::RefCountedBytes::TakeVector(&str_vec)); |
| 820 } | 782 } |
| 821 | 783 |
| 822 protected: | 784 protected: |
| 823 scoped_ptr<PrivetLocalPrintOperation> local_print_operation_; | 785 scoped_ptr<PrivetLocalPrintOperation> local_print_operation_; |
| 824 StrictMock<MockLocalPrintDelegate> local_print_delegate_; | 786 StrictMock<MockLocalPrintDelegate> local_print_delegate_; |
| 825 FakePWGRasterConverter* pwg_converter_; | 787 FakePWGRasterConverter* pwg_converter_; |
| 826 }; | 788 }; |
| 827 | 789 |
| 828 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrint) { | 790 INSTANTIATE_TEST_CASE_P(PrivetTests, |
| 791 PrivetLocalPrintTest, |
| 792 ValuesIn(kTestParams)); |
| 793 |
| 794 TEST_P(PrivetLocalPrintTest, SuccessfulLocalPrint) { |
| 829 local_print_operation_->SetUsername("sample@gmail.com"); | 795 local_print_operation_->SetUsername("sample@gmail.com"); |
| 830 local_print_operation_->SetJobname("Sample job name"); | 796 local_print_operation_->SetJobname("Sample job name"); |
| 831 local_print_operation_->SetData(RefCountedBytesFromString( | 797 local_print_operation_->SetData(RefCountedBytesFromString( |
| 832 "Sample print data")); | 798 "Sample print data")); |
| 833 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 799 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
| 834 local_print_operation_->Start(); | 800 local_print_operation_->Start(); |
| 835 | 801 |
| 836 EXPECT_TRUE(SuccessfulResponseToURL( | 802 EXPECT_TRUE( |
| 837 GURL("http://10.0.0.8:6006/privet/info"), | 803 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 838 kSampleInfoResponse)); | |
| 839 | 804 |
| 840 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 805 EXPECT_TRUE( |
| 841 kSampleInfoResponse)); | 806 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 842 | 807 |
| 843 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 808 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 844 | 809 |
| 845 // TODO(noamsml): Is encoding spaces as pluses standard? | 810 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 846 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 811 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 847 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 812 GetUrl("/privet/printer/submitdoc?" |
| 848 "client_name=Chrome&user_name=sample%40gmail.com&" | 813 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 849 "job_name=Sample+job+name"), | 814 "job_name=Sample+job+name"), |
| 850 "Sample print data", | 815 "Sample print data", kSampleLocalPrintResponse)); |
| 851 kSampleLocalPrintResponse)); | |
| 852 } | 816 } |
| 853 | 817 |
| 854 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { | 818 TEST_P(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { |
| 855 local_print_operation_->SetUsername("sample@gmail.com"); | 819 local_print_operation_->SetUsername("sample@gmail.com"); |
| 856 local_print_operation_->SetJobname("Sample job name"); | 820 local_print_operation_->SetJobname("Sample job name"); |
| 857 local_print_operation_->SetData( | 821 local_print_operation_->SetData( |
| 858 RefCountedBytesFromString("Sample print data")); | 822 RefCountedBytesFromString("Sample print data")); |
| 859 local_print_operation_->SetCapabilities( | 823 local_print_operation_->SetCapabilities( |
| 860 kSampleCapabilitiesResponseWithAnyMimetype); | 824 kSampleCapabilitiesResponseWithAnyMimetype); |
| 861 local_print_operation_->Start(); | 825 local_print_operation_->Start(); |
| 862 | 826 |
| 863 EXPECT_TRUE(SuccessfulResponseToURL( | 827 EXPECT_TRUE( |
| 864 GURL("http://10.0.0.8:6006/privet/info"), | 828 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 865 kSampleInfoResponse)); | |
| 866 | 829 |
| 867 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 830 EXPECT_TRUE( |
| 868 kSampleInfoResponse)); | 831 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 869 | 832 |
| 870 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 833 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 871 | 834 |
| 872 // TODO(noamsml): Is encoding spaces as pluses standard? | 835 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 873 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 836 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 874 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 837 GetUrl("/privet/printer/submitdoc?" |
| 875 "client_name=Chrome&user_name=sample%40gmail.com&" | 838 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 876 "job_name=Sample+job+name"), | 839 "job_name=Sample+job+name"), |
| 877 "Sample print data", | 840 "Sample print data", kSampleLocalPrintResponse)); |
| 878 kSampleLocalPrintResponse)); | |
| 879 } | 841 } |
| 880 | 842 |
| 881 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { | 843 TEST_P(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { |
| 882 local_print_operation_->SetUsername("sample@gmail.com"); | 844 local_print_operation_->SetUsername("sample@gmail.com"); |
| 883 local_print_operation_->SetJobname("Sample job name"); | 845 local_print_operation_->SetJobname("Sample job name"); |
| 884 local_print_operation_->SetData( | 846 local_print_operation_->SetData( |
| 885 RefCountedBytesFromString("path/to/")); | 847 RefCountedBytesFromString("path/to/")); |
| 886 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponsePWGOnly); | 848 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponsePWGOnly); |
| 887 local_print_operation_->Start(); | 849 local_print_operation_->Start(); |
| 888 | 850 |
| 889 EXPECT_TRUE(SuccessfulResponseToURL( | 851 EXPECT_TRUE( |
| 890 GURL("http://10.0.0.8:6006/privet/info"), | 852 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 891 kSampleInfoResponse)); | |
| 892 | 853 |
| 893 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 854 EXPECT_TRUE( |
| 894 kSampleInfoResponse)); | 855 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 895 | 856 |
| 896 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 857 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 897 | 858 |
| 898 // TODO(noamsml): Is encoding spaces as pluses standard? | 859 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 899 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 860 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
| 900 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 861 GetUrl("/privet/printer/submitdoc?" |
| 901 "client_name=Chrome&user_name=sample%40gmail.com" | 862 "client_name=Chrome&user_name=sample%40gmail.com" |
| 902 "&job_name=Sample+job+name"), | 863 "&job_name=Sample+job+name"), |
| 903 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), | 864 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), |
| 904 kSampleLocalPrintResponse)); | 865 kSampleLocalPrintResponse)); |
| 905 | 866 |
| 906 EXPECT_EQ(printing::TRANSFORM_NORMAL, | 867 EXPECT_EQ(printing::TRANSFORM_NORMAL, |
| 907 pwg_converter_->bitmap_settings().odd_page_transform); | 868 pwg_converter_->bitmap_settings().odd_page_transform); |
| 908 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); | 869 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); |
| 909 EXPECT_FALSE(pwg_converter_->bitmap_settings().reverse_page_order); | 870 EXPECT_FALSE(pwg_converter_->bitmap_settings().reverse_page_order); |
| 910 } | 871 } |
| 911 | 872 |
| 912 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrintDuplex) { | 873 TEST_P(PrivetLocalPrintTest, SuccessfulPWGLocalPrintDuplex) { |
| 913 local_print_operation_->SetUsername("sample@gmail.com"); | 874 local_print_operation_->SetUsername("sample@gmail.com"); |
| 914 local_print_operation_->SetJobname("Sample job name"); | 875 local_print_operation_->SetJobname("Sample job name"); |
| 915 local_print_operation_->SetData(RefCountedBytesFromString("path/to/")); | 876 local_print_operation_->SetData(RefCountedBytesFromString("path/to/")); |
| 916 local_print_operation_->SetTicket(kSampleCJTDuplex); | 877 local_print_operation_->SetTicket(kSampleCJTDuplex); |
| 917 local_print_operation_->SetCapabilities( | 878 local_print_operation_->SetCapabilities( |
| 918 kSampleCapabilitiesResponsePWGSettings); | 879 kSampleCapabilitiesResponsePWGSettings); |
| 919 local_print_operation_->Start(); | 880 local_print_operation_->Start(); |
| 920 | 881 |
| 921 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 882 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 922 kSampleInfoResponseWithCreatejob)); | 883 kSampleInfoResponseWithCreatejob)); |
| 923 | 884 |
| 924 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 885 EXPECT_TRUE( |
| 925 kSampleInfoResponse)); | 886 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 926 | 887 |
| 927 EXPECT_TRUE(SuccessfulResponseToURLAndJSONData( | 888 EXPECT_TRUE(SuccessfulResponseToURLAndJSONData( |
| 928 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 889 GetUrl("/privet/printer/createjob"), kSampleCJTDuplex, |
| 929 kSampleCJTDuplex, | |
| 930 kSampleCreatejobResponse)); | 890 kSampleCreatejobResponse)); |
| 931 | 891 |
| 932 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 892 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 933 | 893 |
| 934 // TODO(noamsml): Is encoding spaces as pluses standard? | 894 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 935 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 895 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
| 936 GURL( | 896 GetUrl("/privet/printer/submitdoc?" |
| 937 "http://10.0.0.8:6006/privet/printer/submitdoc?" | 897 "client_name=Chrome&user_name=sample%40gmail.com" |
| 938 "client_name=Chrome&user_name=sample%40gmail.com" | 898 "&job_name=Sample+job+name&job_id=1234"), |
| 939 "&job_name=Sample+job+name&job_id=1234"), | |
| 940 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), | 899 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), |
| 941 kSampleLocalPrintResponse)); | 900 kSampleLocalPrintResponse)); |
| 942 | 901 |
| 943 EXPECT_EQ(printing::TRANSFORM_ROTATE_180, | 902 EXPECT_EQ(printing::TRANSFORM_ROTATE_180, |
| 944 pwg_converter_->bitmap_settings().odd_page_transform); | 903 pwg_converter_->bitmap_settings().odd_page_transform); |
| 945 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); | 904 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); |
| 946 EXPECT_TRUE(pwg_converter_->bitmap_settings().reverse_page_order); | 905 EXPECT_TRUE(pwg_converter_->bitmap_settings().reverse_page_order); |
| 947 } | 906 } |
| 948 | 907 |
| 949 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { | 908 TEST_P(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { |
| 950 local_print_operation_->SetUsername("sample@gmail.com"); | 909 local_print_operation_->SetUsername("sample@gmail.com"); |
| 951 local_print_operation_->SetJobname("Sample job name"); | 910 local_print_operation_->SetJobname("Sample job name"); |
| 952 local_print_operation_->SetTicket(kSampleCJT); | 911 local_print_operation_->SetTicket(kSampleCJT); |
| 953 local_print_operation_->SetData( | 912 local_print_operation_->SetData( |
| 954 RefCountedBytesFromString("Sample print data")); | 913 RefCountedBytesFromString("Sample print data")); |
| 955 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 914 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
| 956 local_print_operation_->Start(); | 915 local_print_operation_->Start(); |
| 957 | 916 |
| 958 EXPECT_TRUE(SuccessfulResponseToURL( | 917 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 959 GURL("http://10.0.0.8:6006/privet/info"), | 918 kSampleInfoResponseWithCreatejob)); |
| 960 kSampleInfoResponseWithCreatejob)); | |
| 961 | 919 |
| 962 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 920 EXPECT_TRUE( |
| 963 kSampleInfoResponse)); | 921 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 964 | 922 |
| 965 EXPECT_TRUE(SuccessfulResponseToURLAndJSONData( | 923 EXPECT_TRUE( |
| 966 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 924 SuccessfulResponseToURLAndJSONData(GetUrl("/privet/printer/createjob"), |
| 967 kSampleCJT, | 925 kSampleCJT, kSampleCreatejobResponse)); |
| 968 kSampleCreatejobResponse)); | |
| 969 | 926 |
| 970 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 927 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 971 | 928 |
| 972 // TODO(noamsml): Is encoding spaces as pluses standard? | 929 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 973 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 930 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 974 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 931 GetUrl("/privet/printer/submitdoc?" |
| 975 "client_name=Chrome&user_name=sample%40gmail.com&" | 932 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 976 "job_name=Sample+job+name&job_id=1234"), | 933 "job_name=Sample+job+name&job_id=1234"), |
| 977 "Sample print data", | 934 "Sample print data", kSampleLocalPrintResponse)); |
| 978 kSampleLocalPrintResponse)); | |
| 979 } | 935 } |
| 980 | 936 |
| 981 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithOverlongName) { | 937 TEST_P(PrivetLocalPrintTest, SuccessfulLocalPrintWithOverlongName) { |
| 982 local_print_operation_->SetUsername("sample@gmail.com"); | 938 local_print_operation_->SetUsername("sample@gmail.com"); |
| 983 local_print_operation_->SetJobname( | 939 local_print_operation_->SetJobname( |
| 984 "123456789:123456789:123456789:123456789:123456789:123456789:123456789:"); | 940 "123456789:123456789:123456789:123456789:123456789:123456789:123456789:"); |
| 985 local_print_operation_->SetTicket(kSampleCJT); | 941 local_print_operation_->SetTicket(kSampleCJT); |
| 986 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 942 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
| 987 local_print_operation_->SetData( | 943 local_print_operation_->SetData( |
| 988 RefCountedBytesFromString("Sample print data")); | 944 RefCountedBytesFromString("Sample print data")); |
| 989 local_print_operation_->Start(); | 945 local_print_operation_->Start(); |
| 990 | 946 |
| 991 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 947 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 992 kSampleInfoResponseWithCreatejob)); | 948 kSampleInfoResponseWithCreatejob)); |
| 993 | 949 |
| 994 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 950 EXPECT_TRUE( |
| 995 kSampleInfoResponse)); | 951 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 996 | 952 |
| 997 EXPECT_TRUE(SuccessfulResponseToURLAndJSONData( | 953 EXPECT_TRUE( |
| 998 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 954 SuccessfulResponseToURLAndJSONData(GetUrl("/privet/printer/createjob"), |
| 999 kSampleCJT, | 955 kSampleCJT, kSampleCreatejobResponse)); |
| 1000 kSampleCreatejobResponse)); | |
| 1001 | 956 |
| 1002 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 957 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 1003 | 958 |
| 1004 // TODO(noamsml): Is encoding spaces as pluses standard? | 959 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 1005 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 960 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 1006 GURL( | 961 GetUrl("/privet/printer/submitdoc?" |
| 1007 "http://10.0.0.8:6006/privet/printer/submitdoc?" | 962 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 1008 "client_name=Chrome&user_name=sample%40gmail.com&" | 963 "job_name=123456789%3A123456789%3A123456789%3A1...123456789" |
| 1009 "job_name=123456789%3A123456789%3A123456789%3A1...123456789" | 964 "%3A123456789%3A123456789%3A&job_id=1234"), |
| 1010 "%3A123456789%3A123456789%3A&job_id=1234"), | 965 "Sample print data", kSampleLocalPrintResponse)); |
| 1011 "Sample print data", | |
| 1012 kSampleLocalPrintResponse)); | |
| 1013 } | 966 } |
| 1014 | 967 |
| 1015 TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { | 968 TEST_P(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { |
| 1016 local_print_operation_->SetUsername("sample@gmail.com"); | 969 local_print_operation_->SetUsername("sample@gmail.com"); |
| 1017 local_print_operation_->SetJobname("Sample job name"); | 970 local_print_operation_->SetJobname("Sample job name"); |
| 1018 local_print_operation_->SetTicket(kSampleCJT); | 971 local_print_operation_->SetTicket(kSampleCJT); |
| 1019 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 972 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
| 1020 local_print_operation_->SetData( | 973 local_print_operation_->SetData( |
| 1021 RefCountedBytesFromString("sample/path/")); | 974 RefCountedBytesFromString("sample/path/")); |
| 1022 local_print_operation_->Start(); | 975 local_print_operation_->Start(); |
| 1023 | 976 |
| 1024 EXPECT_TRUE(SuccessfulResponseToURL( | 977 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 1025 GURL("http://10.0.0.8:6006/privet/info"), | 978 kSampleInfoResponseWithCreatejob)); |
| 1026 kSampleInfoResponseWithCreatejob)); | |
| 1027 | 979 |
| 1028 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 980 EXPECT_TRUE( |
| 1029 kSampleInfoResponse)); | 981 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 1030 | 982 |
| 1031 EXPECT_TRUE(SuccessfulResponseToURLAndJSONData( | 983 EXPECT_TRUE( |
| 1032 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 984 SuccessfulResponseToURLAndJSONData(GetUrl("/privet/printer/createjob"), |
| 1033 kSampleCJT, | 985 kSampleCJT, kSampleCreatejobResponse)); |
| 1034 kSampleCreatejobResponse)); | |
| 1035 | 986 |
| 1036 // TODO(noamsml): Is encoding spaces as pluses standard? | 987 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 1037 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 988 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 1038 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 989 GetUrl("/privet/printer/submitdoc?" |
| 1039 "client_name=Chrome&user_name=sample%40gmail.com&" | 990 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 1040 "job_name=Sample+job+name&job_id=1234"), | 991 "job_name=Sample+job+name&job_id=1234"), |
| 1041 "sample/path/", | 992 "sample/path/", kSampleInvalidDocumentTypeResponse)); |
| 1042 kSampleInvalidDocumentTypeResponse)); | |
| 1043 | 993 |
| 1044 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 994 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 1045 | 995 |
| 1046 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 996 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
| 1047 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 997 GetUrl("/privet/printer/submitdoc?" |
| 1048 "client_name=Chrome&user_name=sample%40gmail.com&" | 998 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 1049 "job_name=Sample+job+name&job_id=1234"), | 999 "job_name=Sample+job+name&job_id=1234"), |
| 1050 base::FilePath(FILE_PATH_LITERAL("sample/path/test.pdf")), | 1000 base::FilePath(FILE_PATH_LITERAL("sample/path/test.pdf")), |
| 1051 kSampleLocalPrintResponse)); | 1001 kSampleLocalPrintResponse)); |
| 1052 } | 1002 } |
| 1053 | 1003 |
| 1054 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { | 1004 TEST_P(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { |
| 1055 local_print_operation_->SetUsername("sample@gmail.com"); | 1005 local_print_operation_->SetUsername("sample@gmail.com"); |
| 1056 local_print_operation_->SetJobname("Sample job name"); | 1006 local_print_operation_->SetJobname("Sample job name"); |
| 1057 local_print_operation_->SetTicket(kSampleCJT); | 1007 local_print_operation_->SetTicket(kSampleCJT); |
| 1058 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 1008 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
| 1059 local_print_operation_->SetData( | 1009 local_print_operation_->SetData( |
| 1060 RefCountedBytesFromString("Sample print data")); | 1010 RefCountedBytesFromString("Sample print data")); |
| 1061 local_print_operation_->Start(); | 1011 local_print_operation_->Start(); |
| 1062 | 1012 |
| 1063 EXPECT_TRUE(SuccessfulResponseToURL( | 1013 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/info"), |
| 1064 GURL("http://10.0.0.8:6006/privet/info"), | 1014 kSampleInfoResponseWithCreatejob)); |
| 1065 kSampleInfoResponseWithCreatejob)); | |
| 1066 | 1015 |
| 1067 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 1016 EXPECT_TRUE( |
| 1068 kSampleInfoResponse)); | 1017 SuccessfulResponseToURL(GetUrl("/privet/info"), kSampleInfoResponse)); |
| 1069 | 1018 |
| 1070 EXPECT_TRUE(SuccessfulResponseToURLAndJSONData( | 1019 EXPECT_TRUE( |
| 1071 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 1020 SuccessfulResponseToURLAndJSONData(GetUrl("/privet/printer/createjob"), |
| 1072 kSampleCJT, | 1021 kSampleCJT, kSampleCreatejobResponse)); |
| 1073 kSampleCreatejobResponse)); | |
| 1074 | 1022 |
| 1075 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 1023 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 1076 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 1024 GetUrl("/privet/printer/submitdoc?" |
| 1077 "client_name=Chrome&user_name=sample%40gmail.com&" | 1025 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 1078 "job_name=Sample+job+name&job_id=1234"), | 1026 "job_name=Sample+job+name&job_id=1234"), |
| 1079 "Sample print data", | 1027 "Sample print data", kSampleErrorResponsePrinterBusy)); |
| 1080 kSampleErrorResponsePrinterBusy)); | |
| 1081 | 1028 |
| 1082 RunFor(base::TimeDelta::FromSeconds(3)); | 1029 RunFor(base::TimeDelta::FromSeconds(3)); |
| 1083 | 1030 |
| 1084 EXPECT_TRUE(SuccessfulResponseToURL( | 1031 EXPECT_TRUE(SuccessfulResponseToURL(GetUrl("/privet/printer/createjob"), |
| 1085 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 1032 kSampleCreatejobResponse)); |
| 1086 kSampleCreatejobResponse)); | |
| 1087 } | 1033 } |
| 1088 #endif // ENABLE_PRINT_PREVIEW | 1034 #endif // ENABLE_PRINT_PREVIEW |
| 1089 | 1035 |
| 1090 class PrivetHttpWithServerTest : public ::testing::Test, | 1036 class PrivetHttpWithServerTest : public ::testing::Test, |
| 1091 public PrivetURLFetcher::Delegate { | 1037 public PrivetURLFetcher::Delegate { |
| 1092 protected: | 1038 protected: |
| 1093 PrivetHttpWithServerTest() | 1039 PrivetHttpWithServerTest() |
| 1094 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {} | 1040 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {} |
| 1095 | 1041 |
| 1096 void SetUp() override { | 1042 void SetUp() override { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 fingerprint = {}; | 1153 fingerprint = {}; |
| 1208 client_->SwitchToHttps(server_->host_port_pair().port(), fingerprint); | 1154 client_->SwitchToHttps(server_->host_port_pair().port(), fingerprint); |
| 1209 Run(); | 1155 Run(); |
| 1210 EXPECT_FALSE(success_); | 1156 EXPECT_FALSE(success_); |
| 1211 EXPECT_EQ(PrivetURLFetcher::REQUEST_CANCELED, error_); | 1157 EXPECT_EQ(PrivetURLFetcher::REQUEST_CANCELED, error_); |
| 1212 } | 1158 } |
| 1213 | 1159 |
| 1214 } // namespace | 1160 } // namespace |
| 1215 | 1161 |
| 1216 } // namespace local_discovery | 1162 } // namespace local_discovery |
| OLD | NEW |