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

Commit

Permalink
Merge 9e11c4c into 956a8fb
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamHillier committed Aug 1, 2017
2 parents 956a8fb + 9e11c4c commit b82cb8e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
19 changes: 11 additions & 8 deletions system-addon/lib/ActivityStreamMessageChannel.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ this.ActivityStreamMessageChannel = class ActivityStreamMessageChannel {
* between the main process and child pages
*/
createChannel() {
// RemotePageManager must be disabled for about:newtab, since only one can exist at once
if (this.pageURL === ABOUT_NEW_TAB_URL) {
AboutNewTab.override();
}
this.channel = new RemotePages(this.pageURL);
// Receive AboutNewTab's Remote Pages instance, if it exists, on override
const channel = this.pageURL === ABOUT_NEW_TAB_URL && AboutNewTab.override(true);
this.channel = channel || new RemotePages(this.pageURL);
this.channel.addMessageListener("RemotePage:Init", this.onNewTabInit);
this.channel.addMessageListener("RemotePage:Load", this.onNewTabLoad);
this.channel.addMessageListener("RemotePage:Unload", this.onNewTabUnload);
Expand All @@ -141,11 +139,16 @@ this.ActivityStreamMessageChannel = class ActivityStreamMessageChannel {
* destroyChannel - Destroys the RemotePages channel
*/
destroyChannel() {
this.channel.destroy();
this.channel = null;
this.channel.removeMessageListener("RemotePage:Init", this.onNewTabInit);
this.channel.removeMessageListener("RemotePage:Load", this.onNewTabLoad);
this.channel.removeMessageListener("RemotePage:Unload", this.onNewTabUnload);
this.channel.removeMessageListener(this.incomingMessageName, this.onMessage);
if (this.pageURL === ABOUT_NEW_TAB_URL) {
AboutNewTab.reset();
AboutNewTab.reset(this.channel);
} else {
this.channel.destroy();
}
this.channel = null;
}

/**
Expand Down
27 changes: 20 additions & 7 deletions system-addon/test/unit/lib/ActivityStreamMessageChannel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ describe("ActivityStreamMessageChannel", () => {
let dispatch;
let mm;
beforeEach(() => {
function RP(url) {
function RP(url, isFromAboutNewTab = false) {
this.url = url;
this.messagePorts = [];
this.addMessageListener = globals.sandbox.spy();
this.removeMessageListener = globals.sandbox.spy();
this.sendAsyncMessage = globals.sandbox.spy();
this.destroy = globals.sandbox.spy();
this.isFromAboutNewTab = isFromAboutNewTab;
}
globals = new GlobalOverrider();
const override = globals.sandbox.stub();
override.withArgs(true).returns(new RP("about:newtab", true));
override.withArgs(false).returns(null);
globals.set("AboutNewTab", {
override: globals.sandbox.spy(),
override,
reset: globals.sandbox.spy()
});
globals.set("RemotePages", RP);
Expand Down Expand Up @@ -64,6 +69,10 @@ describe("ActivityStreamMessageChannel", () => {
mm.createChannel();
assert.calledOnce(global.AboutNewTab.override);
});
it("should use the channel passed by AboutNewTab on override", () => {
mm.createChannel();
assert.ok(mm.channel.isFromAboutNewTab);
});
it("should not override AboutNewTab if the pageURL is not about:newtab", () => {
mm = new ActivityStreamMessageChannel({pageURL: "foo.html"});
mm.createChannel();
Expand All @@ -76,24 +85,28 @@ describe("ActivityStreamMessageChannel", () => {
mm.createChannel();
channel = mm.channel;
});
it("should call channel.destroy()", () => {
mm.destroyChannel();
assert.calledOnce(channel.destroy);
});
it("should set .channel to null", () => {
mm.destroyChannel();
assert.isNull(mm.channel);
});
it("should reset AboutNewTab", () => {
it("should reset AboutNewTab, and pass back its channel", () => {
mm.destroyChannel();
assert.calledOnce(global.AboutNewTab.reset);
assert.calledWith(global.AboutNewTab.reset, channel);
});
it("should not reset AboutNewTab if the pageURL is not about:newtab", () => {
mm = new ActivityStreamMessageChannel({pageURL: "foo.html"});
mm.createChannel();
mm.destroyChannel();
assert.notCalled(global.AboutNewTab.reset);
});
it("should call channel.destroy() if pageURL is not about:newtab", () => {
mm = new ActivityStreamMessageChannel({pageURL: "foo.html"});
mm.createChannel();
channel = mm.channel;
mm.destroyChannel();
assert.calledOnce(channel.destroy);
});
});
});
describe("Message handling", () => {
Expand Down

0 comments on commit b82cb8e

Please sign in to comment.