diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 00:21:33 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 00:21:33 +0000 |
commit | 5ac8b8fb88572ac5f0a910057d8e9baa4054c3c5 (patch) | |
tree | 8c655ca5f79165f7b4ee84fe5b047a0e5063f6ee /chrome/test/data | |
parent | 9aa33e851f4e0e01d302a3440111fd56e34aa664 (diff) | |
download | chromium_src-5ac8b8fb88572ac5f0a910057d8e9baa4054c3c5.zip chromium_src-5ac8b8fb88572ac5f0a910057d8e9baa4054c3c5.tar.gz chromium_src-5ac8b8fb88572ac5f0a910057d8e9baa4054c3c5.tar.bz2 |
Revert 44570 - Fix chrome os flakyness for test ExtensionApiTest.CaptureVisibleTab.
While in the code, add tests for PNG capture, and make code test that the resulting image is the right color.
BUG=41380
TEST=ExtensionApiTest.CaptureVisibleTab
Review URL: http://codereview.chromium.org/1631015
TBR=skerner@chromium.org
Review URL: http://codereview.chromium.org/1525035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44587 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data')
8 files changed, 47 insertions, 98 deletions
diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/a.html b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/a.html new file mode 100644 index 0000000..dcd442e --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/a.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>A</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/b.html b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/b.html new file mode 100644 index 0000000..7bff50a --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/b.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>B</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/black.html b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/black.html deleted file mode 100644 index beb85b8..0000000 --- a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/black.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> - <body bgcolor="#000000"> - </body> -</html> diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/c.html b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/c.html new file mode 100644 index 0000000..ccaad19 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/c.html @@ -0,0 +1,5 @@ +<html> + <body> + <h1>C</h1> + </body> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/red.html b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/red.html deleted file mode 100644 index 782f0f3..0000000 --- a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/red.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> - <body bgcolor="#FF0000"> - </body> -</html> diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/tabs_util.js b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/tabs_util.js index f879681..7d4f6d9 100644 --- a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/tabs_util.js +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/tabs_util.js @@ -52,3 +52,4 @@ function waitForAllTabs(callback) { } waitForTabs(); } + diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/test.js b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/test.js index fea8695..c9352d4 100644 --- a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/test.js +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/test.js @@ -5,49 +5,15 @@ var pass = chrome.test.callbackPass; var assertEq = chrome.test.assertEq; var assertTrue = chrome.test.assertTrue; -var kWidth = 400; -var kHeight = 400; - -function pageUrl(base) { - return chrome.extension.getURL(base + ".html"); +function pageUrl(letter) { + return chrome.extension.getURL(letter + ".html"); } -function testAllPixelsAreExpectedColor(imgUrl, color) { - assertEq("string", typeof(imgUrl)); - var img = new Image(); - img.width = kWidth; - img.height = kHeight; - img.src = imgUrl; - img.onload = pass(function() { - var canvas = document.createElement("canvas"); - - // Comparing pixels is slow enough to hit timeouts. Compare - // a 10x10 region. - canvas.setAttribute('width', 10); - canvas.setAttribute('height', 10); - var context = canvas.getContext('2d'); - context.drawImage(img, 0, 0, 10, 10); - - var imageData = context.getImageData(0, 0, 10, 10).data; - - for (var i = 0, n = imageData.length; i < n; i += 4) { - assertEq(color[0], imageData[i+0]); // Red - assertEq(color[1], imageData[i+1]); // Green - assertEq(color[2], imageData[i+2]); // Blue - assertEq(color[3], imageData[i+3]); // Alpha - } - }); -} - -// Globals used to allow a test to read data from a previous test. -var blackImageUrl; -var whiteImageUrl; - chrome.test.runTests([ // Open a window with one tab, take a snapshot. - function captureVisibleTabWhiteImage() { + function captureVisibleTabSimple() { // Keep the resulting image small by making the window small. - createWindow([pageUrl("white")], {"width": kWidth, "height": kHeight}, + createWindow([pageUrl("a")], {"width": 300, "height": 150}, pass(function(winId, tabIds) { waitForAllTabs(pass(function() { chrome.tabs.getSelected(winId, pass(function(tab) { @@ -56,61 +22,40 @@ chrome.test.runTests([ // The URL should be a data URL with has a JPEG mime type. assertEq("string", typeof(imgDataUrl)); assertEq('data:image/jpg;base64,', imgDataUrl.substr(0,22)); - whiteImageUrl = imgDataUrl; - - testAllPixelsAreExpectedColor(whiteImageUrl, - [255, 255, 255, 255]); // White. })); })); })); })); }, - function captureVisibleTabBlackImage() { - // Keep the resulting image small by making the window small. - createWindow([pageUrl("black")], {"width": kWidth, "height": kHeight}, - pass(function(winId, tabIds) { - waitForAllTabs(pass(function() { - chrome.tabs.getSelected(winId, pass(function(tab) { - assertEq('complete', tab.status); // waitForAllTabs ensures this. - chrome.tabs.captureVisibleTab(winId, pass(function(imgDataUrl) { - // The URL should be a data URL with has a JPEG mime type. - assertEq("string", typeof(imgDataUrl)); - assertEq('data:image/jpg;base64,', imgDataUrl.substr(0,22)); - blackImageUrl = imgDataUrl; - - // Check that previous capture was done. - assertEq('string', typeof(whiteImageUrl)); - - assertTrue(whiteImageUrl != blackImageUrl); - - testAllPixelsAreExpectedColor(blackImageUrl, - [0, 0, 0, 255]); // Black. + // Open a window with three tabs, take a snapshot of each. + function captureVisibleTabMultiTab() { + var snapshotAndRemoveSelectedTab = function(winId, callback) { + chrome.tabs.getSelected(winId, function(tab) { + chrome.tabs.captureVisibleTab(winId, function(imgDataUrl) { + // Test that the URL we got is a data URL which encodes a JPEG image. + assertEq("string", typeof(imgDataUrl)); + assertEq('data:image/jpg;base64,', imgDataUrl.substr(0,22)); + + // TODO(skerner): Once an option allows captureVisibleTab to + // take a lossless snapshot with a set color depth, use + // a canvas to compare |imgDataUrl| to an image of the tab + // we expect. This can't be done with JPEG, as the results + // vary based on the display settings. + chrome.tabs.remove(tab.id, callback); + }); + }); + }; + + createWindow(["a", "b", "c"].map(pageUrl), {"width": 300, "height": 150}, + function(winId, tabIds){ + waitForAllTabs(pass(function() { + snapshotAndRemoveSelectedTab(winId, pass(function() { + snapshotAndRemoveSelectedTab(winId, pass(function() { + snapshotAndRemoveSelectedTab(winId, pass(function() {})); + })); })); })); - })); - })); - }, - - function captureVisibleTabRedPng() { - // Keep the resulting image small by making the window small. - createWindow([pageUrl("red")], {"width": kWidth, "height": kHeight}, - pass(function(winId, tabIds) { - waitForAllTabs(pass(function() { - chrome.tabs.getSelected(winId, pass(function(tab) { - assertEq('complete', tab.status); // waitForAllTabs ensures this. - chrome.tabs.captureVisibleTab(winId, - {"format": "png"}, - pass(function(imgDataUrl) { - // The URL should be a data URL with has a PNG mime type. - assertEq("string", typeof(imgDataUrl)); - assertEq('data:image/png;base64,', imgDataUrl.substr(0,22)); - - testAllPixelsAreExpectedColor(imgDataUrl, - [255, 0, 0, 255]); // Red. - })); - })); - })); - })); + }); } ]); diff --git a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/white.html b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/white.html deleted file mode 100644 index a05a8a0..0000000 --- a/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/white.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> - <body bgcolor="#FFFFFF"> - </body> -</html> |