Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/browser/chromeos/login/screenshot_testing/screenshot_tester.cc

Issue 639283004: Keeping golden screenshots in Google Storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: license Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_testing/screenshot_tester.h" 5 #include "chrome/browser/chromeos/login/screenshot_testing/screenshot_tester.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "chrome/browser/chromeos/login/screenshot_testing/SkDiffPixelsMetric.h" 10 #include "chrome/browser/chromeos/login/screenshot_testing/SkDiffPixelsMetric.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 bool ScreenshotTester::TryInitialize() { 50 bool ScreenshotTester::TryInitialize() {
51 CommandLine& command_line = *CommandLine::ForCurrentProcess(); 51 CommandLine& command_line = *CommandLine::ForCurrentProcess();
52 if (!command_line.HasSwitch(switches::kEnableScreenshotTestingWithMode)) 52 if (!command_line.HasSwitch(switches::kEnableScreenshotTestingWithMode))
53 return false; 53 return false;
54 54
55 std::string mode = command_line.GetSwitchValueASCII( 55 std::string mode = command_line.GetSwitchValueASCII(
56 switches::kEnableScreenshotTestingWithMode); 56 switches::kEnableScreenshotTestingWithMode);
57 CHECK(mode == kUpdateMode || mode == kTestMode || mode == kPdiffTestMode) 57 CHECK(mode == kUpdateMode || mode == kTestMode || mode == kPdiffTestMode)
58 << "Invalid mode for screenshot testing: " << mode; 58 << "Invalid mode for screenshot testing: " << mode;
59
59 CHECK(command_line.HasSwitch(chromeos::switches::kGoldenScreenshotsDir)) 60 CHECK(command_line.HasSwitch(chromeos::switches::kGoldenScreenshotsDir))
60 << "No directory for golden screenshots specified"; 61 << "No directory with golden screenshots specified, use "
62 "--golden-screenshots-dir";
61 63
62 golden_screenshots_dir_ = 64 golden_screenshots_dir_ =
63 command_line.GetSwitchValuePath(switches::kGoldenScreenshotsDir); 65 command_line.GetSwitchValuePath(switches::kGoldenScreenshotsDir);
64 66
65 if (mode == kTestMode || mode == kPdiffTestMode) { 67 if (mode == kTestMode || mode == kPdiffTestMode) {
66 test_mode_ = true; 68 test_mode_ = true;
67 if (!command_line.HasSwitch(switches::kArtifactsDir)) { 69 generate_artifacts_ = command_line.HasSwitch(switches::kArtifactsDir);
68 artifacts_dir_ = golden_screenshots_dir_; 70 if (generate_artifacts_) {
69 LOG(WARNING)
70 << "No directory for artifact storing specified. Artifacts will be "
71 << "saved at golden screenshots directory.";
72 } else {
73 artifacts_dir_ = command_line.GetSwitchValuePath(switches::kArtifactsDir); 71 artifacts_dir_ = command_line.GetSwitchValuePath(switches::kArtifactsDir);
74 } 72 }
75 } 73 }
76 if (mode == kPdiffTestMode) { 74 if (mode == kPdiffTestMode) {
77 pdiff_enabled_ = true; 75 pdiff_enabled_ = true;
78 } 76 }
79 return true; 77 return true;
80 } 78 }
81 79
82 std::string ScreenshotTester::GetImageFileName( 80 std::string ScreenshotTester::GetImageFileName(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 base::FilePath golden_screenshot_path = 116 base::FilePath golden_screenshot_path =
119 GetImageFilePath(test_name, kGoldenScreenshot); 117 GetImageFilePath(test_name, kGoldenScreenshot);
120 PNGFile golden_screenshot = LoadGoldenScreenshot(golden_screenshot_path); 118 PNGFile golden_screenshot = LoadGoldenScreenshot(golden_screenshot_path);
121 if (test_mode_) { 119 if (test_mode_) {
122 CHECK(golden_screenshot.get()) 120 CHECK(golden_screenshot.get())
123 << "A golden screenshot is required for screenshot testing"; 121 << "A golden screenshot is required for screenshot testing";
124 VLOG(0) << "Loaded golden screenshot"; 122 VLOG(0) << "Loaded golden screenshot";
125 Result result = CompareScreenshots(golden_screenshot, current_screenshot); 123 Result result = CompareScreenshots(golden_screenshot, current_screenshot);
126 VLOG(0) << "Compared"; 124 VLOG(0) << "Compared";
127 LogComparisonResults(result); 125 LogComparisonResults(result);
128 if (!result.screenshots_match) { 126 if (!result.screenshots_match && generate_artifacts_) {
129 // Saving diff imag 127 // Saving diff imag
130 if (!pdiff_enabled_) { 128 if (!pdiff_enabled_) {
131 base::FilePath difference_image_path = 129 base::FilePath difference_image_path =
132 GetImageFilePath(test_name, kDifferenceImage); 130 GetImageFilePath(test_name, kDifferenceImage);
133 CHECK(SaveImage(difference_image_path, result.diff_image)); 131 CHECK(SaveImage(difference_image_path, result.diff_image));
134 } 132 }
135 133
136 // Saving failed screenshot 134 // Saving failed screenshot
137 base::FilePath failed_screenshot_path = 135 base::FilePath failed_screenshot_path =
138 GetImageFilePath(test_name, kFailedScreenshot); 136 GetImageFilePath(test_name, kFailedScreenshot);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 343
346 ScreenshotTester::Result testing_result; 344 ScreenshotTester::Result testing_result;
347 testing_result.similarity = result.result; 345 testing_result.similarity = result.result;
348 testing_result.screenshots_match = 346 testing_result.screenshots_match =
349 (result.result == SkImageDiffer::RESULT_CORRECT); 347 (result.result == SkImageDiffer::RESULT_CORRECT);
350 348
351 return testing_result; 349 return testing_result;
352 } 350 }
353 351
354 } // namespace chromeos 352 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698