summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/media-source/mediasource-duration-boundaryconditions.html
blob: b95e495cb1dd1a0f119257f35ab514239290e22c (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
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>MediaSource.duration boundary condition test cases.</title>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
    </head>
    <body>
        <div id="log"></div>
        <script>
          function DurationBoundaryConditionTest(testDurationValue, expectedError, description)
          {
              return mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
              {
                  // Append initialization segment.
                  test.expectEvent(sourceBuffer, "updateend", "sourceBuffer");
                  test.expectEvent(mediaElement, "loadedmetadata", "mediaElement");
                  sourceBuffer.appendBuffer(MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init));
                  test.waitForExpectedEvents(function()
                  {
                      if (expectedError) {
                          assert_throws(expectedError,
                              function() { mediaSource.duration = testDurationValue; },
                              "mediaSource.duration assignment throws an exception for " + testDurationValue);
                          test.done();
                          return;
                      }

                      mediaSource.duration = testDurationValue;

                      assert_equals(mediaSource.duration, testDurationValue, "mediaSource.duration");
                      assert_equals(mediaElement.duration, testDurationValue, "mediaElement.duration");

                      test.expectEvent(mediaElement, "durationchange", "mediaElement");
                      test.waitForExpectedEvents(function()
                      {
                          assert_equals(mediaSource.duration, testDurationValue, "mediaSource.duration");
                          assert_equals(mediaElement.duration, testDurationValue, "mediaElement.duration");
                          test.done();
                      });
                  });

              }, description);
          }

          DurationBoundaryConditionTest(Math.pow(2, 31) - 1, null, "Set duration to 2^31 - 1");
          DurationBoundaryConditionTest(1, null, "Set duration to 1");
          DurationBoundaryConditionTest(Number.MAX_VALUE, null, "Set duration to Number.MAX_VALUE");
          DurationBoundaryConditionTest(Number.MIN_VALUE, null, "Set duration to Number.MIN_VALUE");
          DurationBoundaryConditionTest(Number.MAX_VALUE - 1, null, "Set duration to Number.MAX_VALUE - 1");
          DurationBoundaryConditionTest(Number.MIN_VALUE - 1, new TypeError(), "Set duration to Number.MIN_VALUE - 1");
          DurationBoundaryConditionTest(Number.POSITIVE_INFINITY, null, "Set duration to Number.POSITIVE_INFINITY");
          DurationBoundaryConditionTest(Number.NEGATIVE_INFINITY, new TypeError(), "Set duration to Number.NEGATIVE_INFINITY");
          DurationBoundaryConditionTest(-1 * Number.MAX_VALUE, new TypeError(), "Set duration to lowest value.");
          DurationBoundaryConditionTest(-101.9, new TypeError(), "Set duration to a negative double.");
          DurationBoundaryConditionTest(101.9, null, "Set duration to a positive double.");
          DurationBoundaryConditionTest(0, null, "Set duration to zero");
          DurationBoundaryConditionTest(NaN, new TypeError(), "Set duration to NaN");
        </script>
    </body>
</html>