OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <ostream> | 5 #include <ostream> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "chrome/browser/policy/device_management_backend_impl.h" | 10 #include "chrome/browser/policy/device_management_backend_impl.h" |
11 #include "chrome/browser/policy/device_management_backend_mock.h" | 11 #include "chrome/browser/policy/device_management_backend_mock.h" |
12 #include "chrome/browser/policy/device_management_service.h" | 12 #include "chrome/browser/policy/device_management_service.h" |
13 #include "chrome/browser/policy/proto/device_management_constants.h" | 13 #include "chrome/browser/policy/proto/device_management_constants.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
15 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
16 #include "content/test/test_url_fetcher_factory.h" | 16 #include "content/test/test_url_fetcher_factory.h" |
17 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
| 18 #include "net/base/load_flags.h" |
| 19 #include "net/base/net_errors.h" |
| 20 #include "net/http/http_response_headers.h" |
18 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
19 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
22 | 25 |
23 using testing::IgnoreResult; | 26 using testing::IgnoreResult; |
24 using testing::InvokeWithoutArgs; | 27 using testing::InvokeWithoutArgs; |
25 using testing::_; | 28 using testing::_; |
26 | 29 |
27 namespace policy { | 30 namespace policy { |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 GURL(kServiceUrl), | 517 GURL(kServiceUrl), |
515 status, | 518 status, |
516 500, | 519 500, |
517 net::ResponseCookies(), | 520 net::ResponseCookies(), |
518 ""); | 521 ""); |
519 | 522 |
520 // Backend should have been reset. | 523 // Backend should have been reset. |
521 EXPECT_FALSE(backend_.get()); | 524 EXPECT_FALSE(backend_.get()); |
522 } | 525 } |
523 | 526 |
| 527 TEST_F(DeviceManagementServiceTest, RetryOnProxyError) { |
| 528 // Make a request. |
| 529 DeviceRegisterResponseDelegateMock mock; |
| 530 EXPECT_CALL(mock, HandleRegisterResponse(_)).Times(0); |
| 531 EXPECT_CALL(mock, OnError(_)).Times(0); |
| 532 |
| 533 em::DeviceRegisterRequest request; |
| 534 backend_->ProcessRegisterRequest(kGaiaAuthToken, kOAuthToken, |
| 535 kDeviceId, request, &mock); |
| 536 TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 537 ASSERT_TRUE(fetcher); |
| 538 EXPECT_TRUE((fetcher->load_flags() & net::LOAD_BYPASS_PROXY) == 0); |
| 539 const GURL original_url(fetcher->original_url()); |
| 540 const std::string upload_data(fetcher->upload_data()); |
| 541 |
| 542 // Generate a callback with a proxy failure. |
| 543 net::URLRequestStatus status(net::URLRequestStatus::FAILED, |
| 544 net::ERR_PROXY_CONNECTION_FAILED); |
| 545 fetcher->delegate()->OnURLFetchComplete(fetcher, |
| 546 GURL(kServiceUrl), |
| 547 status, |
| 548 0, |
| 549 net::ResponseCookies(), |
| 550 ""); |
| 551 |
| 552 // Verify that a new URLFetcher was started that bypasses the proxy. |
| 553 fetcher = factory_.GetFetcherByID(0); |
| 554 ASSERT_TRUE(fetcher); |
| 555 EXPECT_TRUE(fetcher->load_flags() & net::LOAD_BYPASS_PROXY); |
| 556 EXPECT_EQ(original_url, fetcher->original_url()); |
| 557 EXPECT_EQ(upload_data, fetcher->upload_data()); |
| 558 } |
| 559 |
| 560 TEST_F(DeviceManagementServiceTest, RetryOnBadResponseFromProxy) { |
| 561 // Make a request. |
| 562 DeviceRegisterResponseDelegateMock mock; |
| 563 EXPECT_CALL(mock, HandleRegisterResponse(_)).Times(0); |
| 564 EXPECT_CALL(mock, OnError(_)).Times(0); |
| 565 |
| 566 em::DeviceRegisterRequest request; |
| 567 backend_->ProcessRegisterRequest(kGaiaAuthToken, kOAuthToken, |
| 568 kDeviceId, request, &mock); |
| 569 TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 570 ASSERT_TRUE(fetcher); |
| 571 EXPECT_TRUE((fetcher->load_flags() & net::LOAD_BYPASS_PROXY) == 0); |
| 572 const GURL original_url(fetcher->original_url()); |
| 573 const std::string upload_data(fetcher->upload_data()); |
| 574 fetcher->set_was_fetched_via_proxy(true); |
| 575 scoped_refptr<net::HttpResponseHeaders> headers; |
| 576 headers = new net::HttpResponseHeaders( |
| 577 "HTTP/1.1 200 OK\0Content-type: bad/type\0\0"); |
| 578 fetcher->set_response_headers(headers); |
| 579 |
| 580 // Generate a callback with a valid http response, that was generated by |
| 581 // a bad/wrong proxy. |
| 582 net::URLRequestStatus status; |
| 583 fetcher->delegate()->OnURLFetchComplete(fetcher, |
| 584 GURL(kServiceUrl), |
| 585 status, |
| 586 200, |
| 587 net::ResponseCookies(), |
| 588 ""); |
| 589 |
| 590 // Verify that a new URLFetcher was started that bypasses the proxy. |
| 591 fetcher = factory_.GetFetcherByID(0); |
| 592 ASSERT_TRUE(fetcher); |
| 593 EXPECT_TRUE((fetcher->load_flags() & net::LOAD_BYPASS_PROXY) != 0); |
| 594 EXPECT_EQ(original_url, fetcher->original_url()); |
| 595 EXPECT_EQ(upload_data, fetcher->upload_data()); |
| 596 } |
| 597 |
524 } // namespace policy | 598 } // namespace policy |
OLD | NEW |