Commit 9b665b72 authored by Alex Ilin's avatar Alex Ilin Committed by Commit Bot

[Signin] Add live Signin test for turning off Sync

This CL adds a new test DemoSignInTest::TurnOffSync to the suite of live
Signin tests.

The test does the following:
- Turn on sync for Account A
- Sign in Account B from the web
- Check that Sync is enabled for Account A
- Turn sync off from the settings
- Check that both accounts are signed out from Chrome and the web

This CL also simplifies JavaScript code used to sign user in.

Fixed: 1006263
Change-Id: Idd901e5d2eaf55fe69fcbc41d304e25d9fd87ab9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893994Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712087}
parent 27fee9a5
...@@ -98,9 +98,7 @@ class DemoSignInTest : public signin::test::LiveTest { ...@@ -98,9 +98,7 @@ class DemoSignInTest : public signin::test::LiveTest {
auto* settings_tab = browser()->tab_strip_model()->GetActiveWebContents(); auto* settings_tab = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(content::ExecuteScript( EXPECT_TRUE(content::ExecuteScript(
settings_tab, settings_tab,
"testElement = document.createElement('settings-sync-account-control');" "settings.SyncBrowserProxyImpl.getInstance().startSignIn()"));
"document.body.appendChild(testElement);"
"testElement.$$('#sign-in').click();"));
SignInFromCurrentPage(test_account); SignInFromCurrentPage(test_account);
} }
...@@ -118,6 +116,18 @@ class DemoSignInTest : public signin::test::LiveTest { ...@@ -118,6 +116,18 @@ class DemoSignInTest : public signin::test::LiveTest {
refresh_token_update_loop.Run(); refresh_token_update_loop.Run();
} }
void TurnOnSync(const TestAccount& test_account) {
SignInFromSettings(test_account);
TestIdentityManagerObserver observer(identity_manager());
base::RunLoop primary_account_set_loop;
observer.SetOnPrimaryAccountSetCallback(
primary_account_set_loop.QuitClosure());
login_ui_test_utils::DismissSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(3));
primary_account_set_loop.Run();
}
void SignOutFromWeb(size_t signed_in_accounts) { void SignOutFromWeb(size_t signed_in_accounts) {
TestIdentityManagerObserver observer(identity_manager()); TestIdentityManagerObserver observer(identity_manager());
base::RunLoop cookie_update_loop; base::RunLoop cookie_update_loop;
...@@ -166,17 +176,11 @@ IN_PROC_BROWSER_TEST_F(DemoSignInTest, SimpleSignInFlow) { ...@@ -166,17 +176,11 @@ IN_PROC_BROWSER_TEST_F(DemoSignInTest, SimpleSignInFlow) {
IN_PROC_BROWSER_TEST_F(DemoSignInTest, WebSignOut) { IN_PROC_BROWSER_TEST_F(DemoSignInTest, WebSignOut) {
TestAccount test_account; TestAccount test_account;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", test_account)); CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", test_account));
SignInFromSettings(test_account); TurnOnSync(test_account);
TestIdentityManagerObserver observer(identity_manager());
base::RunLoop primary_account_set_loop;
observer.SetOnPrimaryAccountSetCallback(
primary_account_set_loop.QuitClosure());
login_ui_test_utils::DismissSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(3));
primary_account_set_loop.Run();
const CoreAccountInfo& primary_account = const CoreAccountInfo& primary_account =
observer.PrimaryAccountFromSetCallback(); identity_manager()->GetPrimaryAccountInfo();
EXPECT_FALSE(primary_account.IsEmpty());
EXPECT_TRUE(gaia::AreEmailsSame(test_account.user, primary_account.email)); EXPECT_TRUE(gaia::AreEmailsSame(test_account.user, primary_account.email));
EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled()); EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
...@@ -245,5 +249,50 @@ IN_PROC_BROWSER_TEST_F(DemoSignInTest, WebSignInAndSignOut) { ...@@ -245,5 +249,50 @@ IN_PROC_BROWSER_TEST_F(DemoSignInTest, WebSignInAndSignOut) {
EXPECT_TRUE(identity_manager()->GetAccountsWithRefreshTokens().empty()); EXPECT_TRUE(identity_manager()->GetAccountsWithRefreshTokens().empty());
} }
// Signs in an account through the settings page and enables Sync. Checks that
// Sync is enabled. Signs in a second account on the web.
// Then, turns Sync off from the settings page and checks that both accounts are
// removed from Chrome and from cookies.
IN_PROC_BROWSER_TEST_F(DemoSignInTest, TurnOffSync) {
TestAccount test_account_1;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", test_account_1));
TurnOnSync(test_account_1);
TestAccount test_account_2;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_2", test_account_2));
SignInFromWeb(test_account_2);
const CoreAccountInfo& primary_account =
identity_manager()->GetPrimaryAccountInfo();
EXPECT_FALSE(primary_account.IsEmpty());
EXPECT_TRUE(gaia::AreEmailsSame(test_account_1.user, primary_account.email));
EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
GURL settings_url("chrome://settings");
AddTabAtIndex(0, settings_url, ui::PageTransition::PAGE_TRANSITION_TYPED);
TestIdentityManagerObserver observer(identity_manager());
base::RunLoop cookie_update_loop;
observer.SetOnAccountsInCookieUpdatedCallback(
cookie_update_loop.QuitClosure());
base::RunLoop primary_account_cleared_loop;
observer.SetOnPrimaryAccountClearedCallback(
primary_account_cleared_loop.QuitClosure());
SignOutTestObserver sign_out_observer(identity_manager());
auto* settings_tab = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(content::ExecuteScript(
settings_tab,
"settings.SyncBrowserProxyImpl.getInstance().signOut(false)"));
primary_account_cleared_loop.Run();
sign_out_observer.WaitForRefreshTokenRemovedForAccounts(2);
cookie_update_loop.Run();
const AccountsInCookieJarInfo& accounts_in_cookie_jar_2 =
identity_manager()->GetAccountsInCookieJar();
EXPECT_TRUE(accounts_in_cookie_jar_2.accounts_are_fresh);
ASSERT_TRUE(accounts_in_cookie_jar_2.signed_in_accounts.empty());
EXPECT_TRUE(identity_manager()->GetAccountsWithRefreshTokens().empty());
EXPECT_FALSE(identity_manager()->HasPrimaryAccount());
}
} // namespace test } // namespace test
} // namespace signin } // namespace signin
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment