Bug 1489417 [wpt PR 12893] - Add tests for mediacapture-image, a=testonly
authorReilly Grant <reillyeon@users.noreply.github.com>
Tue, 11 Sep 2018 10:03:21 +0000
changeset 436015 151d407ff320dcd69086274766df7db1fdf13557
parent 436014 058710dfff1d646bb4873f17c9ffabe3bc074fa9
child 436016 c889c43ddfb97df5d08aa603ccb031488992e7ce
push id34625
push userdvarga@mozilla.com
push dateThu, 13 Sep 2018 02:31:40 +0000
treeherdermozilla-central@51e9e9660b3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1489417, 12893
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1489417 [wpt PR 12893] - Add tests for mediacapture-image, a=testonly Automatic update from web-platform-testsMerge pull request #12893 from kaixinjxq/mediacapture-image_init Add tests for mediacapture-image -- wpt-commits: 5ef977c0087a9f1d970bf229f1130799b0c09010 wpt-pr: 12893
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/mediacapture-image/ImageCapture-creation.https.html
testing/web-platform/tests/mediacapture-image/ImageCapture-track.html
testing/web-platform/tests/mediacapture-image/getPhotoCapabilities.html
testing/web-platform/tests/mediacapture-image/getPhotoSettings.html
testing/web-platform/tests/mediacapture-image/takePhoto.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -371211,16 +371211,22 @@
     ]
    ],
    "mediacapture-image/ImageCapture-grabFrame.html": [
     [
      "/mediacapture-image/ImageCapture-grabFrame.html",
      {}
     ]
    ],
+   "mediacapture-image/ImageCapture-track.html": [
+    [
+     "/mediacapture-image/ImageCapture-track.html",
+     {}
+    ]
+   ],
    "mediacapture-image/MediaStreamTrack-applyConstraints-fast.html": [
     [
      "/mediacapture-image/MediaStreamTrack-applyConstraints-fast.html",
      {}
     ]
    ],
    "mediacapture-image/MediaStreamTrack-applyConstraints-getSettings.html": [
     [
@@ -617457,23 +617463,27 @@
    "c58e63ff12acefc73fc3cfa2f35836778696c827",
    "testharness"
   ],
   "mediacapture-image/ImageCapture-MediaTrackSupportedConstraints.html": [
    "59a54f51d600fa5c8ee1c092afa5a07f6ae2ae3f",
    "testharness"
   ],
   "mediacapture-image/ImageCapture-creation.https.html": [
-   "9e8b5feeeb5cdf5686c36e3972fc9a1a8961de95",
+   "387dceee37a8ee8149f63e5af8c1bd8e5cb8763a",
    "testharness"
   ],
   "mediacapture-image/ImageCapture-grabFrame.html": [
    "bf5e9400a038f2432ce1bee3a3b345f3c82e5ea5",
    "testharness"
   ],
+  "mediacapture-image/ImageCapture-track.html": [
+   "774970ad0c4330983574f78aa3f3aabb9d18fd90",
+   "testharness"
+  ],
   "mediacapture-image/META.yml": [
    "1b4fef5e5a19ed3d7e61320bfa752a19da1f595a",
    "support"
   ],
   "mediacapture-image/MediaStreamTrack-applyConstraints-fast.html": [
    "75ed17a9e3302b0cb2b388846ad73d55c6d9c166",
    "testharness"
   ],
@@ -617509,21 +617519,21 @@
    "5e9256eeb740663675ea93d692481556efd97628",
    "testharness"
   ],
   "mediacapture-image/detached-HTMLCanvasElement.html": [
    "e27950fc5edfea8357344f91198f0105775fef2c",
    "testharness"
   ],
   "mediacapture-image/getPhotoCapabilities.html": [
-   "83329fcac4ad37bea6dd13930103c2fd689a77fd",
+   "6cf14c32987846053beceae71b44df556fc32212",
    "testharness"
   ],
   "mediacapture-image/getPhotoSettings.html": [
-   "6a6184f17cb2f92c01d7bf784047ae17b1e8be66",
+   "f7252b4c89fb24f551ec8861bc7f1139a36ff00e",
    "testharness"
   ],
   "mediacapture-image/idlharness.window.js": [
    "9d8f7eefb84dcc16534f1311c3b3c3d68e84572d",
    "testharness"
   ],
   "mediacapture-image/resources/imagecapture-helpers.js": [
    "6d5ffa1695d807a05edeb75a21d472856bdda252",
@@ -617533,17 +617543,17 @@
    "4deee97d7bc77859602aa25d51e547bd0290409b",
    "testharness"
   ],
   "mediacapture-image/takePhoto-with-PhotoSettings.html": [
    "58708612456fc669c5a445b76ad110fcbb0bb27d",
    "testharness"
   ],
   "mediacapture-image/takePhoto.html": [
-   "49926db1cde6ee6b3e703e920e0812232eac0835",
+   "7382877a3a4b9c6901b430ec79e59c930974c0c0",
    "testharness"
   ],
   "mediacapture-record/BlobEvent-constructor.html": [
    "3bcf4296e68aea1a7b167e570c0dcec148cc95e4",
    "testharness"
   ],
   "mediacapture-record/META.yml": [
    "d59e5e30845eaef12bab6419e348a01779313c56",
--- a/testing/web-platform/tests/mediacapture-image/ImageCapture-creation.https.html
+++ b/testing/web-platform/tests/mediacapture-image/ImageCapture-creation.https.html
@@ -68,9 +68,28 @@ var testAudio = async_test(function() {
                     'an ImageCapturer can only be created from a video track');
 
       this.done();
     }))
     .catch(
     this.unreached_func('Error creating MediaStream.'));
 }, 'verifies that an ImageCapture cannot be created out of an Audio Track');
 
+var testParameter = test(function() {
+  const invalidParameters = [
+    "invalid",
+    null,
+    123,
+    {},
+    "",
+    true
+  ];
+  assert_throws(new TypeError(),
+                function() { var capturer = new ImageCapture(); },
+               'an ImageCapturer can not be created with no parameter');
+  invalidParameters.map(parameter => {
+    assert_throws(new TypeError(),
+                  function() { var capturer = new ImageCapture(parameter); },
+                 `an ImageCapturer can not be created with a ${parameter} parameter`);
+  });
+}, 'throw "TypeError" if parameter is not MediaStreamTrack.');
+
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/mediacapture-image/ImageCapture-track.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>ImageCapture track</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="https://w3c.github.io/mediacapture-image/#dom-imagecapture-track">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<canvas id='canvas' width=10 height=10></canvas>
+<script>
+
+test(t => {
+  let canvas = document.getElementById('canvas');
+  let context = canvas.getContext('2d');
+  context.fillStyle = 'red';
+  context.fillRect(0, 0, 10, 10);
+
+  let stream = canvas.captureStream();
+  let videoTrack = stream.getVideoTracks()[0];
+
+  let capturer = new ImageCapture(videoTrack);
+  assert_true(capturer.track instanceof MediaStreamTrack);
+  assert_equals(capturer.track, videoTrack);
+
+  let cloneTrack = videoTrack.clone();
+  assert_not_equals(videoTrack, cloneTrack);
+
+  capturer.track = cloneTrack;
+  assert_equals(capturer.track, videoTrack);
+}, "ImageCapture track attribute is readonly")
+
+</script>
--- a/testing/web-platform/tests/mediacapture-image/getPhotoCapabilities.html
+++ b/testing/web-platform/tests/mediacapture-image/getPhotoCapabilities.html
@@ -37,9 +37,25 @@ image_capture_test(async (t, imageCaptur
   assert_equals(capabilities.imageWidth.min, mockCapabilities.width.min);
   assert_equals(capabilities.imageWidth.step, mockCapabilities.width.step);
 
   assert_array_equals(capabilities.fillLightMode, [ 'auto', 'flash' ],
                       'fillLightMode');
 
 }, 'exercises ImageCapture.getPhotoCapabilities()');
 
+promise_test(t => {
+  let canvas = document.getElementById('canvas');
+  let context = canvas.getContext('2d');
+  context.fillStyle = 'red';
+  context.fillRect(0, 0, 10, 10);
+  let stream = canvas.captureStream();
+  let videoTrack = stream.getVideoTracks()[0];
+  videoTrack.stop();
+
+  let capturer = new ImageCapture(videoTrack);
+  assert_equals(videoTrack.readyState, 'ended');
+
+  return promise_rejects(t, 'InvalidStateError', capturer.getPhotoCapabilities())
+
+}, 'getPhotoCapabilities() of an ended Track should throw "InvalidStateError"');
+
 </script>
--- a/testing/web-platform/tests/mediacapture-image/getPhotoSettings.html
+++ b/testing/web-platform/tests/mediacapture-image/getPhotoSettings.html
@@ -22,9 +22,25 @@ image_capture_test(async (t, imageCaptur
   let capturer = new ImageCapture(stream.getVideoTracks()[0]);
   let settings = await capturer.getPhotoSettings();
   assert_equals(settings.imageWidth, mockState.width.current, 'width');
   assert_equals(settings.imageHeight, mockState.height.current, 'height');
   // TODO(mcasas): check the remaining two entries https://crbug.com/732521.
 
 }, 'exercises ImageCapture.getPhotoSettings()');
 
+promise_test(t => {
+  let canvas = document.getElementById('canvas');
+  let context = canvas.getContext('2d');
+  context.fillStyle = 'red';
+  context.fillRect(0, 0, 10, 10);
+  let stream = canvas.captureStream();
+  let videoTrack = stream.getVideoTracks()[0];
+  videoTrack.stop();
+
+  let capturer = new ImageCapture(videoTrack);
+  assert_equals(videoTrack.readyState, 'ended');
+
+  return promise_rejects(t, 'InvalidStateError', capturer.getPhotoSettings())
+
+}, 'getPhotoSettings() of an ended Track should throw "InvalidStateError"');
+
 </script>
--- a/testing/web-platform/tests/mediacapture-image/takePhoto.html
+++ b/testing/web-platform/tests/mediacapture-image/takePhoto.html
@@ -21,9 +21,41 @@ image_capture_test(async t => {
   let blob = await capturer.takePhoto();
 
   // JS Blob is almost-opaque, can only check |type| and |size|.
   assert_equals(blob.type, 'image/cat');
   assert_equals(blob.size, 2);
 
 }, 'exercises ImageCapture.takePhoto()');
 
+image_capture_test(async t => {
+  let canvas = document.getElementById('canvas');
+  let context = canvas.getContext('2d');
+  context.fillStyle = 'red';
+  context.fillRect(0, 0, 10, 10);
+  let stream = canvas.captureStream();
+
+  let capturer = new ImageCapture(stream.getVideoTracks()[0]);
+  let blob = await capturer.takePhoto(null);
+
+  // JS Blob is almost-opaque, can only check |type| and |size|.
+  assert_equals(blob.type, 'image/cat');
+  assert_equals(blob.size, 2);
+
+}, 'exercises ImageCapture.takePhoto(null)');
+
+promise_test(t => {
+  let canvas = document.getElementById('canvas');
+  let context = canvas.getContext('2d');
+  context.fillStyle = 'red';
+  context.fillRect(0, 0, 10, 10);
+  let stream = canvas.captureStream();
+  let videoTrack = stream.getVideoTracks()[0];
+  videoTrack.stop();
+
+  let capturer = new ImageCapture(videoTrack);
+  assert_equals(videoTrack.readyState, 'ended');
+
+  return promise_rejects(t, 'InvalidStateError', capturer.takePhoto())
+
+}, 'takePhoto() of an ended Track should throw "InvalidStateError"');
+
 </script>