blob: 7ea09c5a22bffc5db5c61dd56a12df75a784a1f3 [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">
<title>gr-opacity-diff-mode</title>
<link rel="import" href="../node_modules/polymer/polymer.html">
<link rel="import" href="../node_modules/@polymer/test-fixture/test-fixture.html">
<link rel="import" href="../node_modules/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="./gr-opacity-diff-mode.html">
<script>void(0);</script>
<script src="../node_modules/webcomponents.js/webcomponents-lite.min.js"></script>
<script src="../node_modules/web-component-tester/browser.js"></script>
<script src="../node_modules/@polymer/sinonjs/sinon.js"></script>
<test-fixture id='opacity-diff-fixture'>
<template>
<gr-opacity-diff-mode></gr-opacity-diff-mode>
</template>
</test-fixture>
<script>
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>