OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat
or_apiary.h" | 10 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat
or_apiary.h" |
11 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 11 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 12 #include "net/base/net_errors.h" |
12 #include "net/url_request/test_url_fetcher_factory.h" | 13 #include "net/url_request/test_url_fetcher_factory.h" |
13 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const char kAccountId[] = "account@gmail.com"; | 20 const char kAccountId[] = "account@gmail.com"; |
20 | 21 |
21 std::string BuildResponse() { | 22 std::string BuildResponse() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 base::Unretained(this))); | 64 base::Unretained(this))); |
64 } | 65 } |
65 | 66 |
66 net::TestURLFetcher* GetURLFetcher(int id) { | 67 net::TestURLFetcher* GetURLFetcher(int id) { |
67 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID(id); | 68 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID(id); |
68 EXPECT_TRUE(url_fetcher); | 69 EXPECT_TRUE(url_fetcher); |
69 return url_fetcher; | 70 return url_fetcher; |
70 } | 71 } |
71 | 72 |
72 void SendResponse(int url_fetcher_id, | 73 void SendResponse(int url_fetcher_id, |
73 net::URLRequestStatus::Status status, | 74 net::Error error, |
74 const std::string& response) { | 75 const std::string& response) { |
75 net::TestURLFetcher* url_fetcher = GetURLFetcher(url_fetcher_id); | 76 net::TestURLFetcher* url_fetcher = GetURLFetcher(url_fetcher_id); |
76 url_fetcher->set_status(net::URLRequestStatus(status, 0)); | 77 url_fetcher->set_status(net::URLRequestStatus::FromError(error)); |
77 url_fetcher->set_response_code(net::HTTP_OK); | 78 url_fetcher->set_response_code(net::HTTP_OK); |
78 url_fetcher->SetResponseString(response); | 79 url_fetcher->SetResponseString(response); |
79 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); | 80 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
80 } | 81 } |
81 | 82 |
82 void SendValidResponse(int url_fetcher_id) { | 83 void SendValidResponse(int url_fetcher_id) { |
83 SendResponse(url_fetcher_id, | 84 SendResponse(url_fetcher_id, net::OK, BuildResponse()); |
84 net::URLRequestStatus::SUCCESS, | |
85 BuildResponse()); | |
86 } | 85 } |
87 | 86 |
88 void SendFailedResponse(int url_fetcher_id) { | 87 void SendFailedResponse(int url_fetcher_id) { |
89 SendResponse(url_fetcher_id, | 88 SendResponse(url_fetcher_id, net::ERR_ABORTED, std::string()); |
90 net::URLRequestStatus::CANCELED, | |
91 std::string()); | |
92 } | 89 } |
93 | 90 |
94 MOCK_METHOD1(OnRequestCreated, void(bool success)); | 91 MOCK_METHOD1(OnRequestCreated, void(bool success)); |
95 | 92 |
96 base::MessageLoop message_loop_; | 93 base::MessageLoop message_loop_; |
97 FakeProfileOAuth2TokenService token_service_; | 94 FakeProfileOAuth2TokenService token_service_; |
98 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 95 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
99 net::TestURLFetcherFactory url_fetcher_factory_; | 96 net::TestURLFetcherFactory url_fetcher_factory_; |
100 PermissionRequestCreatorApiary permission_creator_; | 97 PermissionRequestCreatorApiary permission_creator_; |
101 }; | 98 }; |
(...skipping 29 matching lines...) Expand all Loading... |
131 | 128 |
132 // We should have gotten a request for an access token. | 129 // We should have gotten a request for an access token. |
133 EXPECT_EQ(1U, token_service_.GetPendingRequests().size()); | 130 EXPECT_EQ(1U, token_service_.GetPendingRequests().size()); |
134 | 131 |
135 IssueAccessTokens(); | 132 IssueAccessTokens(); |
136 | 133 |
137 // Our callback should get called on an error. | 134 // Our callback should get called on an error. |
138 EXPECT_CALL(*this, OnRequestCreated(false)); | 135 EXPECT_CALL(*this, OnRequestCreated(false)); |
139 SendFailedResponse(0); | 136 SendFailedResponse(0); |
140 } | 137 } |
OLD | NEW |