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 #include "chrome/browser/chromeos/login/screenshot_tester.h" | 5 #include "chrome/browser/chromeos/login/screenshot_tester.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/bind_internal.h" | 9 #include "base/bind_internal.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // Sets test mode for screenshot testing. | 29 // Sets test mode for screenshot testing. |
30 const char kTestMode[] = "test"; | 30 const char kTestMode[] = "test"; |
31 | 31 |
32 // Sets update mode for screenshot testing. | 32 // Sets update mode for screenshot testing. |
33 const char kUpdateMode[] = "update"; | 33 const char kUpdateMode[] = "update"; |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 namespace chromeos { | 37 namespace chromeos { |
38 | 38 |
39 ScreenshotTester::ScreenshotTester() : test_mode_(false), weak_factory_(this) { | 39 ScreenshotTester::ScreenshotTester() : test_mode_(false), weak_factory_(this) { |
dzhioev (left Google)
2014/08/07 11:23:56
test_mode_ should be enum.
| |
40 } | 40 } |
41 | 41 |
42 ScreenshotTester::~ScreenshotTester() { | 42 ScreenshotTester::~ScreenshotTester() { |
43 } | 43 } |
44 | 44 |
45 bool ScreenshotTester::TryInitialize() { | 45 bool ScreenshotTester::TryInitialize() { |
dzhioev (left Google)
2014/08/07 11:23:56
I don't like that this class use command line as a
| |
46 CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 46 CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
47 if (!command_line.HasSwitch(switches::kEnableScreenshotTestingWithMode)) | 47 if (!command_line.HasSwitch(switches::kEnableScreenshotTestingWithMode)) |
48 return false; | 48 return false; |
49 if (!command_line.HasSwitch(::switches::kEnablePixelOutputInTests) || | |
50 !command_line.HasSwitch(::switches::kUIEnableImplSidePainting)) { | |
51 // TODO(elizavetai): make turning on --enable-pixel-output-in-tests | |
52 // and --ui-enable-impl-side-painting automatical. | |
53 LOG(ERROR) << "--enable-pixel-output-in-tests and " | |
54 << "--ui-enable-impl-side-painting are required to take " | |
55 << "screenshots"; | |
56 return false; | |
57 } | |
58 | |
59 std::string mode = command_line.GetSwitchValueASCII( | 49 std::string mode = command_line.GetSwitchValueASCII( |
60 switches::kEnableScreenshotTestingWithMode); | 50 switches::kEnableScreenshotTestingWithMode); |
61 if (mode != kUpdateMode && mode != kTestMode) { | 51 if (mode != kUpdateMode && mode != kTestMode) { |
62 CHECK(false) << "Invalid mode for screenshot testing: " << mode; | 52 CHECK(false) << "Invalid mode for screenshot testing: " << mode; |
dzhioev (left Google)
2014/08/07 11:23:56
Use "LOG_ASSERT(condition) << message" instead of
| |
63 } | 53 } |
64 | 54 |
65 if (!command_line.HasSwitch(chromeos::switches::kGoldenScreenshotsDir)) { | 55 if (!command_line.HasSwitch(chromeos::switches::kGoldenScreenshotsDir)) { |
66 CHECK(false) << "No directory for golden screenshots specified"; | 56 CHECK(false) << "No directory for golden screenshots specified"; |
67 } | 57 } |
68 | 58 |
69 golden_screenshots_dir_ = | 59 golden_screenshots_dir_ = |
70 command_line.GetSwitchValuePath(switches::kGoldenScreenshotsDir); | 60 command_line.GetSwitchValuePath(switches::kGoldenScreenshotsDir); |
71 | 61 |
72 if (mode == kTestMode) { | 62 if (mode == kTestMode) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 << screenshot_path.DirName().value(); | 104 << screenshot_path.DirName().value(); |
115 return false; | 105 return false; |
116 } | 106 } |
117 if (static_cast<size_t>( | 107 if (static_cast<size_t>( |
118 base::WriteFile(screenshot_path, | 108 base::WriteFile(screenshot_path, |
119 reinterpret_cast<char*>(&(png_data->data()[0])), | 109 reinterpret_cast<char*>(&(png_data->data()[0])), |
120 png_data->size())) != png_data->size()) { | 110 png_data->size())) != png_data->size()) { |
121 LOG(ERROR) << "Can't save screenshot " << file_name; | 111 LOG(ERROR) << "Can't save screenshot " << file_name; |
122 return false; | 112 return false; |
123 } | 113 } |
124 VLOG(0) << "Screenshot " << file_name << ".png saved successfully to " | 114 VLOG(0) << "Screenshot " << test_name_ + "_" + file_name + ".png" |
125 << screenshot_dir.value(); | 115 << " saved successfully to " << screenshot_dir.value(); |
126 return true; | 116 return true; |
127 } | 117 } |
128 | 118 |
129 void ScreenshotTester::ReturnScreenshot(const PNGFile& screenshot, | 119 void ScreenshotTester::ReturnScreenshot(const PNGFile& screenshot, |
130 PNGFile png_data) { | 120 PNGFile png_data) { |
131 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
132 screenshot->data() = png_data->data(); | 122 screenshot->data() = png_data->data(); |
133 content::BrowserThread::PostTask( | 123 content::BrowserThread::PostTask( |
134 content::BrowserThread::UI, FROM_HERE, run_loop_quitter_); | 124 content::BrowserThread::UI, FROM_HERE, run_loop_quitter_); |
135 } | 125 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 VLOG(0) << "Current screenshot and diff picture saved to " | 205 VLOG(0) << "Current screenshot and diff picture saved to " |
216 << artifacts_dir_.value(); | 206 << artifacts_dir_.value(); |
217 } else { | 207 } else { |
218 VLOG(0) << "Current screenshot matches the golden screenshot. Screenshot " | 208 VLOG(0) << "Current screenshot matches the golden screenshot. Screenshot " |
219 "testing passed."; | 209 "testing passed."; |
220 } | 210 } |
221 ASSERT_TRUE(screenshots_match); | 211 ASSERT_TRUE(screenshots_match); |
222 } | 212 } |
223 | 213 |
224 } // namespace chromeos | 214 } // namespace chromeos |
OLD | NEW |