2012-04-16 23:15:27 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2017-05-31 17:33:30 +02:00
|
|
|
#include "include/test/cef_test_helpers.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2012-04-16 23:15:27 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char* kStartUrl = "https://tests/JSDialogTestHandler.Start";
|
|
|
|
const char* kEndUrl = "https://tests/JSDialogTestHandler.End?r=";
|
2012-04-16 23:15:27 +02:00
|
|
|
|
|
|
|
class JSDialogTestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
enum TestType {
|
|
|
|
TYPE_ALERT,
|
|
|
|
TYPE_CONFIRM,
|
|
|
|
TYPE_PROMPT,
|
|
|
|
TYPE_ONBEFOREUNLOAD,
|
|
|
|
};
|
|
|
|
enum TestMode {
|
|
|
|
MODE_SUPPRESS,
|
|
|
|
MODE_RUN_IMMEDIATE,
|
|
|
|
MODE_RUN_DELAYED,
|
|
|
|
};
|
|
|
|
|
|
|
|
JSDialogTestHandler(TestType type,
|
|
|
|
TestMode mode,
|
|
|
|
bool success,
|
|
|
|
const std::string& user_input,
|
|
|
|
const std::string& result)
|
2017-05-17 11:29:28 +02:00
|
|
|
: type_(type),
|
|
|
|
mode_(mode),
|
|
|
|
success_(success),
|
|
|
|
user_input_(user_input),
|
|
|
|
result_(result) {}
|
2012-04-16 23:15:27 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2012-04-16 23:15:27 +02:00
|
|
|
std::string content = "<html><head><body>START<script>";
|
|
|
|
if (type_ == TYPE_ALERT) {
|
2017-05-17 11:29:28 +02:00
|
|
|
content +=
|
|
|
|
"alert('My alert message'); "
|
|
|
|
"document.location='" +
|
|
|
|
std::string(kEndUrl) + "';";
|
2012-04-16 23:15:27 +02:00
|
|
|
} else if (type_ == TYPE_CONFIRM) {
|
2017-05-17 11:29:28 +02:00
|
|
|
content +=
|
|
|
|
"var r = confirm('My confirm message')?'ok':'cancel'; "
|
|
|
|
"document.location='" +
|
|
|
|
std::string(kEndUrl) + "'+r;";
|
2012-04-16 23:15:27 +02:00
|
|
|
} else if (type_ == TYPE_PROMPT) {
|
2017-05-17 11:29:28 +02:00
|
|
|
content +=
|
|
|
|
"var r = prompt('My prompt message','my default'); "
|
|
|
|
"document.location='" +
|
|
|
|
std::string(kEndUrl) + "'+r;";
|
2012-04-16 23:15:27 +02:00
|
|
|
} else if (type_ == TYPE_ONBEFOREUNLOAD) {
|
2017-05-17 11:29:28 +02:00
|
|
|
content +=
|
|
|
|
"window.onbeforeunload=function() {"
|
|
|
|
" return 'My unload message'; };";
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
content += "</script></body></html>";
|
|
|
|
|
|
|
|
AddResource(kStartUrl, content, "text/html");
|
|
|
|
AddResource(kEndUrl, "<html><body>END</body></html>", "text/html");
|
|
|
|
|
|
|
|
// Create the browser
|
|
|
|
CreateBrowser(kStartUrl);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame->IsMain()) {
|
2012-04-16 23:15:27 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-16 23:15:27 +02:00
|
|
|
|
|
|
|
std::string url = frame->GetURL();
|
|
|
|
if (url.find(kEndUrl) == 0) {
|
|
|
|
got_onloadend_.yes();
|
|
|
|
|
|
|
|
std::string result = url.substr(strlen(kEndUrl));
|
|
|
|
EXPECT_STREQ(result_.c_str(), result.c_str());
|
|
|
|
|
|
|
|
DestroyTest();
|
|
|
|
} else if (type_ == TYPE_ONBEFOREUNLOAD) {
|
2017-05-31 17:33:30 +02:00
|
|
|
// Send the page a user gesture to enable firing of the onbefureunload
|
|
|
|
// handler. See https://crbug.com/707007.
|
|
|
|
CefExecuteJavaScriptWithUserGestureForTests(frame, CefString());
|
|
|
|
|
2012-04-16 23:15:27 +02:00
|
|
|
// Trigger the onunload handler.
|
|
|
|
frame->LoadURL(kEndUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void Continue(CefRefPtr<CefJSDialogCallback> callback) {
|
2012-04-16 23:15:27 +02:00
|
|
|
callback->Continue(success_, user_input_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnJSDialog(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
JSDialogType dialog_type,
|
|
|
|
const CefString& message_text,
|
|
|
|
const CefString& default_prompt_text,
|
|
|
|
CefRefPtr<CefJSDialogCallback> callback,
|
|
|
|
bool& suppress_message) override {
|
2012-04-16 23:15:27 +02:00
|
|
|
got_onjsdialog_.yes();
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
EXPECT_STREQ(kStartUrl, origin_url.ToString().c_str());
|
2012-04-16 23:15:27 +02:00
|
|
|
|
|
|
|
if (type_ == TYPE_ALERT) {
|
|
|
|
EXPECT_EQ(JSDIALOGTYPE_ALERT, dialog_type);
|
|
|
|
EXPECT_STREQ("My alert message", message_text.ToString().c_str());
|
|
|
|
EXPECT_TRUE(default_prompt_text.empty());
|
|
|
|
} else if (type_ == TYPE_CONFIRM) {
|
|
|
|
EXPECT_EQ(JSDIALOGTYPE_CONFIRM, dialog_type);
|
|
|
|
EXPECT_STREQ("My confirm message", message_text.ToString().c_str());
|
|
|
|
EXPECT_TRUE(default_prompt_text.empty());
|
|
|
|
} else if (type_ == TYPE_PROMPT) {
|
|
|
|
EXPECT_EQ(JSDIALOGTYPE_PROMPT, dialog_type);
|
|
|
|
EXPECT_STREQ("My prompt message", message_text.ToString().c_str());
|
|
|
|
EXPECT_STREQ("my default", default_prompt_text.ToString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_FALSE(suppress_message);
|
|
|
|
|
|
|
|
if (mode_ == MODE_SUPPRESS) {
|
|
|
|
// Suppress the dialog.
|
|
|
|
suppress_message = true;
|
|
|
|
return false;
|
|
|
|
} else if (mode_ == MODE_RUN_IMMEDIATE) {
|
|
|
|
// Continue immediately.
|
|
|
|
callback->Continue(success_, user_input_);
|
|
|
|
} else if (mode_ == MODE_RUN_DELAYED) {
|
|
|
|
// Continue asynchronously.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&JSDialogTestHandler::Continue, this,
|
|
|
|
callback));
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& message_text,
|
|
|
|
bool is_reload,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefJSDialogCallback> callback) override {
|
2012-04-16 23:15:27 +02:00
|
|
|
got_onbeforeunloaddialog_.yes();
|
|
|
|
|
|
|
|
if (type_ == TYPE_ONBEFOREUNLOAD) {
|
2016-03-16 03:55:59 +01:00
|
|
|
// The message is no longer configurable via JavaScript.
|
2023-04-29 00:17:03 +02:00
|
|
|
// See https://crbug.com/587940.
|
2016-03-16 03:55:59 +01:00
|
|
|
EXPECT_STREQ("Is it OK to leave/reload this page?",
|
|
|
|
message_text.ToString().c_str());
|
2012-04-16 23:15:27 +02:00
|
|
|
EXPECT_FALSE(is_reload);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode_ == MODE_RUN_IMMEDIATE) {
|
|
|
|
// Continue immediately.
|
|
|
|
callback->Continue(success_, user_input_);
|
|
|
|
} else if (mode_ == MODE_RUN_DELAYED) {
|
|
|
|
// Continue asynchronously.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&JSDialogTestHandler::Continue, this,
|
|
|
|
callback));
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnResetDialogState(CefRefPtr<CefBrowser> browser) override {
|
2012-04-16 23:15:27 +02:00
|
|
|
got_onresetdialogstate_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
TestType type_;
|
|
|
|
TestMode mode_;
|
|
|
|
bool success_;
|
|
|
|
std::string user_input_;
|
|
|
|
std::string result_;
|
|
|
|
|
|
|
|
TrackCallback got_onjsdialog_;
|
|
|
|
TrackCallback got_onbeforeunloaddialog_;
|
|
|
|
TrackCallback got_onresetdialogstate_;
|
|
|
|
TrackCallback got_onloadend_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(JSDialogTestHandler);
|
2012-04-16 23:15:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Alert dialog with suppression.
|
|
|
|
TEST(JSDialogTest, AlertSuppress) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_ALERT, JSDialogTestHandler::MODE_SUPPRESS,
|
|
|
|
true, // success
|
|
|
|
"", // user_input
|
|
|
|
""); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Alert dialog with immediate callback.
|
|
|
|
TEST(JSDialogTest, AlertRunImmediate) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_ALERT, JSDialogTestHandler::MODE_RUN_IMMEDIATE,
|
|
|
|
true, // success
|
|
|
|
"", // user_input
|
|
|
|
""); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Alert dialog with delayed callback.
|
|
|
|
TEST(JSDialogTest, AlertRunDelayed) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_ALERT, JSDialogTestHandler::MODE_RUN_DELAYED,
|
|
|
|
true, // success
|
|
|
|
"", // user_input
|
|
|
|
""); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm dialog with suppression.
|
|
|
|
TEST(JSDialogTest, ConfirmSuppress) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_CONFIRM, JSDialogTestHandler::MODE_SUPPRESS,
|
|
|
|
true, // success
|
|
|
|
"", // user_input
|
|
|
|
"cancel"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm dialog run immediately return OK.
|
|
|
|
TEST(JSDialogTest, ConfirmRunImmediateOk) {
|
|
|
|
CefRefPtr<JSDialogTestHandler> handler =
|
|
|
|
new JSDialogTestHandler(JSDialogTestHandler::TYPE_CONFIRM,
|
|
|
|
JSDialogTestHandler::MODE_RUN_IMMEDIATE,
|
2017-05-17 11:29:28 +02:00
|
|
|
true, // success
|
|
|
|
"", // user_input
|
2012-04-16 23:15:27 +02:00
|
|
|
"ok"); // result
|
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm dialog run immediately return Cancel.
|
|
|
|
TEST(JSDialogTest, ConfirmRunImmediateCancel) {
|
|
|
|
CefRefPtr<JSDialogTestHandler> handler =
|
|
|
|
new JSDialogTestHandler(JSDialogTestHandler::TYPE_CONFIRM,
|
|
|
|
JSDialogTestHandler::MODE_RUN_IMMEDIATE,
|
2017-05-17 11:29:28 +02:00
|
|
|
false, // success
|
|
|
|
"", // user_input
|
2012-04-16 23:15:27 +02:00
|
|
|
"cancel"); // result
|
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm dialog run delayed return OK.
|
|
|
|
TEST(JSDialogTest, ConfirmRunDelayedOk) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_CONFIRM, JSDialogTestHandler::MODE_RUN_DELAYED,
|
|
|
|
true, // success
|
|
|
|
"", // user_input
|
|
|
|
"ok"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm dialog run delayed return Cancel.
|
|
|
|
TEST(JSDialogTest, ConfirmRunDelayedCancel) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_CONFIRM, JSDialogTestHandler::MODE_RUN_DELAYED,
|
|
|
|
false, // success
|
|
|
|
"", // user_input
|
|
|
|
"cancel"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt dialog with suppression.
|
|
|
|
TEST(JSDialogTest, PromptSuppress) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_PROMPT, JSDialogTestHandler::MODE_SUPPRESS,
|
|
|
|
true, // success
|
|
|
|
"some_value", // user_input
|
|
|
|
"null"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt dialog run immediately return OK.
|
|
|
|
TEST(JSDialogTest, PromptRunImmediateOk) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_PROMPT, JSDialogTestHandler::MODE_RUN_IMMEDIATE,
|
|
|
|
true, // success
|
|
|
|
"some_value", // user_input
|
|
|
|
"some_value"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt dialog run immediately return Cancel.
|
|
|
|
TEST(JSDialogTest, PromptRunImmediateCancel) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_PROMPT, JSDialogTestHandler::MODE_RUN_IMMEDIATE,
|
|
|
|
false, // success
|
|
|
|
"some_value", // user_input
|
|
|
|
"null"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt dialog run delayed return OK.
|
|
|
|
TEST(JSDialogTest, PromptRunDelayedOk) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_PROMPT, JSDialogTestHandler::MODE_RUN_DELAYED,
|
|
|
|
true, // success
|
|
|
|
"some_value", // user_input
|
|
|
|
"some_value"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt dialog run delayed return Cancel.
|
|
|
|
TEST(JSDialogTest, PromptRunDelayedCancel) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<JSDialogTestHandler> handler = new JSDialogTestHandler(
|
|
|
|
JSDialogTestHandler::TYPE_PROMPT, JSDialogTestHandler::MODE_RUN_DELAYED,
|
|
|
|
false, // success
|
|
|
|
"some_value", // user_input
|
|
|
|
"null"); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_TRUE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_FALSE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnBeforeUnload dialog with immediate callback.
|
|
|
|
TEST(JSDialogTest, OnBeforeUnloadRunImmediate) {
|
|
|
|
CefRefPtr<JSDialogTestHandler> handler =
|
|
|
|
new JSDialogTestHandler(JSDialogTestHandler::TYPE_ONBEFOREUNLOAD,
|
|
|
|
JSDialogTestHandler::MODE_RUN_IMMEDIATE,
|
|
|
|
true, // success
|
2017-05-17 11:29:28 +02:00
|
|
|
"", // user_input
|
|
|
|
""); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_FALSE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnBeforeUnload dialog with delayed callback.
|
|
|
|
TEST(JSDialogTest, OnBeforeUnloadRunDelayed) {
|
|
|
|
CefRefPtr<JSDialogTestHandler> handler =
|
|
|
|
new JSDialogTestHandler(JSDialogTestHandler::TYPE_ONBEFOREUNLOAD,
|
|
|
|
JSDialogTestHandler::MODE_RUN_DELAYED,
|
|
|
|
true, // success
|
2017-05-17 11:29:28 +02:00
|
|
|
"", // user_input
|
|
|
|
""); // result
|
2012-04-16 23:15:27 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
EXPECT_FALSE(handler->got_onjsdialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onbeforeunloaddialog_);
|
|
|
|
EXPECT_TRUE(handler->got_onresetdialogstate_);
|
|
|
|
EXPECT_TRUE(handler->got_onloadend_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-16 23:15:27 +02:00
|
|
|
}
|