OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/signin/core/browser/signin_header_helper.h" | 5 #include "components/signin/core/browser/signin_header_helper.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "build/build_config.h" | |
14 #include "components/content_settings/core/browser/cookie_settings.h" | 13 #include "components/content_settings/core/browser/cookie_settings.h" |
15 #include "components/signin/core/browser/chrome_connected_header_helper.h" | 14 #include "components/signin/core/browser/chrome_connected_header_helper.h" |
16 #include "components/signin/core/common/profile_management_switches.h" | 15 #include "components/signin/core/common/profile_management_switches.h" |
| 16 #include "components/signin/core/common/signin_features.h" |
17 #include "components/sync_preferences/testing_pref_service_syncable.h" | 17 #include "components/sync_preferences/testing_pref_service_syncable.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 18 #include "google_apis/gaia/gaia_urls.h" |
19 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 19 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
20 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 24 #if BUILDFLAG(ENABLE_DICE_SUPPORT) |
25 #include "components/signin/core/browser/dice_header_helper.h" | 25 #include "components/signin/core/browser/dice_header_helper.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace signin { | 28 namespace signin { |
29 | 29 |
30 class SigninHeaderHelperTest : public testing::Test { | 30 class SigninHeaderHelperTest : public testing::Test { |
31 protected: | 31 protected: |
32 void SetUp() override { | 32 void SetUp() override { |
33 content_settings::CookieSettings::RegisterProfilePrefs(prefs_.registry()); | 33 content_settings::CookieSettings::RegisterProfilePrefs(prefs_.registry()); |
34 HostContentSettingsMap::RegisterProfilePrefs(prefs_.registry()); | 34 HostContentSettingsMap::RegisterProfilePrefs(prefs_.registry()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 void CheckMirrorHeaderRequest(const GURL& url, | 80 void CheckMirrorHeaderRequest(const GURL& url, |
81 const std::string& account_id, | 81 const std::string& account_id, |
82 const std::string& expected_request) { | 82 const std::string& expected_request) { |
83 std::unique_ptr<net::URLRequest> url_request = | 83 std::unique_ptr<net::URLRequest> url_request = |
84 CreateRequest(url, account_id, false /* sync_enabled */); | 84 CreateRequest(url, account_id, false /* sync_enabled */); |
85 CheckAccountConsistencyHeaderRequest( | 85 CheckAccountConsistencyHeaderRequest( |
86 url_request.get(), kChromeConnectedHeader, expected_request); | 86 url_request.get(), kChromeConnectedHeader, expected_request); |
87 } | 87 } |
88 | 88 |
89 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 89 #if BUILDFLAG(ENABLE_DICE_SUPPORT) |
90 void CheckDiceHeaderRequest(const GURL& url, | 90 void CheckDiceHeaderRequest(const GURL& url, |
91 const std::string& account_id, | 91 const std::string& account_id, |
92 bool sync_enabled, | 92 bool sync_enabled, |
93 const std::string& expected_mirror_request, | 93 const std::string& expected_mirror_request, |
94 const std::string& expected_dice_request) { | 94 const std::string& expected_dice_request) { |
95 std::unique_ptr<net::URLRequest> url_request = | 95 std::unique_ptr<net::URLRequest> url_request = |
96 CreateRequest(url, account_id, sync_enabled); | 96 CreateRequest(url, account_id, sync_enabled); |
97 CheckAccountConsistencyHeaderRequest( | 97 CheckAccountConsistencyHeaderRequest( |
98 url_request.get(), kChromeConnectedHeader, expected_mirror_request); | 98 url_request.get(), kChromeConnectedHeader, expected_mirror_request); |
99 CheckAccountConsistencyHeaderRequest(url_request.get(), kDiceRequestHeader, | 99 CheckAccountConsistencyHeaderRequest(url_request.get(), kDiceRequestHeader, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 base::CommandLine::ForCurrentProcess()); | 155 base::CommandLine::ForCurrentProcess()); |
156 CheckMirrorHeaderRequest(GURL("https://www.google.com"), "0123456789", | 156 CheckMirrorHeaderRequest(GURL("https://www.google.com"), "0123456789", |
157 "mode=0,enable_account_consistency=true"); | 157 "mode=0,enable_account_consistency=true"); |
158 CheckMirrorCookieRequest( | 158 CheckMirrorCookieRequest( |
159 GURL("https://www.google.com"), "0123456789", | 159 GURL("https://www.google.com"), "0123456789", |
160 "id=0123456789:mode=0:enable_account_consistency=true"); | 160 "id=0123456789:mode=0:enable_account_consistency=true"); |
161 } | 161 } |
162 | 162 |
163 // Mirror is always enabled on Android and iOS, so these tests are only relevant | 163 // Mirror is always enabled on Android and iOS, so these tests are only relevant |
164 // on Desktop. | 164 // on Desktop. |
165 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 165 #if BUILDFLAG(ENABLE_DICE_SUPPORT) |
166 | 166 |
167 // Tests that the Mirror request is returned when the target is a Gaia URL, even | 167 // Tests that the Mirror request is returned when the target is a Gaia URL, even |
168 // if account consistency is disabled. | 168 // if account consistency is disabled. |
169 TEST_F(SigninHeaderHelperTest, TestMirrorRequestGaiaURL) { | 169 TEST_F(SigninHeaderHelperTest, TestMirrorRequestGaiaURL) { |
170 ASSERT_FALSE(switches::IsAccountConsistencyMirrorEnabled()); | 170 ASSERT_FALSE(switches::IsAccountConsistencyMirrorEnabled()); |
171 CheckMirrorHeaderRequest(GURL("https://accounts.google.com"), "0123456789", | 171 CheckMirrorHeaderRequest(GURL("https://accounts.google.com"), "0123456789", |
172 "mode=0,enable_account_consistency=false"); | 172 "mode=0,enable_account_consistency=false"); |
173 CheckMirrorCookieRequest( | 173 CheckMirrorCookieRequest( |
174 GURL("https://accounts.google.com"), "0123456789", | 174 GURL("https://accounts.google.com"), "0123456789", |
175 "id=0123456789:mode=0:enable_account_consistency=false"); | 175 "id=0123456789:mode=0:enable_account_consistency=false"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 280 |
281 { | 281 { |
282 // Missing non-optional field (email). | 282 // Missing non-optional field (email). |
283 DiceResponseParams params = BuildDiceResponseParams(base::StringPrintf( | 283 DiceResponseParams params = BuildDiceResponseParams(base::StringPrintf( |
284 "action=SIGNIN,id=%s,authuser=%i,authorization_code=%s", | 284 "action=SIGNIN,id=%s,authuser=%i,authorization_code=%s", |
285 kObfuscatedGaiaID, kSessionIndex, kAuthorizationCode)); | 285 kObfuscatedGaiaID, kSessionIndex, kAuthorizationCode)); |
286 EXPECT_EQ(DiceAction::NONE, params.user_intention); | 286 EXPECT_EQ(DiceAction::NONE, params.user_intention); |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 290 #endif // BUILDFLAG(ENABLE_DICE_SUPPORT) |
291 | 291 |
292 // Tests that the Mirror header request is returned normally when the redirect | 292 // Tests that the Mirror header request is returned normally when the redirect |
293 // URL is eligible. | 293 // URL is eligible. |
294 TEST_F(SigninHeaderHelperTest, TestMirrorHeaderEligibleRedirectURL) { | 294 TEST_F(SigninHeaderHelperTest, TestMirrorHeaderEligibleRedirectURL) { |
295 switches::EnableAccountConsistencyMirrorForTesting( | 295 switches::EnableAccountConsistencyMirrorForTesting( |
296 base::CommandLine::ForCurrentProcess()); | 296 base::CommandLine::ForCurrentProcess()); |
297 const GURL url("https://docs.google.com/document"); | 297 const GURL url("https://docs.google.com/document"); |
298 const GURL redirect_url("https://www.google.com"); | 298 const GURL redirect_url("https://www.google.com"); |
299 const std::string account_id = "0123456789"; | 299 const std::string account_id = "0123456789"; |
300 std::unique_ptr<net::URLRequest> url_request = | 300 std::unique_ptr<net::URLRequest> url_request = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 "action=REAUTH,email=%s,is_saml=true,is_same_tab=true,continue_url=%s", | 361 "action=REAUTH,email=%s,is_saml=true,is_same_tab=true,continue_url=%s", |
362 kEmail, kContinueURL)); | 362 kEmail, kContinueURL)); |
363 EXPECT_EQ(GAIA_SERVICE_TYPE_REAUTH, params.service_type); | 363 EXPECT_EQ(GAIA_SERVICE_TYPE_REAUTH, params.service_type); |
364 EXPECT_EQ(kEmail, params.email); | 364 EXPECT_EQ(kEmail, params.email); |
365 EXPECT_EQ(true, params.is_saml); | 365 EXPECT_EQ(true, params.is_saml); |
366 EXPECT_EQ(true, params.is_same_tab); | 366 EXPECT_EQ(true, params.is_same_tab); |
367 EXPECT_EQ(GURL(kContinueURL), params.continue_url); | 367 EXPECT_EQ(GURL(kContinueURL), params.continue_url); |
368 } | 368 } |
369 | 369 |
370 } // namespace signin | 370 } // namespace signin |
OLD | NEW |