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

Unified Diff: components/signin/core/browser/signin_header_helper_unittest.cc

Issue 2923733003: [signin] Add DICe flow for account consistency requests. (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
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..d41c9783d7dd2699632bb333229b9f471a91edef 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,14 +137,42 @@ 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) {
msarda 2017/06/07 13:06:30 We must not pass the mirror header when mirror is
droger 2017/06/07 13:29:57 As said in other comments, this is the current beh
msarda 2017/06/08 02:53:38 You are correct. See my comments in the previous f
+ 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 that no DICe request is returned when the target is not a Gaia URL.
msarda 2017/06/07 13:06:31 Let's use Dice (or dice) and not DICe when referri
+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);
+}
+
// 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 +190,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.

Powered by Google App Engine
This is Rietveld 408576698