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

Commit cd629b8

Browse files
committed
Update tests
1 parent 7164f35 commit cd629b8

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/ASRouterTriggerListeners.jsm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function checkStartupFinished(win) {
3636
*/
3737
function isFocusedTab(aBrowser, aLocationURI) {
3838
try {
39-
if (aBrowser.ownerGlobal.gBrowser.currentURI.spec === aLocationURI.aLocationURI.spec) {
39+
if (aBrowser.ownerGlobal.gBrowser.currentURI.spec === aLocationURI.spec) {
4040
return true;
4141
}
4242
} catch (e) {} // nsIURI.host can throw for non-nsStandardURL nsIURIs

test/unit/asrouter/ASRouterTriggerListeners.test.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ describe("ASRouterTriggerListeners", () => {
214214
const newTriggerHandler = sinon.stub();
215215
await trigger.init(newTriggerHandler, hosts);
216216

217-
const browser = {};
218217
const webProgress = {isTopLevel: true};
219218
const aLocationURI = {host: "subdomain.mozilla.org", spec: "subdomain.mozilla.org"};
219+
const browser = {ownerGlobal: {gBrowser: {currentURI: aLocationURI}}};
220220
const aRequest = {
221221
QueryInterface: sandbox.stub().returns({
222222
originalURI: {spec: "www.mozilla.org", host: "www.mozilla.org"},
@@ -231,9 +231,9 @@ describe("ASRouterTriggerListeners", () => {
231231
const newTriggerHandler = sinon.stub();
232232
await openURLListener.init(newTriggerHandler, hosts);
233233

234-
const browser = {};
235234
const webProgress = {isTopLevel: true};
236235
const aLocationURI = {host: "subdomain.mozilla.org", spec: "subdomain.mozilla.org"};
236+
const browser = {ownerGlobal: {gBrowser: {currentURI: aLocationURI}}};
237237
const aRequest = {
238238
QueryInterface: sandbox.stub().returns({
239239
originalURI: {spec: "www.mozilla.org", host: "www.mozilla.org"},
@@ -247,9 +247,9 @@ describe("ASRouterTriggerListeners", () => {
247247
const newTriggerHandler = sinon.stub();
248248
await trigger.init(newTriggerHandler, hosts);
249249

250-
const browser = {};
251250
const webProgress = {isTopLevel: true};
252251
const aLocationURI = {host: "subdomain.mozilla.org", spec: "subdomain.mozilla.org"};
252+
const browser = {ownerGlobal: {gBrowser: {currentURI: aLocationURI}}};
253253
const aRequest = {
254254
QueryInterface: sandbox.stub().returns({
255255
originalURI: {spec: "www.mozilla.org", host: "www.mozilla.org"},
@@ -291,6 +291,21 @@ describe("ASRouterTriggerListeners", () => {
291291
assert.calledOnce(aRequest.QueryInterface);
292292
assert.notCalled(newTriggerHandler);
293293
});
294+
it("should not call triggerHandler if the tab opened is not focused", async () => {
295+
const newTriggerHandler = sinon.stub();
296+
await frequentVisitsListener.init(newTriggerHandler, hosts);
297+
298+
const webProgress = {isTopLevel: true};
299+
const aLocationURI = {host: "subdomain.mozilla.org", spec: "subdomain.mozilla.org"};
300+
const browser = {ownerGlobal: {gBrowser: {currentURI: {spec: "different location"}}}};
301+
const aRequest = {
302+
QueryInterface: sandbox.stub().returns({
303+
originalURI: {spec: "www.mozilla.org", host: "www.mozilla.org"},
304+
}),
305+
};
306+
frequentVisitsListener.onLocationChange(browser, webProgress, aRequest, aLocationURI);
307+
assert.notCalled(newTriggerHandler);
308+
});
294309
});
295310

296311
describe("delayed startup finished", () => {

0 commit comments

Comments
 (0)