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_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/tracing.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
23 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "third_party/skia/include/core/SkColor.h" | 27 #include "third_party/skia/include/core/SkColor.h" |
27 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 110 } |
110 | 111 |
111 // If the existing ref image was saved from an revision older than the | 112 // If the existing ref image was saved from an revision older than the |
112 // ref_img_update_revision, refresh the ref image. | 113 // ref_img_update_revision, refresh the ref image. |
113 void RunPixelTest(const gfx::Size& tab_container_size, | 114 void RunPixelTest(const gfx::Size& tab_container_size, |
114 const FilePath& url, | 115 const FilePath& url, |
115 int64 ref_img_update_revision) { | 116 int64 ref_img_update_revision) { |
116 ref_img_revision_no_older_than_ = ref_img_update_revision; | 117 ref_img_revision_no_older_than_ = ref_img_update_revision; |
117 ObtainLocalRefImageFilePath(); | 118 ObtainLocalRefImageFilePath(); |
118 | 119 |
| 120 #if defined(OS_WIN) |
| 121 ASSERT_TRUE(tracing::BeginTracing("-test_*")); |
| 122 #endif |
| 123 |
119 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 124 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
120 | 125 |
121 ui_test_utils::DOMMessageQueue message_queue; | 126 ui_test_utils::DOMMessageQueue message_queue; |
122 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(url)); | 127 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(url)); |
123 | 128 |
124 // Wait for notification that page is loaded. | 129 // Wait for notification that page is loaded. |
125 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 130 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
126 message_queue.ClearQueue(); | 131 message_queue.ClearQueue(); |
127 | 132 |
128 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 133 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
(...skipping 12 matching lines...) Expand all Loading... |
141 } | 146 } |
142 | 147 |
143 bool ignore_bottom_corners = false; | 148 bool ignore_bottom_corners = false; |
144 #if defined(OS_MACOSX) | 149 #if defined(OS_MACOSX) |
145 // On Mac Lion, bottom corners have shadows with random pixels. | 150 // On Mac Lion, bottom corners have shadows with random pixels. |
146 ignore_bottom_corners = true; | 151 ignore_bottom_corners = true; |
147 #endif | 152 #endif |
148 | 153 |
149 SkBitmap bitmap; | 154 SkBitmap bitmap; |
150 ASSERT_TRUE(TabSnapShotToImage(&bitmap)); | 155 ASSERT_TRUE(TabSnapShotToImage(&bitmap)); |
151 ASSERT_TRUE(CompareImages(bitmap, ignore_bottom_corners)); | 156 bool is_image_same = CompareImages(bitmap, ignore_bottom_corners); |
| 157 EXPECT_TRUE(is_image_same); |
| 158 |
| 159 #if defined(OS_WIN) |
| 160 // For debugging the flaky test, this prints out a trace of what happened on |
| 161 // failure. |
| 162 std::string trace_events; |
| 163 ASSERT_TRUE(tracing::EndTracing(&trace_events)); |
| 164 if (!is_image_same) |
| 165 fprintf(stderr, "\n\nTRACE JSON:\n\n%s\n\n", trace_events.c_str()); |
| 166 #endif |
152 } | 167 } |
153 | 168 |
154 const FilePath& test_data_dir() const { | 169 const FilePath& test_data_dir() const { |
155 return test_data_dir_; | 170 return test_data_dir_; |
156 } | 171 } |
157 | 172 |
158 private: | 173 private: |
159 FilePath test_data_dir_; | 174 FilePath test_data_dir_; |
160 FilePath generated_img_dir_; | 175 FilePath generated_img_dir_; |
161 FilePath ref_img_dir_; | 176 FilePath ref_img_dir_; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, MAYBE_Canvas2DRedBoxSD) { | 459 IN_PROC_BROWSER_TEST_F(Canvas2DPixelTestSD, MAYBE_Canvas2DRedBoxSD) { |
445 // If test baseline needs to be updated after a given revision, update the | 460 // If test baseline needs to be updated after a given revision, update the |
446 // following number. If no revision requirement, then 0. | 461 // following number. If no revision requirement, then 0. |
447 const int64 ref_img_revision_update = 123489; | 462 const int64 ref_img_revision_update = 123489; |
448 | 463 |
449 gfx::Size container_size(400, 300); | 464 gfx::Size container_size(400, 300); |
450 FilePath url = | 465 FilePath url = |
451 test_data_dir().AppendASCII("pixel_canvas2d.html"); | 466 test_data_dir().AppendASCII("pixel_canvas2d.html"); |
452 RunPixelTest(container_size, url, ref_img_revision_update); | 467 RunPixelTest(container_size, url, ref_img_revision_update); |
453 } | 468 } |
OLD | NEW |