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

Side by Side Diff: google_apis/gaia/fake_gaia.h

Issue 1141163002: Browser tests for the new way of handling device ID in Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@device_id
Patch Set: Comments addressed. Created 5 years, 7 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | google_apis/gaia/fake_gaia.cc » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef GOOGLE_APIS_GAIA_FAKE_GAIA_H_ 5 #ifndef GOOGLE_APIS_GAIA_FAKE_GAIA_H_
6 #define GOOGLE_APIS_GAIA_FAKE_GAIA_H_ 6 #define GOOGLE_APIS_GAIA_FAKE_GAIA_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 13 matching lines...) Expand all
24 struct HttpRequest; 24 struct HttpRequest;
25 class HttpResponse; 25 class HttpResponse;
26 } 26 }
27 } 27 }
28 28
29 // This is a test helper that implements a fake GAIA service for use in browser 29 // This is a test helper that implements a fake GAIA service for use in browser
30 // tests. It's mainly intended for use with EmbeddedTestServer, for which it can 30 // tests. It's mainly intended for use with EmbeddedTestServer, for which it can
31 // be registered as an additional request handler. 31 // be registered as an additional request handler.
32 class FakeGaia { 32 class FakeGaia {
33 public: 33 public:
34 typedef std::set<std::string> ScopeSet; 34 using ScopeSet = std::set<std::string>;
35 using RefreshTokenToDeviceIdMap = std::map<std::string, std::string>;
35 36
36 // Access token details used for token minting and the token info endpoint. 37 // Access token details used for token minting and the token info endpoint.
37 struct AccessTokenInfo { 38 struct AccessTokenInfo {
38 AccessTokenInfo(); 39 AccessTokenInfo();
39 ~AccessTokenInfo(); 40 ~AccessTokenInfo();
40 41
41 std::string token; 42 std::string token;
42 std::string issued_to; 43 std::string issued_to;
43 std::string audience; 44 std::string audience;
44 std::string user_id; 45 std::string user_id;
45 ScopeSet scopes; 46 ScopeSet scopes;
46 int expires_in; 47 int expires_in;
47 std::string email; 48 std::string email;
48 }; 49 };
49 50
50 // Cookies and tokens for /MergeSession call seqeunce. 51 // Cookies and tokens for /MergeSession call seqeunce.
51 struct MergeSessionParams { 52 struct MergeSessionParams {
52 MergeSessionParams(); 53 MergeSessionParams();
53 ~MergeSessionParams(); 54 ~MergeSessionParams();
54 55
56 // Updates params with non-empty values from |params|.
57 void Update(const MergeSessionParams& params);
58
55 // Values of SID and LSID cookie that are set by /ServiceLoginAuth or its 59 // Values of SID and LSID cookie that are set by /ServiceLoginAuth or its
56 // equivalent at the end of the SAML login flow. 60 // equivalent at the end of the SAML login flow.
57 std::string auth_sid_cookie; 61 std::string auth_sid_cookie;
58 std::string auth_lsid_cookie; 62 std::string auth_lsid_cookie;
59 63
60 // auth_code cookie value response for /o/oauth2/programmatic_auth call. 64 // auth_code cookie value response for /o/oauth2/programmatic_auth call.
61 std::string auth_code; 65 std::string auth_code;
62 66
63 // OAuth2 refresh and access token generated by /o/oauth2/token call 67 // OAuth2 refresh and access token generated by /o/oauth2/token call
64 // with "...&grant_type=authorization_code". 68 // with "...&grant_type=authorization_code".
(...skipping 14 matching lines...) Expand all
79 FakeGaia(); 83 FakeGaia();
80 virtual ~FakeGaia(); 84 virtual ~FakeGaia();
81 85
82 void SetFakeMergeSessionParams(const std::string& email, 86 void SetFakeMergeSessionParams(const std::string& email,
83 const std::string& auth_sid_cookie, 87 const std::string& auth_sid_cookie,
84 const std::string& auth_lsid_cookie); 88 const std::string& auth_lsid_cookie);
85 89
86 // Sets the initial value of tokens and cookies. 90 // Sets the initial value of tokens and cookies.
87 void SetMergeSessionParams(const MergeSessionParams& params); 91 void SetMergeSessionParams(const MergeSessionParams& params);
88 92
93 // Updates various params with non-empty values from |params|.
94 void UpdateMergeSessionParams(const MergeSessionParams& params);
95
89 // Sets the specified |gaia_id| as corresponding to the given |email| 96 // Sets the specified |gaia_id| as corresponding to the given |email|
90 // address when setting GAIA response headers. If no mapping is given for 97 // address when setting GAIA response headers. If no mapping is given for
91 // an email address, a default GAIA Id is used. 98 // an email address, a default GAIA Id is used.
92 void MapEmailToGaiaId(const std::string& email, const std::string& gaia_id); 99 void MapEmailToGaiaId(const std::string& email, const std::string& gaia_id);
93 100
94 // Initializes HTTP request handlers. Should be called after switches 101 // Initializes HTTP request handlers. Should be called after switches
95 // for tweaking GaiaUrls are in place. 102 // for tweaking GaiaUrls are in place.
96 void Initialize(); 103 void Initialize();
97 104
98 // Handles a request and returns a response if the request was recognized as a 105 // Handles a request and returns a response if the request was recognized as a
(...skipping 16 matching lines...) Expand all
115 122
116 void set_issue_oauth_code_cookie(bool value) { 123 void set_issue_oauth_code_cookie(bool value) {
117 issue_oauth_code_cookie_ = value; 124 issue_oauth_code_cookie_ = value;
118 } 125 }
119 126
120 // Extracts the parameter named |key| from |query| and places it in |value|. 127 // Extracts the parameter named |key| from |query| and places it in |value|.
121 // Returns false if no parameter is found. 128 // Returns false if no parameter is found.
122 static bool GetQueryParameter(const std::string& query, 129 static bool GetQueryParameter(const std::string& query,
123 const std::string& key, 130 const std::string& key,
124 std::string* value); 131 std::string* value);
132
133 // Returns a device ID associated with a given |refresh_token|.
134 std::string GetDeviceIdByRefreshToken(const std::string& refresh_token) const;
135
136 void SetRefreshTokenToDeviceIdMap(
137 const RefreshTokenToDeviceIdMap& refresh_token_to_device_id_map);
138
139 const RefreshTokenToDeviceIdMap& refresh_token_to_device_id_map() const {
140 return refresh_token_to_device_id_map_;
141 }
142
125 protected: 143 protected:
126 // HTTP handler for /MergeSession. 144 // HTTP handler for /MergeSession.
127 virtual void HandleMergeSession( 145 virtual void HandleMergeSession(
128 const net::test_server::HttpRequest& request, 146 const net::test_server::HttpRequest& request,
129 net::test_server::BasicHttpResponse* http_response); 147 net::test_server::BasicHttpResponse* http_response);
130 148
131 private: 149 private:
132 typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap; 150 typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap;
133 typedef std::map<std::string, std::string> EmailToGaiaIdMap; 151 typedef std::map<std::string, std::string> EmailToGaiaIdMap;
134 typedef std::map<std::string, GURL> SamlAccountIdpMap; 152 typedef std::map<std::string, GURL> SamlAccountIdpMap;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 const std::string& access_token) const; 221 const std::string& access_token) const;
204 222
205 MergeSessionParams merge_session_params_; 223 MergeSessionParams merge_session_params_;
206 EmailToGaiaIdMap email_to_gaia_id_map_; 224 EmailToGaiaIdMap email_to_gaia_id_map_;
207 AccessTokenInfoMap access_token_info_map_; 225 AccessTokenInfoMap access_token_info_map_;
208 RequestHandlerMap request_handlers_; 226 RequestHandlerMap request_handlers_;
209 std::string service_login_response_; 227 std::string service_login_response_;
210 std::string embedded_setup_chromeos_response_; 228 std::string embedded_setup_chromeos_response_;
211 SamlAccountIdpMap saml_account_idp_map_; 229 SamlAccountIdpMap saml_account_idp_map_;
212 bool issue_oauth_code_cookie_; 230 bool issue_oauth_code_cookie_;
231 RefreshTokenToDeviceIdMap refresh_token_to_device_id_map_;
213 232
214 DISALLOW_COPY_AND_ASSIGN(FakeGaia); 233 DISALLOW_COPY_AND_ASSIGN(FakeGaia);
215 }; 234 };
216 235
217 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_ 236 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | google_apis/gaia/fake_gaia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698