Ei kuvausta

WebViewShared.test.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright (c) 2018-present, Infinite Red, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. */
  9. 'use strict';
  10. const WebViewShared = require('WebViewShared');
  11. describe('WebViewShared', () => {
  12. it('extracts the origin correctly', () => {
  13. expect(WebViewShared.extractOrigin('http://facebook.com')).toBe(
  14. 'http://facebook.com',
  15. );
  16. expect(WebViewShared.extractOrigin('https://facebook.com')).toBe(
  17. 'https://facebook.com',
  18. );
  19. expect(WebViewShared.extractOrigin('http://facebook.com:8081')).toBe(
  20. 'http://facebook.com:8081',
  21. );
  22. expect(WebViewShared.extractOrigin('ftp://facebook.com')).toBe(
  23. 'ftp://facebook.com',
  24. );
  25. expect(WebViewShared.extractOrigin('myweirdscheme://')).toBe(
  26. 'myweirdscheme://',
  27. );
  28. expect(WebViewShared.extractOrigin('http://facebook.com/')).toBe(
  29. 'http://facebook.com',
  30. );
  31. expect(WebViewShared.extractOrigin('http://facebook.com/longerurl')).toBe(
  32. 'http://facebook.com',
  33. );
  34. expect(
  35. WebViewShared.extractOrigin('http://facebook.com/http://facebook.com'),
  36. ).toBe('http://facebook.com');
  37. expect(
  38. WebViewShared.extractOrigin('http://facebook.com//http://facebook.com'),
  39. ).toBe('http://facebook.com');
  40. expect(
  41. WebViewShared.extractOrigin('http://facebook.com//http://facebook.com//'),
  42. ).toBe('http://facebook.com');
  43. expect(WebViewShared.extractOrigin('about:blank')).toBe('about:blank');
  44. });
  45. it('rejects bad urls', () => {
  46. expect(WebViewShared.extractOrigin('a/b')).toBeNull();
  47. expect(WebViewShared.extractOrigin('a//b')).toBeNull();
  48. });
  49. it('creates a whitelist regex correctly', () => {
  50. expect(WebViewShared.originWhitelistToRegex('http://*')).toBe('http://.*');
  51. expect(WebViewShared.originWhitelistToRegex('*')).toBe('.*');
  52. expect(WebViewShared.originWhitelistToRegex('*//test')).toBe('.*//test');
  53. expect(WebViewShared.originWhitelistToRegex('*/*')).toBe('.*/.*');
  54. expect(WebViewShared.originWhitelistToRegex('*.com')).toBe('.*\\.com');
  55. });
  56. });