michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: "use strict"; michael@0: michael@0: function test() { michael@0: if (!isTiltEnabled()) { michael@0: info("Skipping notifications test because Tilt isn't enabled."); michael@0: return; michael@0: } michael@0: if (!isWebGLSupported()) { michael@0: info("Skipping visualizer test because WebGL isn't supported."); michael@0: return; michael@0: } michael@0: michael@0: let webGLError = false; michael@0: let webGLLoad = false; michael@0: michael@0: let visualizer = new TiltVisualizer({ michael@0: chromeWindow: window, michael@0: contentWindow: gBrowser.selectedBrowser.contentWindow, michael@0: parentNode: gBrowser.selectedBrowser.parentNode, michael@0: notifications: Tilt.NOTIFICATIONS, michael@0: tab: gBrowser.selectedTab, michael@0: michael@0: onError: function onWebGLError() michael@0: { michael@0: webGLError = true; michael@0: }, michael@0: michael@0: onLoad: function onWebGLLoad() michael@0: { michael@0: webGLLoad = true; michael@0: } michael@0: }); michael@0: visualizer.init(); michael@0: michael@0: ok(webGLError ^ webGLLoad, michael@0: "The WebGL context should either be created or not."); michael@0: michael@0: if (webGLError) { michael@0: info("Skipping visualizer test because WebGL couldn't be initialized."); michael@0: return; michael@0: } michael@0: michael@0: ok(visualizer.canvas, michael@0: "Visualizer constructor should have created a child canvas object."); michael@0: ok(visualizer.presenter, michael@0: "Visualizer constructor should have created a child presenter object."); michael@0: ok(visualizer.controller, michael@0: "Visualizer constructor should have created a child controller object."); michael@0: ok(visualizer.isInitialized(), michael@0: "The visualizer should have been initialized properly."); michael@0: ok(visualizer.presenter.isInitialized(), michael@0: "The visualizer presenter should have been initialized properly."); michael@0: ok(visualizer.controller.isInitialized(), michael@0: "The visualizer controller should have been initialized properly."); michael@0: michael@0: testPresenter(visualizer.presenter); michael@0: testController(visualizer.controller); michael@0: michael@0: visualizer.removeOverlay(); michael@0: is(visualizer.canvas.parentNode, null, michael@0: "The visualizer canvas wasn't removed from the parent node."); michael@0: michael@0: visualizer.cleanup(); michael@0: is(visualizer.presenter, undefined, michael@0: "The visualizer presenter wasn't destroyed."); michael@0: is(visualizer.controller, undefined, michael@0: "The visualizer controller wasn't destroyed."); michael@0: is(visualizer.canvas, undefined, michael@0: "The visualizer canvas wasn't destroyed."); michael@0: } michael@0: michael@0: function testPresenter(presenter) { michael@0: ok(presenter._renderer, michael@0: "The presenter renderer wasn't initialized properly."); michael@0: ok(presenter._visualizationProgram, michael@0: "The presenter visualizationProgram wasn't initialized properly."); michael@0: ok(presenter._texture, michael@0: "The presenter texture wasn't initialized properly."); michael@0: ok(!presenter._meshStacks, michael@0: "The presenter meshStacks shouldn't be initialized yet."); michael@0: ok(!presenter._meshWireframe, michael@0: "The presenter meshWireframe shouldn't be initialized yet."); michael@0: ok(presenter._traverseData, michael@0: "The presenter nodesInformation wasn't initialized properly."); michael@0: ok(presenter._highlight, michael@0: "The presenter highlight wasn't initialized properly."); michael@0: ok(presenter._highlight.disabled, michael@0: "The presenter highlight should be initially disabled."); michael@0: ok(isApproxVec(presenter._highlight.v0, [0, 0, 0]), michael@0: "The presenter highlight first vertex should be initially zeroed."); michael@0: ok(isApproxVec(presenter._highlight.v1, [0, 0, 0]), michael@0: "The presenter highlight second vertex should be initially zeroed."); michael@0: ok(isApproxVec(presenter._highlight.v2, [0, 0, 0]), michael@0: "The presenter highlight third vertex should be initially zeroed."); michael@0: ok(isApproxVec(presenter._highlight.v3, [0, 0, 0]), michael@0: "The presenter highlight fourth vertex should be initially zeroed."); michael@0: ok(presenter.transforms, michael@0: "The presenter transforms wasn't initialized properly."); michael@0: is(presenter.transforms.zoom, 1, michael@0: "The presenter transforms zoom should be initially 1."); michael@0: ok(isApproxVec(presenter.transforms.offset, [0, 0, 0]), michael@0: "The presenter transforms offset should be initially zeroed."); michael@0: ok(isApproxVec(presenter.transforms.translation, [0, 0, 0]), michael@0: "The presenter transforms translation should be initially zeroed."); michael@0: ok(isApproxVec(presenter.transforms.rotation, [0, 0, 0, 1]), michael@0: "The presenter transforms rotation should be initially set to identity."); michael@0: michael@0: presenter.setTranslation([1, 2, 3]); michael@0: presenter.setRotation([5, 6, 7, 8]); michael@0: michael@0: ok(isApproxVec(presenter.transforms.translation, [1, 2, 3]), michael@0: "The presenter transforms translation wasn't modified as it should"); michael@0: ok(isApproxVec(presenter.transforms.rotation, [5, 6, 7, 8]), michael@0: "The presenter transforms rotation wasn't modified as it should"); michael@0: ok(presenter._redraw, michael@0: "The new transforms should have issued a redraw request."); michael@0: } michael@0: michael@0: function testController(controller) { michael@0: ok(controller.arcball, michael@0: "The controller arcball wasn't initialized properly."); michael@0: ok(!controller.coordinates, michael@0: "The presenter meshWireframe shouldn't be initialized yet."); michael@0: }