<commit_before>/*
 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */

'use strict';

// This is a basic test file for use with testling.
// The test script language comes from tape.
var test = require('tape');

var webdriver = require('selenium-webdriver');
var seleniumHelpers = require('../../../../../test/selenium-lib');

test('Fake device selection and check video element dimensions ' +
  'in input-output demo',
  function(t) {
    // FIXME: use env[SELENIUM_BROWSER] instead?
    var driver = seleniumHelpers.buildDriver();

    var browser = process.env.BROWSER;

    driver.get('file://' + process.cwd() +
        '/src/content/devices/input-output/index.html')
      .then(function() {
        t.pass('Page loaded');
        // Making sure we can select the 1st audio device.
        // TODO: Select more devices if Firefox adds a 2nd fake A&V device and
        // Chrome adds another fake video device.
        t.pass('Selecting 1st audio device');
        return driver.wait(webdriver.until.elementLocated(
          webdriver.By.css('#audioSource:nth-of-type(1)')));
      })
      // Check enumerateDevices has returned an id.
      .then(function(element) {
        return driver.wait(webdriver.until.elementIsVisible(element))
        .then(function() {
          element.click();
          return element.getAttribute('value');
        });
      })
      .then(function(deviceId) {
        t.ok(deviceId, 'Device/source id: ' + deviceId);
      })
      .then(function() {
        // Making sure we can select the 1st video device.
        // TODO: Select more devices if Firefox adds a 2nd fake A/V device and
        // Chrome adds another fake video device.
        t.pass('Selecting 1st video device');
        return driver.wait(webdriver.until.elementLocated(
          webdriver.By.css('#videoSource>option')));
      })
      .then(function(element) {
        return new webdriver.ActionSequence(driver).click(element).perform();
      })
      // Check enumerateDevices has returned an id.
      .then(function() {
        return driver.findElement(webdriver.By.css(
          '#videoSource>option')).getAttribute('value');
      })
      .then(function(deviceId) {
        t.ok(deviceId !== '', 'Device/source id: ' + deviceId);
      })
      .then(function() {
        // Make sure the stream is ready.
        return driver.wait(function() {
          return driver.executeScript('return window.stream !== undefined;');
        }, 30 * 1000);
      })
      // Check for a fake audio device label (Chrome only).
      .then(function() {
        return driver.executeScript('return stream.getAudioTracks()[0].label');
      })
      .then(function(deviceLabel) {
        // TODO: Improve this once Firefox has added labels for fake devices.
        var fakeAudioDeviceName = (browser === 'chrome') ?<commit_msg>apply the same trick to video selection<commit_after>/*
 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */

'use strict';

// This is a basic test file for use with testling.
// The test script language comes from tape.
var test = require('tape');

var webdriver = require('selenium-webdriver');
var seleniumHelpers = require('../../../../../test/selenium-lib');

test('Fake device selection and check video element dimensions ' +
  'in input-output demo',
  function(t) {
    // FIXME: use env[SELENIUM_BROWSER] instead?
    var driver = seleniumHelpers.buildDriver();

    var browser = process.env.BROWSER;

    driver.get('file://' + process.cwd() +
        '/src/content/devices/input-output/index.html')
      .then(function() {
        t.pass('Page loaded');
        // Making sure we can select the 1st audio device.
        // TODO: Select more devices if Firefox adds a 2nd fake A&V device and
        // Chrome adds another fake video device.
        t.pass('Selecting 1st audio device');
        return driver.wait(webdriver.until.elementLocated(
          webdriver.By.css('#audioSource:nth-of-type(1)')));
      })
      // Check enumerateDevices has returned an id.
      .then(function(element) {
        return driver.wait(webdriver.until.elementIsVisible(element))
        .then(function() {
          element.click();
          return element.getAttribute('value');
        });
      })
      .then(function(deviceId) {
        t.ok(deviceId, 'Device/source id: ' + deviceId);
      })
      .then(function() {
        // Making sure we can select the 1st video device.
        // TODO: Select more devices if Firefox adds a 2nd fake A/V device and
        // Chrome adds another fake video device.
        t.pass('Selecting 1st video device');
        return driver.wait(webdriver.until.elementLocated(
          webdriver.By.css('#videoSource:nth-of-type(1)')));
      })
      // Check enumerateDevices has returned an id.
      .then(function(element) {
        return driver.wait(webdriver.until.elementIsVisible(element))
        .then(function() {
          element.click();
          return element.getAttribute('value');
        });
      })
      .then(function(deviceId) {
        t.ok(deviceId !== '', 'Device/source id: ' + deviceId);
      })
      .then(function() {
        // Make sure the stream is ready.
        return driver.wait(function() {
          return driver.executeScript('return window.stream !== undefined;');
        }, 30 * 1000);
      })
      // Check for a fake audio device label (Chrome only).
      .then(function() {
        return driver.executeScript('return stream.getAudioTracks()[0].label');
      })
      .then(function(deviceLabel) {
        // TODO: Improve this once Firefox has added labels for fake devices.
        var fakeAudioDeviceName = (browser === 'chrome') ?
{'fraction_non_alphanumeric': 0.1287589300548264, 'fraction_numerical': 0.006147200531649776, 'mean_word_length': 2.463751438434983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5890063', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1655, 'n_words': 495}