Commit 5894c31d authored by chrome-bot's avatar chrome-bot Committed by Commit Bot

Fix & enable TranslateEnabled.

Bug: 967779
Change-Id: I456c2218ca23d9cd4878588f94a82410bfbf056e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1692980
Auto-Submit: Mathieu Binette <mbinette@google.com>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684417}
parent c5eacacb
......@@ -14,10 +14,8 @@ from homepage.homepage import *
from password_manager_enabled.password_manager_enabled import *
from popups_allowed.popups_allowed import *
from restore_on_startup.restore_on_startup import *
from translate_enabled.translate_enabled import *
from url_blacklist.url_blacklist import *
from url_whitelist.url_whitelist import *
from user_data_dir.user_data_dir import *
from youtube_restrict.youtube_restrict import *
# TODO(mbinette): Fix TranslateEnabledTest on LUCI bots.
# from translate_enabled.translate_enabled import *
......@@ -17,13 +17,14 @@ class TranslateEnabledTest(ChromeEnterpriseTestCase):
@before_all
def setup(self):
self.InstallChrome('client2012')
self.InstallWebDriver('client2012')
self.EnableUITest('client2012')
def isChromeTranslateEnabled(self, incognito=False):
dir = os.path.dirname(os.path.abspath(__file__))
output = self.RunWebDriverTest(
'client2012', os.path.join(dir, 'translate_enabled_webdriver_test.py'),
['--incognito'] if incognito else [])
output = self.RunUITest(
'client2012',
os.path.join(dir, 'translate_enabled_webdriver_test.py'),
args=['--incognito'] if incognito else [])
return "TRUE" in output
@test
......
......@@ -5,23 +5,13 @@
import time
import test_util
from absl import app, flags
from pywinauto.application import Application
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# A URL that is in a different language than our Chrome language. It should be
# a site stable enough for us to rely on for our tests, and have a somewhat
# static string we can use to tell if translate worked (see below).
# A URL that is in a different language than our Chrome language.
URL = "https://zh.wikipedia.org/wiki/Chromium"
# The magic string to look for on the translated page.
# This string must NOT be on the original page.
MAGIC_STRING_ENGLISH = "Wikipedia, the free encyclopedia"
# We automatically accept Translate prompts from Chinese (Simpl.) to English.
# Ideally we would detect the Translate prompt and return TRUE/FALSE based on
# that, but webdriver doesn't support this AFAIK.
PREFS = {"translate_whitelists": {"zh-CN": "en"}}
FLAGS = flags.FLAGS
flags.DEFINE_bool('incognito', False,
......@@ -29,15 +19,21 @@ flags.DEFINE_bool('incognito', False,
def main(argv):
driver = test_util.create_chrome_webdriver(
incognito=FLAGS.incognito, prefs=PREFS)
driver = test_util.create_chrome_webdriver(incognito=FLAGS.incognito)
driver.get(URL)
time.sleep(10)
output = driver.find_element_by_css_selector('html').text.encode('utf-8')
app = Application(backend="uia")
app.connect(title_re='.*Chrome|.*Chromium')
translatePopupVisible = False
for desc in app.top_window().descendants():
if 'Translate this page?' in desc.window_text():
translatePopupVisible = True
break
if MAGIC_STRING_ENGLISH in output:
if translatePopupVisible:
print "TRUE"
else:
print "FALSE"
......
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