browser_styleeditor_bug_870339.js (1590B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 const SIMPLE = TEST_BASE_HTTP + "simple.css"; 6 const DOCUMENT_WITH_ONE_STYLESHEET = 7 "data:text/html;charset=UTF-8," + 8 encodeURIComponent( 9 [ 10 "<!DOCTYPE html>", 11 "<html>", 12 " <head>", 13 " <title>Bug 870339</title>", 14 ' <link rel="stylesheet" type="text/css" href="' + SIMPLE + '">', 15 " </head>", 16 " <body>", 17 " </body>", 18 "</html>", 19 ].join("\n") 20 ); 21 22 add_task(async function () { 23 const { ui } = await openStyleEditorForURL(DOCUMENT_WITH_ONE_STYLESHEET); 24 25 // Spam the "devtools.source-map.client-service.enabled" pref observer callback (#onOrigSourcesPrefChanged) 26 // multiple times before the StyleEditorActor has a chance to respond to the first one. 27 const SPAM_COUNT = 2; 28 let prefValue = false; 29 for (let i = 0; i < SPAM_COUNT; ++i) { 30 pushPref("devtools.source-map.client-service.enabled", prefValue); 31 prefValue = !prefValue; 32 } 33 34 // Wait for the StyleEditorActor to respond to each pref changes. 35 await new Promise(resolve => { 36 let loadCount = 0; 37 ui.on("stylesheets-refreshed", function onReset() { 38 ++loadCount; 39 if (loadCount == SPAM_COUNT) { 40 ui.off("stylesheets-refreshed", onReset); 41 // No matter how large SPAM_COUNT is, the number of style 42 // sheets should never be more than the number of style sheets 43 // in the document. 44 is(ui.editors.length, 1, "correct style sheet count"); 45 resolve(); 46 } 47 }); 48 }); 49 });