Chromium Code Reviews| Index: chrome/browser/supervised_user/experimental/safe_search_url_reporter_unittest.cc |
| diff --git a/chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary_unittest.cc b/chrome/browser/supervised_user/experimental/safe_search_url_reporter_unittest.cc |
| similarity index 53% |
| copy from chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary_unittest.cc |
| copy to chrome/browser/supervised_user/experimental/safe_search_url_reporter_unittest.cc |
| index cb873c5a65800dbb18f1ed444073528b5f6366b2..83788591872f06a632a4fca7c3bd17a59c8b37e7 100644 |
| --- a/chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary_unittest.cc |
| +++ b/chrome/browser/supervised_user/experimental/safe_search_url_reporter_unittest.cc |
| @@ -2,12 +2,11 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "base/json/json_writer.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "base/values.h" |
| -#include "chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.h" |
| +#include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h" |
| #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| #include "net/base/net_errors.h" |
| #include "net/url_request/test_url_fetcher_factory.h" |
| @@ -19,49 +18,34 @@ namespace { |
| const char kAccountId[] = "account@gmail.com"; |
| -std::string BuildResponse() { |
| - base::DictionaryValue dict; |
| - base::DictionaryValue* permission_dict = new base::DictionaryValue; |
| - permission_dict->SetStringWithoutPathExpansion("id", "requestid"); |
| - dict.SetWithoutPathExpansion("permissionRequest", permission_dict); |
| - std::string result; |
| - base::JSONWriter::Write(dict, &result); |
| - return result; |
| -} |
| - |
| } // namespace |
| -class PermissionRequestCreatorApiaryTest : public testing::Test { |
| +class SafeSearchUrlReporterTest : public testing::Test { |
| public: |
| - PermissionRequestCreatorApiaryTest() |
| + SafeSearchUrlReporterTest() |
| : request_context_(new net::TestURLRequestContextGetter( |
| base::ThreadTaskRunnerHandle::Get())), |
| - permission_creator_(&token_service_, |
| - kAccountId, |
| - request_context_.get()) { |
| + report_url_(&token_service_, kAccountId, request_context_.get()) { |
| token_service_.UpdateCredentials(kAccountId, "refresh_token"); |
| } |
| protected: |
| void IssueAccessTokens() { |
| token_service_.IssueAllTokensForAccount( |
| - kAccountId, |
| - "access_token", |
| + kAccountId, "access_token", |
| base::Time::Now() + base::TimeDelta::FromHours(1)); |
| } |
| void IssueAccessTokenErrors() { |
| token_service_.IssueErrorForAllPendingRequestsForAccount( |
| - kAccountId, |
| - GoogleServiceAuthError::FromServiceError("Error!")); |
| + kAccountId, GoogleServiceAuthError::FromServiceError("Error!")); |
| } |
| void CreateRequest(int url_fetcher_id, const GURL& url) { |
| - permission_creator_.set_url_fetcher_id_for_testing(url_fetcher_id); |
| - permission_creator_.CreateURLAccessRequest( |
| - url, |
| - base::Bind(&PermissionRequestCreatorApiaryTest::OnRequestCreated, |
| - base::Unretained(this))); |
| + report_url_.set_url_fetcher_id_for_testing(url_fetcher_id); |
| + report_url_.ReportUrl( |
| + url, base::Bind(&SafeSearchUrlReporterTest::OnRequestCreated, |
| + base::Unretained(this))); |
| } |
| net::TestURLFetcher* GetURLFetcher(int id) { |
| @@ -70,38 +54,34 @@ class PermissionRequestCreatorApiaryTest : public testing::Test { |
| return url_fetcher; |
| } |
| - void SendResponse(int url_fetcher_id, |
| - net::Error error, |
| - const std::string& response) { |
| + void SendResponse(int url_fetcher_id, net::Error error) { |
| net::TestURLFetcher* url_fetcher = GetURLFetcher(url_fetcher_id); |
| url_fetcher->set_status(net::URLRequestStatus::FromError(error)); |
| url_fetcher->set_response_code(net::HTTP_OK); |
| - url_fetcher->SetResponseString(response); |
| url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
| } |
| void SendValidResponse(int url_fetcher_id) { |
| - SendResponse(url_fetcher_id, net::OK, BuildResponse()); |
| + SendResponse(url_fetcher_id, net::OK); |
| } |
| void SendFailedResponse(int url_fetcher_id) { |
| - SendResponse(url_fetcher_id, net::ERR_ABORTED, std::string()); |
| + SendResponse(url_fetcher_id, net::ERR_ABORTED); |
| } |
| - MOCK_METHOD1(OnRequestCreated, void(bool success)); |
| + MOCK_METHOD1(OnRequestCreated, void(bool sucess)); |
|
Marc Treib
2016/03/21 12:32:21
typo :)
atanasova
2016/03/22 15:45:41
Done.
|
| base::MessageLoop message_loop_; |
| FakeProfileOAuth2TokenService token_service_; |
| scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| net::TestURLFetcherFactory url_fetcher_factory_; |
| - PermissionRequestCreatorApiary permission_creator_; |
| + SafeSearchUrlReporter report_url_; |
| }; |
| -TEST_F(PermissionRequestCreatorApiaryTest, Success) { |
| - CreateRequest(0, GURL("http://randomurl.com")); |
| - CreateRequest(1, GURL("http://anotherurl.com")); |
| +TEST_F(SafeSearchUrlReporterTest, Success) { |
| + CreateRequest(0, GURL("http://google.com")); |
| + CreateRequest(1, GURL("http://url.com")); |
| - // We should have gotten a request for an access token. |
|
Marc Treib
2016/03/21 12:32:21
Any reason for not keeping the comments?
|
| EXPECT_GT(token_service_.GetPendingRequests().size(), 0U); |
| IssueAccessTokens(); |
| @@ -112,26 +92,22 @@ TEST_F(PermissionRequestCreatorApiaryTest, Success) { |
| SendValidResponse(1); |
| } |
| -TEST_F(PermissionRequestCreatorApiaryTest, AccessTokenError) { |
| - CreateRequest(0, GURL("http://randomurl.com")); |
| +TEST_F(SafeSearchUrlReporterTest, AccessTokenError) { |
| + CreateRequest(0, GURL("http://google.com")); |
| - // We should have gotten a request for an access token. |
| EXPECT_EQ(1U, token_service_.GetPendingRequests().size()); |
| - // Our callback should get called immediately on an error. |
| EXPECT_CALL(*this, OnRequestCreated(false)); |
| IssueAccessTokenErrors(); |
| } |
| -TEST_F(PermissionRequestCreatorApiaryTest, NetworkError) { |
| - CreateRequest(0, GURL("http://randomurl.com")); |
| +TEST_F(SafeSearchUrlReporterTest, NetworkError) { |
| + CreateRequest(0, GURL("http://google.com")); |
| - // We should have gotten a request for an access token. |
| EXPECT_EQ(1U, token_service_.GetPendingRequests().size()); |
| IssueAccessTokens(); |
| - // Our callback should get called on an error. |
| EXPECT_CALL(*this, OnRequestCreated(false)); |
| SendFailedResponse(0); |
| } |