Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Side by Side Diff: chrome/browser/plugins/plugin_power_saver_browsertest.cc

Issue 1863483004: Plugin Power Saver: Update pixel test tolerance and error behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const int kBrowserHeight = 700; 45 const int kBrowserHeight = 700;
46 46
47 // Compare only a portion of the snapshots, as different platforms will 47 // Compare only a portion of the snapshots, as different platforms will
48 // capture different sized snapshots (due to differences in browser chrome). 48 // capture different sized snapshots (due to differences in browser chrome).
49 const int kComparisonWidth = 500; 49 const int kComparisonWidth = 500;
50 const int kComparisonHeight = 600; 50 const int kComparisonHeight = 600;
51 51
52 // Different platforms have slightly different pixel output, due to different 52 // Different platforms have slightly different pixel output, due to different
53 // graphics implementations. Slightly different pixels (in BGR space) are still 53 // graphics implementations. Slightly different pixels (in BGR space) are still
54 // counted as a matching pixel by this simple manhattan distance threshold. 54 // counted as a matching pixel by this simple manhattan distance threshold.
55 const int kPixelManhattanDistanceTolerance = 20; 55 const int kPixelManhattanDistanceTolerance = 25;
56 56
57 std::string RunTestScript(base::StringPiece test_script, 57 std::string RunTestScript(base::StringPiece test_script,
58 content::WebContents* contents, 58 content::WebContents* contents,
59 const std::string& element_id) { 59 const std::string& element_id) {
60 std::string script = base::StringPrintf( 60 std::string script = base::StringPrintf(
61 "var plugin = window.document.getElementById('%s');" 61 "var plugin = window.document.getElementById('%s');"
62 "if (plugin === undefined ||" 62 "if (plugin === undefined ||"
63 " (plugin.nodeName !== 'OBJECT' && plugin.nodeName !== 'EMBED')) {" 63 " (plugin.nodeName !== 'OBJECT' && plugin.nodeName !== 'EMBED')) {"
64 " window.domAutomationController.send('error');" 64 " window.domAutomationController.send('error');"
65 "} else {" 65 "} else {"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return false; 183 return false;
184 } 184 }
185 185
186 if (w < kComparisonWidth || h < kComparisonHeight) 186 if (w < kComparisonWidth || h < kComparisonHeight)
187 return false; 187 return false;
188 188
189 int32_t* ref_pixels = reinterpret_cast<int32_t*>(decoded.data()); 189 int32_t* ref_pixels = reinterpret_cast<int32_t*>(decoded.data());
190 SkAutoLockPixels lock_image(bitmap); 190 SkAutoLockPixels lock_image(bitmap);
191 int32_t* pixels = static_cast<int32_t*>(bitmap.getPixels()); 191 int32_t* pixels = static_cast<int32_t*>(bitmap.getPixels());
192 192
193 int stride = bitmap.rowBytes(); 193 bool success = true;
194 for (int y = 0; y < kComparisonHeight; ++y) { 194 for (int y = 0; y < kComparisonHeight; ++y) {
195 for (int x = 0; x < kComparisonWidth; ++x) { 195 for (int x = 0; x < kComparisonWidth; ++x) {
196 int32_t pixel = pixels[y * stride / sizeof(int32_t) + x]; 196 int32_t pixel = pixels[y * bitmap.rowBytes() / sizeof(int32_t) + x];
197 int pixel_b = pixel & 0xFF; 197 int pixel_b = pixel & 0xFF;
198 int pixel_g = (pixel >> 8) & 0xFF; 198 int pixel_g = (pixel >> 8) & 0xFF;
199 int pixel_r = (pixel >> 16) & 0xFF; 199 int pixel_r = (pixel >> 16) & 0xFF;
200 200
201 int32_t ref_pixel = ref_pixels[y * w + x]; 201 int32_t ref_pixel = ref_pixels[y * w + x];
202 int ref_pixel_b = ref_pixel & 0xFF; 202 int ref_pixel_b = ref_pixel & 0xFF;
203 int ref_pixel_g = (ref_pixel >> 8) & 0xFF; 203 int ref_pixel_g = (ref_pixel >> 8) & 0xFF;
204 int ref_pixel_r = (ref_pixel >> 16) & 0xFF; 204 int ref_pixel_r = (ref_pixel >> 16) & 0xFF;
205 205
206 int manhattan_distance = abs(pixel_b - ref_pixel_b) + 206 int manhattan_distance = abs(pixel_b - ref_pixel_b) +
207 abs(pixel_g - ref_pixel_g) + 207 abs(pixel_g - ref_pixel_g) +
208 abs(pixel_r - ref_pixel_r); 208 abs(pixel_r - ref_pixel_r);
209 209
210 if (manhattan_distance > kPixelManhattanDistanceTolerance) { 210 if (manhattan_distance > kPixelManhattanDistanceTolerance) {
211 ADD_FAILURE() << "Pixel test failed on (" << x << ", " << y << "). " << 211 ADD_FAILURE() << "Pixel test failed on (" << x << ", " << y << "). " <<
212 "Pixel manhattan distance: " << manhattan_distance << "."; 212 "Pixel manhattan distance: " << manhattan_distance << ".";
213 return false; 213 success = false;
214 } 214 }
215 } 215 }
216 } 216 }
217 217
218 return true; 218 return success;
219 } 219 }
220 220
221 // |snapshot_matches| is set to true if the snapshot matches the reference and 221 // |snapshot_matches| is set to true if the snapshot matches the reference and
222 // the test passes. Otherwise, set to false. 222 // the test passes. Otherwise, set to false.
223 void CompareSnapshotToReference(const base::FilePath& reference, 223 void CompareSnapshotToReference(const base::FilePath& reference,
224 bool* snapshot_matches, 224 bool* snapshot_matches,
225 const base::Closure& done_cb, 225 const base::Closure& done_cb,
226 const SkBitmap& bitmap, 226 const SkBitmap& bitmap,
227 content::ReadbackResponse response) { 227 content::ReadbackResponse response) {
228 DCHECK(snapshot_matches); 228 DCHECK(snapshot_matches);
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 633
634 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { 634 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) {
635 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) 635 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents())
636 ->SetZoomLevel(4.0); 636 ->SetZoomLevel(4.0);
637 LoadHTML( 637 LoadHTML(
638 "<object id='plugin' data='http://otherorigin.com/fake.swf' " 638 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
639 " type='application/x-ppapi-tests' width='400' height='200'>" 639 " type='application/x-ppapi-tests' width='400' height='200'>"
640 "</object>"); 640 "</object>");
641 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); 641 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin");
642 } 642 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698