Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: components/policy/core/common/cloud/user_info_fetcher_unittest.cc

Issue 1239993004: Fix all failed and canceled URLRequestStatuses without errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix more failures Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/values.h" 5 #include "base/values.h"
6 #include "components/policy/core/common/cloud/user_info_fetcher.h" 6 #include "components/policy/core/common/cloud/user_info_fetcher.h"
7 #include "google_apis/gaia/google_service_auth_error.h" 7 #include "google_apis/gaia/google_service_auth_error.h"
8 #include "net/base/net_errors.h"
8 #include "net/http/http_status_code.h" 9 #include "net/http/http_status_code.h"
9 #include "net/url_request/test_url_fetcher_factory.h" 10 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "net/url_request/url_request_status.h"
10 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 using testing::_; 15 using testing::_;
14 16
15 namespace policy { 17 namespace policy {
16 18
17 namespace { 19 namespace {
18 20
19 static const char kUserInfoResponse[] = 21 static const char kUserInfoResponse[] =
(...skipping 23 matching lines...) Expand all
43 }; 45 };
44 46
45 TEST_F(UserInfoFetcherTest, FailedFetch) { 47 TEST_F(UserInfoFetcherTest, FailedFetch) {
46 MockUserInfoFetcherDelegate delegate; 48 MockUserInfoFetcherDelegate delegate;
47 UserInfoFetcher fetcher(&delegate, NULL); 49 UserInfoFetcher fetcher(&delegate, NULL);
48 fetcher.Start("access_token"); 50 fetcher.Start("access_token");
49 51
50 // Fake a failed fetch - should result in the failure callback being invoked. 52 // Fake a failed fetch - should result in the failure callback being invoked.
51 EXPECT_CALL(delegate, OnGetUserInfoFailure(_)); 53 EXPECT_CALL(delegate, OnGetUserInfoFailure(_));
52 net::TestURLFetcher* url_fetcher = url_factory_.GetFetcherByID(0); 54 net::TestURLFetcher* url_fetcher = url_factory_.GetFetcherByID(0);
53 url_fetcher->set_status(net::URLRequestStatus( 55 url_fetcher->set_status(net::URLRequestStatus::FromError(net::ERR_FAILED));
54 net::URLRequestStatus::FAILED, -1));
55 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 56 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
56 } 57 }
57 58
58 TEST_F(UserInfoFetcherTest, SuccessfulFetch) { 59 TEST_F(UserInfoFetcherTest, SuccessfulFetch) {
59 MockUserInfoFetcherDelegate delegate; 60 MockUserInfoFetcherDelegate delegate;
60 UserInfoFetcher fetcher(&delegate, NULL); 61 UserInfoFetcher fetcher(&delegate, NULL);
61 fetcher.Start("access_token"); 62 fetcher.Start("access_token");
62 63
63 // Generate what we expect our result will look like (should match 64 // Generate what we expect our result will look like (should match
64 // parsed kUserInfoResponse). 65 // parsed kUserInfoResponse).
65 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 66 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
66 dict->SetString("email", "test_user@test.com"); 67 dict->SetString("email", "test_user@test.com");
67 dict->SetBoolean("verified_email", true); 68 dict->SetBoolean("verified_email", true);
68 dict->SetString("hd", "test.com"); 69 dict->SetString("hd", "test.com");
69 70
70 // Fake a successful fetch - should result in the data being parsed and 71 // Fake a successful fetch - should result in the data being parsed and
71 // the values passed off to the success callback. 72 // the values passed off to the success callback.
72 EXPECT_CALL(delegate, OnGetUserInfoSuccess(MatchDict(dict.get()))); 73 EXPECT_CALL(delegate, OnGetUserInfoSuccess(MatchDict(dict.get())));
73 net::TestURLFetcher* url_fetcher = url_factory_.GetFetcherByID(0); 74 net::TestURLFetcher* url_fetcher = url_factory_.GetFetcherByID(0);
74 url_fetcher->set_response_code(net::HTTP_OK); 75 url_fetcher->set_response_code(net::HTTP_OK);
75 url_fetcher->SetResponseString(kUserInfoResponse); 76 url_fetcher->SetResponseString(kUserInfoResponse);
76 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 77 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
77 } 78 }
78 } // namespace 79 } // namespace
79 80
80 } // namespace policy 81 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698