Bug 852777 - Make Tilt more extensible, r=vporof

This commit is contained in:
Dave Townsend 2013-04-10 02:05:09 +03:00
Родитель 5ea69ec3a9
Коммит c99f710b20
12 изменённых файлов: 383 добавлений и 54 удалений

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

@ -9,6 +9,8 @@ const Cu = Components.utils;
// Tilt notifications dispatched through the nsIObserverService.
const TILT_NOTIFICATIONS = {
// Called early in the startup of a new tilt instance
STARTUP: "tilt-startup",
// Fires when Tilt starts the initialization.
INITIALIZING: "tilt-initializing",
@ -118,12 +120,15 @@ Tilt.prototype = {
// create a visualizer instance for the current tab
this.visualizers[id] = new TiltVisualizer({
chromeWindow: this.chromeWindow,
contentWindow: this.chromeWindow.gBrowser.selectedBrowser.contentWindow,
contentWindow: contentWindow,
parentNode: this.chromeWindow.gBrowser.selectedBrowser.parentNode,
notifications: this.NOTIFICATIONS,
tab: this.chromeWindow.gBrowser.selectedTab
});
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.STARTUP, null);
this.visualizers[id].init();
// make sure the visualizer object was initialized properly
if (!this.visualizers[id].isInitialized()) {
this.destroy(id);
@ -131,8 +136,9 @@ Tilt.prototype = {
return;
}
this.lastInstanceId = id;
this.emit("change", this.chromeWindow.gBrowser.selectedTab);
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.INITIALIZING, null);
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.INITIALIZING, null);
},
/**
@ -166,7 +172,7 @@ Tilt.prototype = {
}
// otherwise, trigger the outro animation and notify necessary observers
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYING, null);
Services.obs.notifyObservers(content, TILT_NOTIFICATIONS.DESTROYING, null);
controller.removeEventListeners();
controller.arcball.reset([-pageXOffset, -pageYOffset]);
@ -181,6 +187,7 @@ Tilt.prototype = {
*/
_finish: function T__finish(aId)
{
let contentWindow = this.visualizers[aId].presenter.contentWindow;
this.visualizers[aId].removeOverlay();
this.visualizers[aId].cleanup();
this.visualizers[aId] = null;
@ -188,7 +195,7 @@ Tilt.prototype = {
this._isDestroying = false;
this.chromeWindow.gBrowser.selectedBrowser.focus();
this.emit("change", this.chromeWindow.gBrowser.selectedTab);
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYED, null);
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.DESTROYED, null);
},
/**
@ -196,11 +203,17 @@ Tilt.prototype = {
*/
_onTabSelect: function T__onTabSelect()
{
if (this.currentInstance) {
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.SHOWN, null);
} else {
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.HIDDEN, null);
if (this.visualizers[this.lastInstanceId]) {
let contentWindow = this.visualizers[this.lastInstanceId].presenter.contentWindow;
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.HIDDEN, null);
}
if (this.currentInstance) {
let contentWindow = this.currentInstance.presenter.contentWindow;
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.SHOWN, null);
}
this.lastInstanceId = this.currentWindowId;
},
/**

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

@ -427,6 +427,9 @@ TiltUtils.DOM = {
* the window content holding the document
* @param {Object} aProperties
* optional, an object containing the following properties:
* {Function} nodeCallback
* a function to call instead of TiltUtils.DOM.getNodePosition
* to get the position and depth to display nodes
* {Object} invisibleElements
* elements which should be ignored
* {Number} minSize
@ -448,6 +451,8 @@ TiltUtils.DOM = {
let aMaxX = aProperties.maxX || Number.MAX_VALUE;
let aMaxY = aProperties.maxY || Number.MAX_VALUE;
let nodeCallback = aProperties.nodeCallback || this.getNodePosition.bind(this);
let nodes = aContentWindow.document.childNodes;
let store = { info: [], nodes: [] };
let depth = 0;
@ -466,7 +471,7 @@ TiltUtils.DOM = {
continue;
}
let coord = this.getNodePosition(aContentWindow, node, parentPosition);
let coord = nodeCallback(aContentWindow, node, parentPosition);
if (!coord) {
continue;
}

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

@ -109,6 +109,14 @@ this.TiltVisualizer = function TiltVisualizer(aProperties)
TiltVisualizer.prototype = {
/**
* Initializes the visualizer
*/
init: function TV_init()
{
this.presenter.init();
},
/**
* Checks if this object was initialized properly.
*
@ -309,6 +317,11 @@ TiltVisualizer.Presenter = function TV_Presenter(
*/
this.NOTIFICATIONS = aNotifications;
/**
* Use the default node callback function
*/
this.nodeCallback = null;
/**
* Create the renderer, containing useful functions for easy drawing.
*/
@ -375,14 +388,19 @@ TiltVisualizer.Presenter = function TV_Presenter(
this._delta = 0;
this._prevFrameTime = 0;
this._currFrameTime = 0;
this._setup();
this._loop();
};
TiltVisualizer.Presenter.prototype = {
/**
* Initializes the presenter and starts the animation loop
*/
init: function TVP_init()
{
this._setup();
this._loop();
},
/**
* The initialization logic.
*/
@ -718,6 +736,7 @@ TiltVisualizer.Presenter.prototype = {
// traverse the document and get the depths, coordinates and local names
this._traverseData = TiltUtils.DOM.traverse(this.contentWindow, {
nodeCallback: this.nodeCallback,
invisibleElements: INVISIBLE_ELEMENTS,
minSize: ELEMENT_MIN_SIZE,
maxX: this._texture.width,
@ -851,7 +870,7 @@ TiltVisualizer.Presenter.prototype = {
this._currentSelection = -1;
this._highlight.disabled = true;
Services.obs.notifyObservers(null, this.NOTIFICATIONS.UNHIGHLIGHTING, null);
Services.obs.notifyObservers(this.contentWindow, this.NOTIFICATIONS.UNHIGHLIGHTING, null);
return;
}
@ -888,7 +907,7 @@ TiltVisualizer.Presenter.prototype = {
vec3.scale(this._highlight.v1, this.transforms.zoom, []), 0.5));
}
Services.obs.notifyObservers(null, this.NOTIFICATIONS.HIGHLIGHTING, null);
Services.obs.notifyObservers(this.contentWindow, this.NOTIFICATIONS.HIGHLIGHTING, null);
},
/**
@ -920,7 +939,7 @@ TiltVisualizer.Presenter.prototype = {
this._highlight.disabled = true;
this._redraw = true;
Services.obs.notifyObservers(null, this.NOTIFICATIONS.NODE_REMOVED, null);
Services.obs.notifyObservers(this.contentWindow, this.NOTIFICATIONS.NODE_REMOVED, null);
},
/**
@ -1044,7 +1063,7 @@ TiltVisualizer.Presenter.prototype = {
!this._isExecutingDestruction) {
this._isInitializationFinished = true;
Services.obs.notifyObservers(null, this.NOTIFICATIONS.INITIALIZED, null);
Services.obs.notifyObservers(this.contentWindow, this.NOTIFICATIONS.INITIALIZED, null);
if ("function" === typeof this._onInitializationFinished) {
this._onInitializationFinished();
@ -1056,7 +1075,7 @@ TiltVisualizer.Presenter.prototype = {
this._isExecutingDestruction) {
this._isDestructionFinished = true;
Services.obs.notifyObservers(null, this.NOTIFICATIONS.BEFORE_DESTROYED, null);
Services.obs.notifyObservers(this.contentWindow, this.NOTIFICATIONS.BEFORE_DESTROYED, null);
if ("function" === typeof this._onDestructionFinished) {
this._onDestructionFinished();

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

@ -15,6 +15,7 @@ MOCHITEST_BROWSER_FILES = \
browser_tilt_01_lazy_getter.js \
browser_tilt_02_notifications-seq.js \
browser_tilt_02_notifications.js \
browser_tilt_02_notifications-tabs.js \
browser_tilt_03_tab_switch.js \
browser_tilt_04_initialization.js \
browser_tilt_05_destruction-esc.js \
@ -53,6 +54,7 @@ MOCHITEST_BROWSER_FILES = \
browser_tilt_utils05.js \
browser_tilt_utils06.js \
browser_tilt_utils07.js \
browser_tilt_utils08.js \
browser_tilt_visualizer.js \
browser_tilt_zoom.js \
$(NULL)

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

@ -19,6 +19,7 @@ function test() {
createTab(function() {
Services.obs.addObserver(finalize, DESTROYED, false);
Services.obs.addObserver(obs_STARTUP, STARTUP, false);
Services.obs.addObserver(obs_INITIALIZING, INITIALIZING, false);
Services.obs.addObserver(obs_INITIALIZED, INITIALIZED, false);
Services.obs.addObserver(obs_DESTROYING, DESTROYING, false);
@ -34,39 +35,51 @@ function test() {
});
}
function obs_INITIALIZING() {
function obs_STARTUP(win) {
info("Handling the STARTUP notification.");
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
tabEvents += "STARTUP;";
}
function obs_INITIALIZING(win) {
info("Handling the INITIALIZING notification.");
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
tabEvents += "INITIALIZING;";
}
function obs_INITIALIZED() {
function obs_INITIALIZED(win) {
info("Handling the INITIALIZED notification.");
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
tabEvents += "INITIALIZED;";
Tilt.destroy(Tilt.currentWindowId, true);
}
function obs_DESTROYING() {
function obs_DESTROYING(win) {
info("Handling the DESTROYING( notification.");
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
tabEvents += "DESTROYING;";
}
function obs_BEFORE_DESTROYED() {
function obs_BEFORE_DESTROYED(win) {
info("Handling the BEFORE_DESTROYED notification.");
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
tabEvents += "BEFORE_DESTROYED;";
}
function obs_DESTROYED() {
function obs_DESTROYED(win) {
info("Handling the DESTROYED notification.");
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
tabEvents += "DESTROYED;";
}
function finalize() {
function finalize(win) {
if (!tabEvents) {
return;
}
is(tabEvents, "INITIALIZING;INITIALIZED;DESTROYING;BEFORE_DESTROYED;DESTROYED;",
is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
is(tabEvents, "STARTUP;INITIALIZING;INITIALIZED;DESTROYING;BEFORE_DESTROYED;DESTROYED;",
"The notifications weren't fired in the correct order.");
cleanup();

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

@ -0,0 +1,173 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let tab0, tab1, tab2;
let testStep = -1;
let expected = [];
function expect(notification, win) {
expected.push({ notification: notification, window: win });
}
function notification(win, topic) {
if (expected.length == 0) {
is(topic, null, "Shouldn't see a notification");
return;
}
let { notification, window } = expected.shift();
is(topic, notification, "Saw the expected notification");
is(win, window, "Saw the expected window");
}
function after(notification, callback) {
function observer() {
Services.obs.removeObserver(observer, notification);
executeSoon(callback);
}
Services.obs.addObserver(observer, notification, false);
}
function test() {
if (!isTiltEnabled()) {
info("Skipping tab switch test because Tilt isn't enabled.");
return;
}
if (!isWebGLSupported()) {
info("Skipping tab switch test because WebGL isn't supported.");
return;
}
Services.obs.addObserver(notification, STARTUP, false);
Services.obs.addObserver(notification, INITIALIZING, false);
Services.obs.addObserver(notification, INITIALIZED, false);
Services.obs.addObserver(notification, DESTROYING, false);
Services.obs.addObserver(notification, BEFORE_DESTROYED, false);
Services.obs.addObserver(notification, DESTROYED, false);
Services.obs.addObserver(notification, SHOWN, false);
Services.obs.addObserver(notification, HIDDEN, false);
waitForExplicitFinish();
tab0 = gBrowser.selectedTab;
nextStep();
}
function createTab2() {
}
let testSteps = [
function step0() {
tab1 = createTab(function() {
expect(STARTUP, tab1.linkedBrowser.contentWindow);
expect(INITIALIZING, tab1.linkedBrowser.contentWindow);
expect(INITIALIZED, tab1.linkedBrowser.contentWindow);
after(INITIALIZED, nextStep);
createTilt({}, false, function suddenDeath()
{
info("Tilt could not be initialized properly.");
cleanup();
});
});
},
function step1() {
expect(HIDDEN, tab1.linkedBrowser.contentWindow);
tab2 = createTab(function() {
expect(STARTUP, tab2.linkedBrowser.contentWindow);
expect(INITIALIZING, tab2.linkedBrowser.contentWindow);
expect(INITIALIZED, tab2.linkedBrowser.contentWindow);
after(INITIALIZED, nextStep);
createTilt({}, false, function suddenDeath()
{
info("Tilt could not be initialized properly.");
cleanup();
});
});
},
function step2() {
expect(HIDDEN, tab2.linkedBrowser.contentWindow);
after(HIDDEN, nextStep);
gBrowser.selectedTab = tab0;
},
function step3() {
expect(SHOWN, tab2.linkedBrowser.contentWindow);
after(SHOWN, nextStep);
gBrowser.selectedTab = tab2;
},
function step4() {
expect(HIDDEN, tab2.linkedBrowser.contentWindow);
expect(SHOWN, tab1.linkedBrowser.contentWindow);
after(SHOWN, nextStep);
gBrowser.selectedTab = tab1;
},
function step5() {
expect(HIDDEN, tab1.linkedBrowser.contentWindow);
expect(SHOWN, tab2.linkedBrowser.contentWindow);
after(SHOWN, nextStep);
gBrowser.selectedTab = tab2;
},
function step6() {
expect(DESTROYING, tab2.linkedBrowser.contentWindow);
expect(BEFORE_DESTROYED, tab2.linkedBrowser.contentWindow);
expect(DESTROYED, tab2.linkedBrowser.contentWindow);
after(DESTROYED, nextStep);
Tilt.destroy(Tilt.currentWindowId, true);
},
function step7() {
expect(SHOWN, tab1.linkedBrowser.contentWindow);
gBrowser.removeCurrentTab();
tab2 = null;
expect(DESTROYING, tab1.linkedBrowser.contentWindow);
expect(HIDDEN, tab1.linkedBrowser.contentWindow);
expect(BEFORE_DESTROYED, tab1.linkedBrowser.contentWindow);
expect(DESTROYED, tab1.linkedBrowser.contentWindow);
after(DESTROYED, nextStep);
gBrowser.removeCurrentTab();
tab1 = null;
},
function step8_cleanup() {
is(gBrowser.selectedTab, tab0, "Should be back to the first tab");
cleanup();
}
];
function cleanup() {
if (tab1) {
gBrowser.removeTab(tab1);
tab1 = null;
}
if (tab2) {
gBrowser.removeTab(tab2);
tab2 = null;
}
Services.obs.removeObserver(notification, STARTUP);
Services.obs.removeObserver(notification, INITIALIZING);
Services.obs.removeObserver(notification, INITIALIZED);
Services.obs.removeObserver(notification, DESTROYING);
Services.obs.removeObserver(notification, BEFORE_DESTROYED);
Services.obs.removeObserver(notification, DESTROYED);
Services.obs.removeObserver(notification, SHOWN);
Services.obs.removeObserver(notification, HIDDEN);
finish();
}
function nextStep() {
let step = testSteps.shift();
info("Executing " + step.name);
step();
}

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

@ -28,6 +28,7 @@ function createNewTab() {
tab1 = createTab(function() {
Services.obs.addObserver(finalize, DESTROYED, false);
Services.obs.addObserver(tab_STARTUP, STARTUP, false);
Services.obs.addObserver(tab_INITIALIZING, INITIALIZING, false);
Services.obs.addObserver(tab_DESTROYING, DESTROYING, false);
Services.obs.addObserver(tab_SHOWN, SHOWN, false);
@ -48,23 +49,33 @@ function createNewTab() {
});
}
function tab_INITIALIZING() {
function tab_STARTUP(win) {
info("Handling the STARTUP notification.");
is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
tabEvents += "STARTUP;";
}
function tab_INITIALIZING(win) {
info("Handling the INITIALIZING notification.");
is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
tabEvents += "INITIALIZING;";
}
function tab_DESTROYING() {
function tab_DESTROYING(win) {
info("Handling the DESTROYING notification.");
is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
tabEvents += "DESTROYING;";
}
function tab_SHOWN() {
function tab_SHOWN(win) {
info("Handling the SHOWN notification.");
is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
tabEvents += "SHOWN;";
}
function tab_HIDDEN() {
function tab_HIDDEN(win) {
info("Handling the HIDDEN notification.");
is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
tabEvents += "HIDDEN;";
}
@ -83,12 +94,14 @@ let testSteps = [
}
];
function finalize() {
function finalize(win) {
if (!tabEvents) {
return;
}
is(tabEvents, "INITIALIZING;HIDDEN;SHOWN;DESTROYING;",
is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
is(tabEvents, "STARTUP;INITIALIZING;HIDDEN;SHOWN;DESTROYING;",
"The notifications weren't fired in the correct order.");
cleanup();

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

@ -74,13 +74,13 @@ function test() {
let store = dom.traverse(iframe.contentWindow);
let expected = [
{ name: "html", depth: 0 * STACK_THICKNESS },
{ name: "head", depth: 1 * STACK_THICKNESS },
{ name: "body", depth: 1 * STACK_THICKNESS },
{ name: "style", depth: 2 * STACK_THICKNESS },
{ name: "script", depth: 2 * STACK_THICKNESS },
{ name: "div", depth: 2 * STACK_THICKNESS },
{ name: "span", depth: 3 * STACK_THICKNESS },
{ name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "style", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "script", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "span", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
];
is(store.nodes.length, expected.length,
@ -93,6 +93,8 @@ function test() {
"traversed node " + (i + 1) + " isn't the expected one.");
is(store.info[i].coord.depth, expected[i].depth,
"traversed node " + (i + 1) + " doesn't have the expected depth.");
is(store.info[i].coord.thickness, expected[i].thickness,
"traversed node " + (i + 1) + " doesn't have the expected thickness.");
}
});
}

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

@ -123,22 +123,22 @@ function test() {
let store = dom.traverse(iframe.contentWindow);
let expected = [
{ name: "html", depth: 0 * STACK_THICKNESS },
{ name: "head", depth: 1 * STACK_THICKNESS },
{ name: "body", depth: 1 * STACK_THICKNESS },
{ name: "div", depth: 2 * STACK_THICKNESS },
{ name: "span", depth: 2 * STACK_THICKNESS },
{ name: "iframe", depth: 2 * STACK_THICKNESS },
{ name: "span", depth: 2 * STACK_THICKNESS },
{ name: "iframe", depth: 2 * STACK_THICKNESS },
{ name: "html", depth: 3 * STACK_THICKNESS },
{ name: "html", depth: 3 * STACK_THICKNESS },
{ name: "head", depth: 4 * STACK_THICKNESS },
{ name: "body", depth: 4 * STACK_THICKNESS },
{ name: "head", depth: 4 * STACK_THICKNESS },
{ name: "body", depth: 4 * STACK_THICKNESS },
{ name: "span", depth: 5 * STACK_THICKNESS },
{ name: "div", depth: 5 * STACK_THICKNESS },
{ name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "span", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "iframe", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "span", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "iframe", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "html", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "html", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "head", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "body", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "head", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "body", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "span", depth: 5 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "div", depth: 5 * STACK_THICKNESS, thickness: STACK_THICKNESS },
];
is(store.nodes.length, expected.length,
@ -151,6 +151,8 @@ function test() {
"traversed node " + (i + 1) + " isn't the expected one.");
is(store.info[i].coord.depth, expected[i].depth,
"traversed node " + (i + 1) + " doesn't have the expected depth.");
is(store.info[i].coord.thickness, expected[i].thickness,
"traversed node " + (i + 1) + " doesn't have the expected thickness.");
}
});
}

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

@ -0,0 +1,85 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const STACK_THICKNESS = 15;
function init(callback) {
let iframe = gBrowser.ownerDocument.createElement("iframe");
iframe.addEventListener("load", function onLoad() {
iframe.removeEventListener("load", onLoad, true);
callback(iframe);
gBrowser.parentNode.removeChild(iframe);
finish();
}, true);
iframe.setAttribute("src", ["data:text/html,",
"<!DOCTYPE html>",
"<html>",
"<body style='margin: 0;'>",
"<div>",
"<p>Foo</p>",
"<div>",
"<span>Bar</span>",
"</div>",
"<div></div>",
"</div>",
"</body>",
"</html>"
].join(""));
gBrowser.parentNode.appendChild(iframe);
}
function nodeCallback(aContentWindow, aNode, aParentPosition) {
let coord = TiltUtils.DOM.getNodePosition(aContentWindow, aNode, aParentPosition);
if (aNode.localName != "div")
coord.thickness = 0;
if (aNode.localName == "span")
coord.depth += STACK_THICKNESS;
return coord;
}
function test() {
waitForExplicitFinish();
ok(TiltUtils, "The TiltUtils object doesn't exist.");
let dom = TiltUtils.DOM;
ok(dom, "The TiltUtils.DOM wasn't found.");
init(function(iframe) {
let store = dom.traverse(iframe.contentWindow, {
nodeCallback: nodeCallback
});
let expected = [
{ name: "html", depth: 0 * STACK_THICKNESS, thickness: 0 },
{ name: "head", depth: 0 * STACK_THICKNESS, thickness: 0 },
{ name: "body", depth: 0 * STACK_THICKNESS, thickness: 0 },
{ name: "div", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "p", depth: 1 * STACK_THICKNESS, thickness: 0 },
{ name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
{ name: "span", depth: 3 * STACK_THICKNESS, thickness: 0 },
];
is(store.nodes.length, expected.length,
"The traverse() function didn't walk the correct number of nodes.");
is(store.info.length, expected.length,
"The traverse() function didn't examine the correct number of nodes.");
for (let i = 0; i < expected.length; i++) {
is(store.info[i].name, expected[i].name,
"traversed node " + (i + 1) + " isn't the expected one.");
is(store.info[i].coord.depth, expected[i].depth,
"traversed node " + (i + 1) + " doesn't have the expected depth.");
is(store.info[i].coord.thickness, expected[i].thickness,
"traversed node " + (i + 1) + " doesn't have the expected thickness.");
}
});
}

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

@ -32,6 +32,7 @@ function test() {
webGLLoad = true;
}
});
visualizer.init();
ok(webGLError ^ webGLLoad,
"The WebGL context should either be created or not.");

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

@ -50,6 +50,7 @@ const DEFAULT_HTML = "data:text/html," +
let Tilt = TiltManager.getTiltForBrowser(window);
const STARTUP = Tilt.NOTIFICATIONS.STARTUP;
const INITIALIZING = Tilt.NOTIFICATIONS.INITIALIZING;
const INITIALIZED = Tilt.NOTIFICATIONS.INITIALIZED;
const DESTROYING = Tilt.NOTIFICATIONS.DESTROYING;