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

Side by Side Diff: tools/privacy_whitepaper/generate_screenshots.py

Issue 2008283002: Tool to generate screenshots of Chrome in various languages Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
(Empty)
1 # -*- coding: utf-8 -*-
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Screenshot generator."""
7
8 import argparse
9 import logging
10 import os
11 import pyautogui
12
13 from environment import Environment
14 from screenshot_generator import ScreenshotGenerator
15
16 # List of all languages supporte by Chrome.
17 # You can find the list of languages as follows:
18 # cd chrome/app/resources
19 # ls -1 google_chrome_strings* | \
20 # sed -e 's/google_chrome_strings_//' -e 's/\.xtb//'
21 # and add en-US, as we don't generate a translation file for en-US.
22 LANGUAGES = ["am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en-GB",
23 "en-US", # This language does not exist in Chrome so produces fallback.
24 "es-419", "es", "et", "fa", "fil", "fi", "fr", "gu", "hi", "hr", "hu",
25 "id", "it", "iw", "ja", "kn", "ko", "lt", "lv", "ml", "mr", "ms", "nl",
26 "no", "pl", "pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sr", "sv", "sw",
27 "ta", "te", "th", "tr", "uk", "vi", "zh-CN", "zh-TW"]
28
29 # List of languages that write in right-to-left direction.
30 RTL_LANGUAGES = ["ar", "fa", "iw"]
31
32
33 # Instructions for creating screenshots.
34
35 class UMA(ScreenshotGenerator):
36 """Generate a screenshot of the UMA setting."""
37
38 def Execute(self):
39 self.GoTo("chrome://settings/")
40 frame = self.driver.find_element_by_css_selector("iframe[name='settings']")
41 self.driver.switch_to_frame(frame)
42 self.Click("#advanced-settings-expander")
43
44 self.CaptureContentScreenshot("#metrics-reporting-setting")
45
46
47 class Omnibox(ScreenshotGenerator):
48 """Generate a screenshot of the omnibox after typing "Flowers"."""
49
50 def Execute(self):
51 self.GoTo("about:blank")
52 pyautogui.hotkey('ctrl', 'l')
53 pyautogui.typewrite("Flowers")
54 self.Wait(2)
55
56 self.CaptureWindowScreenshot(top=200)
57
58
59 class Translate(ScreenshotGenerator):
60 """Generate a screenshot offering to translate a webpage."""
61
62 def Execute(self):
63 if self.environment.language != "ja":
64 self.GoTo("https://www.amazon.co.jp")
melandory 2016/05/30 13:51:49 nit: I would make website prefix a class member, j
65 else:
66 self.GoTo("https://www.amazon.fr")
67 self.Wait(2)
68
69 self.CaptureWindowScreenshot(top=200)
70
71
72 class Geolocation(ScreenshotGenerator):
73 """Generate a screenshot of the geolocation indicator."""
74
75 def Execute(self):
76 self.GoTo("https://www.google.com/maps")
77 self.Wait(5)
78 self.Click("#mylocation * button")
79 self.Wait(2)
80 button_location = pyautogui.locateOnScreen('geolocation-icon.png')
81 pyautogui.click(pyautogui.center(button_location))
82 self.Wait(1)
83
84 self.CaptureWindowScreenshot(top=250)
85
86
87 class Malware(ScreenshotGenerator):
88 """Generate a screenshot of the malware warning for websites."""
89
90 def Execute(self):
91 self.GoTo("http://malware.testing.google.test/testing/malware/")
92 self.Wait(2)
93
94 self.CaptureWindowScreenshot(top=500)
95
96
97 class MalwareDownload(ScreenshotGenerator):
98 """Generate a screenshot of the malware warning for downloads."""
99 # Note that this is currently broken. The malware warning does not trigger
100 # despite the SafeBrowsing database being available. There is some
101 # timing issue that needs to be investigated.
102
103 def Execute(self):
104 # Clean up previously downloaded malware file so that we don't create
105 # screenshots with text "test", "test (1)", "test (2)".
106 target_path = os.path.join(self.environment.downloads_path, 'test')
107 if os.path.exists(target_path):
108 os.remove(target_path)
109
110 self.GoTo("about:blank")
111 self.GoTo("http://download.safebrowsingtest.com/download/test")
112
113 self.Wait(3)
114 if self.environment.is_rtl_language:
115 self.CaptureWindowScreenshot(bottom=60, right=250)
116 else:
117 self.CaptureWindowScreenshot(bottom=60, left=250)
118
119
120 # Map of all defined screenshot types
121 ALL_SCREENSHOTS = {
122 "uma": UMA("uma"),
123 "omnibox": Omnibox("omnibox"),
124 "translate": Translate("translate"),
125 "geolocation": Geolocation("geolocation"),
126 "malware": Malware("malware"),
127 "malware_download": MalwareDownload("malware_download")
128 }
129
130
131 def GenerateScreenshots(chrome_path, chromedriver_path, profile_path,
132 output_path, safebrowsing_path, languages, screenshots):
133 """Generates the selected screenshots for the selected languages
134
135 Args:
136 chrome_path: Path to Chrome binary.
137 chromedriver_path: Path to Chrome driver binary.
138 profile_path: Path to where profile shall be created.
139 output_path: Path into which screenshots shall be written.
140 languages: Languages for which screenshots shall be created.
141 screenshots: Types of screenshots that shall be created.
142 """
143 for language in languages:
144 logging.debug("Setting up environment for language %s", language)
145 if not language in LANGUAGES:
146 raise Exception("Language '{}' is unknown.".format(language))
147 environment = Environment(chrome_path, chromedriver_path, profile_path,
148 output_path, safebrowsing_path, language,
149 language in RTL_LANGUAGES)
150 for screenshot in screenshots:
151 if screenshot in ALL_SCREENSHOTS:
152 environment.AddScreenshotGenerator(ALL_SCREENSHOTS[screenshot])
153 else:
154 raise Exception("Screenshot type '{}' is unknown.".format(screenshot))
155 environment.GenerateScreenshots()
156
157
158 def main():
159 parser = argparse.ArgumentParser(
160 description="Tool to generate screenshots for the privacy whitepaper")
161 parser.add_argument(
162 "--chrome-path", action="store", dest="chrome_path",
163 help="Set the chrome path (required).", required=True)
164 parser.add_argument(
165 "--chromedriver-path", action="store", dest="chromedriver_path",
166 help="Set the chromedriver path (required).", required=True)
167 parser.add_argument(
168 "--profile-path", action="store", dest="profile_path",
169 help="Set the profile path (required). You just need to choose a "
170 "temporary empty folder. If the folder is not empty all its content "
171 "is going to be removed.",
172 required=True)
173 parser.add_argument(
174 "--output-path", action="store", dest="output_path",
175 help="Directory where to store screenshots (required).",
176 required=True)
177 parser.add_argument("--safebrowsing-path", dest="safebrowsing_path",
178 help="A Chrome profile directory that can be used to copy a snapshot "
179 "of the Safe Browsing database.",
180 required=False)
181
182 parser.add_argument("--languages", metavar="languages",
183 help="Languages to process",
184 action="store", nargs="*")
185 parser.add_argument("--screenshots", metavar="screenshots",
186 help="Screenshots to generate",
187 action="store", nargs="*")
188 parser.add_argument("-v", "--verbose",
189 help="Increase output verbosity",
190 action="store_true")
191 args = parser.parse_args()
192
193 if args.verbose:
194 logging.basicConfig(level=logging.DEBUG)
195
196 screenshots = args.screenshots or ALL_SCREENSHOTS.keys()
197 languages = args.languages or LANGUAGES
198
199 GenerateScreenshots(
200 args.chrome_path, args.chromedriver_path, args.profile_path,
201 args.output_path, args.safebrowsing_path, languages, screenshots)
202
203
204 if __name__ == '__main__':
205 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698