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

Side by Side Diff: chrome/browser/extensions/api/identity/identity_apitest.cc

Issue 10701041: implement sign in dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
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/string_util.h"
6 #include "base/values.h"
5 #include "chrome/browser/extensions/api/identity/identity_api.h" 7 #include "chrome/browser/extensions/api/identity/identity_api.h"
6 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 8 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
8 #include "chrome/common/net/gaia/google_service_auth_error.h" 12 #include "chrome/common/net/gaia/google_service_auth_error.h"
9 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" 13 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h"
10 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/test/base/in_process_browser_test.h"
11 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 using extensions::GetAuthTokenFunction;
21 using testing::_;
22 using testing::Return;
23 using testing::ReturnRef;
24
25 namespace utils = extension_function_test_utils;
12 26
13 namespace { 27 namespace {
14 28
15 class IdentityInterceptor : public OAuth2MintTokenFlow::InterceptorForTests { 29 static const char kAccessToken[] = "auth_token";
Mihai Parparita -not on Chrome 2012/07/17 01:01:00 Can you remove the interceptor support from OAuth2
Munjal (Google) 2012/07/19 22:35:42 Let me do it in a separate patch. On 2012/07/17 0
Mihai Parparita -not on Chrome 2012/07/20 18:02:32 OK, filed http://crbug.com/138279
30
31 class TestLoginUI : public LoginUIService::LoginUI {
16 public: 32 public:
17 IdentityInterceptor() : called_(false) { } 33 virtual void FocusUI() OVERRIDE {}
18 34 virtual void CloseUI() OVERRIDE {}
19 virtual bool DoIntercept(const OAuth2MintTokenFlow* flow, 35 };
20 std::string* access_token, 36
21 GoogleServiceAuthError* error) OVERRIDE { 37 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow {
22 *access_token = "auth_token"; 38 public:
23 called_ = true; 39 enum ResultType {
24 return true; 40 ISSUE_ADVICE_SUCCESS,
25 } 41 MINT_TOKEN_SUCCESS,
26 42 MINT_TOKEN_FAILURE
27 bool called() const { return called_; } 43 };
44
45 TestOAuth2MintTokenFlow(ResultType result,
46 OAuth2MintTokenFlow::Delegate* delegate)
47 : OAuth2MintTokenFlow(NULL, delegate, OAuth2MintTokenFlow::Parameters()),
48 result_(result),
49 delegate_(delegate) {
50 }
51
52 virtual void Start() OVERRIDE {
53 switch (result_) {
54 case ISSUE_ADVICE_SUCCESS: {
55 IssueAdviceInfo info;
56 delegate_->OnIssueAdviceSuccess(info);
57 break;
58 }
59 case MINT_TOKEN_SUCCESS: {
60 delegate_->OnMintTokenSuccess(kAccessToken);
61 break;
62 }
63 case MINT_TOKEN_FAILURE: {
64 GoogleServiceAuthError error(
65 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
66 delegate_->OnMintTokenFailure(error);
67 break;
68 }
69 }
70 }
28 71
29 private: 72 private:
30 bool called_; 73 ResultType result_;
74 OAuth2MintTokenFlow::Delegate* delegate_;
31 }; 75 };
32 76
33 class WebAuthFlowInterceptor 77 } // namespace
34 : public extensions::WebAuthFlow::InterceptorForTests { 78
79 class MockGetAuthTokenFunction : public GetAuthTokenFunction {
35 public: 80 public:
36 WebAuthFlowInterceptor() : called_(false) { } 81 MockGetAuthTokenFunction() : install_ui_result_(false),
37 82 login_ui_shown_(false),
38 virtual GURL DoIntercept(const GURL& provider_url) OVERRIDE { 83 install_ui_shown_(false) {
39 called_ = true; 84 }
40 return GURL("https://abcd.chromiumapp.org/cb#access_token=tok"); 85
41 } 86 void set_install_ui_result(bool result) {
42 87 install_ui_result_ = result;
43 bool called() const { return called_; } 88 }
44 89
45 private: 90 bool login_ui_shown() const {
46 bool called_; 91 return login_ui_shown_;
92 }
93
94 bool install_ui_shown() const {
95 return install_ui_shown_;
96 }
97
98 virtual void StartObservingLoginService() OVERRIDE {
99 // Do nothing in tests.
100 }
101 virtual void StopObservingLoginService() OVERRIDE {
102 // Do nothing in tests.
103 }
104
105 virtual void ShowLoginPopup() OVERRIDE {
106 login_ui_shown_ = true;
107 // Explicitly call OnLoginUIClosed.
108 TestLoginUI login_ui;;
109 OnLoginUIClosed(&login_ui);
110 }
111
112 virtual void ShowOAuthApprovalDialog(
113 const IssueAdviceInfo& issue_advice) OVERRIDE {
114 install_ui_shown_ = true;
115 // Call InstallUIProceed or InstallUIAbort based on the flag.
116 if (install_ui_result_)
117 InstallUIProceed();
118 else
119 InstallUIAbort(true);
120 }
121
122 MOCK_CONST_METHOD0(HasLoginToken, bool ());
123 MOCK_CONST_METHOD0(GetExtensionId, const std::string& ());
124 MOCK_CONST_METHOD0(GetOAuth2Info,
125 const extensions::Extension::OAuth2Info& ());
126 MOCK_METHOD1(CreateMintTokenFlow,
127 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode));
128 private:
129 bool install_ui_result_;
130 bool login_ui_shown_;
131 bool install_ui_shown_;
47 }; 132 };
48 133
49 } // namespace 134 class GetAuthTokenFunctionTest : public InProcessBrowserTest {
50 135 protected:
51 IN_PROC_BROWSER_TEST_F(PlatformAppApiTest, Identity) { 136 void CallOnLoginUIClosed(GetAuthTokenFunction* func,
52 IdentityInterceptor id_interceptor; 137 LoginUIService::LoginUI* login_ui) {
53 OAuth2MintTokenFlow::SetInterceptorForTests(&id_interceptor); 138 func->OnLoginUIClosed(login_ui);
54 WebAuthFlowInterceptor waf_interceptor; 139 }
55 extensions::WebAuthFlow::SetInterceptorForTests(&waf_interceptor);
56 ASSERT_TRUE(RunExtensionTest("identity")) << message_;
57 ASSERT_TRUE(id_interceptor.called());
58 ASSERT_TRUE(waf_interceptor.called());
59 }; 140 };
141
142 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
143 NoClientId) {
144 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
145 extensions::Extension::OAuth2Info oauth2_info;
146 EXPECT_CALL(*func.get(), GetOAuth2Info())
147 .WillRepeatedly(ReturnRef(oauth2_info));
148 // Without a callback the function will not generate a result.
Mihai Parparita -not on Chrome 2012/07/17 01:01:00 Instead of having to repeat this every time, can y
Munjal (Google) 2012/07/19 22:35:42 Done.
149 func->set_has_callback(true);
150 std::string error = utils::RunFunctionAndReturnError(
151 func.get(), "[{}]", browser());
152 EXPECT_EQ(std::string(GetAuthTokenFunction::kInvalidClientId),
153 error);
154 EXPECT_FALSE(func->login_ui_shown());
155 EXPECT_FALSE(func->install_ui_shown());
156 }
157
158 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
159 NoScopes) {
160 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
161 extensions::Extension::OAuth2Info oauth2_info;
162 oauth2_info.client_id = "abcdef";
163 EXPECT_CALL(*func.get(), GetOAuth2Info())
164 .WillRepeatedly(ReturnRef(oauth2_info));
165 // Without a callback the function will not generate a result.
166 func->set_has_callback(true);
167 std::string error = utils::RunFunctionAndReturnError(
168 func.get(), "[{}]", browser());
169 EXPECT_EQ(std::string(GetAuthTokenFunction::kInvalidScopes),
170 error);
171 EXPECT_FALSE(func->login_ui_shown());
172 EXPECT_FALSE(func->install_ui_shown());
173 }
174
175 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
176 NonInteractiveNotSignedIn) {
177 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
178 extensions::Extension::OAuth2Info oauth2_info;
179 oauth2_info.client_id = "abcdef";
180 oauth2_info.scopes.push_back("scope1");
181 oauth2_info.scopes.push_back("scope2");
182 EXPECT_CALL(*func.get(), GetOAuth2Info())
183 .WillRepeatedly(ReturnRef(oauth2_info));
184 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
185 // Without a callback the function will not generate a result.
186 func->set_has_callback(true);
187 std::string error = utils::RunFunctionAndReturnError(
188 func.get(), "[{}]", browser());
189 EXPECT_EQ(std::string(GetAuthTokenFunction::kUserNotSignedIn),
190 error);
191 EXPECT_FALSE(func->login_ui_shown());
192 EXPECT_FALSE(func->install_ui_shown());
193 }
194
195 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
196 NonInteractiveMintFailure) {
197 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
198 extensions::Extension::OAuth2Info oauth2_info;
199 oauth2_info.client_id = "abcdef";
200 oauth2_info.scopes.push_back("scope1");
201 oauth2_info.scopes.push_back("scope2");
202 EXPECT_CALL(*func.get(), GetOAuth2Info())
203 .WillRepeatedly(ReturnRef(oauth2_info));
204 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
205 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
206 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
207 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
208 // Without a callback the function will not generate a result.
209 func->set_has_callback(true);
210 std::string error = utils::RunFunctionAndReturnError(
211 func.get(), "[{}]", browser());
212 EXPECT_TRUE(StartsWithASCII(
213 error, GetAuthTokenFunction::kAuthFailure, false));
214 EXPECT_FALSE(func->login_ui_shown());
215 EXPECT_FALSE(func->install_ui_shown());
216 }
217
218 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
219 NonInteractiveSuccess) {
220 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
221 extensions::Extension::OAuth2Info oauth2_info;
222 oauth2_info.client_id = "abcdef";
223 oauth2_info.scopes.push_back("scope1");
224 oauth2_info.scopes.push_back("scope2");
225 EXPECT_CALL(*func.get(), GetOAuth2Info())
226 .WillRepeatedly(ReturnRef(oauth2_info));
227 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true));
228 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
229 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
230 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
231 // Without a callback the function will not generate a result.
232 func->set_has_callback(true);
233 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnResult(
234 func.get(), "[{}]", browser()));
235 std::string access_token;
236 EXPECT_TRUE(value->GetAsString(&access_token));
237 EXPECT_EQ(std::string(kAccessToken), access_token);
238 EXPECT_FALSE(func->login_ui_shown());
239 EXPECT_FALSE(func->install_ui_shown());
240 }
241
242 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
243 InteractiveLoginCanceled) {
244 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
245 extensions::Extension::OAuth2Info oauth2_info;
246 oauth2_info.client_id = "abcdef";
247 oauth2_info.scopes.push_back("scope1");
248 oauth2_info.scopes.push_back("scope2");
249 EXPECT_CALL(*func.get(), GetOAuth2Info())
250 .WillRepeatedly(ReturnRef(oauth2_info));
251 EXPECT_CALL(*func.get(), HasLoginToken()).WillRepeatedly(Return(false));
252 // Without a callback the function will not generate a result.
253 func->set_has_callback(true);
254 std::string error = utils::RunFunctionAndReturnError(
255 func.get(), "[{\"interactive\": true}]", browser());
256 EXPECT_EQ(std::string(GetAuthTokenFunction::kUserNotSignedIn),
257 error);
258 EXPECT_TRUE(func->login_ui_shown());
259 EXPECT_FALSE(func->install_ui_shown());
260 }
261
262 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
263 InteractiveLoginSuccessMintFailure) {
264 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
265 extensions::Extension::OAuth2Info oauth2_info;
266 oauth2_info.client_id = "abcdef";
267 oauth2_info.scopes.push_back("scope1");
268 oauth2_info.scopes.push_back("scope2");
269 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
270 ReturnRef(oauth2_info));
271 EXPECT_CALL(*func.get(), HasLoginToken())
272 .WillOnce(Return(false))
273 .WillOnce(Return(true));
274 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
275 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
276 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
277 // Without a callback the function will not generate a result.
278 func->set_has_callback(true);
279 std::string error = utils::RunFunctionAndReturnError(
280 func.get(), "[{\"interactive\": true}]", browser());
281 EXPECT_TRUE(StartsWithASCII(
282 error, GetAuthTokenFunction::kAuthFailure, false));
283 EXPECT_TRUE(func->login_ui_shown());
284 EXPECT_FALSE(func->install_ui_shown());
285 }
286
287 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
288 InteractiveLoginSuccessMintSuccess) {
289 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
290 extensions::Extension::OAuth2Info oauth2_info;
291 oauth2_info.client_id = "abcdef";
292 oauth2_info.scopes.push_back("scope1");
293 oauth2_info.scopes.push_back("scope2");
294 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
295 ReturnRef(oauth2_info));
296 EXPECT_CALL(*func.get(), HasLoginToken())
297 .WillOnce(Return(false))
298 .WillOnce(Return(true));
299 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
300 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
301 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
302 // Without a callback the function will not generate a result.
303 func->set_has_callback(true);
304 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnResult(
305 func.get(), "[{\"interactive\": true}]", browser()));
306 std::string access_token;
307 EXPECT_TRUE(value->GetAsString(&access_token));
308 EXPECT_EQ(std::string(kAccessToken), access_token);
309 EXPECT_TRUE(func->login_ui_shown());
310 EXPECT_FALSE(func->install_ui_shown());
311 }
312
313 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
314 InteractiveLoginSuccessApprovalAborted) {
315 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
316 extensions::Extension::OAuth2Info oauth2_info;
317 oauth2_info.client_id = "abcdef";
318 oauth2_info.scopes.push_back("scope1");
319 oauth2_info.scopes.push_back("scope2");
320 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
321 ReturnRef(oauth2_info));
322 EXPECT_CALL(*func.get(), HasLoginToken())
323 .WillOnce(Return(false))
324 .WillOnce(Return(true));
325 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
326 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
327 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
328 func->set_install_ui_result(false);
329 // Without a callback the function will not generate a result.
330 func->set_has_callback(true);
331 std::string error = utils::RunFunctionAndReturnError(
332 func.get(), "[{\"interactive\": true}]", browser());
333 EXPECT_EQ(std::string(GetAuthTokenFunction::kUserRejected), error);
334 EXPECT_TRUE(func->login_ui_shown());
335 EXPECT_TRUE(func->install_ui_shown());
336 }
337
338 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
339 InteractiveLoginSuccessApprovalDoneMintFailure) {
340 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
341 extensions::Extension::OAuth2Info oauth2_info;
342 oauth2_info.client_id = "abcdef";
343 oauth2_info.scopes.push_back("scope1");
344 oauth2_info.scopes.push_back("scope2");
345 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
346 ReturnRef(oauth2_info));
347 EXPECT_CALL(*func.get(), HasLoginToken())
348 .WillOnce(Return(false))
349 .WillOnce(Return(true))
350 .WillOnce(Return(true));
351 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
352 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
353 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
354 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
355 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
356 .WillOnce(Return(flow1))
357 .WillOnce(Return(flow2));
358
359 func->set_install_ui_result(true);
360 // Without a callback the function will not generate a result.
361 func->set_has_callback(true);
362 std::string error = utils::RunFunctionAndReturnError(
363 func.get(), "[{\"interactive\": true}]", browser());
364 EXPECT_TRUE(StartsWithASCII(
365 error, GetAuthTokenFunction::kAuthFailure, false));
366 EXPECT_TRUE(func->login_ui_shown());
367 EXPECT_TRUE(func->install_ui_shown());
368 }
369
370 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
371 InteractiveLoginSuccessApprovalDoneMintSuccess) {
372 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
373 extensions::Extension::OAuth2Info oauth2_info;
374 oauth2_info.client_id = "abcdef";
375 oauth2_info.scopes.push_back("scope1");
376 oauth2_info.scopes.push_back("scope2");
377 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
378 ReturnRef(oauth2_info));
379 EXPECT_CALL(*func.get(), HasLoginToken())
380 .WillOnce(Return(false))
381 .WillOnce(Return(true))
382 .WillOnce(Return(true));
383 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
384 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
385 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
386 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
387 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
388 .WillOnce(Return(flow1))
389 .WillOnce(Return(flow2));
390
391 func->set_install_ui_result(true);
392 // Without a callback the function will not generate a result.
393 func->set_has_callback(true);
394 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnResult(
395 func.get(), "[{\"interactive\": true}]", browser()));
396 std::string access_token;
397 EXPECT_TRUE(value->GetAsString(&access_token));
398 EXPECT_EQ(std::string(kAccessToken), access_token);
399 EXPECT_TRUE(func->login_ui_shown());
400 EXPECT_TRUE(func->install_ui_shown());
401 }
402
403 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
404 InteractiveApprovalAborted) {
405 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
406 extensions::Extension::OAuth2Info oauth2_info;
407 oauth2_info.client_id = "abcdef";
408 oauth2_info.scopes.push_back("scope1");
409 oauth2_info.scopes.push_back("scope2");
410 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
411 ReturnRef(oauth2_info));
412 EXPECT_CALL(*func.get(), HasLoginToken())
413 .WillOnce(Return(true))
414 .WillOnce(Return(true));
415 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
416 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
417 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
418 func->set_install_ui_result(false);
419 // Without a callback the function will not generate a result.
420 func->set_has_callback(true);
421 std::string error = utils::RunFunctionAndReturnError(
422 func.get(), "[{\"interactive\": true}]", browser());
423 EXPECT_EQ(std::string(GetAuthTokenFunction::kUserRejected), error);
424 EXPECT_FALSE(func->login_ui_shown());
425 EXPECT_TRUE(func->install_ui_shown());
426 }
427
428 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
429 InteractiveApprovalDoneMintSuccess) {
430 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
431 extensions::Extension::OAuth2Info oauth2_info;
432 oauth2_info.client_id = "abcdef";
433 oauth2_info.scopes.push_back("scope1");
434 oauth2_info.scopes.push_back("scope2");
435 EXPECT_CALL(*func.get(), GetOAuth2Info()).WillRepeatedly(
436 ReturnRef(oauth2_info));
437 EXPECT_CALL(*func.get(), HasLoginToken())
438 .WillOnce(Return(true))
439 .WillOnce(Return(true))
440 .WillOnce(Return(true));
441 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
442 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
443 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
444 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
445 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
446 .WillOnce(Return(flow1))
447 .WillOnce(Return(flow2));
448
449 func->set_install_ui_result(true);
450 // Without a callback the function will not generate a result.
451 func->set_has_callback(true);
452 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnResult(
453 func.get(), "[{\"interactive\": true}]", browser()));
454 std::string access_token;
455 EXPECT_TRUE(value->GetAsString(&access_token));
456 EXPECT_EQ(std::string(kAccessToken), access_token);
457 EXPECT_FALSE(func->login_ui_shown());
458 EXPECT_TRUE(func->install_ui_shown());
459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698