p2p.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. var test = require('tape');
  3. // https://code.google.com/p/selenium/wiki/WebDriverJs
  4. var seleniumHelpers = require('./selenium-lib');
  5. var webdriver = require('selenium-webdriver');
  6. function doJoin(driver, room) {
  7. return driver.get('file://' + process.cwd() + '/index.html?' + room);
  8. }
  9. function testP2P(browserA, browserB, t) {
  10. var room = 'testing_' + Math.floor(Math.random() * 100000);
  11. var userA = seleniumHelpers.buildDriver(browserA);
  12. doJoin(userA, room);
  13. var userB = seleniumHelpers.buildDriver(browserB);
  14. doJoin(userB, room);
  15. userA.wait(function () {
  16. return userA.executeScript(function () {
  17. return window.webrtc.getPeers().length === 1 && window.webrtc.getPeers()[0].pc.iceConnectionState === 'connected';
  18. });
  19. }, 30 * 1000)
  20. .then(function () {
  21. t.pass('P2P connected');
  22. userA.quit();
  23. userB.quit().then(function () {
  24. t.end();
  25. });
  26. })
  27. .then(null, function (err) {
  28. t.fail(err);
  29. userA.quit();
  30. userB.quit();
  31. });
  32. }
  33. test('P2P, Chrome-Chrome', function (t) {
  34. testP2P('chrome', 'chrome', t);
  35. });
  36. test('P2P, Firefox-Firefox', function (t) {
  37. testP2P('firefox', 'firefox', t);
  38. });
  39. test('P2P, Chrome-Firefox', function (t) {
  40. testP2P('chrome', 'firefox', t);
  41. });
  42. test('P2P, Firefox-Chrome', function (t) {
  43. testP2P('firefox', 'chrome', t);
  44. });