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" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_tabstrip.h" |
12 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 14 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_version_info.h" | 16 #include "chrome/common/chrome_version_info.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/test_launcher_utils.h" | 18 #include "chrome/test/base/test_launcher_utils.h" |
18 #include "chrome/test/base/tracing.h" | 19 #include "chrome/test/base/tracing.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 message_queue.ClearQueue(); | 160 message_queue.ClearQueue(); |
160 | 161 |
161 gfx::Rect new_bounds = GetNewTabContainerBounds(tab_container_size); | 162 gfx::Rect new_bounds = GetNewTabContainerBounds(tab_container_size); |
162 | 163 |
163 std::wostringstream js_call; | 164 std::wostringstream js_call; |
164 js_call << "preCallResizeInChromium("; | 165 js_call << "preCallResizeInChromium("; |
165 js_call << new_bounds.width() << ", " << new_bounds.height(); | 166 js_call << new_bounds.width() << ", " << new_bounds.height(); |
166 js_call << ");"; | 167 js_call << ");"; |
167 | 168 |
168 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 169 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
169 browser()->GetActiveWebContents()->GetRenderViewHost(), | 170 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
170 L"", js_call.str())); | 171 L"", js_call.str())); |
171 | 172 |
172 std::string message; | 173 std::string message; |
173 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 174 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
174 message_queue.ClearQueue(); | 175 message_queue.ClearQueue(); |
175 browser()->window()->SetBounds(new_bounds); | 176 browser()->window()->SetBounds(new_bounds); |
176 | 177 |
177 // Wait for message from test page indicating the rendering is done. | 178 // Wait for message from test page indicating the rendering is done. |
178 while (message.compare("\"resized\"")) { | 179 while (message.compare("\"resized\"")) { |
179 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 180 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 << img_diff_path.value(); | 367 << img_diff_path.value(); |
367 } | 368 } |
368 } | 369 } |
369 return rt; | 370 return rt; |
370 } | 371 } |
371 | 372 |
372 // Returns a gfx::Rect representing the bounds that the browser window should | 373 // Returns a gfx::Rect representing the bounds that the browser window should |
373 // have if the tab contents have the desired size. | 374 // have if the tab contents have the desired size. |
374 gfx::Rect GetNewTabContainerBounds(const gfx::Size& desired_size) { | 375 gfx::Rect GetNewTabContainerBounds(const gfx::Size& desired_size) { |
375 gfx::Rect container_rect; | 376 gfx::Rect container_rect; |
376 browser()->GetActiveWebContents()->GetContainerBounds(&container_rect); | 377 chrome::GetActiveWebContents(browser())->GetContainerBounds(&container_rect)
; |
377 // Size cannot be negative, so use a point. | 378 // Size cannot be negative, so use a point. |
378 gfx::Point correction( | 379 gfx::Point correction( |
379 desired_size.width() - container_rect.size().width(), | 380 desired_size.width() - container_rect.size().width(), |
380 desired_size.height() - container_rect.size().height()); | 381 desired_size.height() - container_rect.size().height()); |
381 | 382 |
382 gfx::Rect window_rect = browser()->window()->GetRestoredBounds(); | 383 gfx::Rect window_rect = browser()->window()->GetRestoredBounds(); |
383 gfx::Size new_size = window_rect.size(); | 384 gfx::Size new_size = window_rect.size(); |
384 new_size.Enlarge(correction.x(), correction.y()); | 385 new_size.Enlarge(correction.x(), correction.y()); |
385 window_rect.set_size(new_size); | 386 window_rect.set_size(new_size); |
386 return window_rect; | 387 return window_rect; |
387 } | 388 } |
388 | 389 |
389 // Take snapshot of the current tab, encode it as PNG, and save to a SkBitmap. | 390 // Take snapshot of the current tab, encode it as PNG, and save to a SkBitmap. |
390 bool TabSnapShotToImage(SkBitmap* bitmap) { | 391 bool TabSnapShotToImage(SkBitmap* bitmap) { |
391 CHECK(bitmap); | 392 CHECK(bitmap); |
392 std::vector<unsigned char> png; | 393 std::vector<unsigned char> png; |
393 | 394 |
394 gfx::Rect root_bounds = browser()->window()->GetBounds(); | 395 gfx::Rect root_bounds = browser()->window()->GetBounds(); |
395 gfx::Rect tab_contents_bounds; | 396 gfx::Rect tab_contents_bounds; |
396 browser()->GetActiveWebContents()->GetContainerBounds( | 397 chrome::GetActiveWebContents(browser())->GetContainerBounds( |
397 &tab_contents_bounds); | 398 &tab_contents_bounds); |
398 | 399 |
399 gfx::Rect snapshot_bounds(tab_contents_bounds.x() - root_bounds.x(), | 400 gfx::Rect snapshot_bounds(tab_contents_bounds.x() - root_bounds.x(), |
400 tab_contents_bounds.y() - root_bounds.y(), | 401 tab_contents_bounds.y() - root_bounds.y(), |
401 tab_contents_bounds.width(), | 402 tab_contents_bounds.width(), |
402 tab_contents_bounds.height()); | 403 tab_contents_bounds.height()); |
403 | 404 |
404 gfx::NativeWindow native_window = browser()->window()->GetNativeWindow(); | 405 gfx::NativeWindow native_window = browser()->window()->GetNativeWindow(); |
405 if (!browser::GrabWindowSnapshot(native_window, &png, snapshot_bounds)) { | 406 if (!browser::GrabWindowSnapshot(native_window, &png, snapshot_bounds)) { |
406 LOG(ERROR) << "browser::GrabWindowSnapShot() failed"; | 407 LOG(ERROR) << "browser::GrabWindowSnapShot() failed"; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, Canvas2DRedBoxSD) { | 503 IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, Canvas2DRedBoxSD) { |
503 // If test baseline needs to be updated after a given revision, update the | 504 // If test baseline needs to be updated after a given revision, update the |
504 // following number. If no revision requirement, then 0. | 505 // following number. If no revision requirement, then 0. |
505 const int64 ref_img_revision_update = 123489; | 506 const int64 ref_img_revision_update = 123489; |
506 | 507 |
507 gfx::Size container_size(400, 300); | 508 gfx::Size container_size(400, 300); |
508 FilePath url = | 509 FilePath url = |
509 test_data_dir().AppendASCII("pixel_canvas2d.html"); | 510 test_data_dir().AppendASCII("pixel_canvas2d.html"); |
510 RunPixelTest(container_size, url, ref_img_revision_update); | 511 RunPixelTest(container_size, url, ref_img_revision_update); |
511 } | 512 } |
OLD | NEW |