1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/fontinspector/test/browser_fontinspector.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let tempScope = {}; 1.8 +let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); 1.9 +let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); 1.10 +let TargetFactory = devtools.TargetFactory; 1.11 + 1.12 +let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils); 1.13 + 1.14 +function test() { 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + let doc; 1.18 + let view; 1.19 + let viewDoc; 1.20 + let inspector; 1.21 + 1.22 + gDevTools.testing = true; 1.23 + SimpleTest.registerCleanupFunction(() => { 1.24 + gDevTools.testing = false; 1.25 + }); 1.26 + 1.27 + gBrowser.selectedTab = gBrowser.addTab(); 1.28 + gBrowser.selectedBrowser.addEventListener("load", function onload() { 1.29 + gBrowser.selectedBrowser.removeEventListener("load", onload, true); 1.30 + doc = content.document; 1.31 + waitForFocus(setupTest, content); 1.32 + }, true); 1.33 + 1.34 + content.location = "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_fontinspector.html"; 1.35 + 1.36 + function setupTest() { 1.37 + let rng = doc.createRange(); 1.38 + rng.selectNode(doc.body); 1.39 + let fonts = DOMUtils.getUsedFontFaces(rng); 1.40 + if (fonts.length != 2) { 1.41 + // Fonts are not loaded yet. 1.42 + // Let try again in a couple of milliseconds (hacky, but 1.43 + // there's not better way to do it. See bug 835247). 1.44 + setTimeout(setupTest, 500); 1.45 + } else { 1.46 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.47 + gDevTools.showToolbox(target, "inspector").then(function(toolbox) { 1.48 + openFontInspector(toolbox.getCurrentPanel()); 1.49 + }); 1.50 + } 1.51 + } 1.52 + 1.53 + function openFontInspector(aInspector) { 1.54 + info("Inspector open"); 1.55 + inspector = aInspector; 1.56 + 1.57 + inspector.selection.setNode(doc.body); 1.58 + inspector.sidebar.select("fontinspector"); 1.59 + inspector.sidebar.once("fontinspector-ready", testBodyFonts); 1.60 + } 1.61 + 1.62 + function testBodyFonts() { 1.63 + info("Font Inspector ready"); 1.64 + 1.65 + view = inspector.sidebar.getWindowForTab("fontinspector"); 1.66 + viewDoc = view.document; 1.67 + 1.68 + ok(!!view.fontInspector, "Font inspector document is alive."); 1.69 + 1.70 + let s = viewDoc.querySelectorAll("#all-fonts > section"); 1.71 + is(s.length, 2, "Found 2 fonts"); 1.72 + 1.73 + is(s[0].querySelector(".font-name").textContent, 1.74 + "DeLarge Bold", "font 0: Right font name"); 1.75 + ok(s[0].classList.contains("is-remote"), 1.76 + "font 0: is remote"); 1.77 + is(s[0].querySelector(".font-url").value, 1.78 + "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_font.woff", 1.79 + "font 0: right url"); 1.80 + is(s[0].querySelector(".font-format").textContent, 1.81 + "woff", "font 0: right font format"); 1.82 + is(s[0].querySelector(".font-css-name").textContent, 1.83 + "bar", "font 0: right css name"); 1.84 + 1.85 + let font1Name = s[1].querySelector(".font-name").textContent; 1.86 + let font1CssName = s[1].querySelector(".font-css-name").textContent; 1.87 + 1.88 + // On Linux test machines, the Arial font doesn't exist. 1.89 + // The fallback is "Liberation Sans" 1.90 + 1.91 + ok((font1Name == "Arial") || (font1Name == "Liberation Sans"), 1.92 + "font 1: Right font name"); 1.93 + ok(s[1].classList.contains("is-local"), "font 1: is local"); 1.94 + ok((font1CssName == "Arial") || (font1CssName == "Liberation Sans"), 1.95 + "Arial", "font 1: right css name"); 1.96 + 1.97 + testDivFonts(); 1.98 + } 1.99 + 1.100 + function testDivFonts() { 1.101 + inspector.selection.setNode(doc.querySelector("div")); 1.102 + inspector.once("inspector-updated", () => { 1.103 + let s = viewDoc.querySelectorAll("#all-fonts > section"); 1.104 + is(s.length, 1, "Found 1 font on DIV"); 1.105 + is(s[0].querySelector(".font-name").textContent, "DeLarge Bold", 1.106 + "The DIV font has the right name"); 1.107 + 1.108 + testShowAllFonts(); 1.109 + }); 1.110 + } 1.111 + 1.112 + function testShowAllFonts() { 1.113 + viewDoc.querySelector("#showall").click(); 1.114 + inspector.once("inspector-updated", () => { 1.115 + is(inspector.selection.node, doc.body, "Show all fonts selected the body node"); 1.116 + let s = viewDoc.querySelectorAll("#all-fonts > section"); 1.117 + is(s.length, 2, "And font-inspector still shows 2 fonts for body"); 1.118 + 1.119 + finishUp(); 1.120 + }); 1.121 + } 1.122 + 1.123 + function finishUp() { 1.124 + executeSoon(function() { 1.125 + gDevTools.once("toolbox-destroyed", () => { 1.126 + doc = view = viewDoc = inspector = null; 1.127 + gBrowser.removeCurrentTab(); 1.128 + finish(); 1.129 + }); 1.130 + inspector._toolbox.destroy(); 1.131 + }); 1.132 + } 1.133 +}