OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 139 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
140 | 140 |
141 ui_test_utils::DOMMessageQueue message_queue; | 141 ui_test_utils::DOMMessageQueue message_queue; |
142 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(url)); | 142 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(url)); |
143 | 143 |
144 // Wait for notification that page is loaded. | 144 // Wait for notification that page is loaded. |
145 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 145 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
146 message_queue.ClearQueue(); | 146 message_queue.ClearQueue(); |
147 | 147 |
| 148 gfx::Rect new_bounds = GetNewTabContainerBounds(tab_container_size); |
| 149 |
| 150 std::wostringstream js_call; |
| 151 js_call << "preCallResizeInChromium("; |
| 152 js_call << new_bounds.width() << ", " << new_bounds.height(); |
| 153 js_call << ");"; |
| 154 |
148 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 155 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
149 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 156 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
150 L"", L"preCallResizeInChromium();")); | 157 L"", js_call.str())); |
151 | 158 |
152 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 159 std::string message; |
| 160 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
153 message_queue.ClearQueue(); | 161 message_queue.ClearQueue(); |
154 ResizeTabContainer(tab_container_size); | 162 browser()->window()->SetBounds(new_bounds); |
155 | 163 |
156 // Wait for message from test page indicating the rendering is done. | 164 // Wait for message from test page indicating the rendering is done. |
157 std::string message; | |
158 while (message.compare("\"resized\"")) { | 165 while (message.compare("\"resized\"")) { |
159 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 166 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
160 message_queue.ClearQueue(); | 167 message_queue.ClearQueue(); |
161 } | 168 } |
162 | 169 |
163 bool ignore_bottom_corners = false; | 170 bool ignore_bottom_corners = false; |
164 #if defined(OS_MACOSX) | 171 #if defined(OS_MACOSX) |
165 // On Mac Lion, bottom corners have shadows with random pixels. | 172 // On Mac Lion, bottom corners have shadows with random pixels. |
166 ignore_bottom_corners = true; | 173 ignore_bottom_corners = true; |
167 #endif | 174 #endif |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 LOG(ERROR) << "Can't save generated diff image to: " | 330 LOG(ERROR) << "Can't save generated diff image to: " |
324 << img_diff_path.value(); | 331 << img_diff_path.value(); |
325 } else { | 332 } else { |
326 LOG(INFO) << "Saved difference image to: " | 333 LOG(INFO) << "Saved difference image to: " |
327 << img_diff_path.value(); | 334 << img_diff_path.value(); |
328 } | 335 } |
329 } | 336 } |
330 return rt; | 337 return rt; |
331 } | 338 } |
332 | 339 |
333 // Resizes the browser window so that the tab's contents are at a given size. | 340 // Returns a gfx::Rect representing the bounds that the browser window should |
334 void ResizeTabContainer(const gfx::Size& desired_size) { | 341 // have if the tab contents have the desired size. |
| 342 gfx::Rect GetNewTabContainerBounds(const gfx::Size& desired_size) { |
335 gfx::Rect container_rect; | 343 gfx::Rect container_rect; |
336 browser()->GetSelectedWebContents()->GetContainerBounds(&container_rect); | 344 browser()->GetSelectedWebContents()->GetContainerBounds(&container_rect); |
337 // Size cannot be negative, so use a point. | 345 // Size cannot be negative, so use a point. |
338 gfx::Point correction( | 346 gfx::Point correction( |
339 desired_size.width() - container_rect.size().width(), | 347 desired_size.width() - container_rect.size().width(), |
340 desired_size.height() - container_rect.size().height()); | 348 desired_size.height() - container_rect.size().height()); |
341 | 349 |
342 gfx::Rect window_rect = browser()->window()->GetRestoredBounds(); | 350 gfx::Rect window_rect = browser()->window()->GetRestoredBounds(); |
343 gfx::Size new_size = window_rect.size(); | 351 gfx::Size new_size = window_rect.size(); |
344 new_size.Enlarge(correction.x(), correction.y()); | 352 new_size.Enlarge(correction.x(), correction.y()); |
345 window_rect.set_size(new_size); | 353 window_rect.set_size(new_size); |
346 browser()->window()->SetBounds(window_rect); | 354 return window_rect; |
347 } | 355 } |
348 | 356 |
349 // Take snapshot of the current tab, encode it as PNG, and save to a SkBitmap. | 357 // Take snapshot of the current tab, encode it as PNG, and save to a SkBitmap. |
350 bool TabSnapShotToImage(SkBitmap* bitmap) { | 358 bool TabSnapShotToImage(SkBitmap* bitmap) { |
351 CHECK(bitmap); | 359 CHECK(bitmap); |
352 std::vector<unsigned char> png; | 360 std::vector<unsigned char> png; |
353 | 361 |
354 gfx::Rect root_bounds = browser()->window()->GetBounds(); | 362 gfx::Rect root_bounds = browser()->window()->GetBounds(); |
355 gfx::Rect tab_contents_bounds; | 363 gfx::Rect tab_contents_bounds; |
356 browser()->GetSelectedWebContents()->GetContainerBounds( | 364 browser()->GetSelectedWebContents()->GetContainerBounds( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, MAYBE_Canvas2DRedBoxSD) { | 491 IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, MAYBE_Canvas2DRedBoxSD) { |
484 // If test baseline needs to be updated after a given revision, update the | 492 // If test baseline needs to be updated after a given revision, update the |
485 // following number. If no revision requirement, then 0. | 493 // following number. If no revision requirement, then 0. |
486 const int64 ref_img_revision_update = 123489; | 494 const int64 ref_img_revision_update = 123489; |
487 | 495 |
488 gfx::Size container_size(400, 300); | 496 gfx::Size container_size(400, 300); |
489 FilePath url = | 497 FilePath url = |
490 test_data_dir().AppendASCII("pixel_canvas2d.html"); | 498 test_data_dir().AppendASCII("pixel_canvas2d.html"); |
491 RunPixelTest(container_size, url, ref_img_revision_update); | 499 RunPixelTest(container_size, url, ref_img_revision_update); |
492 } | 500 } |
OLD | NEW |