Index: tools/privacy_whitepaper/generate_screenshots.py |
diff --git a/tools/privacy_whitepaper/generate_screenshots.py b/tools/privacy_whitepaper/generate_screenshots.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c4ce2ee6e8b22dccad21e3f97d1975831c7d6e01 |
--- /dev/null |
+++ b/tools/privacy_whitepaper/generate_screenshots.py |
@@ -0,0 +1,205 @@ |
+# -*- coding: utf-8 -*- |
+# Copyright 2016 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. |
+ |
+"""Screenshot generator.""" |
+ |
+import argparse |
+import logging |
+import os |
+import pyautogui |
+ |
+from environment import Environment |
+from screenshot_generator import ScreenshotGenerator |
+ |
+# List of all languages supporte by Chrome. |
+# You can find the list of languages as follows: |
+# cd chrome/app/resources |
+# ls -1 google_chrome_strings* | \ |
+# sed -e 's/google_chrome_strings_//' -e 's/\.xtb//' |
+# and add en-US, as we don't generate a translation file for en-US. |
+LANGUAGES = ["am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en-GB", |
+ "en-US", # This language does not exist in Chrome so produces fallback. |
+ "es-419", "es", "et", "fa", "fil", "fi", "fr", "gu", "hi", "hr", "hu", |
+ "id", "it", "iw", "ja", "kn", "ko", "lt", "lv", "ml", "mr", "ms", "nl", |
+ "no", "pl", "pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sr", "sv", "sw", |
+ "ta", "te", "th", "tr", "uk", "vi", "zh-CN", "zh-TW"] |
+ |
+# List of languages that write in right-to-left direction. |
+RTL_LANGUAGES = ["ar", "fa", "iw"] |
+ |
+ |
+# Instructions for creating screenshots. |
+ |
+class UMA(ScreenshotGenerator): |
+ """Generate a screenshot of the UMA setting.""" |
+ |
+ def Execute(self): |
+ self.GoTo("chrome://settings/") |
+ frame = self.driver.find_element_by_css_selector("iframe[name='settings']") |
+ self.driver.switch_to_frame(frame) |
+ self.Click("#advanced-settings-expander") |
+ |
+ self.CaptureContentScreenshot("#metrics-reporting-setting") |
+ |
+ |
+class Omnibox(ScreenshotGenerator): |
+ """Generate a screenshot of the omnibox after typing "Flowers".""" |
+ |
+ def Execute(self): |
+ self.GoTo("about:blank") |
+ pyautogui.hotkey('ctrl', 'l') |
+ pyautogui.typewrite("Flowers") |
+ self.Wait(2) |
+ |
+ self.CaptureWindowScreenshot(top=200) |
+ |
+ |
+class Translate(ScreenshotGenerator): |
+ """Generate a screenshot offering to translate a webpage.""" |
+ |
+ def Execute(self): |
+ if self.environment.language != "ja": |
+ self.GoTo("https://www.amazon.co.jp") |
melandory
2016/05/30 13:51:49
nit: I would make website prefix a class member, j
|
+ else: |
+ self.GoTo("https://www.amazon.fr") |
+ self.Wait(2) |
+ |
+ self.CaptureWindowScreenshot(top=200) |
+ |
+ |
+class Geolocation(ScreenshotGenerator): |
+ """Generate a screenshot of the geolocation indicator.""" |
+ |
+ def Execute(self): |
+ self.GoTo("https://www.google.com/maps") |
+ self.Wait(5) |
+ self.Click("#mylocation * button") |
+ self.Wait(2) |
+ button_location = pyautogui.locateOnScreen('geolocation-icon.png') |
+ pyautogui.click(pyautogui.center(button_location)) |
+ self.Wait(1) |
+ |
+ self.CaptureWindowScreenshot(top=250) |
+ |
+ |
+class Malware(ScreenshotGenerator): |
+ """Generate a screenshot of the malware warning for websites.""" |
+ |
+ def Execute(self): |
+ self.GoTo("http://malware.testing.google.test/testing/malware/") |
+ self.Wait(2) |
+ |
+ self.CaptureWindowScreenshot(top=500) |
+ |
+ |
+class MalwareDownload(ScreenshotGenerator): |
+ """Generate a screenshot of the malware warning for downloads.""" |
+ # Note that this is currently broken. The malware warning does not trigger |
+ # despite the SafeBrowsing database being available. There is some |
+ # timing issue that needs to be investigated. |
+ |
+ def Execute(self): |
+ # Clean up previously downloaded malware file so that we don't create |
+ # screenshots with text "test", "test (1)", "test (2)". |
+ target_path = os.path.join(self.environment.downloads_path, 'test') |
+ if os.path.exists(target_path): |
+ os.remove(target_path) |
+ |
+ self.GoTo("about:blank") |
+ self.GoTo("http://download.safebrowsingtest.com/download/test") |
+ |
+ self.Wait(3) |
+ if self.environment.is_rtl_language: |
+ self.CaptureWindowScreenshot(bottom=60, right=250) |
+ else: |
+ self.CaptureWindowScreenshot(bottom=60, left=250) |
+ |
+ |
+# Map of all defined screenshot types |
+ALL_SCREENSHOTS = { |
+ "uma": UMA("uma"), |
+ "omnibox": Omnibox("omnibox"), |
+ "translate": Translate("translate"), |
+ "geolocation": Geolocation("geolocation"), |
+ "malware": Malware("malware"), |
+ "malware_download": MalwareDownload("malware_download") |
+} |
+ |
+ |
+def GenerateScreenshots(chrome_path, chromedriver_path, profile_path, |
+ output_path, safebrowsing_path, languages, screenshots): |
+ """Generates the selected screenshots for the selected languages |
+ |
+ Args: |
+ chrome_path: Path to Chrome binary. |
+ chromedriver_path: Path to Chrome driver binary. |
+ profile_path: Path to where profile shall be created. |
+ output_path: Path into which screenshots shall be written. |
+ languages: Languages for which screenshots shall be created. |
+ screenshots: Types of screenshots that shall be created. |
+ """ |
+ for language in languages: |
+ logging.debug("Setting up environment for language %s", language) |
+ if not language in LANGUAGES: |
+ raise Exception("Language '{}' is unknown.".format(language)) |
+ environment = Environment(chrome_path, chromedriver_path, profile_path, |
+ output_path, safebrowsing_path, language, |
+ language in RTL_LANGUAGES) |
+ for screenshot in screenshots: |
+ if screenshot in ALL_SCREENSHOTS: |
+ environment.AddScreenshotGenerator(ALL_SCREENSHOTS[screenshot]) |
+ else: |
+ raise Exception("Screenshot type '{}' is unknown.".format(screenshot)) |
+ environment.GenerateScreenshots() |
+ |
+ |
+def main(): |
+ parser = argparse.ArgumentParser( |
+ description="Tool to generate screenshots for the privacy whitepaper") |
+ parser.add_argument( |
+ "--chrome-path", action="store", dest="chrome_path", |
+ help="Set the chrome path (required).", required=True) |
+ parser.add_argument( |
+ "--chromedriver-path", action="store", dest="chromedriver_path", |
+ help="Set the chromedriver path (required).", required=True) |
+ parser.add_argument( |
+ "--profile-path", action="store", dest="profile_path", |
+ help="Set the profile path (required). You just need to choose a " |
+ "temporary empty folder. If the folder is not empty all its content " |
+ "is going to be removed.", |
+ required=True) |
+ parser.add_argument( |
+ "--output-path", action="store", dest="output_path", |
+ help="Directory where to store screenshots (required).", |
+ required=True) |
+ parser.add_argument("--safebrowsing-path", dest="safebrowsing_path", |
+ help="A Chrome profile directory that can be used to copy a snapshot " |
+ "of the Safe Browsing database.", |
+ required=False) |
+ |
+ parser.add_argument("--languages", metavar="languages", |
+ help="Languages to process", |
+ action="store", nargs="*") |
+ parser.add_argument("--screenshots", metavar="screenshots", |
+ help="Screenshots to generate", |
+ action="store", nargs="*") |
+ parser.add_argument("-v", "--verbose", |
+ help="Increase output verbosity", |
+ action="store_true") |
+ args = parser.parse_args() |
+ |
+ if args.verbose: |
+ logging.basicConfig(level=logging.DEBUG) |
+ |
+ screenshots = args.screenshots or ALL_SCREENSHOTS.keys() |
+ languages = args.languages or LANGUAGES |
+ |
+ GenerateScreenshots( |
+ args.chrome_path, args.chromedriver_path, args.profile_path, |
+ args.output_path, args.safebrowsing_path, languages, screenshots) |
+ |
+ |
+if __name__ == '__main__': |
+ main() |