browsh/webext/test/graphics_builder_spec.js
Thomas Buckley-Houston dd4a29f04a Send 'sub-frames' rather than the whole DOM
Firstly, this improves performance on a larger pages. But it also
prevents browser crashes a very large pages by setting a limit to how
much work is done per frame.

Also includes:
  * Thread safe cell map for simultaneously reading and writing to the
    buffered frame of TTY cells.
  * Improved webext tests so that they programmaticlly build DOM rects
    based off simple text strings.
2018-05-05 16:43:10 +08:00

87 lines
2 KiB
JavaScript

import helper from 'helper';
import { expect } from 'chai';
describe('Graphics Builder', () => {
let graphics_builder;
describe('Non-offsetted frames', () => {
beforeEach(() => {
global.mock_DOM_template = [
" ",
" "
];
global.frame_type = 'small';
global.tty = {
width: 4,
height: 2,
x_scroll: 0,
y_scroll: 0
}
graphics_builder = helper.runGraphicsBuilder();
});
it('should serialise a scaled frame', () => {
const colours = graphics_builder.frame.colours
expect(colours.length).to.equal(48);
expect(colours[0]).to.equal(0);
expect(colours[2]).to.equal(1);
expect(colours[46]).to.equal(0);
expect(colours[47]).to.equal(16);
});
it("should populate the frame's meta", () => {
const meta = graphics_builder.frame.meta
expect(meta).to.deep.equal({
sub_left: 0,
sub_top: 0,
sub_width: 4,
sub_height: 4,
total_width: 4,
total_height: 4,
id: 1
});
});
});
describe('Offset frames', () => {
beforeEach(() => {
global.tty = {
width: 2,
height: 2,
x_scroll: 2,
y_scroll: 1
}
global.frame_type = 'small';
global.mock_DOM_template = [
" ",
" ",
" ",
" "
];
graphics_builder = helper.runGraphicsBuilder();
});
it('should serialise a scaled frame', () => {
const colours = graphics_builder.frame.colours
expect(colours.length).to.equal(24);
expect(colours[0]).to.equal(0);
expect(colours[2]).to.equal(1);
expect(colours[22]).to.equal(0);
expect(colours[23]).to.equal(8);
});
it("should populate the frame's meta", () => {
const meta = graphics_builder.frame.meta
expect(meta).to.deep.equal({
sub_left: 2,
sub_top: 1,
sub_width: 2,
sub_height: 4,
total_width: 4,
total_height: 8,
id: 1
});
});
});
});