browser/devtools/tilt/test/browser_tilt_visualizer.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/test/browser_tilt_visualizer.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +"use strict";
     1.7 +
     1.8 +function test() {
     1.9 +  if (!isTiltEnabled()) {
    1.10 +    info("Skipping notifications test because Tilt isn't enabled.");
    1.11 +    return;
    1.12 +  }
    1.13 +  if (!isWebGLSupported()) {
    1.14 +    info("Skipping visualizer test because WebGL isn't supported.");
    1.15 +    return;
    1.16 +  }
    1.17 +
    1.18 +  let webGLError = false;
    1.19 +  let webGLLoad = false;
    1.20 +
    1.21 +  let visualizer = new TiltVisualizer({
    1.22 +    chromeWindow: window,
    1.23 +    contentWindow: gBrowser.selectedBrowser.contentWindow,
    1.24 +    parentNode: gBrowser.selectedBrowser.parentNode,
    1.25 +    notifications: Tilt.NOTIFICATIONS,
    1.26 +    tab: gBrowser.selectedTab,
    1.27 +
    1.28 +    onError: function onWebGLError()
    1.29 +    {
    1.30 +      webGLError = true;
    1.31 +    },
    1.32 +
    1.33 +    onLoad: function onWebGLLoad()
    1.34 +    {
    1.35 +      webGLLoad = true;
    1.36 +    }
    1.37 +  });
    1.38 +  visualizer.init();
    1.39 +
    1.40 +  ok(webGLError ^ webGLLoad,
    1.41 +    "The WebGL context should either be created or not.");
    1.42 +
    1.43 +  if (webGLError) {
    1.44 +    info("Skipping visualizer test because WebGL couldn't be initialized.");
    1.45 +    return;
    1.46 +  }
    1.47 +
    1.48 +  ok(visualizer.canvas,
    1.49 +    "Visualizer constructor should have created a child canvas object.");
    1.50 +  ok(visualizer.presenter,
    1.51 +    "Visualizer constructor should have created a child presenter object.");
    1.52 +  ok(visualizer.controller,
    1.53 +    "Visualizer constructor should have created a child controller object.");
    1.54 +  ok(visualizer.isInitialized(),
    1.55 +    "The visualizer should have been initialized properly.");
    1.56 +  ok(visualizer.presenter.isInitialized(),
    1.57 +    "The visualizer presenter should have been initialized properly.");
    1.58 +  ok(visualizer.controller.isInitialized(),
    1.59 +    "The visualizer controller should have been initialized properly.");
    1.60 +
    1.61 +  testPresenter(visualizer.presenter);
    1.62 +  testController(visualizer.controller);
    1.63 +
    1.64 +  visualizer.removeOverlay();
    1.65 +  is(visualizer.canvas.parentNode, null,
    1.66 +    "The visualizer canvas wasn't removed from the parent node.");
    1.67 +
    1.68 +  visualizer.cleanup();
    1.69 +  is(visualizer.presenter, undefined,
    1.70 +    "The visualizer presenter wasn't destroyed.");
    1.71 +  is(visualizer.controller, undefined,
    1.72 +    "The visualizer controller wasn't destroyed.");
    1.73 +  is(visualizer.canvas, undefined,
    1.74 +    "The visualizer canvas wasn't destroyed.");
    1.75 +}
    1.76 +
    1.77 +function testPresenter(presenter) {
    1.78 +  ok(presenter._renderer,
    1.79 +    "The presenter renderer wasn't initialized properly.");
    1.80 +  ok(presenter._visualizationProgram,
    1.81 +    "The presenter visualizationProgram wasn't initialized properly.");
    1.82 +  ok(presenter._texture,
    1.83 +    "The presenter texture wasn't initialized properly.");
    1.84 +  ok(!presenter._meshStacks,
    1.85 +    "The presenter meshStacks shouldn't be initialized yet.");
    1.86 +  ok(!presenter._meshWireframe,
    1.87 +    "The presenter meshWireframe shouldn't be initialized yet.");
    1.88 +  ok(presenter._traverseData,
    1.89 +    "The presenter nodesInformation wasn't initialized properly.");
    1.90 +  ok(presenter._highlight,
    1.91 +    "The presenter highlight wasn't initialized properly.");
    1.92 +  ok(presenter._highlight.disabled,
    1.93 +    "The presenter highlight should be initially disabled.");
    1.94 +  ok(isApproxVec(presenter._highlight.v0, [0, 0, 0]),
    1.95 +    "The presenter highlight first vertex should be initially zeroed.");
    1.96 +  ok(isApproxVec(presenter._highlight.v1, [0, 0, 0]),
    1.97 +    "The presenter highlight second vertex should be initially zeroed.");
    1.98 +  ok(isApproxVec(presenter._highlight.v2, [0, 0, 0]),
    1.99 +    "The presenter highlight third vertex should be initially zeroed.");
   1.100 +  ok(isApproxVec(presenter._highlight.v3, [0, 0, 0]),
   1.101 +    "The presenter highlight fourth vertex should be initially zeroed.");
   1.102 +  ok(presenter.transforms,
   1.103 +    "The presenter transforms wasn't initialized properly.");
   1.104 +  is(presenter.transforms.zoom, 1,
   1.105 +    "The presenter transforms zoom should be initially 1.");
   1.106 +  ok(isApproxVec(presenter.transforms.offset, [0, 0, 0]),
   1.107 +    "The presenter transforms offset should be initially zeroed.");
   1.108 +  ok(isApproxVec(presenter.transforms.translation, [0, 0, 0]),
   1.109 +    "The presenter transforms translation should be initially zeroed.");
   1.110 +  ok(isApproxVec(presenter.transforms.rotation, [0, 0, 0, 1]),
   1.111 +    "The presenter transforms rotation should be initially set to identity.");
   1.112 +
   1.113 +  presenter.setTranslation([1, 2, 3]);
   1.114 +  presenter.setRotation([5, 6, 7, 8]);
   1.115 +
   1.116 +  ok(isApproxVec(presenter.transforms.translation, [1, 2, 3]),
   1.117 +    "The presenter transforms translation wasn't modified as it should");
   1.118 +  ok(isApproxVec(presenter.transforms.rotation, [5, 6, 7, 8]),
   1.119 +    "The presenter transforms rotation wasn't modified as it should");
   1.120 +  ok(presenter._redraw,
   1.121 +    "The new transforms should have issued a redraw request.");
   1.122 +}
   1.123 +
   1.124 +function testController(controller) {
   1.125 +  ok(controller.arcball,
   1.126 +    "The controller arcball wasn't initialized properly.");
   1.127 +  ok(!controller.coordinates,
   1.128 +    "The presenter meshWireframe shouldn't be initialized yet.");
   1.129 +}

mercurial