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

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
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/extensions/api/identity/identity_api.h" 6 #include "chrome/browser/extensions/api/identity/identity_api.h"
6 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 7 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
8 #include "chrome/common/net/gaia/google_service_auth_error.h" 11 #include "chrome/common/net/gaia/google_service_auth_error.h"
9 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h" 12 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h"
10 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h"
11 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 using testing::ReturnRef;
20
21 namespace utils = extension_function_test_utils;
12 22
13 namespace { 23 namespace {
14 24
15 class IdentityInterceptor : public OAuth2MintTokenFlow::InterceptorForTests { 25 class IdentityInterceptor : public OAuth2MintTokenFlow::InterceptorForTests {
16 public: 26 public:
17 IdentityInterceptor() : called_(false) { } 27 IdentityInterceptor() : called_(false) { }
18 28
19 virtual bool DoIntercept(const OAuth2MintTokenFlow* flow, 29 virtual bool DoIntercept(const OAuth2MintTokenFlow* flow,
20 std::string* access_token, 30 std::string* access_token,
21 GoogleServiceAuthError* error) OVERRIDE { 31 GoogleServiceAuthError* error) OVERRIDE {
(...skipping 17 matching lines...) Expand all
39 called_ = true; 49 called_ = true;
40 return GURL("https://abcd.chromiumapp.org/cb#access_token=tok"); 50 return GURL("https://abcd.chromiumapp.org/cb#access_token=tok");
41 } 51 }
42 52
43 bool called() const { return called_; } 53 bool called() const { return called_; }
44 54
45 private: 55 private:
46 bool called_; 56 bool called_;
47 }; 57 };
48 58
59 class MockGetAuthTokenFunction : public extensions::GetAuthTokenFunction {
60 public:
61 void ShowLoginPopup() {
62 // Do nothing in tests.
63 }
64 MOCK_CONST_METHOD0(HasLoginToken, bool ());
65 MOCK_CONST_METHOD0(GetOAuth2Info,
66 const extensions::Extension::OAuth2Info& ());
67 };
68
49 } // namespace 69 } // namespace
50 70
51 IN_PROC_BROWSER_TEST_F(PlatformAppApiTest, Identity) { 71 IN_PROC_BROWSER_TEST_F(PlatformAppApiTest, Identity) {
52 IdentityInterceptor id_interceptor; 72 IdentityInterceptor id_interceptor;
53 OAuth2MintTokenFlow::SetInterceptorForTests(&id_interceptor); 73 OAuth2MintTokenFlow::SetInterceptorForTests(&id_interceptor);
54 WebAuthFlowInterceptor waf_interceptor; 74 WebAuthFlowInterceptor waf_interceptor;
55 extensions::WebAuthFlow::SetInterceptorForTests(&waf_interceptor); 75 extensions::WebAuthFlow::SetInterceptorForTests(&waf_interceptor);
56 ASSERT_TRUE(RunExtensionTest("identity")) << message_; 76 ASSERT_TRUE(RunExtensionTest("identity")) << message_;
57 ASSERT_TRUE(id_interceptor.called()); 77 ASSERT_TRUE(id_interceptor.called());
58 ASSERT_TRUE(waf_interceptor.called()); 78 ASSERT_TRUE(waf_interceptor.called());
59 }; 79 };
80
81 IN_PROC_BROWSER_TEST_F(PlatformAppApiTest, GetAuthToken) {
82 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
83 extensions::Extension::OAuth2Info oauth2_info;
84 ON_CALL(*func.get(), GetOAuth2Info()).WillByDefault(ReturnRef(oauth2_info));
85 // Without a callback the function will not generate a result.
86 func->set_has_callback(true);
87 std::string error = utils::RunFunctionAndReturnError(
88 func.get(), "[]", browser());
89 // scoped_ptr<base::Value> result(utils::RunFunctionAndReturnResult(
90 // func.get(), "{}", browser()));
91 }
92
93
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698