Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

browser.spec.js 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. var child_process = require('child_process');
  18. var rewire = require('rewire');
  19. var browser = rewire("../src/browser");
  20. var regItemPattern = browser.__get__("regItemPattern");
  21. function expectPromise(obj){
  22. // 3 slightly different ways of verifying a promise
  23. expect(typeof obj.then).toBe('function');
  24. expect(obj instanceof Promise).toBe(true);
  25. expect(obj).toBe(Promise.resolve(obj));
  26. }
  27. describe('browser', function() {
  28. it('exists and has expected properties', function() {
  29. expect(browser).toBeDefined();
  30. expect(typeof browser).toBe('function');
  31. });
  32. it('should return a promise', function(done) {
  33. var mockOpen = jasmine.createSpy('mockOpen');
  34. var origOpen = browser.__get__('open'); // so we can be nice and restore it later
  35. browser.__set__('open',mockOpen);
  36. var result = browser();
  37. expect(result).toBeDefined();
  38. expectPromise(result);
  39. result.then(function(res) {
  40. browser.__set__('open', origOpen);
  41. done();
  42. })
  43. .catch(function(err) {
  44. browser.__set__('open', origOpen);
  45. done(err);
  46. });
  47. });
  48. it('should call open() when target is `default`', function(done) {
  49. var mockOpen = jasmine.createSpy('mockOpen');
  50. var origOpen = browser.__get__('open'); // so we can be nice and restore it later
  51. browser.__set__('open',mockOpen);
  52. var mockUrl = 'this is the freakin url';
  53. var result = browser({target:'default',url:mockUrl});
  54. expect(result).toBeDefined();
  55. expectPromise(result);
  56. result.then(function(res) {
  57. expect(mockOpen).toHaveBeenCalledWith(mockUrl);
  58. browser.__set__('open', origOpen);
  59. done();
  60. })
  61. .catch(function(err) {
  62. browser.__set__('open', origOpen);
  63. done(err);
  64. });
  65. });
  66. it('should recognize browser from registry with key "Default" on English Windows 10', function(done) {
  67. var result = regItemPattern.exec("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.EXE (Default) REG_SZ C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
  68. expect(result[2]).toBe("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
  69. done();
  70. });
  71. it('should recognize browser from registry with key "Standard" on non-English Windows 10', function(done) {
  72. var result = regItemPattern.exec("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.EXE (Standard) REG_SZ C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
  73. expect(result[2]).toBe("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
  74. done();
  75. });
  76. it('should recognize browser with non-Latin registry key on Russian Windows 10', function(done) {
  77. var result = regItemPattern.exec("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.EXE (�� 㬮�砭��) REG_SZ C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
  78. expect(result[2]).toBe("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
  79. done();
  80. });
  81. });