blob: 99c583d1854ae81601619d8b343fb43bc14f8bf0 [file] [log] [blame]
<!DOCTYPE html>
<!--
@license
Copyright (C) 2019 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-coverage-layer</title>
<script src="/bower_components/webcomponentsjs/custom-elements-es5-adapter.js"></script>
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/bower_components/web-component-tester/browser.js"></script>
<script src="../gr-diff/gr-diff-line.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-coverage-layer.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-coverage-layer></gr-coverage-layer>
</template>
</test-fixture>
<script>
suite('gr-coverage-layer', () => {
let element;
setup(() => {
const initialCoverageRanges = [
{
type: 'COVERED',
side: 'right',
code_range: {
start_line: 1,
end_line: 2,
},
},
{
type: 'NOT_COVERED',
side: 'right',
code_range: {
start_line: 3,
end_line: 4,
},
},
{
type: 'PARTIALLY_COVERED',
side: 'right',
code_range: {
start_line: 5,
end_line: 6,
},
},
{
type: 'NOT_INSTRUMENTED',
side: 'right',
code_range: {
start_line: 8,
end_line: 9,
},
},
];
element = fixture('basic');
element.coverageRanges = initialCoverageRanges;
element.side = 'right';
});
suite('annotate', () => {
function createLine(lineNumber) {
lineEl = document.createElement('div');
lineEl.setAttribute('data-side', 'right');
lineEl.setAttribute('data-value', lineNumber);
lineEl.className = 'right';
return lineEl;
}
function checkLine(lineNumber, className, opt_negated) {
const line = createLine(lineNumber);
element.annotate(undefined, line, undefined);
let contains = line.classList.contains(className);
if (opt_negated) contains = !contains;
assert.isTrue(contains);
}
test('line 1-2 are covered', () => {
checkLine(1, 'COVERED');
checkLine(2, 'COVERED');
});
test('line 3-4 are not covered', () => {
checkLine(3, 'NOT_COVERED');
checkLine(4, 'NOT_COVERED');
});
test('line 5-6 are partially covered', () => {
checkLine(5, 'PARTIALLY_COVERED');
checkLine(6, 'PARTIALLY_COVERED');
});
test('line 7 is implicitly not instrumented', () => {
checkLine(7, 'COVERED', true);
checkLine(7, 'NOT_COVERED', true);
checkLine(7, 'PARTIALLY_COVERED', true);
checkLine(7, 'NOT_INSTRUMENTED', true);
});
test('line 8-9 are not instrumented', () => {
checkLine(8, 'NOT_INSTRUMENTED');
checkLine(9, 'NOT_INSTRUMENTED');
});
test('coverage correct, if annotate is called out of order', () => {
checkLine(8, 'NOT_INSTRUMENTED');
checkLine(1, 'COVERED');
checkLine(5, 'PARTIALLY_COVERED');
checkLine(3, 'NOT_COVERED');
checkLine(6, 'PARTIALLY_COVERED');
checkLine(4, 'NOT_COVERED');
checkLine(9, 'NOT_INSTRUMENTED');
checkLine(2, 'COVERED');
});
});
});
</script>