diff options
author | jansson@chromium.org <jansson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-17 14:42:05 +0000 |
---|---|---|
committer | jansson@chromium.org <jansson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-17 14:42:05 +0000 |
commit | 3b6d0315cad1f8c3a1276d28113b17424a8c1875 (patch) | |
tree | 41a3660cb505f075df899aaacde9561cc7e6eb6d /chrome/test/data/webrtc | |
parent | 79414e1e180c4a68d653b468d804dbf260a3fd8c (diff) | |
download | chromium_src-3b6d0315cad1f8c3a1276d28113b17424a8c1875.zip chromium_src-3b6d0315cad1f8c3a1276d28113b17424a8c1875.tar.gz chromium_src-3b6d0315cad1f8c3a1276d28113b17424a8c1875.tar.bz2 |
Removed getDevices from window.onload and added a checkbox letting the
user choose if it should be run when the page loads or not.
This is for making it easier testing using sourceID constraints
before getDevices has been called upon.
Also removed the audio and video prefix labels in getDevices() when
enumerating devices in order to show more of the sourceID string in
the device dropdown menus. Renamed the refresh-devices button to get-devices.
Noticed a minor error in failTest (sentToTest should be sendToTest) and changed it to returnToTest so it would
better accommodate peerconnection.html needs. Ran WebrtcBrowser_tests to make sure it did not break anything.
BUG=313192
NOTRY=TRUE
TEST= WebrtcBrowserTest.MANUAL* and manually setup p2p call, request getUserMedia with/without sourceID etc.
Steps to clear LocalStorage for testing:
Delete cookies and other site and plug-in data entry in the Clear browsing data dialog
(chrome://chrome/settings/clearBrowserData
Review URL: https://codereview.chromium.org/111543003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data/webrtc')
-rw-r--r-- | chrome/test/data/webrtc/getusermedia.js | 10 | ||||
-rw-r--r-- | chrome/test/data/webrtc/manual/peerconnection.html | 5 | ||||
-rw-r--r-- | chrome/test/data/webrtc/manual/peerconnection.js | 74 | ||||
-rw-r--r-- | chrome/test/data/webrtc/test_functions.js | 2 |
4 files changed, 72 insertions, 19 deletions
diff --git a/chrome/test/data/webrtc/getusermedia.js b/chrome/test/data/webrtc/getusermedia.js index 1cea955..bee3ae1 100644 --- a/chrome/test/data/webrtc/getusermedia.js +++ b/chrome/test/data/webrtc/getusermedia.js @@ -243,10 +243,10 @@ function displayVideoSize_(videoTag) { * to update the constraints. */ function getDevices() { - if ($('audiosrc') && $('videosrc') && $('refresh-devices')) { + if ($('audiosrc') && $('videosrc') && $('get-devices')) { var audio_select = $('audiosrc'); var video_select = $('videosrc'); - var refresh_devices = $('refresh-devices'); + var get_devices = $('get-devices'); audio_select.innerHTML = ''; video_select.innerHTML = ''; try { @@ -254,7 +254,7 @@ function getDevices() { } catch (exception) { audio_select.disabled = true; video_select.disabled = true; - refresh_devices.disabled = true; + get_devices.disabled = true; updateGetUserMediaConstraints(); debug('Device enumeration not supported. ' + exception); return; @@ -266,13 +266,13 @@ function getDevices() { option.text = devices[i].label; if (devices[i].kind == 'audio') { if (option.text == '') { - option.text = 'Audio: ' + devices[i].id; + option.text = devices[i].id; } audio_select.appendChild(option); } else if (devices[i].kind == 'video') { if (option.text == '') { - option.text = 'Video: ' + devices[i].id; + option.text = devices[i].id; } video_select.appendChild(option); } diff --git a/chrome/test/data/webrtc/manual/peerconnection.html b/chrome/test/data/webrtc/manual/peerconnection.html index ac530c0..ad10e1c 100644 --- a/chrome/test/data/webrtc/manual/peerconnection.html +++ b/chrome/test/data/webrtc/manual/peerconnection.html @@ -34,8 +34,9 @@ onblur="updateGetUserMediaConstraints();">x<input type="text" id="video-height" value="720" size="5px" onblur="updateGetUserMediaConstraints();"> - <button id="refresh-devices" onclick="getDevices();"> - Refresh devices</button> + <button id="get-devices" onclick="getDevices();"> + Get devices</button> + Onload<input type="checkbox" id="get-devices-onload"> You can also use <a href="constraints.html">constraints.html</a> <a href="peerconnection-help.html" target="_blank">Help</a> <br/> diff --git a/chrome/test/data/webrtc/manual/peerconnection.js b/chrome/test/data/webrtc/manual/peerconnection.js index b61508e..e6dd8d7 100644 --- a/chrome/test/data/webrtc/manual/peerconnection.js +++ b/chrome/test/data/webrtc/manual/peerconnection.js @@ -61,7 +61,11 @@ function negotiateCallFromHere() { $('pc-createanswer-constraints').value)); ensureHasPeerConnection_(); - negotiateCall(); + try { + negotiateCall(); + } catch (exception) { + error(exception); + } } function addLocalStreamFromHere() { @@ -233,9 +237,12 @@ window.onload = function() { hookupDtmfSenderCallback_(); displayVideoSize_($('local-view')); displayVideoSize_($('remote-view')); - getDevices(); + updateGetUserMediaConstraints(); setPcDataChannelType(); setupLocalStorageFieldValues(); + if ($('get-devices-onload').checked == true) { + getDevices(); + } }; /** @@ -303,6 +310,16 @@ function debug_(message) { } /** + * Print error message in the debug log + JS console and throw an Error. + * @private + * @param {string} message Text to print. + */ +function error(message) { + $('debug').innerHTML += '<span style="color:red;">' + message + '</span><br>'; + throw new Error(message); +} + +/** * @private * @param {string} stringRepresentation JavaScript as a string. * @return {Object} The PeerConnection constraints as a JavaScript dictionary. @@ -311,10 +328,10 @@ function getEvaluatedJavaScript_(stringRepresentation) { try { var evaluatedJavaScript; eval('evaluatedJavaScript = ' + stringRepresentation); + return evaluatedJavaScript; } catch (exception) { - throw failTest('Not valid JavaScript expression: ' + stringRepresentation); + error('Not valid JavaScript expression: ' + stringRepresentation); } - return evaluatedJavaScript; } /** @@ -399,21 +416,52 @@ function setupLocalStorageFieldValues() { registerLocalStorage_('pc-server'); registerLocalStorage_('pc-createanswer-constraints'); registerLocalStorage_('pc-createoffer-constraints'); + registerLocalStorage_('get-devices-onload'); } /** - * Stores the value of the element_id parameter using local storage. + * Register an input element to use local storage to remember its state between + * sessions (using local storage). Only input elements are supported. * @private - * @param {!string} element_id to be used as a key for local storage + * @param {!string} element_id to be used as a key for local storage and the id + * of the element to store the state for. */ function registerLocalStorage_(element_id) { var element = $(element_id); - element.onblur = function() { storeLocalStorageFieldValue_(this); }; + if (element.tagName != 'INPUT') { + error('You can only use registerLocalStorage_ for input elements. ' + + 'Element \"' + element.tagName +'\" is not an input element. '); + } - if (localStorage.getItem(element.id) === 'undefined') { - storeLocalStorageFieldValue_(element); + if (localStorage.getItem(element.id) == 'undefined') { + storeLocalStorageField_(element); } else { + getLocalStorageField_(element); + } + // Registers the appropriate events for input elements. + if (element.type == 'checkbox') { + element.onclick = function() { storeLocalStorageField_(this); }; + } else if (element.type == 'text') { + element.onblur = function() { storeLocalStorageField_(this); }; + } else { + error('Unsupportered input type: ' + '\"' + element.type + '\"' ); + } +} + +/** + * Fetches the stored values from local storage and updates checkbox status. + * @private + * @param {!Object} element of which id is representing the key parameter for + * local storage. + */ +function getLocalStorageField_(element) { + // Makes sure the checkbox status is matching the local storage value. + if (element.type == 'checkbox') { + element.checked = (localStorage.getItem(element.id) == 'true'); + } else if (element.type == 'text' ) { element.value = localStorage.getItem(element.id); + } else { + error('Unsupportered input type: ' + '\"' + element.type + '\"' ); } } @@ -423,6 +471,10 @@ function registerLocalStorage_(element_id) { * @param {!Object} element of which id is representing the key parameter for * local storage. */ -function storeLocalStorageFieldValue_(element) { - localStorage.setItem(element.id, element.value); +function storeLocalStorageField_(element) { + if (element.type == 'checkbox') { + localStorage.setItem(element.id, element.checked); + } else if (element.type == 'text') { + localStorage.setItem(element.id, element.value); + } } diff --git a/chrome/test/data/webrtc/test_functions.js b/chrome/test/data/webrtc/test_functions.js index 84f7151..8ed2a75 100644 --- a/chrome/test/data/webrtc/test_functions.js +++ b/chrome/test/data/webrtc/test_functions.js @@ -84,7 +84,7 @@ function sendToTest(message) { */ function failTest(reason) { console.error(reason); - sendToTest('Test failed: ' + reason); + returnToTest('Test failed: ' + reason); return new Error(reason); } |