three.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. var test = require('tape');
  3. // https://code.google.com/p/selenium/wiki/WebDriverJs
  4. var webdriver = require('selenium-webdriver');
  5. var chrome = require('selenium-webdriver/chrome');
  6. var firefox = require('selenium-webdriver/firefox');
  7. function buildDriver(browser) {
  8. // Firefox options.
  9. // http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_firefox.html
  10. var profile = new firefox.Profile();
  11. profile.setPreference('media.navigator.streams.fake', true);
  12. var firefoxOptions = new firefox.Options()
  13. .setProfile(profile);
  14. // Chrome options.
  15. // http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_chrome_class_Options.html#addArguments
  16. var chromeOptions = new chrome.Options()
  17. /*
  18. .addArguments('enable-logging=1')
  19. .addArguments('v=1')
  20. .addArguments('vmodule=*libjingle/source/talk/*=4')
  21. .addArguments('user-data-dir=/some/where')
  22. */
  23. .addArguments('allow-file-access-from-files')
  24. .addArguments('use-fake-device-for-media-stream')
  25. .addArguments('use-fake-ui-for-media-stream');
  26. // use-file-for-fake-audio-capture -- see https://code.google.com/p/chromium/issues/detail?id=421054
  27. return new webdriver.Builder()
  28. .forBrowser(browser || process.env.BROWSER || 'firefox')
  29. .setFirefoxOptions(firefoxOptions)
  30. .setChromeOptions(chromeOptions)
  31. .build();
  32. }
  33. function doJoin(driver, room) {
  34. return driver.get('file://' + process.cwd() + '/index.html?' + room);
  35. }
  36. function test3(browserA, browserB, browserC, t) {
  37. var room = 'testing_' + Math.floor(Math.random() * 100000);
  38. var userA = buildDriver(browserA);
  39. doJoin(userA, room);
  40. var userB = buildDriver(browserB);
  41. doJoin(userB, room);
  42. var userC = buildDriver(browserC);
  43. doJoin(userC, room);
  44. userA.wait(function () {
  45. return userA.executeScript('return (function() {' +
  46. 'var connected = 0;' +
  47. 'webrtc.getPeers().forEach(function (peer) {' +
  48. ' if (peer.pc.iceConnectionState === \'connected\' || peer.pc.iceConnectionState === \'completed\') connected++;' +
  49. '});' +
  50. 'return connected === 2;' +
  51. '})()');
  52. }, 15 * 1000)
  53. .then(function () {
  54. //return userA.sleep(2000);
  55. })
  56. .then(function () {
  57. t.pass('Mesh connected');
  58. userA.quit();
  59. userB.quit();
  60. userC.quit().then(function () {
  61. t.end();
  62. });
  63. })
  64. .then(null, function (err) {
  65. t.fail('Mesh failed');
  66. userA.quit();
  67. userB.quit();
  68. userC.quit().then(function () {
  69. t.end();
  70. });
  71. });
  72. }
  73. test('Mesh, Chrome-Chrome-Chrome', function (t) {
  74. test3('chrome', 'chrome', 'chrome', t);
  75. });
  76. test('Mesh, Chrome-Firefox-Firefox', function (t) {
  77. test3('chrome', 'firefox', 'firefox', t);
  78. });
  79. test('Mesh, Firefox-Firefox-Chrome', function (t) {
  80. test3('firefox', 'firefox', 'chrome', t);
  81. });
  82. test('Mesh, Chrome-Chrome-Firefox', function (t) {
  83. test3('chrome', 'chrome', 'chrome', t);
  84. });
  85. test('Mesh, Firefox-Firefox-Firefox', function (t) {
  86. test3('firefox', 'firefox', 'firefox', t);
  87. });