OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 13 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/test_launcher_utils.h" | 17 #include "chrome/test/base/test_launcher_utils.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
26 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
27 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
28 #include "ui/gfx/test/gfx_test_utils.h" | 28 #include "ui/gfx/test/gfx_test_utils.h" |
29 | 29 |
30 #if defined(USE_WEBKIT_COMPOSITOR) | 30 #if defined(USE_WEBKIT_COMPOSITOR) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 file_path, reinterpret_cast<char*>(&png_data[0]), png_data.size()); | 63 file_path, reinterpret_cast<char*>(&png_data[0]), png_data.size()); |
64 if (bytes_written == static_cast<int>(png_data.size())) | 64 if (bytes_written == static_cast<int>(png_data.size())) |
65 return true; | 65 return true; |
66 } | 66 } |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 // Resizes the browser window so that the tab's contents are at a given size. | 70 // Resizes the browser window so that the tab's contents are at a given size. |
71 void ResizeTabContainer(Browser* browser, const gfx::Size& desired_size) { | 71 void ResizeTabContainer(Browser* browser, const gfx::Size& desired_size) { |
72 gfx::Rect container_rect; | 72 gfx::Rect container_rect; |
73 browser->GetSelectedTabContents()->GetContainerBounds(&container_rect); | 73 browser->GetSelectedWebContents()->GetContainerBounds(&container_rect); |
74 // Size cannot be negative, so use a point. | 74 // Size cannot be negative, so use a point. |
75 gfx::Point correction(desired_size.width() - container_rect.size().width(), | 75 gfx::Point correction(desired_size.width() - container_rect.size().width(), |
76 desired_size.height() - container_rect.size().height()); | 76 desired_size.height() - container_rect.size().height()); |
77 | 77 |
78 gfx::Rect window_rect = browser->window()->GetRestoredBounds(); | 78 gfx::Rect window_rect = browser->window()->GetRestoredBounds(); |
79 gfx::Size new_size = window_rect.size(); | 79 gfx::Size new_size = window_rect.size(); |
80 new_size.Enlarge(correction.x(), correction.y()); | 80 new_size.Enlarge(correction.x(), correction.y()); |
81 window_rect.set_size(new_size); | 81 window_rect.set_size(new_size); |
82 browser->window()->SetBounds(window_rect); | 82 browser->window()->SetBounds(window_rect); |
83 } | 83 } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 gfx::Size container_size(500, 500); | 318 gfx::Size container_size(500, 500); |
319 ResizeTabContainer(browser(), container_size); | 319 ResizeTabContainer(browser(), container_size); |
320 | 320 |
321 // Wait for message from teapot page indicating the GL calls have been issued. | 321 // Wait for message from teapot page indicating the GL calls have been issued. |
322 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 322 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
323 | 323 |
324 std::vector<unsigned char> screenshot_png; | 324 std::vector<unsigned char> screenshot_png; |
325 | 325 |
326 gfx::Rect root_bounds = browser()->window()->GetBounds(); | 326 gfx::Rect root_bounds = browser()->window()->GetBounds(); |
327 gfx::Rect tab_contents_bounds; | 327 gfx::Rect tab_contents_bounds; |
328 browser()->GetSelectedTabContents()->GetContainerBounds(&tab_contents_bounds); | 328 browser()->GetSelectedWebContents()->GetContainerBounds(&tab_contents_bounds); |
329 | 329 |
330 gfx::Rect snapshot_bounds(tab_contents_bounds.x() - root_bounds.x(), | 330 gfx::Rect snapshot_bounds(tab_contents_bounds.x() - root_bounds.x(), |
331 tab_contents_bounds.y() - root_bounds.y(), | 331 tab_contents_bounds.y() - root_bounds.y(), |
332 tab_contents_bounds.width(), | 332 tab_contents_bounds.width(), |
333 tab_contents_bounds.height()); | 333 tab_contents_bounds.height()); |
334 | 334 |
335 gfx::NativeWindow native_window = browser()->window()->GetNativeHandle(); | 335 gfx::NativeWindow native_window = browser()->window()->GetNativeHandle(); |
336 bool success = browser::GrabWindowSnapshot(native_window, &screenshot_png, | 336 bool success = browser::GrabWindowSnapshot(native_window, &screenshot_png, |
337 snapshot_bounds); | 337 snapshot_bounds); |
338 ASSERT_TRUE(success); | 338 ASSERT_TRUE(success); |
339 | 339 |
340 SkBitmap bitmap; | 340 SkBitmap bitmap; |
341 success = gfx::PNGCodec::Decode( | 341 success = gfx::PNGCodec::Decode( |
342 reinterpret_cast<unsigned char*>(&*screenshot_png.begin()), | 342 reinterpret_cast<unsigned char*>(&*screenshot_png.begin()), |
343 screenshot_png.size(), | 343 screenshot_png.size(), |
344 &bitmap); | 344 &bitmap); |
345 | 345 |
346 ASSERT_TRUE(success); | 346 ASSERT_TRUE(success); |
347 ASSERT_TRUE(CompareImages(bitmap)); | 347 ASSERT_TRUE(CompareImages(bitmap)); |
348 } | 348 } |
OLD | NEW |