| 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..4c0ef5de2a1949a2efe99ebad0822ff86d4e01bc 100644
|
| --- a/components/signin/core/browser/signin_header_helper_unittest.cc
|
| +++ b/components/signin/core/browser/signin_header_helper_unittest.cc
|
| @@ -2,14 +2,18 @@
|
| // 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/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"
|
| @@ -39,9 +43,11 @@ class SigninHeaderHelperTest : public testing::Test {
|
| expected_request);
|
| }
|
|
|
| - void CheckMirrorHeaderRequest(const GURL& url,
|
| - const std::string& account_id,
|
| - const std::string& expected_request) {
|
| + void CheckAccountConsistencyHeaderRequest(
|
| + const GURL& url,
|
| + const std::string& account_id,
|
| + const char* header_name,
|
| + const std::string& expected_request) {
|
| bool expected_result = !expected_request.empty();
|
| std::unique_ptr<net::URLRequest> url_request =
|
| url_request_context_.CreateRequest(url, net::DEFAULT_PRIORITY, nullptr,
|
| @@ -51,14 +57,27 @@ class SigninHeaderHelperTest : public testing::Test {
|
| signin::PROFILE_MODE_DEFAULT),
|
| expected_result);
|
| 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) {
|
| + return CheckAccountConsistencyHeaderRequest(
|
| + url, account_id, signin::kChromeConnectedHeader, expected_request);
|
| + }
|
| +
|
| + void CheckDiceHeaderRequest(const GURL& url,
|
| + const std::string& expected_request) {
|
| + return CheckAccountConsistencyHeaderRequest(
|
| + url, "", signin::kChromeIDConsistencyRequestHeader, expected_request);
|
| + }
|
| +
|
| base::MessageLoop loop_;
|
|
|
| sync_preferences::TestingPrefServiceSyncable prefs_;
|
| @@ -118,6 +137,37 @@ TEST_F(SigninHeaderHelperTest, TestMirrorRequestGoogleCom) {
|
| "id=0123456789:mode=0:enable_account_consistency=true");
|
| }
|
|
|
| +// 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");
|
| +}
|
| +
|
| +// DICe is only supported on desktop.
|
| +#if !defined(OS_ANDROID) && !defined(OS_IOS)
|
| +// Tests that no DICe request is returned when the target is not a Gaia URL.
|
| +TEST_F(SigninHeaderHelperTest, TestNoDiceRequestNoGaiaURL) {
|
| + switches::EnableAccountConsistencyDiceForTesting(
|
| + base::CommandLine::ForCurrentProcess());
|
| + CheckDiceHeaderRequest(GURL("https://docs.google.com"), "");
|
| +}
|
| +
|
| +// Tests that a DICe request is returned when the target is a Gaia URL.
|
| +TEST_F(SigninHeaderHelperTest, TestDiceRequestGaiaURL) {
|
| + switches::EnableAccountConsistencyDiceForTesting(
|
| + base::CommandLine::ForCurrentProcess());
|
| + std::string client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
|
| + ASSERT_FALSE(client_id.empty());
|
| + CheckDiceHeaderRequest(GURL("https://accounts.google.com"),
|
| + "client_id=" + client_id);
|
| +}
|
| +#endif
|
| +
|
| // Tests that the Mirror request is returned with the GAIA Id on Drive origin,
|
| // even if account consistency is disabled.
|
| //
|
| @@ -125,7 +175,7 @@ TEST_F(SigninHeaderHelperTest, TestMirrorRequestGoogleCom) {
|
| // 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");
|
|
|