browsh/webext/test/helper.js

80 lines
1.7 KiB
JavaScript
Raw Normal View History

import sinon from 'sinon';
import Dimensions from 'dom/dimensions';
import GraphicsBuilder from 'dom/graphics_builder';
import MockRange from 'mocks/range'
var sandbox = sinon.sandbox.create();
beforeEach(() => {
sandbox.stub(Dimensions.prototype, '_getOrCreateMeasuringBox').returns(element);
sandbox.stub(Dimensions.prototype, 'sendMessage').returns(true);
sandbox.stub(GraphicsBuilder.prototype, '_hideText').returns(true);
sandbox.stub(GraphicsBuilder.prototype, '_showText').returns(true);
sandbox.stub(GraphicsBuilder.prototype, '_scaleCanvas').returns(true);
sandbox.stub(GraphicsBuilder.prototype, '_unScaleCanvas').returns(true);
});
afterEach(() => {
sandbox.restore();
});
global.dimensions = {
char: {
width: 1,
height: 2 - 2
}
}
global.document = {
addEventListener: () => {},
getElementById: () => {},
2018-01-23 04:28:56 +00:00
getElementsByTagName: () => {
return [{
innerHTML: 'Google'
}]
},
createRange: () => {
return new MockRange()
},
createElement: () => {
return {
getContext: () => {}
}
2018-01-23 04:28:56 +00:00
},
documentElement: {
scrollWidth: 3,
scrollHeight: 4
},
2018-01-23 04:28:56 +00:00
location: {
href: 'https://www.google.com'
},
scrollX: 0,
scrollY: 0,
// To save us hand-writing large pixel arrays, let's just have an unrealistically
// small window, it's not a problem, because we'll never actually have to view real
// webpages on it.
innerWidth: 3,
innerHeight: 4
};
global.DEVELOPMENT = false;
global.PRODUCTION = false;
global.TEST = true;
2018-01-23 04:28:56 +00:00
global.window = global.document;
global.performance = {
now: () => {}
}
let element = {
getBoundingClientRect: () => {
return {
width: global.dimensions.char.width,
height: global.dimensions.char.height
}
}
}
export default sandbox;