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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
14 #include "chrome/browser/policy/cloud/device_management_service.h" | 14 #include "chrome/browser/policy/cloud/device_management_service.h" |
| 15 #include "chrome/browser/policy/cloud/mock_device_management_service.h" |
15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
16 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
19 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
20 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
21 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 using testing::Mock; | 26 using testing::Mock; |
26 using testing::_; | 27 using testing::_; |
27 | 28 |
28 namespace em = enterprise_management; | 29 namespace em = enterprise_management; |
29 | 30 |
30 namespace policy { | 31 namespace policy { |
31 | 32 |
32 const char kServiceUrl[] = "https://example.com/management_service"; | 33 const char kServiceUrl[] = "https://example.com/management_service"; |
33 const char kUserAgent[] = "Chrome 1.2.3(456)"; | |
34 const char kPlatform[] = "Test|Unit|1.2.3"; | |
35 | 34 |
36 // Encoded empty response messages for testing the error code paths. | 35 // Encoded empty response messages for testing the error code paths. |
37 const char kResponseEmpty[] = "\x08\x00"; | 36 const char kResponseEmpty[] = "\x08\x00"; |
38 | 37 |
39 #define PROTO_STRING(name) (std::string(name, arraysize(name) - 1)) | 38 #define PROTO_STRING(name) (std::string(name, arraysize(name) - 1)) |
40 | 39 |
41 // Some helper constants. | 40 // Some helper constants. |
42 const char kGaiaAuthToken[] = "gaia-auth-token"; | 41 const char kGaiaAuthToken[] = "gaia-auth-token"; |
43 const char kOAuthToken[] = "oauth-token"; | 42 const char kOAuthToken[] = "oauth-token"; |
44 const char kDMToken[] = "device-management-token"; | 43 const char kDMToken[] = "device-management-token"; |
(...skipping 11 matching lines...) Expand all Loading... |
56 ResetService(); | 55 ResetService(); |
57 InitializeService(); | 56 InitializeService(); |
58 } | 57 } |
59 | 58 |
60 ~DeviceManagementServiceTestBase() { | 59 ~DeviceManagementServiceTestBase() { |
61 service_.reset(); | 60 service_.reset(); |
62 base::RunLoop().RunUntilIdle(); | 61 base::RunLoop().RunUntilIdle(); |
63 } | 62 } |
64 | 63 |
65 void ResetService() { | 64 void ResetService() { |
66 service_.reset(new DeviceManagementService( | 65 scoped_ptr<DeviceManagementService::Configuration> configuration( |
67 request_context_, | 66 new MockDeviceManagementServiceConfiguration(kServiceUrl)); |
68 kServiceUrl, | 67 service_.reset( |
69 kUserAgent, | 68 new DeviceManagementService(configuration.Pass(), request_context_)); |
70 kUserAgent, | |
71 kPlatform)); | |
72 } | 69 } |
73 | 70 |
74 void InitializeService() { | 71 void InitializeService() { |
75 service_->ScheduleInitialization(0); | 72 service_->ScheduleInitialization(0); |
76 base::RunLoop().RunUntilIdle(); | 73 base::RunLoop().RunUntilIdle(); |
77 } | 74 } |
78 | 75 |
79 net::TestURLFetcher* GetFetcher() { | 76 net::TestURLFetcher* GetFetcher() { |
80 return factory_.GetFetcherByID(DeviceManagementService::kURLFetcherID); | 77 return factory_.GetFetcherByID(DeviceManagementService::kURLFetcherID); |
81 } | 78 } |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 EXPECT_CALL(*this, OnJobDone(DM_STATUS_REQUEST_FAILED, _, _)); | 691 EXPECT_CALL(*this, OnJobDone(DM_STATUS_REQUEST_FAILED, _, _)); |
695 EXPECT_CALL(*this, OnJobRetry(_)).Times(0); | 692 EXPECT_CALL(*this, OnJobRetry(_)).Times(0); |
696 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 693 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
697 net::ERR_NETWORK_CHANGED)); | 694 net::ERR_NETWORK_CHANGED)); |
698 fetcher->set_url(GURL(kServiceUrl)); | 695 fetcher->set_url(GURL(kServiceUrl)); |
699 fetcher->delegate()->OnURLFetchComplete(fetcher); | 696 fetcher->delegate()->OnURLFetchComplete(fetcher); |
700 Mock::VerifyAndClearExpectations(this); | 697 Mock::VerifyAndClearExpectations(this); |
701 } | 698 } |
702 | 699 |
703 } // namespace policy | 700 } // namespace policy |
OLD | NEW |