summaryrefslogtreecommitdiffstats
path: root/devtools/client/webaudioeditor/test/browser_wa_graph-zoom.js
blob: 240b6d5a141e699407f4b9b7d3f9318c2b6e972b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that the graph's scale and position is reset on a page reload.
 */

add_task(function* () {
  let { target, panel } = yield initWebAudioEditor(SIMPLE_CONTEXT_URL);
  let { panelWin } = panel;
  let { gFront, $, $$, EVENTS, ContextView } = panelWin;

  let started = once(gFront, "start-context");

  yield Promise.all([
    waitForGraphRendered(panelWin, 3, 2),
    reload(target),
  ]);

  is(ContextView.getCurrentScale(), 1, "Default graph scale is 1.");
  is(ContextView.getCurrentTranslation()[0], 20, "Default x-translation is 20.");
  is(ContextView.getCurrentTranslation()[1], 20, "Default y-translation is 20.");

  // Change both attribute and D3's internal store
  panelWin.d3.select("#graph-target").attr("transform", "translate([100, 400]) scale(10)");
  ContextView._zoomBinding.scale(10);
  ContextView._zoomBinding.translate([100, 400]);

  is(ContextView.getCurrentScale(), 10, "After zoom, scale is 10.");
  is(ContextView.getCurrentTranslation()[0], 100, "After zoom, x-translation is 100.");
  is(ContextView.getCurrentTranslation()[1], 400, "After zoom, y-translation is 400.");

  yield Promise.all([
    waitForGraphRendered(panelWin, 3, 2),
    reload(target),
  ]);

  is(ContextView.getCurrentScale(), 1, "After refresh, graph scale is 1.");
  is(ContextView.getCurrentTranslation()[0], 20, "After refresh, x-translation is 20.");
  is(ContextView.getCurrentTranslation()[1], 20, "After refresh, y-translation is 20.");

  yield teardown(target);
});