| Index: components/signin/core/browser/signin_header_helper_unittest.cc
|
| diff --git a/components/signin/core/browser/signin_header_helper_unittest.cc b/components/signin/core/browser/signin_header_helper_unittest.cc
|
| index 92f4f29de941c04f2c075771bb0227d3b431eb49..a0433c6fc6680c9ef3e5a48efcaa1ba07c543295 100644
|
| --- a/components/signin/core/browser/signin_header_helper_unittest.cc
|
| +++ b/components/signin/core/browser/signin_header_helper_unittest.cc
|
| @@ -2,19 +2,28 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "components/signin/core/browser/signin_header_helper.h"
|
| +
|
| #include <memory>
|
| +#include <string>
|
|
|
| #include "base/command_line.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "build/build_config.h"
|
| #include "components/content_settings/core/browser/cookie_settings.h"
|
| -#include "components/signin/core/browser/signin_header_helper.h"
|
| +#include "components/signin/core/browser/chrome_connected_header_helper.h"
|
| #include "components/signin/core/common/profile_management_switches.h"
|
| #include "components/sync_preferences/testing_pref_service_syncable.h"
|
| +#include "google_apis/gaia/gaia_urls.h"
|
| #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| +#if !defined(OS_IOS) && !defined(OS_ANDROID)
|
| +#include "components/signin/core/browser/dice_header_helper.h"
|
| +#endif
|
| +
|
| class SigninHeaderHelperTest : public testing::Test {
|
| protected:
|
| void SetUp() override {
|
| @@ -39,26 +48,56 @@ class SigninHeaderHelperTest : public testing::Test {
|
| expected_request);
|
| }
|
|
|
| - void CheckMirrorHeaderRequest(const GURL& url,
|
| - const std::string& account_id,
|
| - const std::string& expected_request) {
|
| - bool expected_result = !expected_request.empty();
|
| + std::unique_ptr<net::URLRequest> CreateRequest(
|
| + const GURL& url,
|
| + const std::string& account_id) {
|
| std::unique_ptr<net::URLRequest> url_request =
|
| url_request_context_.CreateRequest(url, net::DEFAULT_PRIORITY, nullptr,
|
| TRAFFIC_ANNOTATION_FOR_TESTS);
|
| - EXPECT_EQ(signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| - url_request.get(), GURL(), account_id, cookie_settings_.get(),
|
| - signin::PROFILE_MODE_DEFAULT),
|
| - expected_result);
|
| + signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| + url_request.get(), GURL(), account_id, cookie_settings_.get(),
|
| + signin::PROFILE_MODE_DEFAULT);
|
| + return url_request;
|
| + }
|
| +
|
| + void CheckAccountConsistencyHeaderRequest(
|
| + net::URLRequest* url_request,
|
| + const char* header_name,
|
| + const std::string& expected_request) {
|
| + bool expected_result = !expected_request.empty();
|
| std::string request;
|
| - EXPECT_EQ(url_request->extra_request_headers().GetHeader(
|
| - signin::kChromeConnectedHeader, &request),
|
| - expected_result);
|
| + EXPECT_EQ(
|
| + url_request->extra_request_headers().GetHeader(header_name, &request),
|
| + expected_result);
|
| if (expected_result) {
|
| EXPECT_EQ(expected_request, request);
|
| }
|
| }
|
|
|
| + void CheckMirrorHeaderRequest(const GURL& url,
|
| + const std::string& account_id,
|
| + const std::string& expected_request) {
|
| + std::unique_ptr<net::URLRequest> url_request =
|
| + CreateRequest(url, account_id);
|
| + CheckAccountConsistencyHeaderRequest(
|
| + url_request.get(), signin::kChromeConnectedHeader, expected_request);
|
| + }
|
| +
|
| +#if !defined(OS_IOS) && !defined(OS_ANDROID)
|
| + void CheckDiceHeaderRequest(const GURL& url,
|
| + const std::string& account_id,
|
| + const std::string& expected_mirror_request,
|
| + const std::string& expected_dice_request) {
|
| + std::unique_ptr<net::URLRequest> url_request =
|
| + CreateRequest(url, account_id);
|
| + CheckAccountConsistencyHeaderRequest(url_request.get(),
|
| + signin::kChromeConnectedHeader,
|
| + expected_mirror_request);
|
| + CheckAccountConsistencyHeaderRequest(
|
| + url_request.get(), signin::kDiceRequestHeader, expected_dice_request);
|
| + }
|
| +#endif
|
| +
|
| base::MessageLoop loop_;
|
|
|
| sync_preferences::TestingPrefServiceSyncable prefs_;
|
| @@ -118,14 +157,53 @@ TEST_F(SigninHeaderHelperTest, TestMirrorRequestGoogleCom) {
|
| "id=0123456789:mode=0:enable_account_consistency=true");
|
| }
|
|
|
| +// Mirror is always enabled on Android and iOS, so these tests are only relevant
|
| +// on Desktop.
|
| +#if !defined(OS_ANDROID) && !defined(OS_IOS)
|
| +
|
| +// Tests that the Mirror request is returned when the target is a Gaia URL, even
|
| +// if account consistency is disabled.
|
| +TEST_F(SigninHeaderHelperTest, TestMirrorRequestGaiaURL) {
|
| + ASSERT_FALSE(switches::IsAccountConsistencyMirrorEnabled());
|
| + CheckMirrorHeaderRequest(GURL("https://accounts.google.com"), "0123456789",
|
| + "mode=0,enable_account_consistency=false");
|
| + CheckMirrorCookieRequest(
|
| + GURL("https://accounts.google.com"), "0123456789",
|
| + "id=0123456789:mode=0:enable_account_consistency=false");
|
| +}
|
| +
|
| +// Tests Dice requests.
|
| +TEST_F(SigninHeaderHelperTest, TestDiceRequest) {
|
| + switches::EnableAccountConsistencyDiceForTesting(
|
| + base::CommandLine::ForCurrentProcess());
|
| + // ChromeConnected but no Dice for Docs URLs.
|
| + CheckDiceHeaderRequest(
|
| + GURL("https://docs.google.com"), "0123456789",
|
| + "id=0123456789,mode=0,enable_account_consistency=false", "");
|
| +
|
| + // ChromeConnected and Dice for Gaia URLs.
|
| + std::string client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
|
| + ASSERT_FALSE(client_id.empty());
|
| + CheckDiceHeaderRequest(GURL("https://accounts.google.com"), "0123456789",
|
| + "mode=0,enable_account_consistency=false",
|
| + "client_id=" + client_id);
|
| +
|
| + // No ChromeConnected and no Dice for other URLs.
|
| + CheckDiceHeaderRequest(GURL("https://www.google.com"), "0123456789", "", "");
|
| +}
|
| +
|
| +// Tests that no Dice request is returned when Dice is not enabled.
|
| +TEST_F(SigninHeaderHelperTest, TestNoDiceRequestWhenDisabled) {
|
| + switches::EnableAccountConsistencyMirrorForTesting(
|
| + base::CommandLine::ForCurrentProcess());
|
| + CheckDiceHeaderRequest(GURL("https://accounts.google.com"), "0123456789",
|
| + "mode=0,enable_account_consistency=true", "");
|
| +}
|
| +
|
| // Tests that the Mirror request is returned with the GAIA Id on Drive origin,
|
| // even if account consistency is disabled.
|
| -//
|
| -// Account consistency if always enabled on Android and iOS, so this test is
|
| -// only relevant on Desktop.
|
| -#if !defined(OS_ANDROID) && !defined(OS_IOS)
|
| TEST_F(SigninHeaderHelperTest, TestMirrorRequestDrive) {
|
| - DCHECK(!switches::IsAccountConsistencyMirrorEnabled());
|
| + ASSERT_FALSE(switches::IsAccountConsistencyMirrorEnabled());
|
| CheckMirrorHeaderRequest(
|
| GURL("https://docs.google.com/document"), "0123456789",
|
| "id=0123456789,mode=0,enable_account_consistency=false");
|
| @@ -143,7 +221,8 @@ TEST_F(SigninHeaderHelperTest, TestMirrorRequestDrive) {
|
| GURL("https://drive.google.com/drive"), "0123456789",
|
| "id=0123456789:mode=0:enable_account_consistency=true");
|
| }
|
| -#endif
|
| +
|
| +#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
|
|
|
| // Tests that the Mirror header request is returned normally when the redirect
|
| // URL is eligible.
|
| @@ -156,9 +235,9 @@ TEST_F(SigninHeaderHelperTest, TestMirrorHeaderEligibleRedirectURL) {
|
| std::unique_ptr<net::URLRequest> url_request =
|
| url_request_context_.CreateRequest(url, net::DEFAULT_PRIORITY, nullptr,
|
| TRAFFIC_ANNOTATION_FOR_TESTS);
|
| - EXPECT_TRUE(signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| + signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| url_request.get(), redirect_url, account_id, cookie_settings_.get(),
|
| - signin::PROFILE_MODE_DEFAULT));
|
| + signin::PROFILE_MODE_DEFAULT);
|
| EXPECT_TRUE(url_request->extra_request_headers().HasHeader(
|
| signin::kChromeConnectedHeader));
|
| }
|
| @@ -174,9 +253,9 @@ TEST_F(SigninHeaderHelperTest, TestMirrorHeaderNonEligibleRedirectURL) {
|
| std::unique_ptr<net::URLRequest> url_request =
|
| url_request_context_.CreateRequest(url, net::DEFAULT_PRIORITY, nullptr,
|
| TRAFFIC_ANNOTATION_FOR_TESTS);
|
| - EXPECT_FALSE(signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| + signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| url_request.get(), redirect_url, account_id, cookie_settings_.get(),
|
| - signin::PROFILE_MODE_DEFAULT));
|
| + signin::PROFILE_MODE_DEFAULT);
|
| EXPECT_FALSE(url_request->extra_request_headers().HasHeader(
|
| signin::kChromeConnectedHeader));
|
| }
|
| @@ -195,9 +274,9 @@ TEST_F(SigninHeaderHelperTest, TestIgnoreMirrorHeaderNonEligibleURLs) {
|
| TRAFFIC_ANNOTATION_FOR_TESTS);
|
| url_request->SetExtraRequestHeaderByName(signin::kChromeConnectedHeader,
|
| fake_header, false);
|
| - EXPECT_FALSE(signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| + signin::AppendOrRemoveAccountConsistentyRequestHeader(
|
| url_request.get(), redirect_url, account_id, cookie_settings_.get(),
|
| - signin::PROFILE_MODE_DEFAULT));
|
| + signin::PROFILE_MODE_DEFAULT);
|
| std::string header;
|
| EXPECT_TRUE(url_request->extra_request_headers().GetHeader(
|
| signin::kChromeConnectedHeader, &header));
|
|
|