OLD | NEW |
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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/api/identity/identity_api.h" | 10 #include "chrome/browser/extensions/api/identity/identity_api.h" |
11 #include "chrome/browser/extensions/component_loader.h" | 11 #include "chrome/browser/extensions/component_loader.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_function_test_utils.h" | 14 #include "chrome/browser/extensions/extension_function_test_utils.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 17 #include "chrome/browser/signin/signin_manager.h" |
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | 22 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
23 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
24 #include "chrome/test/base/test_switches.h" | 24 #include "chrome/test/base/test_switches.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
28 #include "extensions/common/id_util.h" | 28 #include "extensions/common/id_util.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 oauth2_info.scopes.end()); | 364 oauth2_info.scopes.end()); |
365 return ext; | 365 return ext; |
366 } | 366 } |
367 | 367 |
368 IdentityAPI* id_api() { | 368 IdentityAPI* id_api() { |
369 return IdentityAPI::GetFactoryInstance()->GetForProfile( | 369 return IdentityAPI::GetFactoryInstance()->GetForProfile( |
370 browser()->profile()); | 370 browser()->profile()); |
371 } | 371 } |
372 | 372 |
373 const std::string GetPrimaryAccountId() { | 373 const std::string GetPrimaryAccountId() { |
374 ProfileOAuth2TokenService* token_service = | 374 SigninManagerBase* signin_manager = |
375 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); | 375 SigninManagerFactory::GetForProfile(browser()->profile()); |
376 return token_service->GetPrimaryAccountId(); | 376 return signin_manager->GetAuthenticatedAccountId(); |
377 } | 377 } |
378 | 378 |
379 void SetCachedToken(const IdentityTokenCacheValue& token_data) { | 379 void SetCachedToken(const IdentityTokenCacheValue& token_data) { |
380 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); | 380 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); |
381 id_api()->SetCachedToken(key, token_data); | 381 id_api()->SetCachedToken(key, token_data); |
382 } | 382 } |
383 | 383 |
384 const IdentityTokenCacheValue& GetCachedToken() { | 384 const IdentityTokenCacheValue& GetCachedToken() { |
385 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); | 385 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); |
386 return id_api()->GetCachedToken(key); | 386 return id_api()->GetCachedToken(key); |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1244 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1245 url); | 1245 url); |
1246 } | 1246 } |
1247 | 1247 |
1248 } // namespace extensions | 1248 } // namespace extensions |
1249 | 1249 |
1250 // Tests the chrome.identity API implemented by custom JS bindings . | 1250 // Tests the chrome.identity API implemented by custom JS bindings . |
1251 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1251 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
1252 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1252 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
1253 } | 1253 } |
OLD | NEW |