Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b1029f65c |
@@ -1403,13 +1403,14 @@ func checkOtherPages(ctx context.Context, t *testing.T, urls ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// answerPrompt stands in for the user at the browser's prompt: it makes
|
// answerPrompt returns a script that stands in for the user at the
|
||||||
// window.confirm record the question in window.asked and give answer.
|
// browser's prompt: it makes window.confirm record the question in
|
||||||
// It also records in window.sent whether a form is sent once its submit
|
// window.asked and give answer. It also records in window.sent whether
|
||||||
// event is handled, from a listener on window, which the event reaches
|
// a form is sent once its submit event is handled, from a listener on
|
||||||
// after the listener static/js/app.js adds to document.
|
// window, which the event reaches after the listener static/js/app.js
|
||||||
func answerPrompt(answer bool) chromedp.Action {
|
// adds to document.
|
||||||
return chromedp.Evaluate(fmt.Sprintf(`
|
func answerPrompt(answer bool) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
window.asked = "";
|
window.asked = "";
|
||||||
window.sent = false;
|
window.sent = false;
|
||||||
window.confirm = (question) => {
|
window.confirm = (question) => {
|
||||||
@@ -1418,7 +1419,7 @@ func answerPrompt(answer bool) chromedp.Action {
|
|||||||
};
|
};
|
||||||
window.addEventListener("submit", (event) => {
|
window.addEventListener("submit", (event) => {
|
||||||
window.sent = !event.defaultPrevented;
|
window.sent = !event.defaultPrevented;
|
||||||
});`, answer), nil)
|
});`, answer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkDeletePrompt loads a webhook page and clicks Delete beside
|
// checkDeletePrompt loads a webhook page and clicks Delete beside
|
||||||
@@ -1441,7 +1442,9 @@ func checkDeletePrompt(
|
|||||||
listed bool
|
listed bool
|
||||||
)
|
)
|
||||||
|
|
||||||
require.NoError(t, chromedp.Run(ctx, loadPage(url), answerPrompt(false)))
|
require.NoError(t, chromedp.Run(
|
||||||
|
ctx, loadPage(url), chromedp.Evaluate(answerPrompt(false), nil),
|
||||||
|
))
|
||||||
click(ctx, t, form+" button")
|
click(ctx, t, form+" button")
|
||||||
require.NoError(t, chromedp.Run(
|
require.NoError(t, chromedp.Run(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -1451,7 +1454,9 @@ func checkDeletePrompt(
|
|||||||
assert.Equal(t, question, asked, "Delete does not ask about the target")
|
assert.Equal(t, question, asked, "Delete does not ask about the target")
|
||||||
assert.False(t, sent, "answering no still sends the delete form")
|
assert.False(t, sent, "answering no still sends the delete form")
|
||||||
|
|
||||||
require.NoError(t, chromedp.Run(ctx, answerPrompt(true)))
|
require.NoError(t, chromedp.Run(
|
||||||
|
ctx, chromedp.Evaluate(answerPrompt(true), nil),
|
||||||
|
))
|
||||||
clickAndLoad(ctx, t, form+" button")
|
clickAndLoad(ctx, t, form+" button")
|
||||||
require.NoError(t, chromedp.Run(ctx, chromedp.Evaluate(
|
require.NoError(t, chromedp.Run(ctx, chromedp.Evaluate(
|
||||||
`document.querySelector('`+form+`') !== null`, &listed,
|
`document.querySelector('`+form+`') !== null`, &listed,
|
||||||
|
|||||||
Reference in New Issue
Block a user