diff --git a/testing/web-platform/tests/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose.tentative.html b/testing/web-platform/tests/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose.tentative.html index 1606216e1cd9..31b40b055008 100644 --- a/testing/web-platform/tests/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose.tentative.html +++ b/testing/web-platform/tests/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose.tentative.html @@ -404,17 +404,595 @@ cancelable ) ; +async +function +setup +( +t +closedby +) +{ +t +. +add_cleanup +( +( +) += +> +{ +dialog +. +close +( +) +; +dialog +. +removeAttribute +( +' +closedby +' +) +; +dialog +. +returnValue += +' +' +; +} +) +; +assert_false +( +dialog +. +hasAttribute +( +' +closedby +' +) +) +; +if +( +closedby +) +{ +dialog +. +setAttribute +( +' +closedby +' +closedby +) +; +} +/ +/ +Be +sure +any +pending +close +events +get +fired +. +await +new +Promise +( +resolve += +> +requestAnimationFrame +( +resolve +) +) +; +return +getSignal +( +t +) +; +} +[ +false +true +] +. +forEach +( +modal += +> +{ +[ +null +' +any +' +' +closedrequest +' +' +none +' +] +. +forEach +( +closedby += +> +{ +const +testDescription += +for +{ +modal +? +" +modal +" +: +" +modeless +" +} +dialog +with +closedby += +{ +closedby +} +; +promise_test +( +async +( +t +) += +> +{ +await +setup +( +t +closedby +) +; +openDialog +( +modal +) +; +if +( +dialog +. +closedBy +! += +" +none +" +) +{ +dialog +. +requestClose +( +) +; +assert_false +( +dialog +. +open +) +; +} +else +{ +assert_throws_dom +( +' +InvalidStateError +' +( +) += +> +dialog +. +requestClose +( +) +) +; +assert_true +( +dialog +. +open +) +; +} +} +requestClose +basic +behavior +{ +testDescription +} +) +; +promise_test +( +async +( +t +) += +> +{ +const +signal += +await +setup +( +t +closedby +) +; +let +events += +[ +] +; +dialog +. +addEventListener +( +' +cancel +' +( +) += +> +events +. +push +( +' +cancel +' +) +{ +signal +} +) +; +dialog +. +addEventListener +( +' +close +' +( +) += +> +events +. +push +( +' +close +' +) +{ +signal +} +) +; +openDialog +( +modal +) +; +assert_array_equals +( +events +[ +] +) +; +if +( +dialog +. +closedBy +! += +" +none +" +) +{ +dialog +. +requestClose +( +) +; +assert_false +( +dialog +. +open +) +; +assert_array_equals +( +events +[ +' +cancel +' +] +' +close +is +scheduled +' +) +; +await +new +Promise +( +resolve += +> +requestAnimationFrame +( +resolve +) +) +; +assert_array_equals +( +events +[ +' +cancel +' +' +close +' +] +) +; +} +else +{ +assert_throws_dom +( +' +InvalidStateError +' +( +) += +> +dialog +. +requestClose +( +) +) +; +} +} +requestClose +fires +both +cancel +and +close +{ +testDescription +} +) +; +promise_test +( +async +( +t +) += +> +{ +const +signal += +await +setup +( +t +' +none +' +) +; +let +events += [ -false -true ] +; +dialog . -forEach +addEventListener +( +' +cancel +' +( +) += +> +events +. +push +( +' +cancel +' +) +{ +signal +} +) +; +dialog +. +addEventListener +( +' +close +' +( +) += +> +events +. +push +( +' +close +' +) +{ +signal +} +) +; +openDialog ( modal +) +; +dialog +. +setAttribute +( +' +closedby +' +closedby +) +; +assert_array_equals +( +events +[ +] +) +; +if +( +dialog +. +closedBy +! += +" +none +" +) +{ +dialog +. +requestClose +( +) +; +assert_false +( +dialog +. +open +) +; +} +else +{ +assert_throws_dom +( +' +InvalidStateError +' +( +) = > +dialog +. +requestClose +( +) +) +; +} +} +changing +closedby +from +' +none +' +to +' +{ +closedby +} +' +for { +modal +? +" +modal +" +: +" +modeless +" +} +dialog +) +; promise_test ( async @@ -424,19 +1002,68 @@ = > { +const +signal += +await +setup +( t +closedby +) +; +let +events += +[ +] +; +dialog . -add_cleanup +addEventListener ( +' +cancel +' ( ) = > +events +. +push +( +' +cancel +' +) +{ +signal +} +) +; dialog . +addEventListener +( +' close +' +( +) += +> +events +. +push ( +' +close +' ) +{ +signal +} ) ; openDialog @@ -446,6 +1073,34 @@ ; dialog . +removeAttribute +( +' +closedby +' +) +; +assert_array_equals +( +events +[ +] +) +; +if +( +dialog +. +closedBy +! += +" +none +" +) +{ +dialog +. requestClose ( ) @@ -458,27 +1113,63 @@ ) ; } +else +{ +assert_throws_dom +( +' +InvalidStateError +' +( +) += +> +dialog +. +requestClose +( +) +) +; +} +} +Removing +closedby +when +closedby += +' +{ +closedby +} +' +for { modal ? " -Modal -: +modal " : " -Non -- -modal -: +modeless " } -requestClose -closes -the dialog ) -; +; +if +( +dialog +. +closedBy +! += +" +none +" +) +{ promise_test ( async @@ -488,27 +1179,14 @@ = > { -t -. -add_cleanup -( -( -) -= -> -dialog -. -close -( -) -) -; const signal = -getSignal +await +setup ( t +closedby ) ; let @@ -628,25 +1306,295 @@ ) ; } +requestClose +can +be +cancelled { +testDescription +} +) +; +promise_test +( +async +( +t +) += +> +{ +await +setup +( +t +closedby +) +; +openDialog +( modal -? -" -Modal -: -" -: -" -Non -- -modal +) +; +assert_equals +( +dialog +. +returnValue +' +' +' +Return +value +starts +out +empty +' +) +; +const +returnValue += +' +The +return +value +' +; +dialog +. +requestClose +( +returnValue +) +; +assert_false +( +dialog +. +open +) +; +assert_equals +( +dialog +. +returnValue +returnValue +' +Return +value +should +be +set +' +) +; +dialog +. +show +( +) +; +dialog +. +close +( +) +; +assert_equals +( +dialog +. +returnValue +returnValue +' +Return +value +should +not +be +changed +by +close +( +) +' +) +; +dialog +. +show +( +) +; +dialog +. +close +( +' +another +' +) +; +assert_equals +( +dialog +. +returnValue +' +another +' +' +Return +value +changes +via +close +( +value +) +' +) +; +} +requestClose +( +returnValue +) +passes +along +the +return +value +{ +testDescription +} +) +; +promise_test +( +async +( +t +) += +> +{ +await +setup +( +t +closedby +) +; +dialog +. +addEventListener +( +' +cancel +' +( +e +) += +> +e +. +preventDefault +( +) +{ +once : -" +true } +) +; +openDialog +( +modal +) +; +dialog +. +returnValue += +' +foo +' +; +assert_equals +( +dialog +. +returnValue +' +foo +' +) +; +dialog +. requestClose -can +( +' +This +should +not +get +saved +' +) +; +assert_true +( +dialog +. +open +' +cancelled +' +) +; +assert_equals +( +dialog +. +returnValue +' +foo +' +' +Return +value +should +not be +changed +' +) +; +} +requestClose +( +returnValue +) +doesn +' +t +change +returnvalue +when cancelled +{ +testDescription +} +) +; +} +} ) ; }