michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let tempScope = {}; michael@0: let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); michael@0: let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: let TargetFactory = devtools.TargetFactory; michael@0: michael@0: let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let doc; michael@0: let view; michael@0: let viewDoc; michael@0: let inspector; michael@0: michael@0: gDevTools.testing = true; michael@0: SimpleTest.registerCleanupFunction(() => { michael@0: gDevTools.testing = false; michael@0: }); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true); michael@0: doc = content.document; michael@0: waitForFocus(setupTest, content); michael@0: }, true); michael@0: michael@0: content.location = "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_fontinspector.html"; michael@0: michael@0: function setupTest() { michael@0: let rng = doc.createRange(); michael@0: rng.selectNode(doc.body); michael@0: let fonts = DOMUtils.getUsedFontFaces(rng); michael@0: if (fonts.length != 2) { michael@0: // Fonts are not loaded yet. michael@0: // Let try again in a couple of milliseconds (hacky, but michael@0: // there's not better way to do it. See bug 835247). michael@0: setTimeout(setupTest, 500); michael@0: } else { michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target, "inspector").then(function(toolbox) { michael@0: openFontInspector(toolbox.getCurrentPanel()); michael@0: }); michael@0: } michael@0: } michael@0: michael@0: function openFontInspector(aInspector) { michael@0: info("Inspector open"); michael@0: inspector = aInspector; michael@0: michael@0: inspector.selection.setNode(doc.body); michael@0: inspector.sidebar.select("fontinspector"); michael@0: inspector.sidebar.once("fontinspector-ready", testBodyFonts); michael@0: } michael@0: michael@0: function testBodyFonts() { michael@0: info("Font Inspector ready"); michael@0: michael@0: view = inspector.sidebar.getWindowForTab("fontinspector"); michael@0: viewDoc = view.document; michael@0: michael@0: ok(!!view.fontInspector, "Font inspector document is alive."); michael@0: michael@0: let s = viewDoc.querySelectorAll("#all-fonts > section"); michael@0: is(s.length, 2, "Found 2 fonts"); michael@0: michael@0: is(s[0].querySelector(".font-name").textContent, michael@0: "DeLarge Bold", "font 0: Right font name"); michael@0: ok(s[0].classList.contains("is-remote"), michael@0: "font 0: is remote"); michael@0: is(s[0].querySelector(".font-url").value, michael@0: "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_font.woff", michael@0: "font 0: right url"); michael@0: is(s[0].querySelector(".font-format").textContent, michael@0: "woff", "font 0: right font format"); michael@0: is(s[0].querySelector(".font-css-name").textContent, michael@0: "bar", "font 0: right css name"); michael@0: michael@0: let font1Name = s[1].querySelector(".font-name").textContent; michael@0: let font1CssName = s[1].querySelector(".font-css-name").textContent; michael@0: michael@0: // On Linux test machines, the Arial font doesn't exist. michael@0: // The fallback is "Liberation Sans" michael@0: michael@0: ok((font1Name == "Arial") || (font1Name == "Liberation Sans"), michael@0: "font 1: Right font name"); michael@0: ok(s[1].classList.contains("is-local"), "font 1: is local"); michael@0: ok((font1CssName == "Arial") || (font1CssName == "Liberation Sans"), michael@0: "Arial", "font 1: right css name"); michael@0: michael@0: testDivFonts(); michael@0: } michael@0: michael@0: function testDivFonts() { michael@0: inspector.selection.setNode(doc.querySelector("div")); michael@0: inspector.once("inspector-updated", () => { michael@0: let s = viewDoc.querySelectorAll("#all-fonts > section"); michael@0: is(s.length, 1, "Found 1 font on DIV"); michael@0: is(s[0].querySelector(".font-name").textContent, "DeLarge Bold", michael@0: "The DIV font has the right name"); michael@0: michael@0: testShowAllFonts(); michael@0: }); michael@0: } michael@0: michael@0: function testShowAllFonts() { michael@0: viewDoc.querySelector("#showall").click(); michael@0: inspector.once("inspector-updated", () => { michael@0: is(inspector.selection.node, doc.body, "Show all fonts selected the body node"); michael@0: let s = viewDoc.querySelectorAll("#all-fonts > section"); michael@0: is(s.length, 2, "And font-inspector still shows 2 fonts for body"); michael@0: michael@0: finishUp(); michael@0: }); michael@0: } michael@0: michael@0: function finishUp() { michael@0: executeSoon(function() { michael@0: gDevTools.once("toolbox-destroyed", () => { michael@0: doc = view = viewDoc = inspector = null; michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }); michael@0: inspector._toolbox.destroy(); michael@0: }); michael@0: } michael@0: }