1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Test configuration used by test page to configure the player app and other
6 // test specific configurations.
7 function TestConfig() {
10 this.mediaType
= null;
11 this.licenseServerURL
= null;
13 this.usePrefixedEME
= false;
15 this.playTwice
= false;
18 TestConfig
.prototype.loadQueryParams = function() {
19 // Load query parameters and set default values.
20 var r
= /([^&=]+)=?([^&]*)/g;
21 // Lambda function for decoding extracted match values. Replaces '+' with
22 // space so decodeURIComponent functions properly.
23 var decodeURI
= function decodeURI(s
) {
24 return decodeURIComponent(s
.replace(/\+/g, ' '));
27 while (match
= r
.exec(window
.location
.search
.substring(1)))
28 this[decodeURI(match
[1])] = decodeURI(match
[2]);
29 this.useMSE
= this.useMSE
== '1' || this.useMSE
== 'true';
31 this.usePrefixedEME
== '1' || this.usePrefixedEME
== 'true';
32 this.playTwice
= this.playTwice
== '1' || this.playTwice
== 'true';
34 // Validate that the prefixed/unprefixed EME is available.
35 if (this.usePrefixedEME
) {
36 if (EME_DISABLED_OPTIONS
.indexOf(EME_PREFIXED_VERSION
) >= 0)
37 Utils
.failTest('Prefixed EME not available.')
39 if (EME_DISABLED_OPTIONS
.indexOf(EME_UNPREFIXED_VERSION
) >= 0)
40 Utils
.failTest('Unprefixed EME not available.')
44 TestConfig
.updateDocument = function() {
45 this.loadQueryParams();
46 Utils
.addOptions(KEYSYSTEM_ELEMENT_ID
, KEY_SYSTEMS
);
47 Utils
.addOptions(MEDIA_TYPE_ELEMENT_ID
, MEDIA_TYPES
);
48 Utils
.addOptions(USE_PREFIXED_EME_ID
, EME_VERSIONS_OPTIONS
,
49 EME_DISABLED_OPTIONS
);
51 document
.getElementById(MEDIA_FILE_ELEMENT_ID
).value
=
52 this.mediaFile
|| DEFAULT_MEDIA_FILE
;
54 document
.getElementById(LICENSE_SERVER_ELEMENT_ID
).value
=
55 this.licenseServerURL
|| DEFAULT_LICENSE_SERVER
;
58 Utils
.ensureOptionInList(KEYSYSTEM_ELEMENT_ID
, this.keySystem
);
60 Utils
.ensureOptionInList(MEDIA_TYPE_ELEMENT_ID
, this.mediaType
);
61 document
.getElementById(USE_MSE_ELEMENT_ID
).value
= this.useMSE
;
62 if (this.usePrefixedEME
)
63 document
.getElementById(USE_PREFIXED_EME_ID
).value
= EME_PREFIXED_VERSION
;
64 document
.getElementById(USE_PLAY_TWICE_ELEMENT_ID
).value
= this.playTwice
;
67 TestConfig
.init = function() {
68 // Reload test configuration from document.
69 this.mediaFile
= document
.getElementById(MEDIA_FILE_ELEMENT_ID
).value
;
70 this.keySystem
= document
.getElementById(KEYSYSTEM_ELEMENT_ID
).value
;
71 this.mediaType
= document
.getElementById(MEDIA_TYPE_ELEMENT_ID
).value
;
72 this.useMSE
= document
.getElementById(USE_MSE_ELEMENT_ID
).value
== 'true';
73 this.usePrefixedEME
= document
.getElementById(USE_PREFIXED_EME_ID
).value
==
76 document
.getElementById(USE_PLAY_TWICE_ELEMENT_ID
).value
== 'true';
77 this.licenseServerURL
=
78 document
.getElementById(LICENSE_SERVER_ELEMENT_ID
).value
;