mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 03:51:24 +08:00
The helpers allow the implementation of screenshot tests in DevTools. A screenshot test that makes use of the helpers is added for the performance panel. The test is disabled because no screenshot test infrastructure is available in our bots. Once this isn't the case the test can be enabled and other screenshot tests added. Screenshot tests are not added as a dedicated new suite but as complementary to the interaction tests already in place. For this purpose, the existing artifacts under test/screenshots/ are removed or moved to be under test/interactions. The image_diff executables are moved under third_party Follow-up: Include dedicated lint rules files. Bug: 1407638 Change-Id: I7106769b085b6aaa32ea4a089a840418c83536bb DISABLE_THIRD_PARTY_CHECK=Including new library to third_party/ Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4190012 Reviewed-by: Simon Zünd <szuend@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Andres Olivares <andoli@chromium.org>
139 lines
3.4 KiB
JavaScript
139 lines
3.4 KiB
JavaScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const main = document.querySelector('main');
|
|
const mainContainer = document.querySelector('.main-container');
|
|
const goldenImageContainer = mainContainer.querySelector('.golden .image-container');
|
|
const generatedImageContainer = mainContainer.querySelector('.generated .image-container');
|
|
const status = document.querySelector('.status');
|
|
const file = document.querySelector('.file');
|
|
const percentage = document.querySelector('.percentage');
|
|
const diffImageContainer = document.querySelector('.diff');
|
|
const testSkip = document.querySelector('.test-skip');
|
|
const testConfirm = document.querySelector('.test-confirm');
|
|
|
|
const choiceMarker = document.createElement('div');
|
|
choiceMarker.classList.add('choice');
|
|
|
|
const leftImage = new Image();
|
|
const rightImage = new Image();
|
|
const diffImage = new Image();
|
|
|
|
let listening = false;
|
|
function setState({type, msg, left, right, diff, rawMisMatchPercentage, fileName}) {
|
|
switch (type) {
|
|
case 'status':
|
|
listening = false;
|
|
document.body.appendChild(status);
|
|
status.textContent = msg;
|
|
mainContainer.remove();
|
|
disableButtons();
|
|
break;
|
|
|
|
case 'outcome':
|
|
main.appendChild(mainContainer);
|
|
status.remove();
|
|
choiceMarker.remove();
|
|
|
|
file.textContent = fileName;
|
|
percentage.textContent = `${rawMisMatchPercentage}%`;
|
|
|
|
// Golden.
|
|
leftImage.src = left;
|
|
goldenImageContainer.appendChild(leftImage);
|
|
|
|
// Generated.
|
|
rightImage.src = right;
|
|
generatedImageContainer.appendChild(rightImage);
|
|
|
|
// Diff.
|
|
diffImage.src = diff;
|
|
diffImageContainer.appendChild(diffImage);
|
|
diffImage.onerror = () => {
|
|
diffImage.src = './no-diff-available.png';
|
|
diffImage.onerror = null;
|
|
};
|
|
|
|
listening = true;
|
|
enableSkipButton();
|
|
break;
|
|
}
|
|
}
|
|
|
|
function makeChoice(which) {
|
|
choiceMarker.dataset.choice = which;
|
|
leftImage.classList.toggle('selected', which === 'golden');
|
|
rightImage.classList.toggle('selected', which === 'generated');
|
|
enableConfirmButton();
|
|
}
|
|
|
|
function commitChoice() {
|
|
document.body.appendChild(choiceMarker);
|
|
setWaiting();
|
|
}
|
|
|
|
function setWaiting() {
|
|
setState({type: 'status', msg: 'Waiting...'});
|
|
}
|
|
|
|
function enableSkipButton() {
|
|
testSkip.disabled = false;
|
|
}
|
|
|
|
function enableConfirmButton() {
|
|
testConfirm.disabled = false;
|
|
}
|
|
|
|
function disableButtons() {
|
|
testSkip.disabled = true;
|
|
testConfirm.disabled = true;
|
|
}
|
|
|
|
function commitSkip() {
|
|
makeChoice('skip');
|
|
commitChoice();
|
|
}
|
|
|
|
function commitChoiceIfPossible() {
|
|
if (!choiceMarker.dataset.choice) {
|
|
return;
|
|
}
|
|
commitChoice();
|
|
}
|
|
|
|
window.addEventListener('keyup', evt => {
|
|
if (!listening) {
|
|
return;
|
|
}
|
|
|
|
switch (evt.key) {
|
|
case 'ArrowLeft':
|
|
makeChoice('golden');
|
|
return;
|
|
|
|
case 'ArrowRight':
|
|
makeChoice('generated');
|
|
return;
|
|
|
|
case 'd':
|
|
diffImageContainer.classList.toggle('visible');
|
|
return;
|
|
|
|
case 's':
|
|
commitSkip();
|
|
return;
|
|
|
|
case 'Enter':
|
|
commitChoiceIfPossible();
|
|
return;
|
|
}
|
|
});
|
|
|
|
leftImage.addEventListener('click', () => makeChoice('golden'));
|
|
rightImage.addEventListener('click', () => makeChoice('generated'));
|
|
testSkip.addEventListener('click', () => commitSkip());
|
|
testConfirm.addEventListener('click', () => commitChoiceIfPossible());
|
|
|
|
setWaiting();
|