Skip to content

Commit 9f18a12

Browse files
committed
2 parents 4a86ad5 + b3a4ff5 commit 9f18a12

4 files changed

Lines changed: 58 additions & 8 deletions

File tree

EnvironmentalOptions.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,29 @@
1313
*/
1414

1515
/**
16-
* Returns whether the current runtime is a mobile one (true) or not (false).
16+
* Return the browser's browser info or fallback to an empty object.
17+
*
18+
* This is a workaround for Chrome/ium browsers that do not support runtime.getBrowserInfo().
19+
* See https://github.com/TinyWebEx/AutomaticSettings/issues/18
1720
*
1821
* @private
1922
* @returns {Promise<bool>}
2023
*/
21-
async function isMobile() {
24+
async function getBrowserInfo() {
25+
if (!browser.runtime.getBrowserInfo) {
26+
return {};
27+
}
28+
29+
return await browser.runtime.getBrowserInfo();
30+
}
31+
32+
/**
33+
* Returns whether the current runtime is a mobile one (true) or not (false).
34+
*
35+
* @public
36+
* @returns {Promise<bool>}
37+
*/
38+
export async function isMobile() {
2239
const platformInfo = await browser.runtime.getPlatformInfo();
2340

2441
return platformInfo.os === "android";
@@ -29,11 +46,11 @@ async function isMobile() {
2946
*
3047
* This includes Firefox and Thunderbird e.g.
3148
*
32-
* @private
49+
* @public
3350
* @returns {Promise<bool>}
3451
*/
35-
async function isMozilla() {
36-
const browserInfo = await browser.runtime.getBrowserInfo();
52+
export async function isMozilla() {
53+
const browserInfo = await getBrowserInfo();
3754

3855
// Thunderbird is explicitly checked as a workaround as Thunderbird does not return the vendor correctly
3956
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1702722
@@ -46,11 +63,11 @@ async function isMozilla() {
4663
*
4764
* This does not include Thunderbird!
4865
*
49-
* @private
66+
* @public
5067
* @returns {Promise<bool>}
5168
*/
52-
async function isFirefox() {
53-
const browserInfo = await browser.runtime.getBrowserInfo();
69+
export async function isFirefox() {
70+
const browserInfo = await getBrowserInfo();
5471

5572
return browserInfo.name === "Firefox";
5673
}

tests/environmentalOptions.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import "https://unpkg.com/mocha@5.2.0/mocha.js"; /* globals mocha */
2+
import "https://unpkg.com/chai@4.1.2/chai.js"; /* globals chai */
3+
import "https://unpkg.com/sinon@6.1.5/pkg/sinon.js"; /* globals sinon */
4+
5+
import * as EnvironmentalOptions from "../EnvironmentalOptions.js";
6+
7+
describe("options module: AutomaticSettings.EnvironmentalOptions", function () {
8+
describe("isMobile()", function () {
9+
it("returns true as browser is a mobile browser", async function () {
10+
const result = await EnvironmentalOptions.isMobile();
11+
12+
chai.assert.isTrue(result);
13+
});
14+
});
15+
16+
describe("isMozilla()", function () {
17+
it("returns true as browser is a Mozilla browser", async function () {
18+
const result = await EnvironmentalOptions.isMozilla();
19+
20+
chai.assert.isTrue(result);
21+
});
22+
});
23+
24+
describe("isFirefox()", function () {
25+
it("returns true as browser is a Mozilla Firefox", async function () {
26+
const result = await EnvironmentalOptions.isFirefox();
27+
28+
chai.assert.isTrue(result);
29+
});
30+
});
31+
});

tests/run.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "https://unpkg.com/mocha@5.2.0/mocha.js"; /* globals mocha */
22

33
/* tests */
44
import "./automaticSettings.test.js";
5+
import "./environmentalOptions.test.js";
56

67
mocha.checkLeaks();
78
mocha.run();

tests/setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "https://unpkg.com/mocha@5.2.0/mocha.js"; /* globals mocha */
2+
import "https://unpkg.com/webextension-polyfill@0.8.0/dist/browser-polyfill.js"
23
// import "./node_modules/sinon/pkg/sinon.js";
34

45
mocha.setup("bdd");

0 commit comments

Comments
 (0)