chromium/third_party/blink/web_tests/http/tests/media/media-source/mediasource-duration-boundaryconditions.html

<!DOCTYPE html>
<html>
    <head>
        <script src="/w3c/resources/testharness.js"></script>
        <script src="/w3c/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
        <link rel='stylesheet' href='/w3c/resources/testharness.css'>
    </head>
    <body>
        <div id="log"></div>
        <script>
          function DurationBoundaryConditionTest(testDurationValue, expectTypeError, 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 (expectTypeError) {
                          assert_throws_js(TypeError,
                              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, false, "Set duration to 2^31 - 1");
          DurationBoundaryConditionTest(1, false, "Set duration to 1");
          DurationBoundaryConditionTest(Number.MAX_VALUE, false, "Set duration to Number.MAX_VALUE");
          DurationBoundaryConditionTest(Number.MIN_VALUE, false, "Set duration to Number.MIN_VALUE");
          DurationBoundaryConditionTest(Number.MAX_VALUE - 1, false, "Set duration to Number.MAX_VALUE - 1");
          DurationBoundaryConditionTest(Number.MIN_VALUE - 1, true, "Set duration to Number.MIN_VALUE - 1");
          DurationBoundaryConditionTest(Number.POSITIVE_INFINITY, false, "Set duration to Number.POSITIVE_INFINITY");
          DurationBoundaryConditionTest(Number.NEGATIVE_INFINITY, true, "Set duration to Number.NEGATIVE_INFINITY");
          DurationBoundaryConditionTest(-1 * Number.MAX_VALUE, true, "Set duration to lowest value.");
          DurationBoundaryConditionTest(-101.9, true, "Set duration to a negative double.");
          DurationBoundaryConditionTest(101.9, false, "Set duration to a positive double.");
          DurationBoundaryConditionTest(0, false, "Set duration to zero");
          DurationBoundaryConditionTest(NaN, true, "Set duration to NaN");
        </script>
    </body>
</html>