OLD | NEW |
1 // Copyright (c) 2010 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 <errno.h> | 5 #include <errno.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/chromeos/login/client_login_response_handler.h" | 10 #include "chrome/browser/chromeos/login/client_login_response_handler.h" |
11 #include "chrome/browser/chromeos/login/cookie_fetcher.h" | 11 #include "chrome/browser/chromeos/login/cookie_fetcher.h" |
(...skipping 27 matching lines...) Expand all Loading... |
39 const std::string client_login_data_; | 39 const std::string client_login_data_; |
40 const std::string token_; | 40 const std::string token_; |
41 MessageLoopForUI message_loop_; | 41 MessageLoopForUI message_loop_; |
42 BrowserThread ui_thread_; | 42 BrowserThread ui_thread_; |
43 TestingProfile profile_; | 43 TestingProfile profile_; |
44 }; | 44 }; |
45 | 45 |
46 // Check that successful HTTP responses from both end points results in | 46 // Check that successful HTTP responses from both end points results in |
47 // the browser window getting put up. | 47 // the browser window getting put up. |
48 TEST_F(CookieFetcherTest, SuccessfulFetchTest) { | 48 TEST_F(CookieFetcherTest, SuccessfulFetchTest) { |
49 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); | 49 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
50 | 50 |
51 MockAuthResponseHandler* cl_handler = | 51 MockAuthResponseHandler* cl_handler = |
52 new MockAuthResponseHandler(iat_url_, status, kHttpSuccess, token_); | 52 new MockAuthResponseHandler(iat_url_, status, kHttpSuccess, token_); |
53 MockAuthResponseHandler* i_handler = | 53 MockAuthResponseHandler* i_handler = |
54 new MockAuthResponseHandler(ta_url_, status, kHttpSuccess, std::string()); | 54 new MockAuthResponseHandler(ta_url_, status, kHttpSuccess, std::string()); |
55 | 55 |
56 CookieFetcher* cf = new CookieFetcher(NULL, cl_handler, i_handler); | 56 CookieFetcher* cf = new CookieFetcher(NULL, cl_handler, i_handler); |
57 | 57 |
58 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) | 58 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) |
59 .Times(1); | 59 .Times(1); |
60 | 60 |
61 EXPECT_CALL(*i_handler, CanHandle(iat_url_)) | 61 EXPECT_CALL(*i_handler, CanHandle(iat_url_)) |
62 .WillOnce(Return(true)); | 62 .WillOnce(Return(true)); |
63 EXPECT_CALL(*i_handler, CanHandle(ta_url_)) | 63 EXPECT_CALL(*i_handler, CanHandle(ta_url_)) |
64 .WillOnce(Return(false)); | 64 .WillOnce(Return(false)); |
65 EXPECT_CALL(*i_handler, Handle(token_, cf)) | 65 EXPECT_CALL(*i_handler, Handle(token_, cf)) |
66 .Times(1); | 66 .Times(1); |
67 | 67 |
68 cf->AttemptFetch(client_login_data_); | 68 cf->AttemptFetch(client_login_data_); |
69 message_loop_.RunAllPending(); | 69 message_loop_.RunAllPending(); |
70 } | 70 } |
71 | 71 |
72 // Check that a network failure when trying IssueAuthToken results in us bailing | 72 // Check that a network failure when trying IssueAuthToken results in us bailing |
73 // and putting up the browser window. | 73 // and putting up the browser window. |
74 TEST_F(CookieFetcherTest, IssueAuthTokenNetworkFailureTest) { | 74 TEST_F(CookieFetcherTest, IssueAuthTokenNetworkFailureTest) { |
75 URLRequestStatus failed(URLRequestStatus::FAILED, ECONNRESET); | 75 net::URLRequestStatus failed(net::URLRequestStatus::FAILED, ECONNRESET); |
76 | 76 |
77 MockAuthResponseHandler* cl_handler = | 77 MockAuthResponseHandler* cl_handler = |
78 new MockAuthResponseHandler(iat_url_, failed, kHttpSuccess, token_); | 78 new MockAuthResponseHandler(iat_url_, failed, kHttpSuccess, token_); |
79 // I expect nothing in i_handler to get called anyway | 79 // I expect nothing in i_handler to get called anyway |
80 MockAuthResponseHandler* i_handler = | 80 MockAuthResponseHandler* i_handler = |
81 new MockAuthResponseHandler(ta_url_, failed, kHttpSuccess, std::string()); | 81 new MockAuthResponseHandler(ta_url_, failed, kHttpSuccess, std::string()); |
82 | 82 |
83 CookieFetcher* cf = new CookieFetcher(&profile_, | 83 CookieFetcher* cf = new CookieFetcher(&profile_, |
84 cl_handler, | 84 cl_handler, |
85 i_handler); | 85 i_handler); |
86 | 86 |
87 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) | 87 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) |
88 .Times(1); | 88 .Times(1); |
89 | 89 |
90 cf->AttemptFetch(client_login_data_); | 90 cf->AttemptFetch(client_login_data_); |
91 message_loop_.RunAllPending(); | 91 message_loop_.RunAllPending(); |
92 } | 92 } |
93 | 93 |
94 // Check that a network failure when trying TokenAuth results in us bailing | 94 // Check that a network failure when trying TokenAuth results in us bailing |
95 // and putting up the browser window. | 95 // and putting up the browser window. |
96 TEST_F(CookieFetcherTest, TokenAuthNetworkFailureTest) { | 96 TEST_F(CookieFetcherTest, TokenAuthNetworkFailureTest) { |
97 URLRequestStatus success; | 97 net::URLRequestStatus success; |
98 URLRequestStatus failed(URLRequestStatus::FAILED, ECONNRESET); | 98 net::URLRequestStatus failed(net::URLRequestStatus::FAILED, ECONNRESET); |
99 | 99 |
100 MockAuthResponseHandler* cl_handler = | 100 MockAuthResponseHandler* cl_handler = |
101 new MockAuthResponseHandler(iat_url_, success, kHttpSuccess, token_); | 101 new MockAuthResponseHandler(iat_url_, success, kHttpSuccess, token_); |
102 MockAuthResponseHandler* i_handler = | 102 MockAuthResponseHandler* i_handler = |
103 new MockAuthResponseHandler(ta_url_, failed, 0, std::string()); | 103 new MockAuthResponseHandler(ta_url_, failed, 0, std::string()); |
104 | 104 |
105 CookieFetcher* cf = new CookieFetcher(&profile_, | 105 CookieFetcher* cf = new CookieFetcher(&profile_, |
106 cl_handler, | 106 cl_handler, |
107 i_handler); | 107 i_handler); |
108 | 108 |
109 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) | 109 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) |
110 .Times(1); | 110 .Times(1); |
111 | 111 |
112 EXPECT_CALL(*i_handler, CanHandle(iat_url_)) | 112 EXPECT_CALL(*i_handler, CanHandle(iat_url_)) |
113 .WillOnce(Return(true)); | 113 .WillOnce(Return(true)); |
114 EXPECT_CALL(*i_handler, Handle(token_, cf)) | 114 EXPECT_CALL(*i_handler, Handle(token_, cf)) |
115 .Times(1); | 115 .Times(1); |
116 | 116 |
117 cf->AttemptFetch(client_login_data_); | 117 cf->AttemptFetch(client_login_data_); |
118 message_loop_.RunAllPending(); | 118 message_loop_.RunAllPending(); |
119 } | 119 } |
120 | 120 |
121 // Check that an unsuccessful HTTP response when trying IssueAuthToken results | 121 // Check that an unsuccessful HTTP response when trying IssueAuthToken results |
122 // in us bailing and putting up the browser window. | 122 // in us bailing and putting up the browser window. |
123 TEST_F(CookieFetcherTest, IssueAuthTokenDeniedTest) { | 123 TEST_F(CookieFetcherTest, IssueAuthTokenDeniedTest) { |
124 URLRequestStatus success; | 124 net::URLRequestStatus success; |
125 | 125 |
126 MockAuthResponseHandler* cl_handler = | 126 MockAuthResponseHandler* cl_handler = |
127 new MockAuthResponseHandler(iat_url_, success, 403, std::string()); | 127 new MockAuthResponseHandler(iat_url_, success, 403, std::string()); |
128 // I expect nothing in i_handler to get called anyway. | 128 // I expect nothing in i_handler to get called anyway. |
129 MockAuthResponseHandler* i_handler = | 129 MockAuthResponseHandler* i_handler = |
130 new MockAuthResponseHandler(ta_url_, success, 0, std::string()); | 130 new MockAuthResponseHandler(ta_url_, success, 0, std::string()); |
131 | 131 |
132 CookieFetcher* cf = new CookieFetcher(&profile_, | 132 CookieFetcher* cf = new CookieFetcher(&profile_, |
133 cl_handler, | 133 cl_handler, |
134 i_handler); | 134 i_handler); |
135 | 135 |
136 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) | 136 EXPECT_CALL(*cl_handler, Handle(client_login_data_, cf)) |
137 .Times(1); | 137 .Times(1); |
138 | 138 |
139 cf->AttemptFetch(client_login_data_); | 139 cf->AttemptFetch(client_login_data_); |
140 message_loop_.RunAllPending(); | 140 message_loop_.RunAllPending(); |
141 } | 141 } |
142 | 142 |
143 // Check that an unsuccessful HTTP response when trying TokenAuth results | 143 // Check that an unsuccessful HTTP response when trying TokenAuth results |
144 // in us bailing and putting up the browser window. | 144 // in us bailing and putting up the browser window. |
145 TEST_F(CookieFetcherTest, TokenAuthDeniedTest) { | 145 TEST_F(CookieFetcherTest, TokenAuthDeniedTest) { |
146 URLRequestStatus success; | 146 net::URLRequestStatus success; |
147 | 147 |
148 MockAuthResponseHandler* cl_handler = | 148 MockAuthResponseHandler* cl_handler = |
149 new MockAuthResponseHandler(iat_url_, | 149 new MockAuthResponseHandler(iat_url_, |
150 success, | 150 success, |
151 kHttpSuccess, | 151 kHttpSuccess, |
152 token_); | 152 token_); |
153 MockAuthResponseHandler* i_handler = | 153 MockAuthResponseHandler* i_handler = |
154 new MockAuthResponseHandler(ta_url_, success, 403, std::string()); | 154 new MockAuthResponseHandler(ta_url_, success, 403, std::string()); |
155 | 155 |
156 CookieFetcher* cf = new CookieFetcher(&profile_, | 156 CookieFetcher* cf = new CookieFetcher(&profile_, |
(...skipping 26 matching lines...) Expand all Loading... |
183 IssueResponseHandler handler(NULL); | 183 IssueResponseHandler handler(NULL); |
184 std::string input("a\n"); | 184 std::string input("a\n"); |
185 std::string expected(IssueResponseHandler::kTokenAuthUrl); | 185 std::string expected(IssueResponseHandler::kTokenAuthUrl); |
186 expected.append(input); | 186 expected.append(input); |
187 | 187 |
188 scoped_ptr<URLFetcher> fetcher(handler.Handle(input, NULL)); | 188 scoped_ptr<URLFetcher> fetcher(handler.Handle(input, NULL)); |
189 EXPECT_EQ(expected, handler.token_url()); | 189 EXPECT_EQ(expected, handler.token_url()); |
190 } | 190 } |
191 | 191 |
192 } // namespace chromeos | 192 } // namespace chromeos |
OLD | NEW |