Commit 340cab2e authored by elizavetai's avatar elizavetai Committed by Commit bot

Now golden screenshots are kept in Google Storage. To download them...

Now golden screenshots are kept in Google Storage. To download them automatically, a hook should be added to .gclient. Specifying directories for golden screenshots and artifacts is optional now. There is also a python script that should be run to update screenshots in Google Storage after using update mode.

BUG=395653

Review URL: https://codereview.chromium.org/639283004

Cr-Commit-Position: refs/heads/master@{#299109}
parent 914ea755
...@@ -72,6 +72,8 @@ v8.log ...@@ -72,6 +72,8 @@ v8.log
/chrome/app/theme/default_200_percent/google_chrome /chrome/app/theme/default_200_percent/google_chrome
/chrome/app/theme/google_chrome /chrome/app/theme/google_chrome
/chrome/browser/autofill/internal /chrome/browser/autofill/internal
/chrome/browser/chromeos/login/screenshot_testing/golden_screenshots/*.png
/chrome/browser/chromeos/login/screenshot_testing/artifacts
/chrome/browser/extensions/api/ledger/ /chrome/browser/extensions/api/ledger/
/chrome/browser/extensions/default_extensions/chromeos /chrome/browser/extensions/default_extensions/chromeos
/chrome/browser/google/linkdoctor_internal /chrome/browser/google/linkdoctor_internal
......
...@@ -56,20 +56,18 @@ bool ScreenshotTester::TryInitialize() { ...@@ -56,20 +56,18 @@ bool ScreenshotTester::TryInitialize() {
switches::kEnableScreenshotTestingWithMode); switches::kEnableScreenshotTestingWithMode);
CHECK(mode == kUpdateMode || mode == kTestMode || mode == kPdiffTestMode) CHECK(mode == kUpdateMode || mode == kTestMode || mode == kPdiffTestMode)
<< "Invalid mode for screenshot testing: " << mode; << "Invalid mode for screenshot testing: " << mode;
CHECK(command_line.HasSwitch(chromeos::switches::kGoldenScreenshotsDir)) CHECK(command_line.HasSwitch(chromeos::switches::kGoldenScreenshotsDir))
<< "No directory for golden screenshots specified"; << "No directory with golden screenshots specified, use "
"--golden-screenshots-dir";
golden_screenshots_dir_ = golden_screenshots_dir_ =
command_line.GetSwitchValuePath(switches::kGoldenScreenshotsDir); command_line.GetSwitchValuePath(switches::kGoldenScreenshotsDir);
if (mode == kTestMode || mode == kPdiffTestMode) { if (mode == kTestMode || mode == kPdiffTestMode) {
test_mode_ = true; test_mode_ = true;
if (!command_line.HasSwitch(switches::kArtifactsDir)) { generate_artifacts_ = command_line.HasSwitch(switches::kArtifactsDir);
artifacts_dir_ = golden_screenshots_dir_; if (generate_artifacts_) {
LOG(WARNING)
<< "No directory for artifact storing specified. Artifacts will be "
<< "saved at golden screenshots directory.";
} else {
artifacts_dir_ = command_line.GetSwitchValuePath(switches::kArtifactsDir); artifacts_dir_ = command_line.GetSwitchValuePath(switches::kArtifactsDir);
} }
} }
...@@ -125,7 +123,7 @@ void ScreenshotTester::Run(const std::string& test_name) { ...@@ -125,7 +123,7 @@ void ScreenshotTester::Run(const std::string& test_name) {
Result result = CompareScreenshots(golden_screenshot, current_screenshot); Result result = CompareScreenshots(golden_screenshot, current_screenshot);
VLOG(0) << "Compared"; VLOG(0) << "Compared";
LogComparisonResults(result); LogComparisonResults(result);
if (!result.screenshots_match) { if (!result.screenshots_match && generate_artifacts_) {
// Saving diff imag // Saving diff imag
if (!pdiff_enabled_) { if (!pdiff_enabled_) {
base::FilePath difference_image_path = base::FilePath difference_image_path =
......
...@@ -148,6 +148,9 @@ class ScreenshotTester { ...@@ -148,6 +148,9 @@ class ScreenshotTester {
// be used to compare images. // be used to compare images.
bool pdiff_enabled_; bool pdiff_enabled_;
// Is true when switches specify that artifacts should be saved somewhere.
bool generate_artifacts_;
// Vector which holds areas which the comparison ignores because // Vector which holds areas which the comparison ignores because
// them being different is not a bug (e.g. time on the clock). // them being different is not a bug (e.g. time on the clock).
std::vector<SkIRect> ignored_areas_; std::vector<SkIRect> ignored_areas_;
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import sys
import getopt
import os
here = os.path.realpath(__file__)
src_path = (os.path.normpath(os.path.join(here, '..', '..', '..')))
sys.path.append(os.path.normpath(os.path.join(src_path, '..', 'depot_tools')))
USAGE = 'The utility uploads .png files to ' \
'chrome-os-oobe-ui-screenshot-testing Google Storage bucket.\n' \
'-i:\n\tdirectory with .png files which have to be uploaded\n' \
'-o (optional):\n\tdirectory to store generated .sha1 files. ' \
'Is set to chrome/browser/chromeos/login/screenshot_testing' \
'/golden_screenshots by default\n--help:\n\thelp'
import upload_to_google_storage
import download_from_google_storage
def upload(png_path):
# Creating a list of files which need to be uploaded to Google Storage:
# all .png files from the directory containing golden screenshots.
target = []
for file in os.listdir(png_path):
if file.endswith('.png'):
target.append(os.path.join(png_path, file))
# Creating a standard gsutil object, assuming there are depot_tools
# and everything related is set up already.
gsutil_path = os.path.abspath(os.path.join(src_path, '..', 'depot_tools',
'third_party', 'gsutil',
'gsutil'))
gsutil = download_from_google_storage.Gsutil(gsutil_path,
boto_path=None,
bypass_prodaccess=True)
# URL of the bucket used for storing screenshots.
bucket_url = 'gs://chrome-os-oobe-ui-screenshot-testing'
# Uploading using the most simple way,
# see depot_tools/upload_to_google_storage.py to have better understanding
# of this False and 1 arguments.
upload_to_google_storage.upload_to_google_storage(target, bucket_url, gsutil,
False, False, 1, False)
print 'All images are uploaded to Google Storage.'
def move_sha1(from_path, to_path):
from shutil import move
for file in os.listdir(from_path):
if (file.endswith('.sha1')):
old_place = os.path.join(from_path, file)
new_place = os.path.join(to_path, file)
if not os.path.exists(os.path.dirname(new_place)):
os.makedirs(os.path.dirname(new_place))
move(old_place, new_place)
def main(argv):
png_path = ''
sha1_path = os.path.join(src_path,
'chrome', 'browser', 'chromeos', 'login',
'screenshot_testing', 'golden_screenshots')
try:
opts, args = getopt.getopt(argv,'i:o:', ['--help'])
except getopt.GetoptError:
print USAGE
sys.exit(1)
for opt, arg in opts:
if opt == '--help':
print USAGE
sys.exit()
elif opt == '-i':
png_path = arg
elif opt =='-o':
sha1_path = arg
if png_path == '':
print USAGE
sys.exit(1)
png_path = os.path.abspath(png_path)
sha1_path = os.path.abspath(sha1_path)
upload(png_path)
move_sha1(png_path, sha1_path)
# TODO(elizavetai): Can this git stuff be done automatically?
print 'Please add new .sha1 files from ' \
+ str(sha1_path) + \
' to git manually.'
if __name__ == "__main__":
main(sys.argv[1:])
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment