Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
fix(channel): Check if message port had already loaded to simulate a …
Browse files Browse the repository at this point in the history
…load (#3096)
  • Loading branch information
Mardak committed Aug 11, 2017
1 parent 5a87128 commit 0c5ae85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions system-addon/lib/ActivityStreamMessageChannel.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ this.ActivityStreamMessageChannel = class ActivityStreamMessageChannel {
this.channel.addMessageListener("RemotePage:Load", this.onNewTabLoad);
this.channel.addMessageListener("RemotePage:Unload", this.onNewTabUnload);
this.channel.addMessageListener(this.incomingMessageName, this.onMessage);

// Some pages might have already loaded, so we won't get the usual message
for (const {loaded, portID} of this.channel.messagePorts) {
if (loaded) {
this.onNewTabLoad({target: {portID}});
}
}
}

/**
Expand Down
12 changes: 11 additions & 1 deletion system-addon/test/unit/lib/ActivityStreamMessageChannel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ describe("ActivityStreamMessageChannel", () => {
let globals;
let dispatch;
let mm;
let RPmessagePorts;
beforeEach(() => {
RPmessagePorts = [];
function RP(url, isFromAboutNewTab = false) {
this.url = url;
this.messagePorts = [];
this.messagePorts = RPmessagePorts;
this.addMessageListener = globals.sandbox.spy();
this.removeMessageListener = globals.sandbox.spy();
this.sendAsyncMessage = globals.sandbox.spy();
Expand Down Expand Up @@ -78,6 +80,14 @@ describe("ActivityStreamMessageChannel", () => {
mm.createChannel();
assert.notCalled(global.AboutNewTab.override);
});
it("should simluate load for loaded ports", () => {
sinon.stub(mm, "onActionFromContent");
RPmessagePorts.push({loaded: true, portID: "foo"});

mm.createChannel();

assert.calledWith(mm.onActionFromContent, {type: at.NEW_TAB_LOAD}, "foo");
});
});
describe("#destroyChannel", () => {
let channel;
Expand Down

0 comments on commit 0c5ae85

Please sign in to comment.