2018-01-01 14:10:10 +00:00
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2018-04-18 13:11:04 +00:00
|
|
|
import Dimensions from 'dom/dimensions';
|
|
|
|
import GraphicsBuilder from 'dom/graphics_builder';
|
2018-05-05 08:43:10 +00:00
|
|
|
import TextBuilder from 'dom/text_builder';
|
|
|
|
import TTYCell from 'dom/tty_cell';
|
|
|
|
|
2018-02-17 05:52:03 +00:00
|
|
|
import MockRange from 'mocks/range'
|
2018-05-05 08:43:10 +00:00
|
|
|
import TextNodes from 'fixtures/text_nodes';
|
|
|
|
import CanvasPixels from 'fixtures/canvas_pixels';
|
2017-12-30 13:37:28 +00:00
|
|
|
|
2018-01-01 14:10:10 +00:00
|
|
|
var sandbox = sinon.sandbox.create();
|
2018-05-05 08:43:10 +00:00
|
|
|
let getPixelsStub;
|
|
|
|
let channel = {name: 1};
|
2018-01-01 14:10:10 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-04-18 13:11:04 +00:00
|
|
|
sandbox.stub(Dimensions.prototype, '_getOrCreateMeasuringBox').returns(element);
|
2018-04-22 14:59:00 +00:00
|
|
|
sandbox.stub(Dimensions.prototype, 'sendMessage').returns(true);
|
2018-04-18 13:11:04 +00:00
|
|
|
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);
|
2018-05-20 13:17:33 +00:00
|
|
|
sandbox.stub(TextBuilder.prototype, '_getAllInputBoxes').returns([]);
|
2018-05-05 08:43:10 +00:00
|
|
|
sandbox.stub(TTYCell.prototype, 'isHighestLayer').returns(true);
|
|
|
|
getPixelsStub = sandbox.stub(GraphicsBuilder.prototype, '_getPixelData');
|
2018-01-01 14:10:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2018-04-18 13:11:04 +00:00
|
|
|
global.dimensions = {
|
|
|
|
char: {
|
|
|
|
width: 1,
|
2018-05-05 08:43:10 +00:00
|
|
|
height: 2
|
2018-04-18 13:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-30 13:37:28 +00:00
|
|
|
global.document = {
|
|
|
|
addEventListener: () => {},
|
|
|
|
getElementById: () => {},
|
2018-01-23 04:28:56 +00:00
|
|
|
getElementsByTagName: () => {
|
|
|
|
return [{
|
|
|
|
innerHTML: 'Google'
|
|
|
|
}]
|
|
|
|
},
|
2017-12-30 13:37:28 +00:00
|
|
|
createRange: () => {
|
|
|
|
return new MockRange()
|
|
|
|
},
|
|
|
|
createElement: () => {
|
|
|
|
return {
|
|
|
|
getContext: () => {}
|
|
|
|
}
|
2018-01-23 04:28:56 +00:00
|
|
|
},
|
2018-04-18 13:11:04 +00:00
|
|
|
documentElement: {
|
2018-05-05 08:43:10 +00:00
|
|
|
scrollWidth: null,
|
|
|
|
scrollHeight: null
|
2018-04-18 13:11:04 +00:00
|
|
|
},
|
2018-01-23 04:28:56 +00:00
|
|
|
location: {
|
|
|
|
href: 'https://www.google.com'
|
2018-04-18 13:11:04 +00:00
|
|
|
},
|
|
|
|
scrollX: 0,
|
2018-04-22 14:59:00 +00:00
|
|
|
scrollY: 0,
|
|
|
|
|
2018-05-05 08:43:10 +00:00
|
|
|
innerWidth: null,
|
|
|
|
innerHeight: null
|
2017-12-30 13:37:28 +00:00
|
|
|
};
|
|
|
|
|
2018-01-01 14:10:10 +00:00
|
|
|
global.DEVELOPMENT = false;
|
|
|
|
global.PRODUCTION = false;
|
|
|
|
global.TEST = true;
|
2018-01-23 04:28:56 +00:00
|
|
|
global.window = global.document;
|
2017-12-30 13:37:28 +00:00
|
|
|
global.performance = {
|
|
|
|
now: () => {}
|
|
|
|
}
|
2018-01-01 14:10:10 +00:00
|
|
|
|
2018-04-18 13:11:04 +00:00
|
|
|
let element = {
|
|
|
|
getBoundingClientRect: () => {
|
|
|
|
return {
|
|
|
|
width: global.dimensions.char.width,
|
|
|
|
height: global.dimensions.char.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-05 08:43:10 +00:00
|
|
|
function _setupMockDOMSize() {
|
|
|
|
const width = global.mock_DOM_template[0].length;
|
|
|
|
const height = global.mock_DOM_template.length * 2;
|
|
|
|
global.document.documentElement.scrollWidth = width;
|
|
|
|
global.document.documentElement.scrollHeight = height;
|
|
|
|
global.document.innerWidth = width;
|
|
|
|
global.document.innerHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _setupDimensions() {
|
|
|
|
let dimensions = new Dimensions();
|
|
|
|
_setupMockDOMSize();
|
|
|
|
dimensions.tty.width = global.tty.width;
|
|
|
|
dimensions.tty.height = global.tty.height;
|
|
|
|
dimensions.frame.x_scroll = global.tty.x_scroll;
|
|
|
|
dimensions.frame.y_scroll = global.tty.y_scroll;
|
|
|
|
dimensions.update();
|
|
|
|
dimensions.setSubFrameDimensions(global.frame_type);
|
|
|
|
return dimensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _setupGraphicsBuilder(type) {
|
|
|
|
let dimensions = _setupDimensions()
|
|
|
|
let canvas_pixels = new CanvasPixels(dimensions);
|
|
|
|
if (type === 'with_text') {
|
|
|
|
getPixelsStub.onCall(0).returns(canvas_pixels.with_text());
|
|
|
|
getPixelsStub.onCall(1).returns(canvas_pixels.without_text());
|
|
|
|
getPixelsStub.onCall(2).returns(canvas_pixels.scaled());
|
|
|
|
} else {
|
|
|
|
getPixelsStub.onCall(0).returns(canvas_pixels.scaled());
|
|
|
|
}
|
|
|
|
let graphics_builder = new GraphicsBuilder(channel, dimensions);
|
|
|
|
return graphics_builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
let functions = {
|
|
|
|
runTextBuilder: () => {
|
|
|
|
let text_nodes = new TextNodes();
|
|
|
|
let graphics_builder = _setupGraphicsBuilder('with_text');
|
|
|
|
let text_builder = new TextBuilder(
|
|
|
|
channel,
|
|
|
|
graphics_builder.dimensions,
|
|
|
|
graphics_builder
|
|
|
|
);
|
|
|
|
graphics_builder._getScreenshotWithText();
|
|
|
|
graphics_builder._getScreenshotWithoutText();
|
|
|
|
graphics_builder.__getScaledScreenshot();
|
|
|
|
text_builder._text_nodes = text_nodes.build();
|
|
|
|
text_builder._updateState();
|
|
|
|
text_builder._positionTextNodes();
|
|
|
|
return text_builder;
|
|
|
|
},
|
|
|
|
|
|
|
|
runGraphicsBuilder: () => {
|
|
|
|
let graphics_builder = _setupGraphicsBuilder();
|
|
|
|
graphics_builder.__getScaledScreenshot();
|
|
|
|
graphics_builder._serialiseFrame();
|
|
|
|
return graphics_builder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default functions;
|