|
| 1 | +/* |
| 2 | + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | + * |
| 4 | + * Use of this source code is governed by a BSD-style license |
| 5 | + * that can be found in the LICENSE file in the root of the source |
| 6 | + * tree. |
| 7 | + */ |
| 8 | + /* eslint-env node */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +// This is a basic test file for use with testling. |
| 13 | +// The test script language comes from tape. |
| 14 | +var test = require('tape'); |
| 15 | + |
| 16 | +var webdriver = require('selenium-webdriver'); |
| 17 | +var seleniumHelpers = require('webrtc-utilities').seleniumLib; |
| 18 | + |
| 19 | +test('Fake device selection and check video element dimensions ' + |
| 20 | + 'in input-output demo', |
| 21 | + function(t) { |
| 22 | + // FIXME: use env[SELENIUM_BROWSER] instead? |
| 23 | + var driver = seleniumHelpers.buildDriver(); |
| 24 | + |
| 25 | + var browser = process.env.BROWSER; |
| 26 | + |
| 27 | + driver.get('file://' + process.cwd() + |
| 28 | + '/src/content/devices/input-output/index.html') |
| 29 | + .then(function() { |
| 30 | + t.pass('Page loaded'); |
| 31 | + // Making sure we can select the 1st audio device. |
| 32 | + // TODO: Select more devices if Firefox adds a 2nd fake A&V device and |
| 33 | + // Chrome adds another fake video device. |
| 34 | + t.pass('Selecting 1st audio device'); |
| 35 | + return driver.wait(webdriver.until.elementLocated( |
| 36 | + webdriver.By.css('#audioSource:nth-of-type(1)'))); |
| 37 | + }) |
| 38 | + // Check enumerateDevices has returned an id. |
| 39 | + .then(function(element) { |
| 40 | + return driver.wait(webdriver.until.elementIsVisible(element)) |
| 41 | + .then(function() { |
| 42 | + element.click(); |
| 43 | + return element.getAttribute('value'); |
| 44 | + }); |
| 45 | + }) |
| 46 | + .then(function(deviceId) { |
| 47 | + t.ok(deviceId, 'Device/source id: ' + deviceId); |
| 48 | + }) |
| 49 | + .then(function() { |
| 50 | + // Making sure we can select the 1st video device. |
| 51 | + // TODO: Select more devices if Firefox adds a 2nd fake A/V device and |
| 52 | + // Chrome adds another fake video device. |
| 53 | + t.pass('Selecting 1st video device'); |
| 54 | + return driver.wait(webdriver.until.elementLocated( |
| 55 | + webdriver.By.css('#videoSource:nth-of-type(1)'))); |
| 56 | + }) |
| 57 | + // Check enumerateDevices has returned an id. |
| 58 | + .then(function(element) { |
| 59 | + return driver.wait(webdriver.until.elementIsVisible(element)) |
| 60 | + .then(function() { |
| 61 | + element.click(); |
| 62 | + return element.getAttribute('value'); |
| 63 | + }); |
| 64 | + }) |
| 65 | + .then(function(deviceId) { |
| 66 | + t.ok(deviceId !== '', 'Device/source id: ' + deviceId); |
| 67 | + }) |
| 68 | + .then(function() { |
| 69 | + // Make sure the stream is ready. |
| 70 | + return driver.wait(function() { |
| 71 | + return driver.executeScript('return window.stream !== undefined;'); |
| 72 | + }, 30 * 1000); |
| 73 | + }) |
| 74 | + // Check for a fake audio device label (Chrome only). |
| 75 | + .then(function() { |
| 76 | + return driver.executeScript('return stream.getAudioTracks()[0].label'); |
| 77 | + }) |
| 78 | + .then(function(deviceLabel) { |
| 79 | + var fakeAudioDeviceName = null; |
| 80 | + |
| 81 | + switch (browser) { |
| 82 | + case 'chrome': |
| 83 | + fakeAudioDeviceName = 'Fake Audio 1'; |
| 84 | + break; |
| 85 | + case 'firefox': |
| 86 | + // TODO: Remove the "deviceLabel === ''" check once Firefox ESR |
| 87 | + // reaches 46 (supports device labels for fake devices). |
| 88 | + fakeAudioDeviceName = (deviceLabel === '') ? '' : |
| 89 | + 'Default Audio Device'; |
| 90 | + break; |
| 91 | + default: |
| 92 | + t.skip('unsupported browser'); |
| 93 | + } |
| 94 | + t.ok(fakeAudioDeviceName === deviceLabel, |
| 95 | + 'Fake audio device found with label: ' + deviceLabel); |
| 96 | + }) |
| 97 | + // Check for a fake video device label (Chrome only). |
| 98 | + .then(function() { |
| 99 | + return driver.executeScript('return stream.getVideoTracks()[0].label'); |
| 100 | + }) |
| 101 | + .then(function(deviceLabel) { |
| 102 | + var fakeVideoDeviceName = null; |
| 103 | + |
| 104 | + switch (browser) { |
| 105 | + case 'chrome': |
| 106 | + fakeVideoDeviceName = 'fake_device_0'; |
| 107 | + break; |
| 108 | + case 'firefox': |
| 109 | + // TODO: Remove the "deviceLabel === ''" check once Firefox ESR |
| 110 | + // reaches 46 (supports device labels for fake devices). |
| 111 | + fakeVideoDeviceName = (deviceLabel === '') ? '' : |
| 112 | + 'Default Video Device'; |
| 113 | + break; |
| 114 | + default: |
| 115 | + t.pass('unsupported browser'); |
| 116 | + throw 'skip-test'; |
| 117 | + } |
| 118 | + |
| 119 | + t.ok(fakeVideoDeviceName === deviceLabel, |
| 120 | + 'Fake video device found with label: ' + deviceLabel); |
| 121 | + }) |
| 122 | + // Check that there is a video element and it is displaying something. |
| 123 | + .then(function() { |
| 124 | + return driver.findElement(webdriver.By.id('video')); |
| 125 | + }) |
| 126 | + .then(function(videoElement) { |
| 127 | + t.pass('Found video element'); |
| 128 | + var width = 0; |
| 129 | + var height = 0; |
| 130 | + return new webdriver.promise.Promise(function(resolve) { |
| 131 | + videoElement.getAttribute('videoWidth').then(function(w) { |
| 132 | + width = w; |
| 133 | + t.pass('Got videoWidth ' + w); |
| 134 | + if (width && height) { |
| 135 | + resolve([width, height]); |
| 136 | + } |
| 137 | + }); |
| 138 | + videoElement.getAttribute('videoHeight').then(function(h) { |
| 139 | + height = h; |
| 140 | + t.pass('Got videoHeight ' + h); |
| 141 | + if (width && height) { |
| 142 | + resolve([width, height]); |
| 143 | + } |
| 144 | + }); |
| 145 | + }); |
| 146 | + }) |
| 147 | + .then(function(dimensions) { |
| 148 | + t.pass('Got video dimensions ' + dimensions.join('x')); |
| 149 | + }) |
| 150 | + .then(function() { |
| 151 | + t.end(); |
| 152 | + }) |
| 153 | + .then(null, function(err) { |
| 154 | + t.fail(err); |
| 155 | + t.end(); |
| 156 | + }); |
| 157 | + }); |
0 commit comments