@ -20,6 +20,11 @@
* code by having a tag called "padding" and a property
* value called "margin" .
* /
const { PrefObserver } = require ( "devtools/client/shared/prefs" ) ;
const PREF _ENABLE _MDN _DOCS _TOOLTIP =
"devtools.inspector.mdnDocsTooltip.enabled" ;
const TEST _URI = `
< html >
< head >
@ -35,12 +40,50 @@ const TEST_URI = `
` ;
add _task ( function * ( ) {
info ( "Ensure the pref is true to begin with" ) ;
let initial = Services . prefs . getBoolPref ( PREF _ENABLE _MDN _DOCS _TOOLTIP ) ;
if ( initial != true ) {
yield setBooleanPref ( PREF _ENABLE _MDN _DOCS _TOOLTIP , true ) ;
}
yield addTab ( "data:text/html;charset=utf8," + encodeURIComponent ( TEST _URI ) ) ;
let { inspector , view } = yield openRuleView ( ) ;
yield selectNode ( "padding" , inspector ) ;
yield testMdnContextMenuItemVisibility ( view ) ;
info ( "Ensure the pref is reset to its initial value" ) ;
let eventual = Services . prefs . getBoolPref ( PREF _ENABLE _MDN _DOCS _TOOLTIP ) ;
if ( eventual != initial ) {
yield setBooleanPref ( PREF _ENABLE _MDN _DOCS _TOOLTIP , initial ) ;
}
} ) ;
/ * *
* Set a boolean pref , and wait for the pref observer to
* trigger , so that code listening for the pref change
* has had a chance to update itself .
*
* @ param pref { string } Name of the pref to change
* @ param state { boolean } Desired value of the pref .
*
* Note that if the pref already has the value in ` state ` ,
* then the prefObserver will not trigger . So you should only
* call this function if you know the pref ' s current value is
* not ` state ` .
* /
function * setBooleanPref ( pref , state ) {
let oncePrefChanged = defer ( ) ;
let prefObserver = new PrefObserver ( "devtools." ) ;
prefObserver . on ( pref , oncePrefChanged . resolve ) ;
info ( "Set the pref " + pref + " to: " + state ) ;
Services . prefs . setBoolPref ( pref , state ) ;
info ( "Wait for prefObserver to call back so the UI can update" ) ;
yield oncePrefChanged . promise ;
prefObserver . off ( pref , oncePrefChanged . resolve ) ;
}
/ * *
* Tests that the MDN context menu item is shown when it should be ,
* and hidden when it should be .