| Index: chrome/test/data/extensions/api_test/tab_capture/offscreen_end_to_end.js
|
| diff --git a/chrome/test/data/extensions/api_test/tab_capture/offscreen_end_to_end.js b/chrome/test/data/extensions/api_test/tab_capture/offscreen_end_to_end.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e073d0704e03704b23355de8402bbbeb768b7af6
|
| --- /dev/null
|
| +++ b/chrome/test/data/extensions/api_test/tab_capture/offscreen_end_to_end.js
|
| @@ -0,0 +1,64 @@
|
| +// 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]];
|
| + var colorDeviation = 10;
|
| +
|
| + 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);
|
| + }
|
| +]);
|
|
|