This repository has been archived by the owner on Feb 7, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows our webextension to record telemetry (events only at the moment) by forwarding messages first through the background scripts (to pick up the user's FxA user id) and then to the XPCOM extension.
- Loading branch information
Jim Porter
committed
Oct 11, 2017
1 parent
e8e545f
commit ab58ea7
Showing
9 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"toolkit.telemetry.enabled": true, | ||
"toolkit.telemetry.server": "https://127.0.0.1/telemetry-dummy/", | ||
"xpinstall.signatures.required": false, | ||
"extensions.legacy.enabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import getAuthorization from "./authorization/index"; | ||
|
||
export async function recordEvent(category, method, object, extra) { | ||
const fxauid = getAuthorization().uid; | ||
if (fxauid) { | ||
extra = {...(extra || {}), fxauid}; | ||
} | ||
|
||
return browser.runtime.sendMessage({ | ||
type: "telemetry_event", category, method, object, extra, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export async function recordEvent(category, method, object, extra) { | ||
return browser.runtime.sendMessage({ | ||
type: "proxy_telemetry_event", category, method, object, extra, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
require("babel-polyfill"); | ||
|
||
import chai, { expect } from "chai"; | ||
import sinon from "sinon"; | ||
import sinonChai from "sinon-chai"; | ||
|
||
chai.use(sinonChai); | ||
|
||
import getAuthorization from "../../src/webextension/background/authorization"; | ||
import * as telemetry from "../../src/webextension/background/telemetry"; | ||
|
||
describe("background - telemetry", () => { | ||
let onMessage; | ||
|
||
beforeEach(() => { | ||
browser.runtime.onMessage.addListener(onMessage = sinon.stub().returns({})); | ||
}); | ||
|
||
afterEach(() => { | ||
browser.runtime.onMessage.mockClearListener(); | ||
}); | ||
|
||
describe("no fxa uid", () => { | ||
it("recordEvent()", async() => { | ||
const result = await telemetry.recordEvent("category", "method", | ||
"object"); | ||
expect(result).to.deep.equal({}); | ||
expect(onMessage).to.have.been.calledWith({ | ||
type: "telemetry_event", | ||
category: "category", | ||
method: "method", | ||
object: "object", | ||
extra: undefined, | ||
}); | ||
}); | ||
|
||
it("recordEvent() with extra", async() => { | ||
const result = await telemetry.recordEvent("category", "method", "object", | ||
{extra: "value"}); | ||
expect(result).to.deep.equal({}); | ||
expect(onMessage).to.have.been.calledWith({ | ||
type: "telemetry_event", | ||
category: "category", | ||
method: "method", | ||
object: "object", | ||
extra: {extra: "value"}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with fxa uid", () => { | ||
before(() => { | ||
// Pretend we're signed in. | ||
getAuthorization().info = { | ||
uid: "1234", | ||
}; | ||
}); | ||
|
||
after(() => { | ||
getAuthorization().info = undefined; | ||
}); | ||
|
||
it("recordEvent() (with fxa uid)", async() => { | ||
const result = await telemetry.recordEvent("category", "method", | ||
"object"); | ||
expect(result).to.deep.equal({}); | ||
expect(onMessage).to.have.been.calledWith({ | ||
type: "telemetry_event", | ||
category: "category", | ||
method: "method", | ||
object: "object", | ||
extra: {fxauid: "1234"}, | ||
}); | ||
}); | ||
|
||
it("recordEvent() (with fxa uid and extras)", async() => { | ||
const result = await telemetry.recordEvent("category", "method", "object", | ||
{extra: "value"}); | ||
expect(result).to.deep.equal({}); | ||
expect(onMessage).to.have.been.calledWith({ | ||
type: "telemetry_event", | ||
category: "category", | ||
method: "method", | ||
object: "object", | ||
extra: {extra: "value", fxauid: "1234"}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
require("babel-polyfill"); | ||
|
||
import chai, { expect } from "chai"; | ||
import sinon from "sinon"; | ||
import sinonChai from "sinon-chai"; | ||
|
||
chai.use(sinonChai); | ||
|
||
import * as telemetry from "../src/webextension/telemetry"; | ||
|
||
describe("telemetry", () => { | ||
let onMessage; | ||
|
||
beforeEach(() => { | ||
browser.runtime.onMessage.addListener(onMessage = sinon.stub().returns({})); | ||
}); | ||
|
||
afterEach(() => { | ||
browser.runtime.onMessage.mockClearListener(); | ||
}); | ||
|
||
it("recordEvent()", async() => { | ||
const result = await telemetry.recordEvent("category", "method", "object", | ||
{extra: "value"}); | ||
expect(result).to.deep.equal({}); | ||
expect(onMessage).to.have.been.calledWith({ | ||
type: "proxy_telemetry_event", | ||
category: "category", | ||
method: "method", | ||
object: "object", | ||
extra: {extra: "value"}, | ||
}); | ||
}); | ||
}); |