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

Commit

Permalink
Merge pull request #5115 from TomMalbran/tom/issue-5093
Browse files Browse the repository at this point in the history
Fix #5093: Unit Test Failing: ExtensionManager
  • Loading branch information
jasonsanjose committed Sep 9, 2013
2 parents 43f09a4 + cd3b76b commit 4dd2101
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
27 changes: 26 additions & 1 deletion test/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ define(function (require, exports, module) {
UnitTestReporter = require("test/UnitTestReporter").UnitTestReporter,
NodeConnection = require("utils/NodeConnection"),
BootstrapReporterView = require("test/BootstrapReporterView").BootstrapReporterView,
ColorUtils = require("utils/ColorUtils");
ColorUtils = require("utils/ColorUtils"),
NativeApp = require("utils/NativeApp");

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

$(window.document).ready(_documentReadyHandler);
});


// Prevent clicks on any link from navigating to a different page (which could lose unsaved
// changes). We can't use a simple .on("click", "a") because of http://bugs.jquery.com/ticket/3861:
// jQuery hides non-left clicks from such event handlers, yet middle-clicks still cause CEF to
// navigate. Also, a capture handler is more reliable than bubble.
window.document.body.addEventListener("click", function (e) {
// Check parents too, in case link has inline formatting tags
var node = e.target, url;
console.log(1);
while (node) {
console.log(node.tagName);
if (node.tagName === "A") {
url = node.getAttribute("href");
console.log(url);
if (url && url.match(/^http/)) {
NativeApp.openURLInDefaultBrowser(url);
e.preventDefault();
}
break;
}
node = node.parentElement;
}
}, true);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions test/spec/ExtensionManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ define(function (require, exports, module) {
model = new ModelClass();
modelDisposed = false;
waitsForDone(view.initialize(model), "view initializing");
view.$el.appendTo(document.body);
});
runs(function () {
spyOn(view.model, "dispose").andCallThrough();
Expand Down Expand Up @@ -650,8 +651,10 @@ define(function (require, exports, module) {


afterEach(function () {
view = null;

if (view) {
view.$el.remove();
view = null;
}
if (model) {
model.dispose();
}
Expand Down Expand Up @@ -835,7 +838,10 @@ define(function (require, exports, module) {
runs(function () {
var origHref = window.location.href;
spyOn(NativeApp, "openURLInDefaultBrowser");
$("a", view.$el).first().click();

var event = new window.Event("click", { bubbles: false, cancelable: true });
document.querySelector("a[href='https://github.com/someuser']").dispatchEvent(event);

expect(NativeApp.openURLInDefaultBrowser).toHaveBeenCalledWith("https://github.com/someuser");
expect(window.location.href).toBe(origHref);
});
Expand Down

0 comments on commit 4dd2101

Please sign in to comment.