OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_SCREENSHOT_TESTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_SCREENSHOT_TESTER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_SCREENSHOT_TESTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_SCREENSHOT_TESTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
17 | 17 |
18 namespace chromeos { | 18 namespace chromeos { |
19 | 19 |
20 // A class that allows taking, saving and comparing screnshots while | 20 // A class that allows taking, saving and comparing screnshots while |
21 // running tests. | 21 // running tests. |
22 class ScreenshotTester { | 22 class ScreenshotTester { |
23 public: | 23 public: |
24 ScreenshotTester(); | 24 ScreenshotTester(); |
25 virtual ~ScreenshotTester(); | 25 virtual ~ScreenshotTester(); |
26 | 26 |
27 typedef scoped_refptr<base::RefCountedMemory> PNGFile; | 27 typedef scoped_refptr<base::RefCountedBytes> PNGFile; |
28 | 28 |
29 // Contains the results of comparison | 29 // Contains the results of comparison |
30 struct Result { | 30 struct Result { |
31 Result(); | 31 Result(); |
32 Result(const Result& other); | 32 Result(const Result& other); |
33 ~Result(); | 33 ~Result(); |
34 | 34 |
35 // Is true if screenshots are considered to be equal, false otherwise. | 35 // Is true if screenshots are considered to be equal, false otherwise. |
36 bool screenshots_match; | 36 bool screenshots_match; |
37 | 37 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void UpdateGoldenScreenshot(PNGFile png_data); | 99 void UpdateGoldenScreenshot(PNGFile png_data); |
100 | 100 |
101 // Saves an image |png_data|, assuming it is a .png file. | 101 // Saves an image |png_data|, assuming it is a .png file. |
102 // Returns true if image was saved successfully. | 102 // Returns true if image was saved successfully. |
103 bool SaveImage(const base::FilePath& image_path, PNGFile png_data); | 103 bool SaveImage(const base::FilePath& image_path, PNGFile png_data); |
104 | 104 |
105 // Logs results of comparison accordint to information in |result|. | 105 // Logs results of comparison accordint to information in |result|. |
106 void LogComparisonResults(const ScreenshotTester::Result& result); | 106 void LogComparisonResults(const ScreenshotTester::Result& result); |
107 | 107 |
108 // Saves |png_data| as a current screenshot. | 108 // Saves |png_data| as a current screenshot. |
109 void ReturnScreenshot(PNGFile* screenshot, PNGFile png_data); | 109 void ReturnScreenshot(const PNGFile& screenshot, PNGFile png_data); |
110 | 110 |
111 // Loads golden screenshot from the disk, assuming it lies at |image_path|. | 111 // Loads golden screenshot from the disk, assuming it lies at |image_path|. |
112 // Fails if there is no such a file. | 112 // Fails if there is no such a file. |
113 PNGFile LoadGoldenScreenshot(base::FilePath image_path); | 113 PNGFile LoadGoldenScreenshot(base::FilePath image_path); |
114 | 114 |
115 // Converts .png file to a bitmap which is ready for comparison (erasing | 115 // Converts .png file to a bitmap which is ready for comparison (erasing |
116 // ignored areas included). | 116 // ignored areas included). |
117 SkBitmap ProcessImageForComparison(const PNGFile& image); | 117 SkBitmap ProcessImageForComparison(const PNGFile& image); |
118 | 118 |
119 // Calls comparing two given screenshots with one of the comparators. | 119 // Calls comparing two given screenshots with one of the comparators. |
(...skipping 11 matching lines...) Expand all Loading... |
131 SkBitmap sample_bitmap); | 131 SkBitmap sample_bitmap); |
132 | 132 |
133 // Path to the directory for golden screenshots. | 133 // Path to the directory for golden screenshots. |
134 base::FilePath golden_screenshots_dir_; | 134 base::FilePath golden_screenshots_dir_; |
135 | 135 |
136 // Path to the directory where screenshots that failed comparing | 136 // Path to the directory where screenshots that failed comparing |
137 // and difference between them and golden ones will be stored. | 137 // and difference between them and golden ones will be stored. |
138 base::FilePath artifacts_dir_; | 138 base::FilePath artifacts_dir_; |
139 | 139 |
140 // |run_loop_quitter_| is used to stop waiting when | 140 // |run_loop_quitter_| is used to stop waiting when |
141 // ui::GrabWindowSnapshotAsyncPNG completes. | 141 // ui::GrabWindowSnapshotAsync completes. |
142 base::Closure run_loop_quitter_; | 142 base::Closure run_loop_quitter_; |
143 | 143 |
144 // Is true when we're in test mode: | 144 // Is true when we're in test mode: |
145 // comparing golden screenshots and current ones. | 145 // comparing golden screenshots and current ones. |
146 bool test_mode_; | 146 bool test_mode_; |
147 | 147 |
148 // Is true when switches specify that PerceptualDiff should | 148 // Is true when switches specify that PerceptualDiff should |
149 // be used to compare images. | 149 // be used to compare images. |
150 bool pdiff_enabled_; | 150 bool pdiff_enabled_; |
151 | 151 |
152 // Is true when switches specify that artifacts should be saved somewhere. | 152 // Is true when switches specify that artifacts should be saved somewhere. |
153 bool generate_artifacts_; | 153 bool generate_artifacts_; |
154 | 154 |
155 // Vector which holds areas which the comparison ignores because | 155 // Vector which holds areas which the comparison ignores because |
156 // them being different is not a bug (e.g. time on the clock). | 156 // them being different is not a bug (e.g. time on the clock). |
157 std::vector<SkIRect> ignored_areas_; | 157 std::vector<SkIRect> ignored_areas_; |
158 | 158 |
159 base::WeakPtrFactory<ScreenshotTester> weak_factory_; | 159 base::WeakPtrFactory<ScreenshotTester> weak_factory_; |
160 | 160 |
161 DISALLOW_COPY_AND_ASSIGN(ScreenshotTester); | 161 DISALLOW_COPY_AND_ASSIGN(ScreenshotTester); |
162 }; | 162 }; |
163 | 163 |
164 } // namespace chromeos | 164 } // namespace chromeos |
165 | 165 |
166 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_SCREENSHOT_TESTER_H_ | 166 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTING_SCREENSHOT_TESTER_H_ |
OLD | NEW |