@@ -29,183 +29,68 @@ var a = $("link"),
checkOpened = function ( ) { ok ( window . open ( "http://example.com" ) , "not properly opened" ) } ,
checkBlocked = function ( ) { ok ( ! window . open ( "http://example.com" ) , "not properly blocked" ) } ;
add _task ( async function check _sanity ( ) {
await new Promise ( resolve => setTimeout ( resolve , 200 ) ) ;
const popupSpamMaximum = 3 ;
const eventInAllowedList = "click" ;
const eventNotInAllowedList = "mouseup" ;
async function testPopupSpamMaximum ( ) {
// Opening a popup from an event in the allowed event list doesn’ t affect the
// popup spam count.
for ( var count = 0 , n = 0 ; n < popupSpamMaximum ; n ++ ) {
sendWithUserActivation ( a , eventInAllowedList , checkOpened ) ;
}
sendWithUserActivation ( a , eventInAllowedList , checkOpened ) ;
for ( var count = 0 , n = 0 ; n < popupSpamMaximum ; n ++ ) {
sendWithUserActivation ( a , eventNotInAllowedList , checkOpened ) ;
}
sendWithUserActivation ( a , eventNotInAllowedList , checkBlocked ) ;
// Close one spam popup.
await window . open . close ( 1 ) ;
sendWithUserActivation ( a , eventNotInAllowedList , checkOpened ) ;
sendWithUserActivation ( a , eventNotInAllowedList , checkBlocked ) ;
// Still allow opening a popup from an event in the allowed event list even if
// the popup spam count has reached its maximum.
sendWithUserActivation ( a , eventInAllowedList , checkOpened ) ;
await window . open . close ( ) ;
}
add _setup ( async function init ( ) {
await SpecialPowers . pushPrefEnv ( { "set" : [
// Enable popup blocker
[ "dom.disable_open_during_load" , true ] ,
[ "dom.popup_allowed_events" , eventInAllowedList ] ,
[ "dom.popup_maximum" , popupSpamMaximum ] ,
] } ) ;
} ) ;
add _task ( async function test _unknown _permission ( ) {
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'remove' : true , 'context' : document } ] ) ;
ok ( await SpecialPowers . testPermission ( 'popup' , UNKNOWN _ACTION , document ) , 'popup value should have UNKNOWN permission' ) ;
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'allow' : true , 'context' : document } ] ) ;
await testPopupSpamMaximum ( ) ;
await SpecialPowers . popPermissions ( ) ;
} )
add _task ( async function run _allow _permission ( ) {
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'allow' : ALLOW _ACTION , 'context' : document } ] ) ;
ok ( await SpecialPowers . testPermission ( 'popup' , ALLOW _ACTION , document ) , 'popup value should have ALLOW permission' ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [
[ "dom.disable_open_during_load" , true ] ,
// XXXedgar: Now dom.block_multiple_popups is also true by default in testng
// profile. However, this test primarily focuses on behavior when the
// preference is turned off. If dom.block_multiple_popups is removed in the
// future at some point, this test will need to be updated accordingly.
[ "dom.block_multiple_popups" , false ] ,
[ "dom.popup_allowed_events" , "click mouseup" ] ,
[ "dom.popup_maximum" , 3 ]
] } ) ;
await testPopupSpamMaximum ( ) ;
// Note: UNKNOWN_ACTION is the same as DENY_ACTION.
await SpecialPowers . popPermissions ( ) ;
} ) ;
add _task ( async function run _deny _permission ( ) {
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'allow' : DENY _ACTION , 'context' : document } ] ) ;
} ) ;
ok ( await SpecialPowers . testPermission ( 'popup' , DENY _ACTION , document ) , 'popup value should have ALLOW permission' ) ;
add _task ( async function run _tests ( ) {
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
await window . open . close ( ) ;
await testPopupSpamMaximum ( ) ;
// dom.block_multiple_popups is true by default in testing profile, but we
// modify it above.
await SpecialPowers . pushPrefEnv ( { set : [ [ "dom.block_multiple_popups" , true ] ] } ) ;
SpecialPowers . wrap ( document ) . notifyUserGestureActivation ( ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkBlocked ) ;
await window . open . close ( ) ;
await SpecialPowers . popPrefEnv ( ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [ [ "dom.popup_maximum" , 3 ] ] } ) ;
} ) ;
add _task ( async function run _tests2 ( ) {
for ( var count = 0 , n = 0 ; n < 3 ; n ++ ) {
send ( a , "mouseup" , function ( ) { if ( window . open ( "http://example.com" ) ) count ++ } ) ;
}
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( 1 ) ;
send ( a , "mouseup" , checkOpened ) ;
send ( a , "mouseup" , checkBlocked ) ;
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( ) ;
ok ( count > 0 , "Windows left open by previous tests?" ) ;
while ( count -- > 0 ) {
send ( a , "mouseup" , checkOpened ) ;
}
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [ [ "dom.popup_maximum" , 2 ] ] } ) ;
} ) ;
add _task ( async function run _tests3 ( ) {
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( ) ;
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'allow' : ALLOW _ACTION , 'context' : document } ] ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [ [ "dom.popup_maximum" , 3 ] ] } ) ;
} ) ;
add _task ( async function run _tests4 ( ) {
var count ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
await window . open . close ( ) ;
send ( a , "mouseup" , checkOpened ) ;
send ( a , "mouseup" , checkOpened ) ;
send ( a , "mouseup" , checkOpened ) ;
send ( a , "mouseup" , checkOpened ) ;
await window . open . close ( ) ;
for ( count = 0 , n = 0 ; n < 3 ; n ++ ) {
send ( a , "mouseover" , function ( ) { if ( window . open ( "http://example.com" ) ) count ++ } ) ;
}
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( 1 ) ;
send ( a , "mouseover" , checkOpened ) ;
send ( a , "mouseover" , checkBlocked ) ;
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( ) ;
ok ( count > 0 , "Windows left open by previous tests?" ) ;
while ( count -- > 0 ) {
send ( a , "mouseover" , checkOpened ) ;
}
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [ [ "dom.popup_allowed_events" , "click" ] ] } ) ;
} ) ;
add _task ( async function run _tests5 ( ) {
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'allow' : DENY _ACTION , 'context' : document } ] ) ;
} ) ;
add _task ( async function run _tests6 ( ) {
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
await window . open . close ( ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [ [ "dom.popup_maximum" , 2 ] ] } ) ;
} ) ;
add _task ( async function run _tests7 ( ) {
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( ) ;
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( ) ;
await SpecialPowers . pushPermissions ( [ { 'type' : 'popup' , 'allow' : ALLOW _ACTION , 'context' : document } ] ) ;
await SpecialPowers . pushPrefEnv ( { "set" : [ [ "dom.popup_maximum" , 3 ] ] } ) ;
} ) ;
add _task ( async function run _tests8 ( ) {
var count ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
send ( a , "click" , checkOpened ) ;
await window . open . close ( ) ;
for ( count = 0 , n = 0 ; n < 3 ; n ++ ) {
send ( a , "mouseup" , function ( ) { if ( window . open ( "http://example.com" ) ) count ++ } ) ;
}
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( 1 ) ;
send ( a , "mouseup" , checkOpened ) ;
send ( a , "mouseup" , checkBlocked ) ;
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( ) ;
ok ( count > 0 , "Windows left open by previous tests?" ) ;
while ( count -- > 0 ) {
send ( a , "mouseup" , checkOpened ) ;
}
send ( a , "mouseup" , checkBlocked ) ;
await window . open . close ( ) ;
for ( count = 0 , n = 0 ; n < 3 ; n ++ ) {
send ( a , "mouseover" , function ( ) { if ( window . open ( "http://example.com" ) ) count ++ } ) ;
}
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( 1 ) ;
send ( a , "mouseover" , checkOpened ) ;
send ( a , "mouseover" , checkBlocked ) ;
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( ) ;
ok ( count > 0 , "Windows left open by previous tests?" ) ;
while ( count -- > 0 ) {
send ( a , "mouseover" , checkOpened ) ;
}
send ( a , "mouseover" , checkBlocked ) ;
await window . open . close ( ) ;
await SpecialPowers . popPermissions ( ) ;
} ) ;
< / script >