4 <script src=
"/w3c/resources/testharness.js"></script>
5 <script src=
"/w3c/resources/testharnessreport.js"></script>
6 <script src=
"mediasource-util.js"></script>
7 <link rel='stylesheet' href='/w3c/resources/testharness.css'
>
12 function DurationBoundaryConditionTest(testDurationValue
, expectedError
, description
)
14 return mediasource_testafterdataloaded(function(test
, mediaElement
, mediaSource
, segmentInfo
, sourceBuffer
, mediaData
)
16 // Append initialization segment.
17 test
.expectEvent(sourceBuffer
, 'updateend', 'sourceBuffer');
18 test
.expectEvent(mediaElement
, 'loadedmetadata', 'mediaElement');
19 sourceBuffer
.appendBuffer(MediaSourceUtil
.extractSegmentData(mediaData
, segmentInfo
.init
));
20 test
.waitForExpectedEvents(function()
23 assert_throws(expectedError
,
24 function() { mediaSource
.duration
= testDurationValue
; },
25 "mediaSource.duration assignment throws an exception for " + testDurationValue
);
30 mediaSource
.duration
= testDurationValue
;
32 assert_equals(mediaSource
.duration
, testDurationValue
, "mediaSource.duration");
33 assert_equals(mediaElement
.duration
, testDurationValue
, "mediaElement.duration");
35 test
.expectEvent(mediaElement
, 'durationchange', 'mediaElement');
36 test
.waitForExpectedEvents(function()
38 assert_equals(mediaSource
.duration
, testDurationValue
, "mediaSource.duration");
39 assert_equals(mediaElement
.duration
, testDurationValue
, "mediaElement.duration");
47 DurationBoundaryConditionTest(Math
.pow(2, 31) - 1, null, "Set duration to 2^31 - 1");
48 DurationBoundaryConditionTest(1, null, "Set duration to 1");
49 DurationBoundaryConditionTest(Number
.MAX_VALUE
, null, "Set duration to Number.MAX_VALUE");
50 DurationBoundaryConditionTest(Number
.MIN_VALUE
, null, "Set duration to Number.MIN_VALUE");
51 DurationBoundaryConditionTest(Number
.MAX_VALUE
- 1, null, "Set duration to Number.MAX_VALUE - 1");
52 DurationBoundaryConditionTest(Number
.MIN_VALUE
- 1, "InvalidAccessError", "Set duration to Number.MIN_VALUE - 1");
53 DurationBoundaryConditionTest(Number
.POSITIVE_INFINITY
, null, "Set duration to Number.POSITIVE_INFINITY");
54 DurationBoundaryConditionTest(Number
.NEGATIVE_INFINITY
, "InvalidAccessError", "Set duration to Number.NEGATIVE_INFINITY");
55 DurationBoundaryConditionTest(-1 * Number
.MAX_VALUE
, "InvalidAccessError", "Set duration to lowest value.");
56 DurationBoundaryConditionTest(-101.9, "InvalidAccessError", "Set duration to a negative double.");
57 DurationBoundaryConditionTest(101.9, null, "Set duration to a positive double.");
58 DurationBoundaryConditionTest(0, null, "Set duration to zero");
59 DurationBoundaryConditionTest(NaN
, "InvalidAccessError", "Set duration to NaN");