Commit 03d520b6 authored by Alex Ilin's avatar Alex Ilin Committed by Commit Bot

[signin] Add a browser test for opening links in the reauth dialog

The test checks that the links that suppose to open a new tab work as
expected in the reauth dialog.

Bug: 1045515
Change-Id: I4abddb7506b0bae209c6865d59cc8b3be4526ded
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226754
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775073}
parent 527ab1e2
...@@ -145,6 +145,11 @@ void SigninReauthViewController::OnGaiaReauthPageComplete( ...@@ -145,6 +145,11 @@ void SigninReauthViewController::OnGaiaReauthPageComplete(
OnStateChanged(); OnStateChanged();
} }
void SigninReauthViewController::SetObserverForTesting(
Observer* test_observer) {
test_observer_ = test_observer;
}
void SigninReauthViewController::CompleteReauth(signin::ReauthResult result) { void SigninReauthViewController::CompleteReauth(signin::ReauthResult result) {
if (dialog_delegate_) { if (dialog_delegate_) {
dialog_delegate_observer_.Remove(dialog_delegate_); dialog_delegate_observer_.Remove(dialog_delegate_);
...@@ -204,6 +209,9 @@ void SigninReauthViewController::ShowGaiaReauthPage() { ...@@ -204,6 +209,9 @@ void SigninReauthViewController::ShowGaiaReauthPage() {
// This corresponds to a SAML account. // This corresponds to a SAML account.
ShowGaiaReauthPageInNewTab(); ShowGaiaReauthPageInNewTab();
} }
if (test_observer_)
test_observer_->OnGaiaReauthPageShown();
} }
void SigninReauthViewController::ShowGaiaReauthPageInDialog() { void SigninReauthViewController::ShowGaiaReauthPageInDialog() {
......
...@@ -40,6 +40,15 @@ class SigninReauthViewController ...@@ -40,6 +40,15 @@ class SigninReauthViewController
: public SigninViewControllerDelegate, : public SigninViewControllerDelegate,
public SigninViewControllerDelegate::Observer { public SigninViewControllerDelegate::Observer {
public: public:
// An observer class currently used only for tests.
class Observer {
public:
virtual ~Observer() = default;
// Called when the WebContents displaying the reauth confirmation UI has
// been swapped with Gaia reauth WebContents.
virtual void OnGaiaReauthPageShown() = 0;
};
enum class GaiaReauthPageState { enum class GaiaReauthPageState {
kStarted = 0, // The Gaia Reauth page is loading in background. kStarted = 0, // The Gaia Reauth page is loading in background.
kNavigated = 1, // The first navigation has been committed. kNavigated = 1, // The first navigation has been committed.
...@@ -80,6 +89,9 @@ class SigninReauthViewController ...@@ -80,6 +89,9 @@ class SigninReauthViewController
// Called when the Gaia reauth has been completed and the result is available. // Called when the Gaia reauth has been completed and the result is available.
void OnGaiaReauthPageComplete(signin::ReauthResult result); void OnGaiaReauthPageComplete(signin::ReauthResult result);
// Public for testing.
void SetObserverForTesting(Observer* test_observer);
private: private:
// Calls |reauth_callback_| with |result| and closes all Reauth UIs. // Calls |reauth_callback_| with |result| and closes all Reauth UIs.
void CompleteReauth(signin::ReauthResult result); void CompleteReauth(signin::ReauthResult result);
...@@ -114,6 +126,8 @@ class SigninReauthViewController ...@@ -114,6 +126,8 @@ class SigninReauthViewController
GaiaReauthPageState gaia_reauth_page_state_ = GaiaReauthPageState::kStarted; GaiaReauthPageState gaia_reauth_page_state_ = GaiaReauthPageState::kStarted;
base::Optional<signin::ReauthResult> gaia_reauth_page_result_; base::Optional<signin::ReauthResult> gaia_reauth_page_result_;
Observer* test_observer_ = nullptr;
base::WeakPtrFactory<SigninReauthViewController> weak_ptr_factory_{this}; base::WeakPtrFactory<SigninReauthViewController> weak_ptr_factory_{this};
}; };
......
...@@ -80,6 +80,20 @@ std::unique_ptr<net::test_server::HttpResponse> HandleReauthURL( ...@@ -80,6 +80,20 @@ std::unique_ptr<net::test_server::HttpResponse> HandleReauthURL(
return nullptr; return nullptr;
} }
class ReauthTestObserver : SigninReauthViewController::Observer {
public:
explicit ReauthTestObserver(SigninReauthViewController* controller) {
controller->SetObserverForTesting(this);
}
void WaitUntilGaiaReauthPageIsShown() { run_loop_.Run(); }
void OnGaiaReauthPageShown() override { run_loop_.Quit(); }
private:
base::RunLoop run_loop_;
};
} // namespace } // namespace
// Browser tests for SigninReauthViewController. // Browser tests for SigninReauthViewController.
...@@ -102,6 +116,7 @@ class SigninReauthViewControllerBrowserTest : public InProcessBrowserTest { ...@@ -102,6 +116,7 @@ class SigninReauthViewControllerBrowserTest : public InProcessBrowserTest {
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread(); InProcessBrowserTest::SetUpOnMainThread();
https_server()->ServeFilesFromSourceDirectory("chrome/test/data");
https_server()->RegisterRequestHandler( https_server()->RegisterRequestHandler(
base::BindRepeating(&HandleReauthURL, base_url())); base::BindRepeating(&HandleReauthURL, base_url()));
reauth_challenge_response_ = reauth_challenge_response_ =
...@@ -238,3 +253,36 @@ IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest, ...@@ -238,3 +253,36 @@ IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
RedirectGaiaChallengeTo(https_server()->GetURL(kReauthDonePath)); RedirectGaiaChallengeTo(https_server()->GetURL(kReauthDonePath));
EXPECT_EQ(WaitForReauthResult(), signin::ReauthResult::kSuccess); EXPECT_EQ(WaitForReauthResult(), signin::ReauthResult::kSuccess);
} }
// Tests that links from the Gaia page are opened in a new tab.
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
OpenLinksInNewTab) {
content::WebContents* original_contents =
browser()->tab_strip_model()->GetActiveWebContents();
const GURL& target_url = https_server()->GetURL("/link_with_target.html");
content::TestNavigationObserver target_content_observer(target_url);
target_content_observer.StartWatchingNewWebContents();
ShowReauthPrompt();
RedirectGaiaChallengeTo(target_url);
ReauthTestObserver reauth_observer(signin_reauth_view_controller());
ASSERT_TRUE(login_ui_test_utils::ConfirmReauthConfirmationDialog(
browser(), kReauthDialogTimeout));
reauth_observer.WaitUntilGaiaReauthPageIsShown();
target_content_observer.Wait();
content::WebContents* dialog_contents =
signin_reauth_view_controller()->GetWebContents();
content::TestNavigationObserver new_tab_observer(nullptr);
new_tab_observer.StartWatchingNewWebContents();
ASSERT_TRUE(content::ExecuteScript(
dialog_contents, "document.getElementsByTagName('a')[0].click();"));
new_tab_observer.Wait();
content::WebContents* new_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_NE(new_contents, original_contents);
EXPECT_NE(new_contents, dialog_contents);
EXPECT_EQ(new_contents->GetURL(), https_server()->GetURL("/title1.html"));
}
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