| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Test fixture for GPU image comparison tests. | 102 // Test fixture for GPU image comparison tests. |
| 103 // TODO(kkania): Document how to add to/modify these tests. | 103 // TODO(kkania): Document how to add to/modify these tests. |
| 104 class GpuPixelBrowserTest : public InProcessBrowserTest { | 104 class GpuPixelBrowserTest : public InProcessBrowserTest { |
| 105 public: | 105 public: |
| 106 GpuPixelBrowserTest() {} | 106 GpuPixelBrowserTest() {} |
| 107 | 107 |
| 108 virtual void SetUpCommandLine(CommandLine* command_line) { | 108 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 109 // This enables DOM automation for tab contents. | 109 // This enables DOM automation for tab contents. |
| 110 EnableDOMAutomation(); | 110 EnableDOMAutomation(); |
| 111 | 111 |
| 112 // These tests by default use OSMesa. This can be changed if the |kUseGL| | 112 // These tests by default use any GL implementation it can find. |
| 113 // switch is explicitly set to something else or if |kUseGpuInTests| is | 113 // This can be changed if the |kUseGL| switch is explicitly set to |
| 114 // present. | 114 // something or if |kUseGpuInTests| is present. |
| 115 if (command_line->HasSwitch(switches::kUseGL)) { | 115 if (!command_line->HasSwitch(switches::kUseGL) && |
| 116 using_gpu_ = command_line->GetSwitchValueASCII(switches::kUseGL) != | 116 !command_line->HasSwitch(kUseGpuInTests)) { |
| 117 gfx::kGLImplementationOSMesaName; | 117 command_line->AppendSwitchASCII(switches::kUseGL, "any"); |
| 118 } else if (command_line->HasSwitch(kUseGpuInTests)) { | |
| 119 using_gpu_ = true; | |
| 120 } else { | |
| 121 // OSMesa will be used by default. | |
| 122 EXPECT_TRUE(test_launcher_utils::OverrideGLImplementation( | |
| 123 command_line, | |
| 124 gfx::kGLImplementationOSMesaName)); | |
| 125 #if defined(OS_MACOSX) | |
| 126 // Accelerated compositing does not work with OSMesa. AcceleratedSurface | |
| 127 // assumes GL contexts are native. | |
| 128 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | |
| 129 #endif | |
| 130 using_gpu_ = false; | |
| 131 } | 118 } |
| 132 // Allow file access from "file://" protocol. Otherwise, test fails with | 119 // Allow file access from "file://" protocol. Otherwise, test fails with |
| 133 // "Uncaught Error: SECURITY_ERR: DOM Exception 18." | 120 // "Uncaught Error: SECURITY_ERR: DOM Exception 18." |
| 134 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); | 121 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); |
| 135 } | 122 } |
| 136 | 123 |
| 137 virtual void SetUpInProcessBrowserTestFixture() { | 124 virtual void SetUpInProcessBrowserTestFixture() { |
| 138 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | 125 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); |
| 139 test_data_dir_ = test_data_dir_.AppendASCII("gpu"); | 126 test_data_dir_ = test_data_dir_.AppendASCII("gpu"); |
| 140 | 127 |
| 141 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 128 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 142 if (command_line->HasSwitch(kGeneratedDir)) | 129 if (command_line->HasSwitch(kGeneratedDir)) |
| 143 generated_img_dir_ = command_line->GetSwitchValuePath(kGeneratedDir); | 130 generated_img_dir_ = command_line->GetSwitchValuePath(kGeneratedDir); |
| 144 else | 131 else |
| 145 generated_img_dir_ = test_data_dir_.AppendASCII("generated"); | 132 generated_img_dir_ = test_data_dir_.AppendASCII("generated"); |
| 146 | 133 |
| 147 if (using_gpu_) | |
| 148 reference_img_dir_ = test_data_dir_.AppendASCII("gpu_reference"); | |
| 149 else | |
| 150 reference_img_dir_ = test_data_dir_.AppendASCII("sw_reference"); | |
| 151 | |
| 152 test_name_ = testing::UnitTest::GetInstance()->current_test_info()->name(); | 134 test_name_ = testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 153 const char* test_status_prefixes[] = {"DISABLED_", "FLAKY_", "FAILS_"}; | 135 const char* test_status_prefixes[] = {"DISABLED_", "FLAKY_", "FAILS_"}; |
| 154 for (size_t i = 0; i < arraysize(test_status_prefixes); ++i) { | 136 for (size_t i = 0; i < arraysize(test_status_prefixes); ++i) { |
| 155 ReplaceFirstSubstringAfterOffset( | 137 ReplaceFirstSubstringAfterOffset( |
| 156 &test_name_, 0, test_status_prefixes[i], ""); | 138 &test_name_, 0, test_status_prefixes[i], ""); |
| 157 } | 139 } |
| 158 } | 140 } |
| 159 | 141 |
| 160 // Compares the generated bitmap with the appropriate reference image on disk. | 142 // Compares the generated bitmap with the appropriate reference image on disk. |
| 161 // The reference image is determined by the name of the test, the |postfix|, | 143 // The reference image is determined by the name of the test, the |postfix|, |
| 162 // and the vendor and device ID. Returns true iff the images were the same. | 144 // and the vendor and device ID. Returns true iff the images were the same. |
| 163 // | 145 // |
| 164 // |postfix|, is an optional name that can be appended onto the images name to | 146 // |postfix|, is an optional name that can be appended onto the images name to |
| 165 // distinguish between images from a single test. | 147 // distinguish between images from a single test. |
| 166 // | 148 // |
| 167 // On failure, the image will be written to disk, and can be collected as a | 149 // On failure, the image will be written to disk, and can be collected as a |
| 168 // baseline. The image format is: | 150 // baseline. The image format is: |
| 169 // <test_name>_<postfix>_<os>_<vendor_id>-<device_id>.png | 151 // <test_name>_<postfix>_<os>_<vendor_id>-<device_id>.png |
| 170 // E.g., | 152 // E.g., |
| 171 // WebGLFishTank_FirstTab_120981-1201.png | 153 // WebGLFishTank_FirstTab_120981-1201.png |
| 172 bool CompareImages(const SkBitmap& gen_bmp, const std::string& postfix) { | 154 bool CompareImages(const SkBitmap& gen_bmp, const std::string& postfix) { |
| 173 // Determine the name of the image. | 155 // Determine the name of the image. |
| 174 std::string img_name = test_name_; | 156 std::string img_name = test_name_; |
| 157 FilePath ref_img_dir; |
| 175 if (postfix.length()) | 158 if (postfix.length()) |
| 176 img_name += "_" + postfix; | 159 img_name += "_" + postfix; |
| 177 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
| 178 const char* os_label = "win"; | 161 const char* os_label = "win"; |
| 179 #elif defined(OS_MACOSX) | 162 #elif defined(OS_MACOSX) |
| 180 const char* os_label = "mac"; | 163 const char* os_label = "mac"; |
| 181 #elif defined(OS_LINUX) | 164 #elif defined(OS_LINUX) |
| 182 const char* os_label = "linux"; | 165 const char* os_label = "linux"; |
| 183 #else | 166 #else |
| 184 #error "Not implemented for this platform" | 167 #error "Not implemented for this platform" |
| 185 #endif | 168 #endif |
| 186 if (using_gpu_) { | 169 GPUInfo info; |
| 187 GPUInfo info; | 170 if (!GetGPUInfo(&info)) { |
| 188 if (!GetGPUInfo(&info)) { | 171 LOG(ERROR) << "Could not get gpu info"; |
| 189 LOG(ERROR) << "Could not get gpu info"; | 172 return false; |
| 190 return false; | 173 } |
| 191 } | 174 // TODO(alokp): Why do we treat Mesa differently? |
| 175 bool using_gpu = info.gl_renderer.compare(0, 4, "Mesa") != 0; |
| 176 if (using_gpu) { |
| 177 ref_img_dir = test_data_dir_.AppendASCII("gpu_reference"); |
| 192 img_name = base::StringPrintf("%s_%s_%04x-%04x.png", | 178 img_name = base::StringPrintf("%s_%s_%04x-%04x.png", |
| 193 img_name.c_str(), os_label, info.vendor_id, info.device_id); | 179 img_name.c_str(), os_label, info.vendor_id, info.device_id); |
| 194 } else { | 180 } else { |
| 181 ref_img_dir = test_data_dir_.AppendASCII("sw_reference"); |
| 195 img_name = base::StringPrintf("%s_%s_mesa.png", | 182 img_name = base::StringPrintf("%s_%s_mesa.png", |
| 196 img_name.c_str(), os_label); | 183 img_name.c_str(), os_label); |
| 197 } | 184 } |
| 198 | 185 |
| 199 // Read the reference image and verify the images' dimensions are equal. | 186 // Read the reference image and verify the images' dimensions are equal. |
| 200 FilePath ref_img_path = reference_img_dir_.AppendASCII(img_name); | 187 FilePath ref_img_path = ref_img_dir.AppendASCII(img_name); |
| 201 SkBitmap ref_bmp; | 188 SkBitmap ref_bmp; |
| 202 bool should_compare = true; | 189 bool should_compare = true; |
| 203 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { | 190 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { |
| 204 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); | 191 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); |
| 205 should_compare = false; | 192 should_compare = false; |
| 206 } | 193 } |
| 207 if (should_compare && | 194 if (should_compare && |
| 208 (ref_bmp.width() != gen_bmp.width() || | 195 (ref_bmp.width() != gen_bmp.width() || |
| 209 ref_bmp.height() != gen_bmp.height())) { | 196 ref_bmp.height() != gen_bmp.height())) { |
| 210 LOG(ERROR) | 197 LOG(ERROR) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 244 } |
| 258 return false; | 245 return false; |
| 259 } | 246 } |
| 260 return true; | 247 return true; |
| 261 } | 248 } |
| 262 | 249 |
| 263 protected: | 250 protected: |
| 264 FilePath test_data_dir_; | 251 FilePath test_data_dir_; |
| 265 | 252 |
| 266 private: | 253 private: |
| 267 FilePath reference_img_dir_; | |
| 268 FilePath generated_img_dir_; | 254 FilePath generated_img_dir_; |
| 269 // The name of the test, with any special prefixes dropped. | 255 // The name of the test, with any special prefixes dropped. |
| 270 std::string test_name_; | 256 std::string test_name_; |
| 271 // Whether the gpu, or OSMesa is being used for rendering. | |
| 272 bool using_gpu_; | |
| 273 | 257 |
| 274 DISALLOW_COPY_AND_ASSIGN(GpuPixelBrowserTest); | 258 DISALLOW_COPY_AND_ASSIGN(GpuPixelBrowserTest); |
| 275 }; | 259 }; |
| 276 | 260 |
| 277 #if defined(OS_LINUX) | 261 #if defined(OS_LINUX) |
| 278 // Currently fails (and times out) on linux due to a NOTIMPLEMENTED() statement. | 262 // Currently fails (and times out) on linux due to a NOTIMPLEMENTED() statement. |
| 279 // (http://crbug.com/89964) | 263 // (http://crbug.com/89964) |
| 280 #define MAYBE_WebGLTeapot DISABLED_WebGLTeapot | 264 #define MAYBE_WebGLTeapot DISABLED_WebGLTeapot |
| 281 #elif defined(OS_WIN) | 265 #elif defined(OS_WIN) |
| 282 // Fails (and times out) on Windows due to pixel mismatch. | 266 // Fails (and times out) on Windows due to pixel mismatch. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 297 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 281 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
| 298 | 282 |
| 299 SkBitmap bitmap; | 283 SkBitmap bitmap; |
| 300 gfx::Size container_size(500, 500); | 284 gfx::Size container_size(500, 500); |
| 301 ResizeTabContainer(browser(), container_size); | 285 ResizeTabContainer(browser(), container_size); |
| 302 ASSERT_TRUE(ui_test_utils::TakeRenderWidgetSnapshot( | 286 ASSERT_TRUE(ui_test_utils::TakeRenderWidgetSnapshot( |
| 303 browser()->GetSelectedTabContents()->render_view_host(), | 287 browser()->GetSelectedTabContents()->render_view_host(), |
| 304 container_size, &bitmap)); | 288 container_size, &bitmap)); |
| 305 ASSERT_TRUE(CompareImages(bitmap, "")); | 289 ASSERT_TRUE(CompareImages(bitmap, "")); |
| 306 } | 290 } |
| OLD | NEW |