OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "app/app_switches.h" | 8 #include "app/app_switches.h" |
9 #include "app/gfx/gl/gl_implementation.h" | 9 #include "app/gfx/gl/gl_implementation.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
35 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Command line flag for forcing the machine's GPU to be used instead of OSMesa. | 39 // Command line flag for forcing the machine's GPU to be used instead of OSMesa. |
40 const char kUseGpuInTests[] = "use-gpu-in-tests"; | 40 const char kUseGpuInTests[] = "use-gpu-in-tests"; |
41 | 41 |
| 42 // Command line flag for overriding the default location for putting generated |
| 43 // test images that do not match references. |
| 44 const char kGeneratedDir[] = "generated-dir"; |
| 45 |
42 // Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG | 46 // Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG |
43 // should have been encoded using |gfx::PNGCodec::Encode|. | 47 // should have been encoded using |gfx::PNGCodec::Encode|. |
44 bool ReadPNGFile(const FilePath& file_path, SkBitmap* bitmap) { | 48 bool ReadPNGFile(const FilePath& file_path, SkBitmap* bitmap) { |
45 DCHECK(bitmap); | 49 DCHECK(bitmap); |
46 std::string png_data; | 50 std::string png_data; |
47 return file_util::ReadFileToString(file_path, &png_data) && | 51 return file_util::ReadFileToString(file_path, &png_data) && |
48 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), | 52 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), |
49 png_data.length(), | 53 png_data.length(), |
50 bitmap); | 54 bitmap); |
51 } | 55 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // assumes GL contexts are native. | 158 // assumes GL contexts are native. |
155 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | 159 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); |
156 #endif | 160 #endif |
157 using_gpu_ = false; | 161 using_gpu_ = false; |
158 } | 162 } |
159 } | 163 } |
160 | 164 |
161 virtual void SetUpInProcessBrowserTestFixture() { | 165 virtual void SetUpInProcessBrowserTestFixture() { |
162 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | 166 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); |
163 test_data_dir_ = test_data_dir_.AppendASCII("gpu"); | 167 test_data_dir_ = test_data_dir_.AppendASCII("gpu"); |
164 generated_img_dir_ = test_data_dir_.AppendASCII("generated"); | 168 |
| 169 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 170 if (command_line->HasSwitch(kGeneratedDir)) |
| 171 generated_img_dir_ = command_line->GetSwitchValuePath(kGeneratedDir); |
| 172 else |
| 173 generated_img_dir_ = test_data_dir_.AppendASCII("generated"); |
| 174 |
165 if (using_gpu_) | 175 if (using_gpu_) |
166 reference_img_dir_ = test_data_dir_.AppendASCII("gpu_reference"); | 176 reference_img_dir_ = test_data_dir_.AppendASCII("gpu_reference"); |
167 else | 177 else |
168 reference_img_dir_ = test_data_dir_.AppendASCII("sw_reference"); | 178 reference_img_dir_ = test_data_dir_.AppendASCII("sw_reference"); |
169 | 179 |
170 test_name_ = testing::UnitTest::GetInstance()->current_test_info()->name(); | 180 test_name_ = testing::UnitTest::GetInstance()->current_test_info()->name(); |
171 const char* test_status_prefixes[] = {"DISABLED_", "FLAKY_", "FAILS_"}; | 181 const char* test_status_prefixes[] = {"DISABLED_", "FLAKY_", "FAILS_"}; |
172 for (size_t i = 0; i < arraysize(test_status_prefixes); ++i) { | 182 for (size_t i = 0; i < arraysize(test_status_prefixes); ++i) { |
173 ReplaceFirstSubstringAfterOffset( | 183 ReplaceFirstSubstringAfterOffset( |
174 &test_name_, 0, test_status_prefixes[i], ""); | 184 &test_name_, 0, test_status_prefixes[i], ""); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 FilePath reference_img_dir_; | 295 FilePath reference_img_dir_; |
286 FilePath generated_img_dir_; | 296 FilePath generated_img_dir_; |
287 // The name of the test, with any special prefixes dropped. | 297 // The name of the test, with any special prefixes dropped. |
288 std::string test_name_; | 298 std::string test_name_; |
289 // Whether the gpu, or OSMesa is being used for rendering. | 299 // Whether the gpu, or OSMesa is being used for rendering. |
290 bool using_gpu_; | 300 bool using_gpu_; |
291 | 301 |
292 DISALLOW_COPY_AND_ASSIGN(GpuPixelBrowserTest); | 302 DISALLOW_COPY_AND_ASSIGN(GpuPixelBrowserTest); |
293 }; | 303 }; |
294 | 304 |
295 // This test does not run on Linux because the information about the gfx card is | 305 IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, WebGLTeapot) { |
296 // not available yet. | |
297 #if !defined(OS_LINUX) | |
298 // Mark this as failing because we don't have the reference images yet. Once the | |
299 // images are generated on the bots, they will be uploaded and this status will | |
300 // be changed. | |
301 #define MAYBE_WebGLTeapot FAILS_WebGLTeapot | |
302 #else | |
303 #define MAYBE_WebGLTeapot DISABLED_WebGLTeapot | |
304 #endif | |
305 IN_PROC_BROWSER_TEST_F(GpuPixelBrowserTest, MAYBE_WebGLTeapot) { | |
306 ui_test_utils::DOMMessageQueue message_queue; | 306 ui_test_utils::DOMMessageQueue message_queue; |
307 ui_test_utils::NavigateToURL( | 307 ui_test_utils::NavigateToURL( |
308 browser(), | 308 browser(), |
309 net::FilePathToFileURL(test_data_dir_.AppendASCII("webgl_teapot"). | 309 net::FilePathToFileURL(test_data_dir_.AppendASCII("webgl_teapot"). |
310 AppendASCII("teapot.html"))); | 310 AppendASCII("teapot.html"))); |
311 | 311 |
312 // Wait for message from teapot page indicating the GL calls have been issued. | 312 // Wait for message from teapot page indicating the GL calls have been issued. |
313 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 313 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
314 | 314 |
315 SkBitmap bitmap; | 315 SkBitmap bitmap; |
316 gfx::Size container_size(500, 500); | 316 gfx::Size container_size(500, 500); |
317 ResizeTabContainer(browser(), container_size); | 317 ResizeTabContainer(browser(), container_size); |
318 ASSERT_TRUE(ui_test_utils::TakeRenderWidgetSnapshot( | 318 ASSERT_TRUE(ui_test_utils::TakeRenderWidgetSnapshot( |
319 browser()->GetSelectedTabContents()->render_view_host(), | 319 browser()->GetSelectedTabContents()->render_view_host(), |
320 container_size, &bitmap)); | 320 container_size, &bitmap)); |
321 ASSERT_TRUE(CompareImages(bitmap, "")); | 321 ASSERT_TRUE(CompareImages(bitmap, "")); |
322 } | 322 } |
OLD | NEW |