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 <ostream> | 5 #include <ostream> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 scoped_ptr<DeviceManagementRequestJob> request_job(StartRegistrationJob()); | 506 scoped_ptr<DeviceManagementRequestJob> request_job(StartRegistrationJob()); |
507 net::TestURLFetcher* fetcher = GetFetcher(); | 507 net::TestURLFetcher* fetcher = GetFetcher(); |
508 ASSERT_TRUE(fetcher); | 508 ASSERT_TRUE(fetcher); |
509 | 509 |
510 EXPECT_CALL(*this, OnJobDone(_, _)) | 510 EXPECT_CALL(*this, OnJobDone(_, _)) |
511 .WillOnce(ResetPointer(&request_job)); | 511 .WillOnce(ResetPointer(&request_job)); |
512 EXPECT_CALL(*this, OnJobRetry(_)).Times(0); | 512 EXPECT_CALL(*this, OnJobRetry(_)).Times(0); |
513 | 513 |
514 // Generate a callback. | 514 // Generate a callback. |
515 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 515 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
516 SendResponse(fetcher, status, 500, ""); | 516 SendResponse(fetcher, status, 500, std::string()); |
517 | 517 |
518 // Job should have been reset. | 518 // Job should have been reset. |
519 EXPECT_FALSE(request_job.get()); | 519 EXPECT_FALSE(request_job.get()); |
520 } | 520 } |
521 | 521 |
522 TEST_F(DeviceManagementServiceTest, RetryOnProxyError) { | 522 TEST_F(DeviceManagementServiceTest, RetryOnProxyError) { |
523 // Make a request. | 523 // Make a request. |
524 EXPECT_CALL(*this, OnJobDone(_, _)).Times(0); | 524 EXPECT_CALL(*this, OnJobDone(_, _)).Times(0); |
525 EXPECT_CALL(*this, OnJobRetry(_)); | 525 EXPECT_CALL(*this, OnJobRetry(_)); |
526 | 526 |
527 scoped_ptr<DeviceManagementRequestJob> request_job(StartRegistrationJob()); | 527 scoped_ptr<DeviceManagementRequestJob> request_job(StartRegistrationJob()); |
528 net::TestURLFetcher* fetcher = GetFetcher(); | 528 net::TestURLFetcher* fetcher = GetFetcher(); |
529 ASSERT_TRUE(fetcher); | 529 ASSERT_TRUE(fetcher); |
530 EXPECT_TRUE((fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY) == 0); | 530 EXPECT_TRUE((fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY) == 0); |
531 const GURL original_url(fetcher->GetOriginalURL()); | 531 const GURL original_url(fetcher->GetOriginalURL()); |
532 const std::string upload_data(fetcher->upload_data()); | 532 const std::string upload_data(fetcher->upload_data()); |
533 | 533 |
534 // Generate a callback with a proxy failure. | 534 // Generate a callback with a proxy failure. |
535 net::URLRequestStatus status(net::URLRequestStatus::FAILED, | 535 net::URLRequestStatus status(net::URLRequestStatus::FAILED, |
536 net::ERR_PROXY_CONNECTION_FAILED); | 536 net::ERR_PROXY_CONNECTION_FAILED); |
537 SendResponse(fetcher, status, 200, ""); | 537 SendResponse(fetcher, status, 200, std::string()); |
538 | 538 |
539 // Verify that a new URLFetcher was started that bypasses the proxy. | 539 // Verify that a new URLFetcher was started that bypasses the proxy. |
540 fetcher = GetFetcher(); | 540 fetcher = GetFetcher(); |
541 ASSERT_TRUE(fetcher); | 541 ASSERT_TRUE(fetcher); |
542 EXPECT_TRUE(fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY); | 542 EXPECT_TRUE(fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY); |
543 EXPECT_EQ(original_url, fetcher->GetOriginalURL()); | 543 EXPECT_EQ(original_url, fetcher->GetOriginalURL()); |
544 EXPECT_EQ(upload_data, fetcher->upload_data()); | 544 EXPECT_EQ(upload_data, fetcher->upload_data()); |
545 } | 545 } |
546 | 546 |
547 TEST_F(DeviceManagementServiceTest, RetryOnBadResponseFromProxy) { | 547 TEST_F(DeviceManagementServiceTest, RetryOnBadResponseFromProxy) { |
548 // Make a request. | 548 // Make a request. |
549 EXPECT_CALL(*this, OnJobDone(_, _)).Times(0); | 549 EXPECT_CALL(*this, OnJobDone(_, _)).Times(0); |
550 EXPECT_CALL(*this, OnJobRetry(_)); | 550 EXPECT_CALL(*this, OnJobRetry(_)); |
551 | 551 |
552 scoped_ptr<DeviceManagementRequestJob> request_job(StartRegistrationJob()); | 552 scoped_ptr<DeviceManagementRequestJob> request_job(StartRegistrationJob()); |
553 net::TestURLFetcher* fetcher = GetFetcher(); | 553 net::TestURLFetcher* fetcher = GetFetcher(); |
554 ASSERT_TRUE(fetcher); | 554 ASSERT_TRUE(fetcher); |
555 EXPECT_TRUE((fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY) == 0); | 555 EXPECT_TRUE((fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY) == 0); |
556 const GURL original_url(fetcher->GetOriginalURL()); | 556 const GURL original_url(fetcher->GetOriginalURL()); |
557 const std::string upload_data(fetcher->upload_data()); | 557 const std::string upload_data(fetcher->upload_data()); |
558 fetcher->set_was_fetched_via_proxy(true); | 558 fetcher->set_was_fetched_via_proxy(true); |
559 scoped_refptr<net::HttpResponseHeaders> headers; | 559 scoped_refptr<net::HttpResponseHeaders> headers; |
560 headers = new net::HttpResponseHeaders( | 560 headers = new net::HttpResponseHeaders( |
561 "HTTP/1.1 200 OK\0Content-type: bad/type\0\0"); | 561 "HTTP/1.1 200 OK\0Content-type: bad/type\0\0"); |
562 fetcher->set_response_headers(headers); | 562 fetcher->set_response_headers(headers); |
563 | 563 |
564 // Generate a callback with a valid http response, that was generated by | 564 // Generate a callback with a valid http response, that was generated by |
565 // a bad/wrong proxy. | 565 // a bad/wrong proxy. |
566 net::URLRequestStatus status; | 566 net::URLRequestStatus status; |
567 SendResponse(fetcher, status, 200, ""); | 567 SendResponse(fetcher, status, 200, std::string()); |
568 | 568 |
569 // Verify that a new URLFetcher was started that bypasses the proxy. | 569 // Verify that a new URLFetcher was started that bypasses the proxy. |
570 fetcher = GetFetcher(); | 570 fetcher = GetFetcher(); |
571 ASSERT_TRUE(fetcher); | 571 ASSERT_TRUE(fetcher); |
572 EXPECT_TRUE((fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY) != 0); | 572 EXPECT_TRUE((fetcher->GetLoadFlags() & net::LOAD_BYPASS_PROXY) != 0); |
573 EXPECT_EQ(original_url, fetcher->GetOriginalURL()); | 573 EXPECT_EQ(original_url, fetcher->GetOriginalURL()); |
574 EXPECT_EQ(upload_data, fetcher->upload_data()); | 574 EXPECT_EQ(upload_data, fetcher->upload_data()); |
575 } | 575 } |
576 | 576 |
577 TEST_F(DeviceManagementServiceTest, RetryOnNetworkChanges) { | 577 TEST_F(DeviceManagementServiceTest, RetryOnNetworkChanges) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 EXPECT_CALL(*this, OnJobDone(DM_STATUS_REQUEST_FAILED, _)); | 625 EXPECT_CALL(*this, OnJobDone(DM_STATUS_REQUEST_FAILED, _)); |
626 EXPECT_CALL(*this, OnJobRetry(_)).Times(0); | 626 EXPECT_CALL(*this, OnJobRetry(_)).Times(0); |
627 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 627 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
628 net::ERR_NETWORK_CHANGED)); | 628 net::ERR_NETWORK_CHANGED)); |
629 fetcher->set_url(GURL(kServiceUrl)); | 629 fetcher->set_url(GURL(kServiceUrl)); |
630 fetcher->delegate()->OnURLFetchComplete(fetcher); | 630 fetcher->delegate()->OnURLFetchComplete(fetcher); |
631 Mock::VerifyAndClearExpectations(this); | 631 Mock::VerifyAndClearExpectations(this); |
632 } | 632 } |
633 | 633 |
634 } // namespace policy | 634 } // namespace policy |
OLD | NEW |