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; |
28 using testing::Mock; | |
29 using testing::StrictMock; | |
25 using testing::_; | 30 using testing::_; |
26 | 31 |
27 namespace policy { | 32 namespace policy { |
28 | 33 |
29 const char kServiceUrl[] = "https://example.com/management_service"; | 34 const char kServiceUrl[] = "https://example.com/management_service"; |
30 | 35 |
31 // Encoded empty response messages for testing the error code paths. | 36 // Encoded empty response messages for testing the error code paths. |
32 const char kResponseEmpty[] = "\x08\x00"; | 37 const char kResponseEmpty[] = "\x08\x00"; |
33 | 38 |
34 #define PROTO_STRING(name) (std::string(name, arraysize(name) - 1)) | 39 #define PROTO_STRING(name) (std::string(name, arraysize(name) - 1)) |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 GURL(kServiceUrl), | 519 GURL(kServiceUrl), |
515 status, | 520 status, |
516 500, | 521 500, |
517 net::ResponseCookies(), | 522 net::ResponseCookies(), |
518 ""); | 523 ""); |
519 | 524 |
520 // Backend should have been reset. | 525 // Backend should have been reset. |
521 EXPECT_FALSE(backend_.get()); | 526 EXPECT_FALSE(backend_.get()); |
522 } | 527 } |
523 | 528 |
529 TEST_F(DeviceManagementServiceTest, RetryOnProxyError) { | |
530 // Make a request. | |
531 StrictMock<DeviceRegisterResponseDelegateMock> mock; | |
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) != 0); | |
Mattias Nissler (ping if slow)
2011/09/28 09:06:18
you can drop the != 0
Joao da Silva
2011/09/28 19:20:27
Done.
| |
556 EXPECT_EQ(original_url, fetcher->original_url()); | |
557 EXPECT_EQ(upload_data, fetcher->upload_data()); | |
558 | |
559 // No calls should have been made to the mock. | |
Mattias Nissler (ping if slow)
2011/09/28 09:06:18
Other code uses EXPECT_CALL().Times(0) instead of
Joao da Silva
2011/09/28 19:20:27
Done.
| |
560 Mock::VerifyAndClearExpectations(&mock); | |
561 } | |
562 | |
563 TEST_F(DeviceManagementServiceTest, RetryOnBadResponseFromProxy) { | |
564 // Make a request. | |
565 StrictMock<DeviceRegisterResponseDelegateMock> mock; | |
566 | |
567 em::DeviceRegisterRequest request; | |
568 backend_->ProcessRegisterRequest(kGaiaAuthToken, kOAuthToken, | |
569 kDeviceId, request, &mock); | |
570 TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | |
571 ASSERT_TRUE(fetcher); | |
572 EXPECT_TRUE((fetcher->load_flags() & net::LOAD_BYPASS_PROXY) == 0); | |
573 const GURL original_url(fetcher->original_url()); | |
574 const std::string upload_data(fetcher->upload_data()); | |
575 fetcher->set_was_fetched_via_proxy(true); | |
576 scoped_refptr<net::HttpResponseHeaders> headers; | |
577 headers = new net::HttpResponseHeaders( | |
578 "HTTP/1.1 200 OK\0Content-type: bad/type\0\0"); | |
579 fetcher->set_response_headers(headers); | |
580 | |
581 // Generate a callback with a valid http response, that was generated by | |
582 // a bad/wrong proxy. | |
583 net::URLRequestStatus status; | |
584 fetcher->delegate()->OnURLFetchComplete(fetcher, | |
585 GURL(kServiceUrl), | |
586 status, | |
587 200, | |
588 net::ResponseCookies(), | |
589 ""); | |
590 | |
591 // Verify that a new URLFetcher was started that bypasses the proxy. | |
592 fetcher = factory_.GetFetcherByID(0); | |
593 ASSERT_TRUE(fetcher); | |
594 EXPECT_TRUE((fetcher->load_flags() & net::LOAD_BYPASS_PROXY) != 0); | |
595 EXPECT_EQ(original_url, fetcher->original_url()); | |
596 EXPECT_EQ(upload_data, fetcher->upload_data()); | |
597 | |
598 // No calls should have been made to the mock. | |
599 Mock::VerifyAndClearExpectations(&mock); | |
600 } | |
601 | |
524 } // namespace policy | 602 } // namespace policy |
OLD | NEW |