DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (409f3966645a)

VCS Links

Line Code
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test Background Video Suspends</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="manifest.js"></script>
<script src="background_video.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript">
"use strict";

var manager = new MediaTestManager;

function testSameContent(video1, video2) {
  if (video1.videoWidth != video2.videoWidth ||
      video1.videoHeight != video2.videoHeight) {
    ok(false, `${video1.token} video1 and video2 have different dimensions.`);
    return;
  }

  let w = video1.videoWidth;
  let h = video1.videoHeight;
  let c1 = document.createElement('canvas');
  let c2 = document.createElement('canvas');
  c1.width = w;
  c1.height = h;
  c2.width = w;
  c2.height = h;

  let gfx1 = c1.getContext('2d');
  let gfx2 = c2.getContext('2d');
  if (!gfx1 || !gfx2) {
    ok(false, "Unable to obtain context '2d' from canvas");
    return;
  }

  gfx1.drawImage(video1, 0, 0, w, h);
  gfx2.drawImage(video2, 0, 0, w, h);

  // Get content out.
  let contentWidth = 4;
  let contentHeight = 4;
  let imageData1 = gfx1.getImageData(0, 0, contentWidth, contentHeight);
  let imageData2 = gfx2.getImageData(0, 0, contentWidth, contentHeight);
  let pixels1 = imageData1.data;
  let pixels2 = imageData2.data;

  // Check that the content of two video are identical.
  for (let i = 0; i < contentWidth*contentHeight; i++) {
    let pixelCount = 4 * i;
    if (pixels1[pixelCount+0] != pixels2[pixelCount+0] ||
        pixels1[pixelCount+1] != pixels2[pixelCount+1] ||
        pixels1[pixelCount+2] != pixels2[pixelCount+2] ||
        pixels1[pixelCount+3] != pixels2[pixelCount+3]) {
      ok(false, `${video1.token} video1 and video2 have different content.`);
      return;
    }
  }

  ok(true, `${video1.token} video1 and video2 have identical content.`);
}

function waitUntilSeekToLastFrame(video) {
  Log(video.token, "Waiting for seeking to the last frame");
  function callSeekToNextFrame() {
    video.seekToNextFrame().then(
      () => {
        if (!video.seenEnded) {
          callSeekToNextFrame();
        }
      },
      () => {
        // When seek reaches the end, the promise is resolved before 'ended'
        // is fired. The resolver calls callSeekToNextFrame() to schedule
        // another seek and then the 'ended' handler calls finish() to shut
        // down the MediaDecoder which will reject the seek promise. So we don't
        // raise an error in this case.
        ok(video.seenEnded, "seekToNextFrame() failed.");
      }
    );
  }

  return new Promise(function(resolve, reject) {
    video.seenEnded = false;
    video.addEventListener("ended", () => {
      video.seenEnded = true;
      resolve();
    }, true);
    callSeekToNextFrame(video);
  });
}

function appendVideoToDocWithoutLoad(token, width, height) {
  // Default size of (160, 120) is used by other media tests.
  if (width === undefined) { width = 160; }
  if (height === undefined) { height = 3*width/4; }

  let v = document.createElement('video');
  v.token = token;
  document.body.appendChild(v);
  v.width = width;
  v.height = height;
  return v;
}

function loadAndWaitUntilLoadedmetadata(video, url, preloadType = "metadata") {
  return new Promise((resolve, reject) => {
    video.preload = preloadType;
    video.addEventListener("loadedmetadata", () => { resolve(); }, true);
    video.src = url;
  });
}

startTest({
  desc: "Test resume an ended video shows the last frame.",
  prefs: [
    [ "media.test.video-suspend", true ],
    [ "media.suspend-bkgnd-video.enabled", true ],
    [ "media.suspend-bkgnd-video.delay-ms", 100 ],
    [ "media.dormant-on-pause-timeout-ms", -1],
    [ "media.decoder.skip-to-next-key-frame.enabled", false]
  ],
  tests: gDecodeSuspendTests,

  runTest: (test, token) => {
    let v = appendVideoToDoc(test.name, token);
    let vReference = appendVideoToDocWithoutLoad(token+"-ref");
    manager.started(token);

    /*
     * This test checks that, after a video element had finished its playback,
     * resuming video decoder should seek to the last frame.
     * This issue was found in bug 1358057.
     */
    Promise.all([waitUntilPlaying(v), loadAndWaitUntilLoadedmetadata(vReference, test.name, "auto")])
      .then(() => testVideoSuspendsWhenHidden(v))
      .then(() => {
        return Promise.all([waitUntilEnded(v), waitUntilSeekToLastFrame(vReference)]);
      })
      .then(() => testVideoOnlySeekCompletedWhenShown(v))
      .then(() => {
        testSameContent(v, vReference);
        removeNodeAndSource(v);
        removeNodeAndSource(vReference);
        manager.finished(token);
      });
    }
});
</script>