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