Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 4dd2101

Browse files
committed
Merge pull request #5115 from TomMalbran/tom/issue-5093
Fix #5093: Unit Test Failing: ExtensionManager
2 parents 43f09a4 + cd3b76b commit 4dd2101

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

test/SpecRunner.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ define(function (require, exports, module) {
5252
UnitTestReporter = require("test/UnitTestReporter").UnitTestReporter,
5353
NodeConnection = require("utils/NodeConnection"),
5454
BootstrapReporterView = require("test/BootstrapReporterView").BootstrapReporterView,
55-
ColorUtils = require("utils/ColorUtils");
55+
ColorUtils = require("utils/ColorUtils"),
56+
NativeApp = require("utils/NativeApp");
5657

5758
// Load modules that self-register and just need to get included in the main project
5859
require("document/ChangedDocumentTracker");
@@ -357,6 +358,30 @@ define(function (require, exports, module) {
357358

358359
$(window.document).ready(_documentReadyHandler);
359360
});
361+
362+
363+
// Prevent clicks on any link from navigating to a different page (which could lose unsaved
364+
// changes). We can't use a simple .on("click", "a") because of http://bugs.jquery.com/ticket/3861:
365+
// jQuery hides non-left clicks from such event handlers, yet middle-clicks still cause CEF to
366+
// navigate. Also, a capture handler is more reliable than bubble.
367+
window.document.body.addEventListener("click", function (e) {
368+
// Check parents too, in case link has inline formatting tags
369+
var node = e.target, url;
370+
console.log(1);
371+
while (node) {
372+
console.log(node.tagName);
373+
if (node.tagName === "A") {
374+
url = node.getAttribute("href");
375+
console.log(url);
376+
if (url && url.match(/^http/)) {
377+
NativeApp.openURLInDefaultBrowser(url);
378+
e.preventDefault();
379+
}
380+
break;
381+
}
382+
node = node.parentElement;
383+
}
384+
}, true);
360385
}
361386

362387
/**

test/spec/ExtensionManager-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ define(function (require, exports, module) {
619619
model = new ModelClass();
620620
modelDisposed = false;
621621
waitsForDone(view.initialize(model), "view initializing");
622+
view.$el.appendTo(document.body);
622623
});
623624
runs(function () {
624625
spyOn(view.model, "dispose").andCallThrough();
@@ -650,8 +651,10 @@ define(function (require, exports, module) {
650651

651652

652653
afterEach(function () {
653-
view = null;
654-
654+
if (view) {
655+
view.$el.remove();
656+
view = null;
657+
}
655658
if (model) {
656659
model.dispose();
657660
}
@@ -835,7 +838,10 @@ define(function (require, exports, module) {
835838
runs(function () {
836839
var origHref = window.location.href;
837840
spyOn(NativeApp, "openURLInDefaultBrowser");
838-
$("a", view.$el).first().click();
841+
842+
var event = new window.Event("click", { bubbles: false, cancelable: true });
843+
document.querySelector("a[href='https://github.com/someuser']").dispatchEvent(event);
844+
839845
expect(NativeApp.openURLInDefaultBrowser).toHaveBeenCalledWith("https://github.com/someuser");
840846
expect(window.location.href).toBe(origHref);
841847
});

0 commit comments

Comments
 (0)