Commit 7421705b authored by Jun Cai's avatar Jun Cai Committed by Commit Bot

[sms] Refactor SMS dialog to use xml layout

This CL updates SMS dialog to use xml layout.

I uploaded some screenshots of the SMS dialog on the issue page.

Bug: 987799
Change-Id: I46e27aefd19104b4bba5032076bc31b0b203a730
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1725519
Commit-Queue: Jun Cai <juncai@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684114}
parent 4c79cd0d
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/default_bg_color_light"/>
<corners android:radius="10dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:background="@drawable/sms_receiver_dialog_background">
<!-- The title at the top. -->
<TextView
android:id="@+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingBottom="12dp"
android:text="@string/sms_dialog_title"
android:textAppearance="@style/TextAppearance.BlackHint1" />
<!-- Status row. -->
<LinearLayout
android:id="@+id/status_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="32dp"
android:gravity="center" >
<!-- A layout containing a spinning progress bar that gets replaced with a
done icon. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/done_icon"
android:layout_height="20dp"
android:layout_width="20dp"
android:visibility="gone"
app:srcCompat="@drawable/ic_check_circle_blue_18dp"
tools:ignore="ContentDescription" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="20dp"
android:layout_height="20dp"
android:indeterminate="true" />
</FrameLayout>
<!-- The status. -->
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="@string/sms_dialog_status_waiting"
android:textAppearance="@style/TextAppearance.BlackTitle1" />
</LinearLayout>
<!-- Button row. -->
<org.chromium.chrome.browser.widget.DualControlLayout
android:id="@+id/button_bar"
android:layout_width="match_parent"
android:layout_height="36dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:stackedMargin="@dimen/button_bar_stacked_margin"
app:buttonAlignment="end">
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/confirm_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:text="@string/sms_dialog_confirm_button_text"
android:enabled="false"
style="@style/TextButton" />
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/cancel_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:text="@string/cancel"
android:enabled="true"
style="@style/TextButton" />
</org.chromium.chrome.browser.widget.DualControlLayout>
</LinearLayout>
...@@ -5,12 +5,18 @@ ...@@ -5,12 +5,18 @@
package org.chromium.chrome.browser.sms; package org.chromium.chrome.browser.sms;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.Dialog;
import android.content.DialogInterface; import android.graphics.Color;
import android.content.DialogInterface.OnClickListener; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.view.LayoutInflater;
import android.support.v7.content.res.AppCompatResources; import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
...@@ -27,8 +33,13 @@ public class SmsReceiverDialog { ...@@ -27,8 +33,13 @@ public class SmsReceiverDialog {
private static final String TAG = "SmsReceiverDialog"; private static final String TAG = "SmsReceiverDialog";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private long mNativeSmsDialogAndroid; private long mNativeSmsDialogAndroid;
private ProgressDialog mDialog;
private Activity mActivity; private Activity mActivity;
// The dialog this class encapsulates.
private Dialog mDialog;
private ProgressBar mProgressBar;
private ImageView mDoneIcon;
private TextView mStatus;
private Button mConfirmButton;
@VisibleForTesting @VisibleForTesting
@CalledByNative @CalledByNative
...@@ -37,40 +48,48 @@ public class SmsReceiverDialog { ...@@ -37,40 +48,48 @@ public class SmsReceiverDialog {
return new SmsReceiverDialog(nativeSmsDialogAndroid); return new SmsReceiverDialog(nativeSmsDialogAndroid);
} }
private static ProgressDialog createDialog(Activity activity, long nativeSmsDialogAndroid) {
ProgressDialog dialog = new ProgressDialog(activity);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setTitle(activity.getText(R.string.sms_dialog_title));
dialog.setMessage(activity.getText(R.string.sms_dialog_status_waiting));
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getText(R.string.cancel),
new OnClickListener() {
@Override
public void onClick(DialogInterface prompt, int which) {
assert nativeSmsDialogAndroid != 0;
prompt.dismiss();
SmsReceiverDialogJni.get().onCancel(nativeSmsDialogAndroid);
}
});
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
activity.getText(R.string.sms_dialog_continue_button_text), new OnClickListener() {
@Override
public void onClick(DialogInterface prompt, int which) {
assert nativeSmsDialogAndroid != 0;
prompt.dismiss();
SmsReceiverDialogJni.get().onContinue(nativeSmsDialogAndroid);
}
});
return dialog;
}
private SmsReceiverDialog(long nativeSmsDialogAndroid) { private SmsReceiverDialog(long nativeSmsDialogAndroid) {
mNativeSmsDialogAndroid = nativeSmsDialogAndroid; mNativeSmsDialogAndroid = nativeSmsDialogAndroid;
} }
private void createAndShowDialog(WindowAndroid windowAndroid) {
mActivity = windowAndroid.getActivity().get();
LinearLayout dialogContainer = (LinearLayout) LayoutInflater.from(mActivity).inflate(
R.layout.sms_receiver_dialog, null);
mProgressBar = (ProgressBar) dialogContainer.findViewById(R.id.progress);
mDoneIcon = (ImageView) dialogContainer.findViewById(R.id.done_icon);
mStatus = (TextView) dialogContainer.findViewById(R.id.status);
Button cancelButton = (Button) dialogContainer.findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(v -> {
assert mNativeSmsDialogAndroid != 0;
SmsReceiverDialogJni.get().onCancel(mNativeSmsDialogAndroid);
});
mConfirmButton = (Button) dialogContainer.findViewById(R.id.confirm_button);
mConfirmButton.setOnClickListener(v -> {
assert mNativeSmsDialogAndroid != 0;
SmsReceiverDialogJni.get().onConfirm(mNativeSmsDialogAndroid);
});
mDialog = new Dialog(mActivity);
mDialog.setCanceledOnTouchOutside(false);
mDialog.addContentView(dialogContainer,
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
Window window = mDialog.getWindow();
window.setLayout(Math.round(mActivity.getWindow().getDecorView().getWidth() * 0.9f),
LayoutParams.WRAP_CONTENT);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mDialog.show();
}
@VisibleForTesting @VisibleForTesting
@CalledByNative @CalledByNative
void destroy() { void destroy() {
...@@ -86,11 +105,7 @@ public class SmsReceiverDialog { ...@@ -86,11 +105,7 @@ public class SmsReceiverDialog {
assert mNativeSmsDialogAndroid != 0 : "open() called after object was destroyed"; assert mNativeSmsDialogAndroid != 0 : "open() called after object was destroyed";
mActivity = window.getActivity().get(); createAndShowDialog(window);
mDialog = createDialog(mActivity, mNativeSmsDialogAndroid);
mDialog.show();
Button continueButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
continueButton.setEnabled(false);
} }
@VisibleForTesting @VisibleForTesting
...@@ -108,23 +123,17 @@ public class SmsReceiverDialog { ...@@ -108,23 +123,17 @@ public class SmsReceiverDialog {
void smsReceived() { void smsReceived() {
if (DEBUG) Log.d(TAG, "SmsReceiverDialog.smsReceived()"); if (DEBUG) Log.d(TAG, "SmsReceiverDialog.smsReceived()");
mDialog.dismiss(); mProgressBar.setVisibility(View.GONE);
mDialog = createDialog(mActivity, mNativeSmsDialogAndroid); mDoneIcon.setVisibility(View.VISIBLE);
Drawable smsReceivedDrawable = mStatus.setText(mActivity.getText(R.string.sms_dialog_status_sms_received));
AppCompatResources.getDrawable(mActivity, R.drawable.ic_check_circle_blue_18dp); mConfirmButton.setEnabled(true);
mDialog.setIndeterminateDrawable(smsReceivedDrawable);
mDialog.setMessage(mActivity.getText(R.string.sms_dialog_status_sms_received));
mDialog.show();
Button continueButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
continueButton.setEnabled(true);
} }
/** /**
* Returns the dialog associated with this class. For use with tests only. * Returns the dialog associated with this class. For use with tests only.
*/ */
@VisibleForTesting @VisibleForTesting
ProgressDialog getDialogForTesting() { Dialog getDialogForTesting() {
return mDialog; return mDialog;
} }
...@@ -136,6 +145,6 @@ public class SmsReceiverDialog { ...@@ -136,6 +145,6 @@ public class SmsReceiverDialog {
@NativeMethods @NativeMethods
interface Natives { interface Natives {
void onCancel(long nativeSmsDialogAndroid); void onCancel(long nativeSmsDialogAndroid);
void onContinue(long nativeSmsDialogAndroid); void onConfirm(long nativeSmsDialogAndroid);
} }
} }
...@@ -4038,8 +4038,8 @@ The site does NOT gain access to the camera. The camera images are only visible ...@@ -4038,8 +4038,8 @@ The site does NOT gain access to the camera. The camera images are only visible
<message name="IDS_SMS_DIALOG_STATUS_SMS_RECEIVED" desc="Message shown when Chrome has received an SMS on the user's behalf"> <message name="IDS_SMS_DIALOG_STATUS_SMS_RECEIVED" desc="Message shown when Chrome has received an SMS on the user's behalf">
Text message received Text message received
</message> </message>
<message name="IDS_SMS_DIALOG_CONTINUE_BUTTON_TEXT" desc="Label on the button that users can click to continue SMS verification by passing the incoming SMS to the site."> <message name="IDS_SMS_DIALOG_CONFIRM_BUTTON_TEXT" desc="Label on the button that users can click to confirm SMS verification by passing the incoming SMS to the site.">
Continue Confirm
</message> </message>
</messages> </messages>
......
3851b10baa9e6cd314477667cdac69e549ba2e52
\ No newline at end of file
e067863e769ed41d1efb48ab2e27479e08d92e6f 3851b10baa9e6cd314477667cdac69e549ba2e52
\ No newline at end of file \ No newline at end of file
d63f3910bdd45cea1f0a5fcc83c9e7aa4acf9216 9a38cd3599c74c36b46f3bf4edf565fa8280eb9d
\ No newline at end of file \ No newline at end of file
a720e515aa7361b083ffad3b584d97d42051c14f 9a38cd3599c74c36b46f3bf4edf565fa8280eb9d
\ No newline at end of file \ No newline at end of file
...@@ -4,11 +4,14 @@ ...@@ -4,11 +4,14 @@
package org.chromium.chrome.browser.sms; package org.chromium.chrome.browser.sms;
import android.app.ProgressDialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest; import android.support.test.filters.LargeTest;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -19,6 +22,7 @@ import org.junit.runner.RunWith; ...@@ -19,6 +22,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.JniMocker; import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
...@@ -44,7 +48,7 @@ public class SmsReceiverDialogTest { ...@@ -44,7 +48,7 @@ public class SmsReceiverDialogTest {
private SmsReceiverDialog mSmsDialog; private SmsReceiverDialog mSmsDialog;
final private CallbackHelper mCancelButtonClickedCallback = new CallbackHelper(); final private CallbackHelper mCancelButtonClickedCallback = new CallbackHelper();
final private CallbackHelper mContinueButtonClickedCallback = new CallbackHelper(); final private CallbackHelper mConfirmButtonClickedCallback = new CallbackHelper();
private class TestSmsReceiverDialogJni implements SmsReceiverDialog.Natives { private class TestSmsReceiverDialogJni implements SmsReceiverDialog.Natives {
@Override @Override
...@@ -53,8 +57,8 @@ public class SmsReceiverDialogTest { ...@@ -53,8 +57,8 @@ public class SmsReceiverDialogTest {
} }
@Override @Override
public void onContinue(long nativeSmsDialogAndroid) { public void onConfirm(long nativeSmsDialogAndroid) {
mContinueButtonClickedCallback.notifyCalled(); mConfirmButtonClickedCallback.notifyCalled();
} }
} }
...@@ -76,25 +80,24 @@ public class SmsReceiverDialogTest { ...@@ -76,25 +80,24 @@ public class SmsReceiverDialogTest {
@Test @Test
@LargeTest @LargeTest
public void testCancelButtonAndContinueButton() { public void testCancelButtonAndConfirmButton() {
ProgressDialog dialog = mSmsDialog.getDialogForTesting(); Dialog dialog = mSmsDialog.getDialogForTesting();
Button cancelButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
Assert.assertTrue(cancelButton.isEnabled()); Assert.assertTrue(cancelButton.isEnabled());
Button continueButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); Button confirmButton = (Button) dialog.findViewById(R.id.confirm_button);
Assert.assertFalse(continueButton.isEnabled()); Assert.assertFalse(confirmButton.isEnabled());
TestThreadUtils.runOnUiThreadBlocking(mSmsDialog::smsReceived); TestThreadUtils.runOnUiThreadBlocking(mSmsDialog::smsReceived);
Assert.assertTrue(mSmsDialog.getDialogForTesting() Assert.assertTrue(confirmButton.isEnabled());
.getButton(DialogInterface.BUTTON_POSITIVE)
.isEnabled());
} }
@Test @Test
@LargeTest @LargeTest
public void testClickCancelButton() throws Throwable { public void testClickCancelButton() throws Throwable {
ProgressDialog dialog = mSmsDialog.getDialogForTesting(); Dialog dialog = mSmsDialog.getDialogForTesting();
Button cancelButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
TestTouchUtils.performClickOnMainSync( TestTouchUtils.performClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), cancelButton); InstrumentationRegistry.getInstrumentation(), cancelButton);
...@@ -104,20 +107,44 @@ public class SmsReceiverDialogTest { ...@@ -104,20 +107,44 @@ public class SmsReceiverDialogTest {
@Test @Test
@LargeTest @LargeTest
public void testClickContinueButton() throws Throwable { public void testClickConfirmButton() throws Throwable {
ProgressDialog dialog = mSmsDialog.getDialogForTesting(); Dialog dialog = mSmsDialog.getDialogForTesting();
Button continueButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); Button confirmButton = (Button) dialog.findViewById(R.id.confirm_button);
TestTouchUtils.performClickOnMainSync( TestTouchUtils.performClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), continueButton); InstrumentationRegistry.getInstrumentation(), confirmButton);
mConfirmButtonClickedCallback.waitForCallback(0, 1);
}
@Test
@LargeTest
public void testStatusRowChangesWhenMessageReceived() {
Dialog dialog = mSmsDialog.getDialogForTesting();
ProgressBar progressBar = (ProgressBar) dialog.findViewById(R.id.progress);
ImageView doneIcon = (ImageView) dialog.findViewById(R.id.done_icon);
TextView status = (TextView) dialog.findViewById(R.id.status);
Assert.assertEquals(View.VISIBLE, progressBar.getVisibility());
Assert.assertEquals(View.GONE, doneIcon.getVisibility());
Assert.assertEquals(
mActivityTestRule.getActivity().getString(R.string.sms_dialog_status_waiting),
status.getText().toString());
TestThreadUtils.runOnUiThreadBlocking(mSmsDialog::smsReceived);
mContinueButtonClickedCallback.waitForCallback(0, 1); Assert.assertEquals(View.GONE, progressBar.getVisibility());
Assert.assertEquals(View.VISIBLE, doneIcon.getVisibility());
Assert.assertEquals(
mActivityTestRule.getActivity().getString(R.string.sms_dialog_status_sms_received),
status.getText().toString());
} }
@Test @Test
@LargeTest @LargeTest
public void testDialogClose() { public void testDialogClose() {
ProgressDialog dialog = mSmsDialog.getDialogForTesting(); Dialog dialog = mSmsDialog.getDialogForTesting();
Assert.assertTrue(dialog.isShowing()); Assert.assertTrue(dialog.isShowing());
TestThreadUtils.runOnUiThreadBlocking(mSmsDialog::close); TestThreadUtils.runOnUiThreadBlocking(mSmsDialog::close);
......
...@@ -25,9 +25,9 @@ SmsDialogAndroid::~SmsDialogAndroid() { ...@@ -25,9 +25,9 @@ SmsDialogAndroid::~SmsDialogAndroid() {
} }
void SmsDialogAndroid::Open(content::RenderFrameHost* host, void SmsDialogAndroid::Open(content::RenderFrameHost* host,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_ = std::move(on_continue); on_confirm_ = std::move(on_confirm);
on_cancel_ = std::move(on_cancel); on_cancel_ = std::move(on_cancel);
content::WebContents* web_contents = content::WebContents* web_contents =
...@@ -48,8 +48,8 @@ void SmsDialogAndroid::SmsReceived() { ...@@ -48,8 +48,8 @@ void SmsDialogAndroid::SmsReceived() {
Java_SmsReceiverDialog_smsReceived(AttachCurrentThread(), java_dialog_); Java_SmsReceiverDialog_smsReceived(AttachCurrentThread(), java_dialog_);
} }
void SmsDialogAndroid::OnContinue(JNIEnv* env) { void SmsDialogAndroid::OnConfirm(JNIEnv* env) {
std::move(on_continue_).Run(); std::move(on_confirm_).Run();
} }
void SmsDialogAndroid::OnCancel(JNIEnv* env) { void SmsDialogAndroid::OnCancel(JNIEnv* env) {
......
...@@ -16,20 +16,20 @@ class SmsDialogAndroid : public content::SmsDialog { ...@@ -16,20 +16,20 @@ class SmsDialogAndroid : public content::SmsDialog {
~SmsDialogAndroid() override; ~SmsDialogAndroid() override;
void Open(content::RenderFrameHost*, void Open(content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) override; base::OnceClosure on_cancel) override;
void Close() override; void Close() override;
void SmsReceived() override; void SmsReceived() override;
// Report the user manually clicks the 'Continue' button. // Report the user manually clicks the 'Confirm' button.
void OnContinue(JNIEnv* env); void OnConfirm(JNIEnv* env);
// Report the user manually dismisses the SMS dialog. // Report the user manually dismisses the SMS dialog.
void OnCancel(JNIEnv* env); void OnCancel(JNIEnv* env);
private: private:
base::android::ScopedJavaGlobalRef<jobject> java_dialog_; base::android::ScopedJavaGlobalRef<jobject> java_dialog_;
base::OnceClosure on_continue_; base::OnceClosure on_confirm_;
base::OnceClosure on_cancel_; base::OnceClosure on_cancel_;
DISALLOW_COPY_AND_ASSIGN(SmsDialogAndroid); DISALLOW_COPY_AND_ASSIGN(SmsDialogAndroid);
}; };
......
...@@ -108,22 +108,21 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, Receive) { ...@@ -108,22 +108,21 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, Receive) {
auto* dialog = new NiceMock<MockSmsDialog>(); auto* dialog = new NiceMock<MockSmsDialog>();
base::OnceClosure on_continue_callback; base::OnceClosure on_confirm_callback;
EXPECT_CALL(delegate_, CreateSmsDialog()) EXPECT_CALL(delegate_, CreateSmsDialog())
.WillOnce(Return(ByMove(base::WrapUnique(dialog)))); .WillOnce(Return(ByMove(base::WrapUnique(dialog))));
EXPECT_CALL(*dialog, Open(_, _, _)) EXPECT_CALL(*dialog, Open(_, _, _))
.WillOnce(Invoke([&on_continue_callback](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm_callback](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_callback = std::move(on_continue); on_confirm_callback = std::move(on_confirm);
})); }));
EXPECT_CALL(*dialog, SmsReceived()) EXPECT_CALL(*dialog, SmsReceived()).WillOnce(Invoke([&on_confirm_callback]() {
.WillOnce(Invoke([&on_continue_callback]() { std::move(on_confirm_callback).Run();
std::move(on_continue_callback).Run(); }));
}));
auto* provider = new NiceMock<MockSmsProvider>(); auto* provider = new NiceMock<MockSmsProvider>();
BrowserMainLoop::GetInstance()->SetSmsProviderForTesting( BrowserMainLoop::GetInstance()->SetSmsProviderForTesting(
...@@ -154,22 +153,21 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, AtMostOnePendingSmsRequest) { ...@@ -154,22 +153,21 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, AtMostOnePendingSmsRequest) {
auto* dialog = new NiceMock<MockSmsDialog>(); auto* dialog = new NiceMock<MockSmsDialog>();
base::OnceClosure on_continue_callback; base::OnceClosure on_confirm_callback;
EXPECT_CALL(delegate_, CreateSmsDialog()) EXPECT_CALL(delegate_, CreateSmsDialog())
.WillOnce(Return(ByMove(base::WrapUnique(dialog)))); .WillOnce(Return(ByMove(base::WrapUnique(dialog))));
EXPECT_CALL(*dialog, Open(_, _, _)) EXPECT_CALL(*dialog, Open(_, _, _))
.WillOnce(Invoke([&on_continue_callback](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm_callback](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_callback = std::move(on_continue); on_confirm_callback = std::move(on_confirm);
})); }));
EXPECT_CALL(*dialog, SmsReceived()) EXPECT_CALL(*dialog, SmsReceived()).WillOnce(Invoke([&on_confirm_callback]() {
.WillOnce(Invoke([&on_continue_callback]() { std::move(on_confirm_callback).Run();
std::move(on_continue_callback).Run(); }));
}));
auto* provider = new NiceMock<MockSmsProvider>(); auto* provider = new NiceMock<MockSmsProvider>();
BrowserMainLoop::GetInstance()->SetSmsProviderForTesting( BrowserMainLoop::GetInstance()->SetSmsProviderForTesting(
...@@ -282,7 +280,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) { ...@@ -282,7 +280,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) {
true true
)"; )";
base::OnceClosure on_continue1, on_continue2; base::OnceClosure on_confirm1, on_confirm2;
{ {
base::RunLoop loop; base::RunLoop loop;
...@@ -299,10 +297,10 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) { ...@@ -299,10 +297,10 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) {
})); }));
EXPECT_CALL(*dialog, Open(_, _, _)) EXPECT_CALL(*dialog, Open(_, _, _))
.WillOnce(Invoke([&on_continue1](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm1](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue1 = std::move(on_continue); on_confirm1 = std::move(on_confirm);
})); }));
// First tab registers an observer. // First tab registers an observer.
...@@ -326,10 +324,10 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) { ...@@ -326,10 +324,10 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) {
})); }));
EXPECT_CALL(*dialog, Open(_, _, _)) EXPECT_CALL(*dialog, Open(_, _, _))
.WillOnce(Invoke([&on_continue2](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm2](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue2 = std::move(on_continue); on_confirm2 = std::move(on_confirm);
})); }));
// Second tab registers an observer. // Second tab registers an observer.
...@@ -342,7 +340,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) { ...@@ -342,7 +340,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) {
provider->NotifyReceive(url::Origin::Create(url), "hello1"); provider->NotifyReceive(url::Origin::Create(url), "hello1");
std::move(on_continue1).Run(); std::move(on_confirm1).Run();
EXPECT_EQ("hello1", EvalJs(tab1, "sms")); EXPECT_EQ("hello1", EvalJs(tab1, "sms"));
...@@ -350,7 +348,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) { ...@@ -350,7 +348,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsSameOrigin) {
provider->NotifyReceive(url::Origin::Create(url), "hello2"); provider->NotifyReceive(url::Origin::Create(url), "hello2");
std::move(on_continue2).Run(); std::move(on_confirm2).Run();
EXPECT_EQ("hello2", EvalJs(tab2, "sms")); EXPECT_EQ("hello2", EvalJs(tab2, "sms"));
...@@ -394,25 +392,25 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsDifferentOrigin) { ...@@ -394,25 +392,25 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsDifferentOrigin) {
auto* dialog1 = new NiceMock<MockSmsDialog>(); auto* dialog1 = new NiceMock<MockSmsDialog>();
auto* dialog2 = new NiceMock<MockSmsDialog>(); auto* dialog2 = new NiceMock<MockSmsDialog>();
base::OnceClosure on_continue_callback1; base::OnceClosure on_confirm_callback1;
base::OnceClosure on_continue_callback2; base::OnceClosure on_confirm_callback2;
EXPECT_CALL(delegate_, CreateSmsDialog()) EXPECT_CALL(delegate_, CreateSmsDialog())
.WillOnce(Return(ByMove(base::WrapUnique(dialog1)))) .WillOnce(Return(ByMove(base::WrapUnique(dialog1))))
.WillOnce(Return(ByMove(base::WrapUnique(dialog2)))); .WillOnce(Return(ByMove(base::WrapUnique(dialog2))));
EXPECT_CALL(*dialog1, Open(_, _, _)) EXPECT_CALL(*dialog1, Open(_, _, _))
.WillOnce(Invoke([&on_continue_callback1](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm_callback1](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_callback1 = std::move(on_continue); on_confirm_callback1 = std::move(on_confirm);
})); }));
EXPECT_CALL(*dialog2, Open(_, _, _)) EXPECT_CALL(*dialog2, Open(_, _, _))
.WillOnce(Invoke([&on_continue_callback2](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm_callback2](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_callback2 = std::move(on_continue); on_confirm_callback2 = std::move(on_confirm);
})); }));
EXPECT_EQ(true, EvalJs(tab1, script)); EXPECT_EQ(true, EvalJs(tab1, script));
...@@ -424,7 +422,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsDifferentOrigin) { ...@@ -424,7 +422,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsDifferentOrigin) {
provider->NotifyReceive(url::Origin::Create(url1), "hello1"); provider->NotifyReceive(url::Origin::Create(url1), "hello1");
std::move(on_continue_callback1).Run(); std::move(on_confirm_callback1).Run();
EXPECT_EQ("hello1", EvalJs(tab1, "sms")); EXPECT_EQ("hello1", EvalJs(tab1, "sms"));
...@@ -432,7 +430,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsDifferentOrigin) { ...@@ -432,7 +430,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, TwoTabsDifferentOrigin) {
provider->NotifyReceive(url::Origin::Create(url2), "hello2"); provider->NotifyReceive(url::Origin::Create(url2), "hello2");
std::move(on_continue_callback2).Run(); std::move(on_confirm_callback2).Run();
EXPECT_EQ("hello2", EvalJs(tab2, "sms")); EXPECT_EQ("hello2", EvalJs(tab2, "sms"));
...@@ -486,7 +484,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, Cancels) { ...@@ -486,7 +484,7 @@ IN_PROC_BROWSER_TEST_F(SmsBrowserTest, Cancels) {
EXPECT_CALL(*dialog, Open(_, _, _)) EXPECT_CALL(*dialog, Open(_, _, _))
.WillOnce( .WillOnce(
Invoke([](content::RenderFrameHost*, base::OnceClosure on_continue, Invoke([](content::RenderFrameHost*, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
// Simulates the user pressing "cancel". // Simulates the user pressing "cancel".
std::move(on_cancel).Run(); std::move(on_cancel).Run();
......
...@@ -116,7 +116,7 @@ void SmsService::OnTimeout() { ...@@ -116,7 +116,7 @@ void SmsService::OnTimeout() {
Dismiss(); Dismiss();
} }
void SmsService::OnContinue() { void SmsService::OnConfirm() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(sms_); DCHECK(sms_);
...@@ -145,7 +145,7 @@ void SmsService::Prompt() { ...@@ -145,7 +145,7 @@ void SmsService::Prompt() {
if (prompt_) { if (prompt_) {
prompt_->Open( prompt_->Open(
render_frame_host(), render_frame_host(),
base::BindOnce(&SmsService::OnContinue, base::Unretained(this)), base::BindOnce(&SmsService::OnConfirm, base::Unretained(this)),
base::BindOnce(&SmsService::OnCancel, base::Unretained(this))); base::BindOnce(&SmsService::OnCancel, base::Unretained(this)));
} }
} }
......
...@@ -60,8 +60,8 @@ class CONTENT_EXPORT SmsService ...@@ -60,8 +60,8 @@ class CONTENT_EXPORT SmsService
// Callback when the |timer_| times out. // Callback when the |timer_| times out.
void OnTimeout(); void OnTimeout();
// Callback when the user manually clicks 'Continue' button. // Callback when the user manually clicks 'Confirm' button.
void OnContinue(); void OnConfirm();
// Callback when the user manually dismisses the dialog. // Callback when the user manually dismisses the dialog.
void OnCancel(); void OnCancel();
......
...@@ -127,15 +127,15 @@ class Service { ...@@ -127,15 +127,15 @@ class Service {
EXPECT_CALL(*dialog, Open(rfh, _, _)) EXPECT_CALL(*dialog, Open(rfh, _, _))
.WillOnce( .WillOnce(
Invoke([&](content::RenderFrameHost*, base::OnceClosure on_continue, Invoke([&](content::RenderFrameHost*, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_callback_ = std::move(on_continue); on_confirm_callback_ = std::move(on_confirm);
})); }));
EXPECT_CALL(*dialog, SmsReceived()).WillOnce(Invoke([&]() { EXPECT_CALL(*dialog, SmsReceived()).WillOnce(Invoke([&]() {
// Simulates user clicking the "Continue" button to verify received // Simulates user clicking the "Confirm" button to verify received
// sms. // sms.
std::move(on_continue_callback_).Run(); std::move(on_confirm_callback_).Run();
})); }));
EXPECT_CALL(*dialog, Close()).WillOnce(Return()); EXPECT_CALL(*dialog, Close()).WillOnce(Return());
...@@ -154,7 +154,7 @@ class Service { ...@@ -154,7 +154,7 @@ class Service {
NiceMock<MockSmsProvider> provider_; NiceMock<MockSmsProvider> provider_;
blink::mojom::SmsReceiverPtr service_ptr_; blink::mojom::SmsReceiverPtr service_ptr_;
std::unique_ptr<SmsService> service_; std::unique_ptr<SmsService> service_;
base::OnceClosure on_continue_callback_; base::OnceClosure on_confirm_callback_;
}; };
class SmsServiceTest : public RenderViewHostTestHarness { class SmsServiceTest : public RenderViewHostTestHarness {
...@@ -484,7 +484,7 @@ TEST_F(SmsServiceTest, Cancel) { ...@@ -484,7 +484,7 @@ TEST_F(SmsServiceTest, Cancel) {
EXPECT_CALL(*dialog, Open(main_rfh(), _, _)) EXPECT_CALL(*dialog, Open(main_rfh(), _, _))
.WillOnce( .WillOnce(
Invoke([](content::RenderFrameHost*, base::OnceClosure on_continue, Invoke([](content::RenderFrameHost*, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
// Simulates the user pressing "Cancel". // Simulates the user pressing "Cancel".
std::move(on_cancel).Run(); std::move(on_cancel).Run();
...@@ -537,25 +537,24 @@ TEST_F(SmsServiceTest, SecondRequestTimesOutEarlierThanFirstRequest) { ...@@ -537,25 +537,24 @@ TEST_F(SmsServiceTest, SecondRequestTimesOutEarlierThanFirstRequest) {
auto* dialog1 = new NiceMock<MockSmsDialog>(); auto* dialog1 = new NiceMock<MockSmsDialog>();
auto* dialog2 = new NiceMock<MockSmsDialog>(); auto* dialog2 = new NiceMock<MockSmsDialog>();
base::OnceClosure on_continue_callback; base::OnceClosure on_confirm_callback;
EXPECT_CALL(*service.delegate(), CreateSmsDialog()) EXPECT_CALL(*service.delegate(), CreateSmsDialog())
.WillOnce(Return(ByMove(base::WrapUnique(dialog1)))) .WillOnce(Return(ByMove(base::WrapUnique(dialog1))))
.WillOnce(Return(ByMove(base::WrapUnique(dialog2)))); .WillOnce(Return(ByMove(base::WrapUnique(dialog2))));
EXPECT_CALL(*dialog1, Open(main_rfh(), _, _)) EXPECT_CALL(*dialog1, Open(main_rfh(), _, _))
.WillOnce(Invoke([&on_continue_callback](content::RenderFrameHost*, .WillOnce(Invoke([&on_confirm_callback](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_continue_callback = std::move(on_continue); on_confirm_callback = std::move(on_confirm);
})); }));
EXPECT_CALL(*dialog2, Open(main_rfh(), _, _)).Times(1); EXPECT_CALL(*dialog2, Open(main_rfh(), _, _)).Times(1);
EXPECT_CALL(*dialog1, SmsReceived()) EXPECT_CALL(*dialog1, SmsReceived())
.WillOnce(Invoke([&on_continue_callback]() { .WillOnce(Invoke(
std::move(on_continue_callback).Run(); [&on_confirm_callback]() { std::move(on_confirm_callback).Run(); }));
}));
EXPECT_CALL(*service.provider(), Retrieve()) EXPECT_CALL(*service.provider(), Retrieve())
.WillOnce(Invoke([&service]() { .WillOnce(Invoke([&service]() {
...@@ -641,7 +640,7 @@ TEST_F(SmsServiceTest, RecordCancelOnSuccessTimeMetric) { ...@@ -641,7 +640,7 @@ TEST_F(SmsServiceTest, RecordCancelOnSuccessTimeMetric) {
EXPECT_CALL(*dialog, Open(main_rfh(), _, _)) EXPECT_CALL(*dialog, Open(main_rfh(), _, _))
.WillOnce( .WillOnce(
Invoke([](content::RenderFrameHost*, base::OnceClosure on_continue, Invoke([](content::RenderFrameHost*, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
// Simulates the user pressing "Cancel". // Simulates the user pressing "Cancel".
std::move(on_cancel).Run(); std::move(on_cancel).Run();
...@@ -678,7 +677,7 @@ TEST_F(SmsServiceTest, RecordCancelOnSuccessTimeMetric) { ...@@ -678,7 +677,7 @@ TEST_F(SmsServiceTest, RecordCancelOnSuccessTimeMetric) {
EXPECT_CALL(*dialog, Open(main_rfh(), _, _)) EXPECT_CALL(*dialog, Open(main_rfh(), _, _))
.WillOnce(Invoke([&on_cancel_callback](content::RenderFrameHost*, .WillOnce(Invoke([&on_cancel_callback](content::RenderFrameHost*,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) { base::OnceClosure on_cancel) {
on_cancel_callback = std::move(on_cancel); on_cancel_callback = std::move(on_cancel);
})); }));
......
...@@ -19,7 +19,7 @@ class CONTENT_EXPORT SmsDialog { ...@@ -19,7 +19,7 @@ class CONTENT_EXPORT SmsDialog {
SmsDialog() = default; SmsDialog() = default;
virtual ~SmsDialog() = default; virtual ~SmsDialog() = default;
virtual void Open(content::RenderFrameHost* host, virtual void Open(content::RenderFrameHost* host,
base::OnceClosure on_continue, base::OnceClosure on_confirm,
base::OnceClosure on_cancel) = 0; base::OnceClosure on_cancel) = 0;
virtual void Close() = 0; virtual void Close() = 0;
virtual void SmsReceived() = 0; virtual void SmsReceived() = 0;
......
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