| // 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]]; |
| |
| // Note: The range of acceptable colors is quite large because there's no way |
| // to know whether software compositing is being used for screen capture; and, |
| // if software compositing is being used, there is no color space management |
| // and color values can be off by a lot. That said, color accuracy is being |
| // tested by a suite of content_browsertests. |
| 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); |
| } |
| ]); |