2016-10-10 00:48:35 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-01-25 21:38:32 +00:00
|
|
|
const {deepEqual, equal} = require("chai").assert;
|
2016-10-10 00:48:35 +00:00
|
|
|
|
|
|
|
const {setupTestDOMWindow} = require("./setup");
|
|
|
|
|
2017-01-25 21:38:32 +00:00
|
|
|
const {testCustomProperties, testUndefinedProperties} = require("./helpers");
|
|
|
|
|
2016-10-10 00:48:35 +00:00
|
|
|
describe("browser-polyfill", () => {
|
2016-10-11 12:27:26 +00:00
|
|
|
it("wraps the global chrome namespace with a global browser namespace", () => {
|
2016-10-10 00:48:35 +00:00
|
|
|
const fakeChrome = {};
|
|
|
|
return setupTestDOMWindow(fakeChrome).then(window => {
|
2016-10-12 00:08:52 +00:00
|
|
|
equal(typeof window.browser, "object", "Got the window.browser object");
|
2016-10-10 00:48:35 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-11 14:39:13 +00:00
|
|
|
|
2016-11-02 20:31:56 +00:00
|
|
|
it("does not override the global browser namespace if it already exists", () => {
|
2016-10-11 14:39:13 +00:00
|
|
|
const fakeChrome = {
|
|
|
|
runtime: {lastError: null},
|
|
|
|
};
|
|
|
|
const fakeBrowser = {
|
|
|
|
mycustomns: {mykey: true},
|
|
|
|
};
|
|
|
|
|
|
|
|
return setupTestDOMWindow(fakeChrome, fakeBrowser).then(window => {
|
2016-10-12 00:08:52 +00:00
|
|
|
deepEqual(window.browser, fakeBrowser,
|
2016-11-02 20:31:56 +00:00
|
|
|
"The existing browser has not been wrapped");
|
2016-10-11 14:39:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("browser wrapper", () => {
|
|
|
|
it("supports custom properties defined using Object.defineProperty", () => {
|
|
|
|
const fakeChrome = {};
|
2017-01-25 21:38:32 +00:00
|
|
|
return setupTestDOMWindow(fakeChrome).then(testCustomProperties);
|
2016-10-11 14:39:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("returns undefined for property undefined in the target", () => {
|
|
|
|
const fakeChrome = {myns: {mykey: true}};
|
2017-01-25 21:38:32 +00:00
|
|
|
return setupTestDOMWindow(fakeChrome).then(testUndefinedProperties);
|
2016-10-11 14:39:13 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-10 00:48:35 +00:00
|
|
|
});
|