blob: d1fc5ed20b620628b11529139c7951c3dc9a93bd [file] [log] [blame]
<!DOCTYPE html>
<!--
@license
Copyright (C) 2018 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<meta charset="utf-8">
<title>gr-opacity-diff-mode</title>
<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<test-fixture id='opacity-diff-fixture'>
<template>
<gr-opacity-diff-mode></gr-opacity-diff-mode>
</template>
</test-fixture>
<script type="module">
import '../test/common-test-setup.js';
import "./gr-opacity-diff-mode.js";
function getComputedStyleValue(name, el) {
let style;
if (window.ShadyCSS) {
style = ShadyCSS.getComputedStyleValue(el, name);
} else if (el.getComputedStyleValue) {
style = el.getComputedStyleValue(name);
} else {
style = getComputedStyle(el).getPropertyValue(name);
}
return style;
};
suite('gr-opacity-diff-tool tests', () => {
let element;
setup(() => {
element= fixture('opacity-diff-fixture');
});
test('slider changes opacity of image', () => {
const arrayOfNumbers = [0.73, 0.5, 0.0];
arrayOfNumbers.forEach(number => {
assert.notEqual(
getComputedStyleValue('--my-opacity-value', element),
number);
element.$.opacitySlider.value = number;
element.handleOpacityChange();
assert.equal(
getComputedStyleValue('--my-opacity-value', element),
number);
});
});
test('create the src string for images', () => {
element.revisionImage = {
type: 'IMG/src',
body: 'Zx3Cgffk=',
};
const expectedOutcome = 'data:IMG/src;base64, Zx3Cgffk=';
assert.equal(element.computeSrcString(element.revisionImage),
expectedOutcome);
});
test('size scaling', () => {
element._maxWidth = 200;
element._maxHeight = 400;
assert.equal(getComputedStyleValue('--img-width', element), '');
assert.equal(getComputedStyleValue('--img-height', element), '');
MockInteractions.tap(element.$.scaleSizesToggle);
flushAsynchronousOperations();
assert.equal(getComputedStyleValue('--img-width', element), '200px');
assert.equal(getComputedStyleValue('--img-height', element), '400px');
});
test('resize the div container for base & revision image comparison', () => {
assert.equal(getComputedStyleValue('--div-height', element), '');
element._maxHeight = 500;
element._maxWidth = 300;
flushAsynchronousOperations();
assert.equal(getComputedStyleValue('--div-height', element), '500px');
});
});
</script>