Commit febed4e2 authored by Alex Ilin's avatar Alex Ilin Committed by Commit Bot

[Signin] Live signin test for cancel sync with existing account

This CL adds a new LiveSigninTest::CancelSyncWithWebAccount to the suite
of live signin tests.

The test does the following:
- Signs in on the web
- Goes to the settings page and starts the enable Sync flow
- Cancels the sync confirmation dialog
- Checks that the account is still signed in but Sync is disabled

This CL adds a new method to cancel the sync confirmation dialog to
login_ui_test_utils.

The CL also fixes a bug in the javascript injected to the sync
confirmation dialog from
SigninViewControllerTestUtil::TryDismissSyncConfirmationDialog.
"document.querySelector('sync-confirmation-app')" may evaluate in null
that causes the subsequent attempt to access "shadowRoot" to throw an
exception. content::ExecuteScriptAndExtractString(), however, stays
blocked because it waits for a message to be sent through
"window.domAutomationController.send()". All of this makes the test
timeout.

Bug: 1008891
Change-Id: I6793e40d400ca62f97ea1d60b99b628aabefb369
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944389Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720444}
parent 3129a652
...@@ -141,7 +141,7 @@ ...@@ -141,7 +141,7 @@
on-click="onConfirm_" consent-confirmation> on-click="onConfirm_" consent-confirmation>
$i18n{syncConfirmationConfirmLabel} $i18n{syncConfirmationConfirmLabel}
</cr-button> </cr-button>
<cr-button on-click="onUndo_"> <cr-button id="cancelButton" on-click="onUndo_">
$i18n{syncConfirmationUndoLabel} $i18n{syncConfirmationUndoLabel}
</cr-button> </cr-button>
<cr-button id="settingsButton" on-click="onGoToSettings_" <cr-button id="settingsButton" on-click="onGoToSettings_"
......
...@@ -823,7 +823,7 @@ IN_PROC_BROWSER_TEST_F(DiceBrowserTest, EnableSyncAfterToken) { ...@@ -823,7 +823,7 @@ IN_PROC_BROWSER_TEST_F(DiceBrowserTest, EnableSyncAfterToken) {
ntp_url_observer.Wait(); ntp_url_observer.Wait();
// Dismiss the Sync confirmation UI. // Dismiss the Sync confirmation UI.
EXPECT_TRUE(login_ui_test_utils::DismissSyncConfirmationDialog( EXPECT_TRUE(login_ui_test_utils::ConfirmSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(30))); browser(), base::TimeDelta::FromSeconds(30)));
} }
...@@ -877,7 +877,7 @@ IN_PROC_BROWSER_TEST_F(DiceBrowserTest, EnableSyncBeforeToken) { ...@@ -877,7 +877,7 @@ IN_PROC_BROWSER_TEST_F(DiceBrowserTest, EnableSyncBeforeToken) {
ntp_url_observer.Wait(); ntp_url_observer.Wait();
// Dismiss the Sync confirmation UI. // Dismiss the Sync confirmation UI.
EXPECT_TRUE(login_ui_test_utils::DismissSyncConfirmationDialog( EXPECT_TRUE(login_ui_test_utils::ConfirmSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(30))); browser(), base::TimeDelta::FromSeconds(30)));
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/signin/e2e_tests/live_test.h" #include "chrome/browser/signin/e2e_tests/live_test.h"
...@@ -124,7 +125,7 @@ class LiveSignInTest : public signin::test::LiveTest { ...@@ -124,7 +125,7 @@ class LiveSignInTest : public signin::test::LiveTest {
base::RunLoop primary_account_set_loop; base::RunLoop primary_account_set_loop;
observer.SetOnPrimaryAccountSetCallback( observer.SetOnPrimaryAccountSetCallback(
primary_account_set_loop.QuitClosure()); primary_account_set_loop.QuitClosure());
login_ui_test_utils::DismissSyncConfirmationDialog( login_ui_test_utils::ConfirmSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(3)); browser(), base::TimeDelta::FromSeconds(3));
primary_account_set_loop.Run(); primary_account_set_loop.Run();
} }
...@@ -307,5 +308,35 @@ IN_PROC_BROWSER_TEST_F(LiveSignInTest, MAYBE_TurnOffSync) { ...@@ -307,5 +308,35 @@ IN_PROC_BROWSER_TEST_F(LiveSignInTest, MAYBE_TurnOffSync) {
EXPECT_FALSE(identity_manager()->HasPrimaryAccount()); EXPECT_FALSE(identity_manager()->HasPrimaryAccount());
} }
// Signs in an account on the web. Goes to the Chrome settings to enable Sync
// but cancels the sync confirmation dialog. Checks that the account is still
// signed in on the web but Sync is disabled.
IN_PROC_BROWSER_TEST_F(LiveSignInTest, CancelSyncWithWebAccount) {
TestAccount test_account;
CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", test_account));
SignInFromWeb(test_account);
GURL settings_url("chrome://settings");
AddTabAtIndex(0, settings_url, ui::PageTransition::PAGE_TRANSITION_TYPED);
auto* settings_tab = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(content::ExecuteScript(
settings_tab,
base::StringPrintf("settings.SyncBrowserProxyImpl.getInstance()."
"startSyncingWithEmail(\"%s\", true)",
test_account.user.c_str())));
login_ui_test_utils::CancelSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(3));
const AccountsInCookieJarInfo& accounts_in_cookie_jar =
identity_manager()->GetAccountsInCookieJar();
EXPECT_TRUE(accounts_in_cookie_jar.accounts_are_fresh);
ASSERT_EQ(1u, accounts_in_cookie_jar.signed_in_accounts.size());
const gaia::ListedAccount& account =
accounts_in_cookie_jar.signed_in_accounts[0];
EXPECT_TRUE(gaia::AreEmailsSame(test_account.user, account.email));
EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account.id));
EXPECT_FALSE(identity_manager()->HasPrimaryAccount());
}
} // namespace test } // namespace test
} // namespace signin } // namespace signin
...@@ -370,7 +370,7 @@ bool ProfileSyncServiceHarness::SetupSyncImpl( ...@@ -370,7 +370,7 @@ bool ProfileSyncServiceHarness::SetupSyncImpl(
FinishSyncSetup(); FinishSyncSetup();
if ((signin_type_ == SigninType::UI_SIGNIN) && if ((signin_type_ == SigninType::UI_SIGNIN) &&
!login_ui_test_utils::DismissSyncConfirmationDialog( !login_ui_test_utils::ConfirmSyncConfirmationDialog(
chrome::FindBrowserWithProfile(profile_), chrome::FindBrowserWithProfile(profile_),
base::TimeDelta::FromSeconds(30))) { base::TimeDelta::FromSeconds(30))) {
LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; LOG(ERROR) << "Failed to dismiss sync confirmation dialog.";
......
...@@ -950,7 +950,7 @@ PROFILE_MENU_CLICK_TEST(kActionableItems_WithUnconsentedPrimaryAccount, ...@@ -950,7 +950,7 @@ PROFILE_MENU_CLICK_TEST(kActionableItems_WithUnconsentedPrimaryAccount,
// The sync confirmation dialog was opened after clicking the signin button // The sync confirmation dialog was opened after clicking the signin button
// in the profile menu. It needs to be manually dismissed to not cause any // in the profile menu. It needs to be manually dismissed to not cause any
// crashes during shutdown. // crashes during shutdown.
EXPECT_TRUE(login_ui_test_utils::DismissSyncConfirmationDialog( EXPECT_TRUE(login_ui_test_utils::ConfirmSyncConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(30))); browser(), base::TimeDelta::FromSeconds(30)));
} }
} }
......
...@@ -175,12 +175,28 @@ void WaitUntilAnyElementExistsInSigninFrame( ...@@ -175,12 +175,28 @@ void WaitUntilAnyElementExistsInSigninFrame(
"Could not find elements in the signin frame"); "Could not find elements in the signin frame");
} }
enum class SyncConfirmationDialogAction { kConfirm, kCancel };
#if !defined(OS_CHROMEOS)
std::string GetButtonIdForSyncConfirmationDialogAction(
SyncConfirmationDialogAction action) {
switch (action) {
case SyncConfirmationDialogAction::kConfirm:
return "confirmButton";
case SyncConfirmationDialogAction::kCancel:
return "cancelButton";
}
}
#endif // !defined(OS_CHROMEOS)
} // namespace } // namespace
namespace login_ui_test_utils { namespace login_ui_test_utils {
class SigninViewControllerTestUtil { class SigninViewControllerTestUtil {
public: public:
static bool TryDismissSyncConfirmationDialog(Browser* browser) { static bool TryDismissSyncConfirmationDialog(
Browser* browser,
SyncConfirmationDialogAction action) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
NOTREACHED(); NOTREACHED();
return false; return false;
...@@ -193,15 +209,18 @@ class SigninViewControllerTestUtil { ...@@ -193,15 +209,18 @@ class SigninViewControllerTestUtil {
content::WebContents* dialog_web_contents = content::WebContents* dialog_web_contents =
signin_view_controller->GetModalDialogWebContentsForTesting(); signin_view_controller->GetModalDialogWebContentsForTesting();
DCHECK_NE(dialog_web_contents, nullptr); DCHECK_NE(dialog_web_contents, nullptr);
std::string confirm_button_selector = std::string button_id = GetButtonIdForSyncConfirmationDialogAction(action);
std::string button_selector =
"(document.querySelector('sync-confirmation-app') == null ? null :"
"document.querySelector('sync-confirmation-app').shadowRoot." "document.querySelector('sync-confirmation-app').shadowRoot."
"querySelector('#confirmButton')"; "querySelector('#" +
button_id + "'))";
std::string message; std::string message;
std::string find_button_js = std::string find_button_js =
"if (document.readyState != 'complete') {" "if (document.readyState != 'complete') {"
" window.domAutomationController.send('DocumentNotReady');" " window.domAutomationController.send('DocumentNotReady');"
"} else if (" + "} else if (" +
confirm_button_selector + button_selector +
" == null) {" " == null) {"
" window.domAutomationController.send('NotFound');" " window.domAutomationController.send('NotFound');"
"} else {" "} else {"
...@@ -215,7 +234,7 @@ class SigninViewControllerTestUtil { ...@@ -215,7 +234,7 @@ class SigninViewControllerTestUtil {
// This cannot be a synchronous call, because it closes the window as a side // This cannot be a synchronous call, because it closes the window as a side
// effect, which may cause the javascript execution to never finish. // effect, which may cause the javascript execution to never finish.
content::ExecuteScriptAsync(dialog_web_contents, content::ExecuteScriptAsync(dialog_web_contents,
confirm_button_selector + ".click();"); button_selector + ".click();");
return true; return true;
#endif #endif
} }
...@@ -319,7 +338,9 @@ bool SignInWithUI(Browser* browser, ...@@ -319,7 +338,9 @@ bool SignInWithUI(Browser* browser,
#endif #endif
} }
bool DismissSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) { bool DismissSyncConfirmationDialog(Browser* browser,
base::TimeDelta timeout,
SyncConfirmationDialogAction action) {
SyncConfirmationClosedObserver confirmation_closed_observer; SyncConfirmationClosedObserver confirmation_closed_observer;
ScopedObserver<LoginUIService, LoginUIService::Observer> ScopedObserver<LoginUIService, LoginUIService::Observer>
scoped_confirmation_closed_observer(&confirmation_closed_observer); scoped_confirmation_closed_observer(&confirmation_closed_observer);
...@@ -329,7 +350,7 @@ bool DismissSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) { ...@@ -329,7 +350,7 @@ bool DismissSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) {
const base::Time expire_time = base::Time::Now() + timeout; const base::Time expire_time = base::Time::Now() + timeout;
while (base::Time::Now() <= expire_time) { while (base::Time::Now() <= expire_time) {
if (SigninViewControllerTestUtil::TryDismissSyncConfirmationDialog( if (SigninViewControllerTestUtil::TryDismissSyncConfirmationDialog(
browser)) { browser, action)) {
confirmation_closed_observer.WaitForConfirmationClosed(); confirmation_closed_observer.WaitForConfirmationClosed();
return true; return true;
} }
...@@ -338,4 +359,14 @@ bool DismissSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) { ...@@ -338,4 +359,14 @@ bool DismissSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) {
return false; return false;
} }
bool ConfirmSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) {
return DismissSyncConfirmationDialog(browser, timeout,
SyncConfirmationDialogAction::kConfirm);
}
bool CancelSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout) {
return DismissSyncConfirmationDialog(browser, timeout,
SyncConfirmationDialogAction::kCancel);
}
} // namespace login_ui_test_utils } // namespace login_ui_test_utils
...@@ -44,7 +44,12 @@ bool SignInWithUI(Browser* browser, ...@@ -44,7 +44,12 @@ bool SignInWithUI(Browser* browser,
// Waits for sync confirmation dialog to get displayed, then executes javascript // Waits for sync confirmation dialog to get displayed, then executes javascript
// to click on confirm button. Returns false if dialog wasn't dismissed before // to click on confirm button. Returns false if dialog wasn't dismissed before
// |timeout|. // |timeout|.
bool DismissSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout); bool ConfirmSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout);
// Waits for sync confirmation dialog to get displayed, then executes javascript
// to click on cancel button. Returns false if dialog wasn't dismissed before
// |timeout|.
bool CancelSyncConfirmationDialog(Browser* browser, base::TimeDelta timeout);
} // namespace login_ui_test_utils } // namespace login_ui_test_utils
......
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