blob: 8361fd868f3bfb8a354f973e854688389d144bf1 [file] [log] [blame]
// Copyright 2015 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.
// Returs a full HTML test document for the off-screen tab that renders rotating
// color fills of red, then green, then blue.
function makeRotatingColorTestDocument() {
return makeOffscreenTabTestDocument('\
// The test pattern cycles as a color fill of red, then green, then blue.\n\
var colors = [redColor, greenColor, blueColor];\n\
\n\
function colorRotationLoop() {\n\
if (!this.iterCount) {\n\
this.iterCount = 1;\n\
} else {\n\
++this.iterCount;\n\
}\n\
if (!this.stepTimeMillis) {\n\
this.stepTimeMillis = 100;\n\
}\n\
var idx = this.iterCount % colors.length;\n\
if (idx == 0) { // Completed a cycle.\n\
// Increase the wait time between switching test patterns for\n\
// overloaded bots that are not capturing all the frames of video.\n\
this.stepTimeMillis *= 1.25;\n\
}\n\
setFillColor(colors[idx]);\n\
setTimeout(colorRotationLoop, this.stepTimeMillis);\n\
}\n\
colorRotationLoop();');
}
// Observer side of this end-to-end test. |stream| is monitored for each of the
// three fill colors to be generated by the off-screen tab. Once all three have
// been observed, the test ends successfully.
function waitForExpectedColorsAndEndTest(stream) {
// Elements from this array are removed as each color is observed. When it
// becomes empty, the test succeeds.
var remainingColors = [[255, 0, 0], [0, 255, 0], [0, 0, 255]];
// TODO(crbug/758057): Determine why color accuracy went down in this test
// with the new VIZ-based tab capturer.
var colorDeviation = 50;
function onMatchedNextColor(idx) {
chrome.test.assertTrue(idx < remainingColors.length);
remainingColors.splice(idx, 1);
if (remainingColors.length == 0) {
stopAllTracks(stream);
chrome.test.succeed();
} else {
waitForAnExpectedColor(stream, remainingColors, colorDeviation,
onMatchedNextColor);
}
}
waitForAnExpectedColor(stream, remainingColors, colorDeviation,
onMatchedNextColor);
}
chrome.test.runTests([
function offscreenTabTest() {
chrome.tabCapture.captureOffscreenTab(
makeDataUriFromDocument(makeRotatingColorTestDocument()),
getCaptureOptions(),
waitForExpectedColorsAndEndTest);
}
]);