Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / test / data / eme_player_js / test_config.js
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.
4
5 // Test configuration used by test page to configure the player app and other
6 // test specific configurations.
7 function TestConfig() {
8   this.mediaFile = null;
9   this.keySystem = null;
10   this.mediaType = null;
11   this.licenseServerURL = null;
12   this.useMSE = false;
13   this.usePrefixedEME = false;
14   this.runFPS = false;
15 }
16
17 TestConfig.prototype.loadQueryParams = function() {
18   // Load query parameters and set default values.
19   var r = /([^&=]+)=?([^&]*)/g;
20   // Lambda function for decoding extracted match values. Replaces '+' with
21   // space so decodeURIComponent functions properly.
22   var decodeURI = function decodeURI(s) {
23       return decodeURIComponent(s.replace(/\+/g, ' '));
24   };
25   var match;
26   while (match = r.exec(window.location.search.substring(1)))
27     this[decodeURI(match[1])] = decodeURI(match[2]);
28   this.useMSE = this.useMSE == '1' || this.useMSE == 'true';
29   this.usePrefixedEME =
30       this.usePrefixedEME == '1' || this.usePrefixedEME == 'true';
31
32   // Validate that the prefixed/unprefixed EME is available.
33   if (this.usePrefixedEME) {
34     if (EME_DISABLED_OPTIONS.indexOf(EME_PREFIXED_VERSION) >= 0)
35       Utils.failTest('Prefixed EME not available.')
36   } else {
37     if (EME_DISABLED_OPTIONS.indexOf(EME_UNPREFIXED_VERSION) >= 0)
38       Utils.failTest('Unprefixed EME not available.')
39   }
40 };
41
42 TestConfig.updateDocument = function() {
43   this.loadQueryParams();
44   Utils.addOptions(KEYSYSTEM_ELEMENT_ID, KEY_SYSTEMS);
45   Utils.addOptions(MEDIA_TYPE_ELEMENT_ID, MEDIA_TYPES);
46   Utils.addOptions(USE_PREFIXED_EME_ID, EME_VERSIONS_OPTIONS,
47                    EME_DISABLED_OPTIONS);
48
49   document.getElementById(MEDIA_FILE_ELEMENT_ID).value =
50       this.mediaFile || DEFAULT_MEDIA_FILE;
51
52   document.getElementById(LICENSE_SERVER_ELEMENT_ID).value =
53       this.licenseServerURL || DEFAULT_LICENSE_SERVER;
54
55   if (this.keySystem)
56     Utils.ensureOptionInList(KEYSYSTEM_ELEMENT_ID, this.keySystem);
57   if (this.mediaType)
58     Utils.ensureOptionInList(MEDIA_TYPE_ELEMENT_ID, this.mediaType);
59   document.getElementById(USE_MSE_ELEMENT_ID).value = this.useMSE;
60   if (this.usePrefixedEME)
61     document.getElementById(USE_PREFIXED_EME_ID).value = EME_PREFIXED_VERSION;
62 };
63
64 TestConfig.init = function() {
65   // Reload test configuration from document.
66   this.mediaFile = document.getElementById(MEDIA_FILE_ELEMENT_ID).value;
67   this.keySystem = document.getElementById(KEYSYSTEM_ELEMENT_ID).value;
68   this.mediaType = document.getElementById(MEDIA_TYPE_ELEMENT_ID).value;
69   this.useMSE = document.getElementById(USE_MSE_ELEMENT_ID).value == 'true';
70   this.usePrefixedEME = document.getElementById(USE_PREFIXED_EME_ID).value ==
71       EME_PREFIXED_VERSION;
72   this.licenseServerURL =
73       document.getElementById(LICENSE_SERVER_ELEMENT_ID).value;
74 };