diff options
author | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 19:08:22 +0000 |
---|---|---|
committer | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 19:08:22 +0000 |
commit | ca7272b8db0d425979bd1853cea37e0379d6baf8 (patch) | |
tree | 6e09b91429a55484f4dcc2a4afd02a290074c534 /chrome | |
parent | 9aa2eaaeadd97c8ed9018a63ca701a42eb731c9b (diff) | |
download | chromium_src-ca7272b8db0d425979bd1853cea37e0379d6baf8.zip chromium_src-ca7272b8db0d425979bd1853cea37e0379d6baf8.tar.gz chromium_src-ca7272b8db0d425979bd1853cea37e0379d6baf8.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
9 files changed, 109 insertions, 55 deletions
diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc index 64d42ed..c50fbd9 100644 --- a/chrome/browser/extensions/extension_tabs_apitest.cc +++ b/chrome/browser/extensions/extension_tabs_apitest.cc @@ -38,14 +38,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs2) { ASSERT_TRUE(RunExtensionTest("tabs/basics2")) << message_; } -// TODO(skerner): This test is flaky on chrome os: http://crbug.com/41380 -#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) -#define MAYBE_CaptureVisibleTab FLAKY_CaptureVisibleTab -#else -#define MAYBE_CaptureVisibleTab CaptureVisibleTab -#endif - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_CaptureVisibleTab) { +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTab) { StartHTTPServer(); ASSERT_TRUE(RunExtensionTest("tabs/capture_visible_tab")) << message_; 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 index dcd442e..e69de29 100644 --- 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 @@ -1,5 +0,0 @@ -<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 index 7bff50a..e69de29 100644 --- 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 @@ -1,5 +0,0 @@ -<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 new file mode 100644 index 0000000..beb85b8 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/black.html @@ -0,0 +1,4 @@ +<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 index ccaad19..e69de29 100644 --- 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 @@ -1,5 +0,0 @@ -<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 new file mode 100644 index 0000000..782f0f3 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/red.html @@ -0,0 +1,4 @@ +<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 7d4f6d9..f879681 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,4 +52,3 @@ 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 c9352d4..2a6020a 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,15 +5,78 @@ var pass = chrome.test.callbackPass; var assertEq = chrome.test.assertEq; var assertTrue = chrome.test.assertTrue; -function pageUrl(letter) { - return chrome.extension.getURL(letter + ".html"); +var kWidth = 400; +var kHeight = 400; + +function pageUrl(base) { + return chrome.extension.getURL(base + ".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(1, 1, 9, 9).data; + + var badPixels = []; + + for (var i = 0, n = imageData.length; i < n; i += 4) { + if (color[0] != imageData[i+0] || + color[1] != imageData[i+1] || + color[2] != imageData[i+2] || + color[3] != imageData[i+3] ) { + badPixels.push({"i": i, + "color": [imageData[i+0], imageData[i+1], + imageData[i+2], imageData[i+3]] + }); + } + } + assertEq("[]", JSON.stringify(badPixels, null, 2)) + }); +} + +// 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 captureVisibleTabSimple() { + function captureVisibleTabWhiteImage() { + // Keep the resulting image small by making the window small. + createWindow([pageUrl("white")], {"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)); + whiteImageUrl = imgDataUrl; + + testAllPixelsAreExpectedColor(whiteImageUrl, + [255, 255, 255, 255]); // White. + })); + })); + })); + })); + }, + + function captureVisibleTabBlackImage() { // Keep the resulting image small by making the window small. - createWindow([pageUrl("a")], {"width": 300, "height": 150}, + createWindow([pageUrl("black")], {"width": kWidth, "height": kHeight}, pass(function(winId, tabIds) { waitForAllTabs(pass(function() { chrome.tabs.getSelected(winId, pass(function(tab) { @@ -22,40 +85,42 @@ 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)); + 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)); + + // TODO(skerner): The pixel comparison test fails on XP. + // Find out why. + //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 new file mode 100644 index 0000000..a05a8a0 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/capture_visible_tab/white.html @@ -0,0 +1,4 @@ +<html> + <body bgcolor="#FFFFFF"> + </body> +</html> |