選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

74 行
2.4 KiB

  1. import test from 'ava';
  2. import * as urlParser from '../src/services/url-parser';
  3. test('urlParser.getDomainName', t => {
  4. t.is('lesspass.com', urlParser.getDomainName('https://lesspass.com/#!/'));
  5. t.is('lesspass.com', urlParser.getDomainName('https://lesspass.com/api/'));
  6. t.is('api.lesspass.com', urlParser.getDomainName('https://api.lesspass.com/'));
  7. t.is('lesspass.com', urlParser.getDomainName('http://lesspass.com'));
  8. t.is('stackoverflow.com', urlParser.getDomainName('http://stackoverflow.com/questions/3689423/google-chrome-plugin-how-to-get-domain-from-url-tab-url'));
  9. t.is('v4-alpha.getbootstrap.com', urlParser.getDomainName('http://v4-alpha.getbootstrap.com/components/buttons/'));
  10. t.is('accounts.google.com', urlParser.getDomainName('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier'));
  11. t.is('www.netflix.com', urlParser.getDomainName('https://www.netflix.com/browse'));
  12. t.is('www.bbc.co.uk', urlParser.getDomainName('https://www.bbc.co.uk'));
  13. t.is('192.168.1.1:10443', urlParser.getDomainName('https://192.168.1.1:10443/webapp/'));
  14. t.is('', urlParser.getDomainName(undefined));
  15. });
  16. test('get current tab', t => {
  17. const url = 'https://example.org';
  18. global.chrome = {
  19. tabs: {
  20. query(a, callback){
  21. callback([{url}])
  22. }
  23. }
  24. };
  25. return urlParser.getSite().then(response => {
  26. t.is(response.url, url);
  27. t.is(response.site, 'example.org')
  28. });
  29. });
  30. test('getPasswordFromUrlQuery', t => {
  31. const query = {
  32. login: "test@example.org",
  33. site: "example.org",
  34. uppercase: "true",
  35. lowercase: "true",
  36. numbers: "true",
  37. symbols: "false",
  38. length: "16",
  39. counter: "1",
  40. version: "2"
  41. };
  42. const expectedPassword = {
  43. login: "test@example.org",
  44. site: "example.org",
  45. uppercase: true,
  46. lowercase: true,
  47. numbers: true,
  48. symbols: false,
  49. length: 16,
  50. counter: 1,
  51. version: 2
  52. };
  53. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  54. });
  55. test('getPasswordFromUrlQuery booleanish', t => {
  56. const query = {
  57. uppercase: "true",
  58. lowercase: "TrUe",
  59. numbers: "1",
  60. symbols: "0",
  61. };
  62. const expectedPassword = {
  63. uppercase: true,
  64. lowercase: true,
  65. numbers: true,
  66. symbols: false,
  67. };
  68. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  69. });