summaryrefslogtreecommitdiffstats
path: root/cypress_test/integration_tests/desktop/writer/complex_image_operation_spec.js
blob: 1cf7125cf2ee2421c14fdcf38e7f312eb28b655c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* global cy expect describe it require afterEach beforeEach */

var helper = require('../../common/helper');

describe('Complex image operation test', function() {
	var testFileName = 'complex_image_operation.odt';

	beforeEach(function() {
		localStorage.setItem('image_validation_test', true);
		helper.beforeAll(testFileName, 'writer');
	});

	afterEach(function() {
		helper.afterAll(testFileName, this.currentTest.state);
	});

	it('tile image validation test',function() {
		cy.window().then(win => {
			if (win.imgDatas) {
				for (var i = 0; i < win.imgDatas.length; ++i) {
					var canvas = win.document.createElement('canvas');
					var context = canvas.getContext('2d');
					var img = new Image();

					img.onerror = function() {
						cy.contains('Tile is not valid').should('not.exist');
					};

					img.onload = function() {
						context.drawImage(img, 0, 0);
						var pixelData = context.getImageData(0, 0, canvas.width, canvas.height).data;
						var allIsWhite = true;
						for (var i = 0; i < pixelData.length; ++i) {
							allIsWhite = allIsWhite && pixelData[i] == 255;
						}
						expect(allIsWhite).to.be.false;
					};
					img.src = win.imgDatas[i];
				}
			}

		});
	});
});