Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let tempScope = {}; |
michael@0 | 5 | let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); |
michael@0 | 6 | let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 7 | let TargetFactory = devtools.TargetFactory; |
michael@0 | 8 | |
michael@0 | 9 | let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils); |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | waitForExplicitFinish(); |
michael@0 | 13 | |
michael@0 | 14 | let doc; |
michael@0 | 15 | let view; |
michael@0 | 16 | let viewDoc; |
michael@0 | 17 | let inspector; |
michael@0 | 18 | |
michael@0 | 19 | gDevTools.testing = true; |
michael@0 | 20 | SimpleTest.registerCleanupFunction(() => { |
michael@0 | 21 | gDevTools.testing = false; |
michael@0 | 22 | }); |
michael@0 | 23 | |
michael@0 | 24 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 25 | gBrowser.selectedBrowser.addEventListener("load", function onload() { |
michael@0 | 26 | gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
michael@0 | 27 | doc = content.document; |
michael@0 | 28 | waitForFocus(setupTest, content); |
michael@0 | 29 | }, true); |
michael@0 | 30 | |
michael@0 | 31 | content.location = "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_fontinspector.html"; |
michael@0 | 32 | |
michael@0 | 33 | function setupTest() { |
michael@0 | 34 | let rng = doc.createRange(); |
michael@0 | 35 | rng.selectNode(doc.body); |
michael@0 | 36 | let fonts = DOMUtils.getUsedFontFaces(rng); |
michael@0 | 37 | if (fonts.length != 2) { |
michael@0 | 38 | // Fonts are not loaded yet. |
michael@0 | 39 | // Let try again in a couple of milliseconds (hacky, but |
michael@0 | 40 | // there's not better way to do it. See bug 835247). |
michael@0 | 41 | setTimeout(setupTest, 500); |
michael@0 | 42 | } else { |
michael@0 | 43 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 44 | gDevTools.showToolbox(target, "inspector").then(function(toolbox) { |
michael@0 | 45 | openFontInspector(toolbox.getCurrentPanel()); |
michael@0 | 46 | }); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function openFontInspector(aInspector) { |
michael@0 | 51 | info("Inspector open"); |
michael@0 | 52 | inspector = aInspector; |
michael@0 | 53 | |
michael@0 | 54 | inspector.selection.setNode(doc.body); |
michael@0 | 55 | inspector.sidebar.select("fontinspector"); |
michael@0 | 56 | inspector.sidebar.once("fontinspector-ready", testBodyFonts); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function testBodyFonts() { |
michael@0 | 60 | info("Font Inspector ready"); |
michael@0 | 61 | |
michael@0 | 62 | view = inspector.sidebar.getWindowForTab("fontinspector"); |
michael@0 | 63 | viewDoc = view.document; |
michael@0 | 64 | |
michael@0 | 65 | ok(!!view.fontInspector, "Font inspector document is alive."); |
michael@0 | 66 | |
michael@0 | 67 | let s = viewDoc.querySelectorAll("#all-fonts > section"); |
michael@0 | 68 | is(s.length, 2, "Found 2 fonts"); |
michael@0 | 69 | |
michael@0 | 70 | is(s[0].querySelector(".font-name").textContent, |
michael@0 | 71 | "DeLarge Bold", "font 0: Right font name"); |
michael@0 | 72 | ok(s[0].classList.contains("is-remote"), |
michael@0 | 73 | "font 0: is remote"); |
michael@0 | 74 | is(s[0].querySelector(".font-url").value, |
michael@0 | 75 | "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_font.woff", |
michael@0 | 76 | "font 0: right url"); |
michael@0 | 77 | is(s[0].querySelector(".font-format").textContent, |
michael@0 | 78 | "woff", "font 0: right font format"); |
michael@0 | 79 | is(s[0].querySelector(".font-css-name").textContent, |
michael@0 | 80 | "bar", "font 0: right css name"); |
michael@0 | 81 | |
michael@0 | 82 | let font1Name = s[1].querySelector(".font-name").textContent; |
michael@0 | 83 | let font1CssName = s[1].querySelector(".font-css-name").textContent; |
michael@0 | 84 | |
michael@0 | 85 | // On Linux test machines, the Arial font doesn't exist. |
michael@0 | 86 | // The fallback is "Liberation Sans" |
michael@0 | 87 | |
michael@0 | 88 | ok((font1Name == "Arial") || (font1Name == "Liberation Sans"), |
michael@0 | 89 | "font 1: Right font name"); |
michael@0 | 90 | ok(s[1].classList.contains("is-local"), "font 1: is local"); |
michael@0 | 91 | ok((font1CssName == "Arial") || (font1CssName == "Liberation Sans"), |
michael@0 | 92 | "Arial", "font 1: right css name"); |
michael@0 | 93 | |
michael@0 | 94 | testDivFonts(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | function testDivFonts() { |
michael@0 | 98 | inspector.selection.setNode(doc.querySelector("div")); |
michael@0 | 99 | inspector.once("inspector-updated", () => { |
michael@0 | 100 | let s = viewDoc.querySelectorAll("#all-fonts > section"); |
michael@0 | 101 | is(s.length, 1, "Found 1 font on DIV"); |
michael@0 | 102 | is(s[0].querySelector(".font-name").textContent, "DeLarge Bold", |
michael@0 | 103 | "The DIV font has the right name"); |
michael@0 | 104 | |
michael@0 | 105 | testShowAllFonts(); |
michael@0 | 106 | }); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function testShowAllFonts() { |
michael@0 | 110 | viewDoc.querySelector("#showall").click(); |
michael@0 | 111 | inspector.once("inspector-updated", () => { |
michael@0 | 112 | is(inspector.selection.node, doc.body, "Show all fonts selected the body node"); |
michael@0 | 113 | let s = viewDoc.querySelectorAll("#all-fonts > section"); |
michael@0 | 114 | is(s.length, 2, "And font-inspector still shows 2 fonts for body"); |
michael@0 | 115 | |
michael@0 | 116 | finishUp(); |
michael@0 | 117 | }); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function finishUp() { |
michael@0 | 121 | executeSoon(function() { |
michael@0 | 122 | gDevTools.once("toolbox-destroyed", () => { |
michael@0 | 123 | doc = view = viewDoc = inspector = null; |
michael@0 | 124 | gBrowser.removeCurrentTab(); |
michael@0 | 125 | finish(); |
michael@0 | 126 | }); |
michael@0 | 127 | inspector._toolbox.destroy(); |
michael@0 | 128 | }); |
michael@0 | 129 | } |
michael@0 | 130 | } |