summaryrefslogtreecommitdiffstats
path: root/devtools/client/canvasdebugger/test/browser_canvas-frontend-slider-02.js
blob: 5074ab206a0237b4a2a2975a1842372107bc8b30 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests if the slider in the calls list view works as advertised.
 */

function* ifTestingSupported() {
  let { target, panel } = yield initCanvasDebuggerFrontend(SIMPLE_CANVAS_URL);
  let { window, $, EVENTS, gFront, SnapshotsListView, CallsListView } = panel.panelWin;

  yield reload(target);

  let recordingFinished = once(window, EVENTS.SNAPSHOT_RECORDING_FINISHED);
  let callListPopulated = once(window, EVENTS.CALL_LIST_POPULATED);
  let thumbnailsDisplayed = once(window, EVENTS.THUMBNAILS_DISPLAYED);
  SnapshotsListView._onRecordButtonClick();
  yield promise.all([recordingFinished, callListPopulated, thumbnailsDisplayed]);

  let firstSnapshot = SnapshotsListView.getItemAtIndex(0);
  let firstSnapshotOverview = yield firstSnapshot.attachment.actor.getOverview();

  let thumbnails = firstSnapshotOverview.thumbnails;
  is(thumbnails.length, 4,
    "There should be 4 thumbnails cached for the snapshot item.");

  let thumbnailImageElementSet = waitForMozSetImageElement(window);
  $("#calls-slider").value = 1;
  let thumbnailPixels = yield thumbnailImageElementSet;

  ok(sameArray(thumbnailPixels, thumbnails[0].pixels),
    "The screenshot element should have a thumbnail as an immediate background.");

  yield once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  ok(true, "The full-sized screenshot was displayed for the item at index 1.");

  thumbnailImageElementSet = waitForMozSetImageElement(window);
  $("#calls-slider").value = 2;
  thumbnailPixels = yield thumbnailImageElementSet;

  ok(sameArray(thumbnailPixels, thumbnails[1].pixels),
    "The screenshot element should have a thumbnail as an immediate background.");

  yield once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  ok(true, "The full-sized screenshot was displayed for the item at index 2.");

  thumbnailImageElementSet = waitForMozSetImageElement(window);
  $("#calls-slider").value = 7;
  thumbnailPixels = yield thumbnailImageElementSet;

  ok(sameArray(thumbnailPixels, thumbnails[3].pixels),
    "The screenshot element should have a thumbnail as an immediate background.");

  yield once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  ok(true, "The full-sized screenshot was displayed for the item at index 7.");

  thumbnailImageElementSet = waitForMozSetImageElement(window);
  $("#calls-slider").value = 4;
  thumbnailPixels = yield thumbnailImageElementSet;

  ok(sameArray(thumbnailPixels, thumbnails[2].pixels),
    "The screenshot element should have a thumbnail as an immediate background.");

  yield once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  ok(true, "The full-sized screenshot was displayed for the item at index 4.");

  thumbnailImageElementSet = waitForMozSetImageElement(window);
  $("#calls-slider").value = 0;
  thumbnailPixels = yield thumbnailImageElementSet;

  ok(sameArray(thumbnailPixels, thumbnails[0].pixels),
    "The screenshot element should have a thumbnail as an immediate background.");

  yield once(window, EVENTS.CALL_SCREENSHOT_DISPLAYED);
  ok(true, "The full-sized screenshot was displayed for the item at index 0.");

  yield teardown(panel);
  finish();
}

function waitForMozSetImageElement(panel) {
  let deferred = promise.defer();
  panel._onMozSetImageElement = deferred.resolve;
  return deferred.promise;
}

function sameArray(a, b) {
  if (a.length != b.length) {
    return false;
  }
  for (let i = 0; i < a.length; i++) {
    if (a[i] !== b[i]) {
      return false;
    }
  }
  return true;
}