Commit 9f3abede authored by Nancy Wang's avatar Nancy Wang Committed by Commit Bot

Call the callback function when the pause app dialog is closed.

SetAcceptCallback for the pause app dialog only quarantines the callback
function is called when the OK button is clicked. When press 'esc' to
dismiss the dialog, the callback is not called.

For the pause app dialog, the callback function should be called when:
1: the OK button is called
2: 'esc' is pressed to dismiss the dialog,

The dialog view needs 2 separate callback functions for Accept and Close
cases separately, however, we have 1 callback only. So we don't use the
dialog view's function, but create the local closed_callback_ variable,
and when the pause app dialog is destroyed, call the closed_callback_,
so both the above 2 scenarios can call the callback function.

The browser test is modified to test the above 2 scenarios.

BUG=1144386

Change-Id: I5dd7accfd4e16fcafb7d019877c648b25d71b881
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515864
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823872}
parent a7eaa278
......@@ -73,6 +73,17 @@ class AppDialogViewBrowserTest : public DialogBrowserTest {
apps::AppServiceProxy* app_service_proxy() { return app_service_proxy_; }
bool IsAppPaused() {
app_service_proxy()->FlushMojoCallsForTesting();
bool is_app_paused = false;
app_service_proxy()->AppRegistryCache().ForOneApp(
app_id(), [&is_app_paused](const apps::AppUpdate& update) {
is_app_paused = (update.Paused() == apps::mojom::OptionalBool::kTrue);
});
return is_app_paused;
}
void ShowUi(const std::string& name) override {
arc::mojom::AppInfo app;
app.name = "Fake App 0";
......@@ -126,7 +137,10 @@ class AppDialogViewBrowserTest : public DialogBrowserTest {
EXPECT_TRUE(state_is_set);
} else {
ActiveView(name)->AcceptDialog();
if (name == "pause_close")
ActiveView(name)->Close();
else
ActiveView(name)->AcceptDialog();
}
}
......@@ -143,14 +157,10 @@ IN_PROC_BROWSER_TEST_F(AppDialogViewBrowserTest, InvokeUi_block) {
IN_PROC_BROWSER_TEST_F(AppDialogViewBrowserTest, InvokeUi_pause) {
ShowAndVerifyUi();
EXPECT_TRUE(IsAppPaused());
}
app_service_proxy()->FlushMojoCallsForTesting();
bool state_is_set = false;
app_service_proxy()->AppRegistryCache().ForOneApp(
app_id(), [&state_is_set](const apps::AppUpdate& update) {
state_is_set = (update.Paused() == apps::mojom::OptionalBool::kTrue);
});
EXPECT_TRUE(state_is_set);
IN_PROC_BROWSER_TEST_F(AppDialogViewBrowserTest, InvokeUi_pause_close) {
ShowAndVerifyUi();
EXPECT_TRUE(IsAppPaused());
}
......@@ -42,7 +42,7 @@ AppPauseDialogView::AppPauseDialogView(
SetTitle(l10n_util::GetStringFUTF16(IDS_APP_PAUSE_PROMPT_TITLE,
base::UTF8ToUTF16(app_name)));
SetAcceptCallback(std::move(closed_callback));
closed_callback_ = std::move(closed_callback);
const int cutoff = pause_data.minutes == 0 || pause_data.hours == 0 ? 0 : -1;
base::string16 heading_text = l10n_util::GetStringFUTF16(
......@@ -63,6 +63,8 @@ AppPauseDialogView::AppPauseDialogView(
AppPauseDialogView::~AppPauseDialogView() {
g_app_pause_dialog_view = nullptr;
if (closed_callback_)
std::move(closed_callback_).Run();
}
// static
......
......@@ -25,6 +25,9 @@ class AppPauseDialogView : public AppDialogView {
~AppPauseDialogView() override;
static AppPauseDialogView* GetActiveViewForTesting();
private:
base::OnceClosure closed_callback_;
};
#endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_PAUSE_DIALOG_VIEW_H_
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