Commit 43dbc2b1 authored by David Roger's avatar David Roger Committed by Commit Bot

Fix extra call to Cancel() in ProfileSigninConfirmationDialogViews

Bug: 1091232
Change-Id: Idfbecb611c0bde730a375a3bf3059c19c4d115ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231221Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775155}
parent 85351fad
...@@ -254,10 +254,6 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged( ...@@ -254,10 +254,6 @@ void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
kPreferredWidth, explanation_label_height); kPreferredWidth, explanation_label_height);
} }
void ProfileSigninConfirmationDialogViews::WindowClosing() {
Cancel();
}
void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked( void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked(
views::StyledLabel* label, views::StyledLabel* label,
const gfx::Range& range, const gfx::Range& range,
......
...@@ -50,9 +50,6 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView, ...@@ -50,9 +50,6 @@ class ProfileSigninConfirmationDialogViews : public views::DialogDelegateView,
void ViewHierarchyChanged( void ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) override; const views::ViewHierarchyChangedDetails& details) override;
// views::WidgetDelegate::
void WindowClosing() override;
// views::StyledLabelListener: // views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label, void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range, const gfx::Range& range,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.h" #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.h"
#include "chrome/test/views/chrome_views_test_base.h" #include "chrome/test/views/chrome_views_test_base.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/test/widget_test.h" #include "ui/views/test/widget_test.h"
namespace { namespace {
...@@ -27,29 +28,21 @@ class TestDelegate : public ui::ProfileSigninConfirmationDelegate { ...@@ -27,29 +28,21 @@ class TestDelegate : public ui::ProfileSigninConfirmationDelegate {
} // namespace } // namespace
using ProfileSigninConfirmationDialogTest = ChromeViewsTestBase; class ProfileSigninConfirmationDialogTest : public ChromeViewsTestBase {
public:
// Regression test for https://crbug.com/1054866 void BuildDialog(
TEST_F(ProfileSigninConfirmationDialogTest, CloseButtonOnlyCallsDelegateOnce) { std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) {
int cancels = 0;
int continues = 0;
int signins = 0;
auto delegate =
std::make_unique<TestDelegate>(&cancels, &continues, &signins);
auto dialog = std::make_unique<ProfileSigninConfirmationDialogViews>( auto dialog = std::make_unique<ProfileSigninConfirmationDialogViews>(
nullptr, "foo@bar.com", std::move(delegate), true); nullptr, "foo@bar.com", std::move(delegate), true);
ProfileSigninConfirmationDialogViews* weak_dialog = dialog.get(); weak_dialog_ = dialog.get();
views::Widget* widget = views::DialogDelegate::CreateDialogWidget(
dialog.release(), GetContext(), nullptr);
views::test::WidgetDestroyedWaiter destroy_waiter(widget);
widget->Show(); widget_ = views::DialogDelegate::CreateDialogWidget(dialog.release(),
GetContext(), nullptr);
widget_->Show();
}
// Press the "continue signin" button. void PressButton(views::Button* button) {
views::Button* button = views::test::WidgetDestroyedWaiter destroy_waiter(widget_);
static_cast<views::Button*>(weak_dialog->GetExtraView());
// Synthesize both press & release - different platforms have different // Synthesize both press & release - different platforms have different
// notions about whether buttons activate on press or on release. // notions about whether buttons activate on press or on release.
button->OnKeyPressed( button->OnKeyPressed(
...@@ -57,6 +50,26 @@ TEST_F(ProfileSigninConfirmationDialogTest, CloseButtonOnlyCallsDelegateOnce) { ...@@ -57,6 +50,26 @@ TEST_F(ProfileSigninConfirmationDialogTest, CloseButtonOnlyCallsDelegateOnce) {
button->OnKeyReleased( button->OnKeyReleased(
ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_SPACE, ui::EF_NONE)); ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_SPACE, ui::EF_NONE));
destroy_waiter.Wait(); destroy_waiter.Wait();
}
ProfileSigninConfirmationDialogViews* weak_dialog_ = nullptr;
views::Widget* widget_ = nullptr;
};
// Regression test for https://crbug.com/1054866
TEST_F(ProfileSigninConfirmationDialogTest, CloseButtonOnlyCallsDelegateOnce) {
int cancels = 0;
int continues = 0;
int signins = 0;
auto delegate =
std::make_unique<TestDelegate>(&cancels, &continues, &signins);
BuildDialog(std::move(delegate));
widget_->Show();
// Press the "continue signin" button.
views::Button* button =
static_cast<views::Button*>(weak_dialog_->GetExtraView());
PressButton(button);
// The delegate should *not* have gotten a call back to OnCancelSignin. If the // The delegate should *not* have gotten a call back to OnCancelSignin. If the
// fix for https://crbug.com/1054866 regresses, either it will, or we'll have // fix for https://crbug.com/1054866 regresses, either it will, or we'll have
...@@ -65,3 +78,42 @@ TEST_F(ProfileSigninConfirmationDialogTest, CloseButtonOnlyCallsDelegateOnce) { ...@@ -65,3 +78,42 @@ TEST_F(ProfileSigninConfirmationDialogTest, CloseButtonOnlyCallsDelegateOnce) {
EXPECT_EQ(continues, 1); EXPECT_EQ(continues, 1);
EXPECT_EQ(signins, 0); EXPECT_EQ(signins, 0);
} }
// Regression test for https://crbug.com/1091232
TEST_F(ProfileSigninConfirmationDialogTest, CancelButtonOnlyCallsDelegateOnce) {
int cancels = 0;
int continues = 0;
int signins = 0;
auto delegate =
std::make_unique<TestDelegate>(&cancels, &continues, &signins);
BuildDialog(std::move(delegate));
widget_->Show();
// Press the "Cancel" button.
views::Button* button = weak_dialog_->GetCancelButton();
PressButton(button);
EXPECT_EQ(cancels, 1);
EXPECT_EQ(continues, 0);
EXPECT_EQ(signins, 0);
}
// Regression test for https://crbug.com/1091232
TEST_F(ProfileSigninConfirmationDialogTest,
NewProfileButtonOnlyCallsDelegateOnce) {
int cancels = 0;
int continues = 0;
int signins = 0;
auto delegate =
std::make_unique<TestDelegate>(&cancels, &continues, &signins);
BuildDialog(std::move(delegate));
widget_->Show();
// Press the "Signin with new profile" button.
views::Button* button = weak_dialog_->GetOkButton();
PressButton(button);
EXPECT_EQ(cancels, 0);
EXPECT_EQ(continues, 0);
EXPECT_EQ(signins, 1);
}
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