Bug 1158634 - Modify font-inspector tests for better code sharing. r=pbrosset

This patch adds a new method openFontInspectorForURL to the head.js file which
a) opens a new tab with the given URL
b) opens inspector for the tab
c) selects font-inspector and waits for it to initialize

Previously the only font-inspector test was doing all that inside the test but
as new tests require the similar functionality it's better to reside in
head.js.

--HG--
extra : rebase_source : 96d31183bdbd0131beadc9540ad2b7e2e4f9a67b
extra : histedit_source : 3a9a9cb62e9b480e6f6e349570f3cbf23543487f
This commit is contained in:
Sami Jaktholm 2015-05-14 14:21:53 +03:00
Родитель dcbfc55e0d
Коммит dfc7a247b3
2 изменённых файлов: 60 добавлений и 36 удалений

Просмотреть файл

@ -1,17 +1,9 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let tempScope = {}; const TEST_URI = BASE_URI + "browser_fontinspector.html";
let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
let TargetFactory = devtools.TargetFactory;
let TEST_URI = "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/browser_fontinspector.html";
let view, viewDoc;
const BASE_URI = "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/"
const FONTS = [ const FONTS = [
{name: "Ostrich Sans Medium", remote: true, url: BASE_URI + "ostrich-regular.ttf", {name: "Ostrich Sans Medium", remote: true, url: BASE_URI + "ostrich-regular.ttf",
format: "truetype", cssName: "bar"}, format: "truetype", cssName: "bar"},
@ -24,33 +16,17 @@ const FONTS = [
]; ];
add_task(function*() { add_task(function*() {
yield loadTab(TEST_URI); let { inspector, fontInspector } = yield openFontInspectorForURL(TEST_URI);
let {toolbox, inspector} = yield openInspector(); ok(!!fontInspector, "Font inspector document is alive.");
info("Selecting the test node"); let viewDoc = fontInspector.chromeDoc;
yield selectNode("body", inspector);
let updated = inspector.once("fontinspector-updated"); yield testBodyFonts(inspector, viewDoc);
inspector.sidebar.select("fontinspector"); yield testDivFonts(inspector, viewDoc);
yield updated; yield testShowAllFonts(inspector, viewDoc);
info("Font Inspector ready");
view = inspector.sidebar.getWindowForTab("fontinspector");
viewDoc = view.document;
ok(!!view.fontInspector, "Font inspector document is alive.");
yield testBodyFonts(inspector);
yield testDivFonts(inspector);
yield testShowAllFonts(inspector);
view = viewDoc = null;
}); });
function* testBodyFonts(inspector) { function* testBodyFonts(inspector, viewDoc) {
let s = viewDoc.querySelectorAll("#all-fonts > section"); let s = viewDoc.querySelectorAll("#all-fonts > section");
is(s.length, 5, "Found 5 fonts"); is(s.length, 5, "Found 5 fonts");
@ -89,7 +65,7 @@ function* testBodyFonts(inspector) {
"Arial", "local font has right css name"); "Arial", "local font has right css name");
} }
function* testDivFonts(inspector) { function* testDivFonts(inspector, viewDoc) {
let updated = inspector.once("fontinspector-updated"); let updated = inspector.once("fontinspector-updated");
yield selectNode("div", inspector); yield selectNode("div", inspector);
yield updated; yield updated;
@ -100,7 +76,7 @@ function* testDivFonts(inspector) {
"The DIV font has the right name"); "The DIV font has the right name");
} }
function* testShowAllFonts(inspector) { function* testShowAllFonts(inspector, viewDoc) {
info("testing showing all fonts"); info("testing showing all fonts");
let updated = inspector.once("fontinspector-updated"); let updated = inspector.once("fontinspector-updated");

Просмотреть файл

@ -13,6 +13,8 @@ const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {})
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
let TargetFactory = devtools.TargetFactory; let TargetFactory = devtools.TargetFactory;
const BASE_URI = "http://mochi.test:8888/browser/browser/devtools/fontinspector/test/"
// All test are asynchronous // All test are asynchronous
waitForExplicitFinish(); waitForExplicitFinish();
@ -98,6 +100,52 @@ let openInspector = Task.async(function*(cb) {
} }
}); });
/**
* Adds a new tab with the given URL, opens the inspector and selects the
* font-inspector tab.
*
* @return Object
* {
* toolbox,
* inspector,
* fontInspector
* }
*/
let openFontInspectorForURL = Task.async(function* (url) {
info("Opening tab " + url);
yield loadTab(url);
let { toolbox, inspector } = yield openInspector();
/**
* Call selectNode to trigger font-inspector update so that we don't timeout
* if following conditions hold
* a) the initial 'fontinspector-updated' was emitted while we were waiting
* for openInspector to resolve
* b) the font-inspector tab was selected by default which means the call to
* select will not trigger another update.
*
* selectNode calls setNodeFront which always emits 'new-node' which calls
* FontInspector.update that emits the 'fontinspector-updated' event.
*/
let updated = inspector.once("fontinspector-updated");
yield selectNode("body", inspector);
inspector.sidebar.select("fontinspector");
info("Waiting for font-inspector to update.");
yield updated;
info("Font Inspector ready.");
let { fontInspector } = inspector.sidebar.getWindowForTab("fontinspector");
return {
fontInspector,
inspector,
toolbox
};
});
/** /**
* Select a node in the inspector given its selector. * Select a node in the inspector given its selector.
*/ */