mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 17:25:36 +00:00
Bug 1316984 - Update Puppeteer to use new localization module of Marionette. r=maja_zf
MozReview-Commit-ID: 5BZDyWGUz0a --HG-- extra : rebase_source : d3d067dba7f54755df7f797063fbf4fab8ce2b2a
This commit is contained in:
parent
586d376932
commit
5630cfb170
@ -16,7 +16,7 @@ class TestBrowserWindowShortcuts(PuppeteerMixin, MarionetteTestCase):
|
||||
|
||||
# TODO: To be moved to the upcoming add-ons library
|
||||
def opener(tab):
|
||||
tab.window.send_shortcut(tab.window.get_entity('addons.commandkey'),
|
||||
tab.window.send_shortcut(tab.window.localize_entity('addons.commandkey'),
|
||||
accel=True, shift=True)
|
||||
self.browser.tabbar.open_tab(opener)
|
||||
|
||||
@ -41,7 +41,8 @@ class TestBrowserWindowShortcuts(PuppeteerMixin, MarionetteTestCase):
|
||||
key = 'searchFocusUnix.commandkey'
|
||||
else:
|
||||
key = 'searchFocus.commandkey'
|
||||
self.browser.send_shortcut(self.browser.get_entity(key), accel=True)
|
||||
self.browser.send_shortcut(self.browser.localize_entity(key),
|
||||
accel=True)
|
||||
|
||||
# TODO: Check that the right input box is focused
|
||||
# Located below searchbar as class="autocomplete-textbox textbox-input"
|
||||
|
@ -33,7 +33,7 @@ class TestAboutPrivateBrowsing(PuppeteerMixin, MarionetteTestCase):
|
||||
|
||||
status_node = self.marionette.find_element(By.CSS_SELECTOR, 'p.showNormal')
|
||||
self.assertEqual(status_node.text,
|
||||
self.browser.get_entity('aboutPrivateBrowsing.notPrivate'),
|
||||
self.browser.localize_entity('aboutPrivateBrowsing.notPrivate'),
|
||||
'Status text indicates we are not in private browsing mode')
|
||||
|
||||
def window_opener(win):
|
||||
|
@ -61,7 +61,7 @@ class TestDVCertificate(PuppeteerMixin, MarionetteTestCase):
|
||||
insecure_label = self.identity_popup.view.security.insecure_connection_label
|
||||
self.assertEqual(insecure_label.value_of_css_property('display'), 'none')
|
||||
|
||||
verifier_label = self.browser.get_property('identity.identified.verifier')
|
||||
verifier_label = self.browser.localize_property('identity.identified.verifier')
|
||||
self.assertEqual(self.identity_popup.view.security.verifier.get_attribute('textContent'),
|
||||
verifier_label.replace("%S", cert['issuerOrganization']))
|
||||
|
||||
@ -77,7 +77,7 @@ class TestDVCertificate(PuppeteerMixin, MarionetteTestCase):
|
||||
cert['commonName'])
|
||||
|
||||
self.assertEqual(deck.security.owner.get_attribute('value'),
|
||||
page_info_window.get_property('securityNoOwner'))
|
||||
page_info_window.localize_property('securityNoOwner'))
|
||||
|
||||
self.assertEqual(deck.security.verifier.get_attribute('value'),
|
||||
cert['issuerOrganization'])
|
||||
|
@ -79,14 +79,14 @@ class TestEVCertificate(PuppeteerMixin, MarionetteTestCase):
|
||||
# Check the owner location string
|
||||
# More information:
|
||||
# hg.mozilla.org/mozilla-central/file/eab4a81e4457/browser/base/content/browser.js#l7012
|
||||
location = self.browser.get_property('identity.identified.state_and_country')
|
||||
location = self.browser.localize_property('identity.identified.state_and_country')
|
||||
location = location.replace('%S', address['state'], 1).replace('%S', address['country'])
|
||||
location = address['city'] + '\n' + location
|
||||
self.assertEqual(security_view.owner_location.get_attribute('textContent'),
|
||||
location)
|
||||
|
||||
# Check the verifier
|
||||
l10n_verifier = self.browser.get_property('identity.identified.verifier')
|
||||
l10n_verifier = self.browser.localize_property('identity.identified.verifier')
|
||||
l10n_verifier = l10n_verifier.replace('%S', cert['issuerOrganization'])
|
||||
self.assertEqual(security_view.verifier.get_attribute('textContent'),
|
||||
l10n_verifier)
|
||||
|
@ -74,8 +74,8 @@ class TestNoCertificate(PuppeteerMixin, MarionetteTestCase):
|
||||
|
||||
# Check the owner label equals localized 'securityNoOwner'
|
||||
self.assertEqual(page_info.deck.security.owner.get_attribute('value'),
|
||||
page_info.get_property('securityNoOwner'))
|
||||
page_info.localize_property('securityNoOwner'))
|
||||
|
||||
# Check the verifier label equals localized 'notset'
|
||||
self.assertEqual(page_info.deck.security.verifier.get_attribute('value'),
|
||||
page_info.get_property('notset'))
|
||||
page_info.localize_property('notset'))
|
||||
|
@ -107,7 +107,7 @@ class TestSafeBrowsingNotificationBar(PuppeteerMixin, MarionetteTestCase):
|
||||
def check_not_badware_button(self, button_property, report_page):
|
||||
with self.marionette.using_context('chrome'):
|
||||
# TODO: update to use safe browsing notification bar class when bug 1139544 lands
|
||||
label = self.browser.get_property(button_property)
|
||||
label = self.browser.localize_property(button_property)
|
||||
button = (self.marionette.find_element(By.ID, 'content')
|
||||
.find_element('anon attribute', {'label': label}))
|
||||
|
||||
@ -124,7 +124,7 @@ class TestSafeBrowsingNotificationBar(PuppeteerMixin, MarionetteTestCase):
|
||||
def check_get_me_out_of_here_button(self):
|
||||
with self.marionette.using_context('chrome'):
|
||||
# TODO: update to use safe browsing notification bar class when bug 1139544 lands
|
||||
label = self.browser.get_property('safebrowsing.getMeOutOfHereButton.label')
|
||||
label = self.browser.localize_property('safebrowsing.getMeOutOfHereButton.label')
|
||||
button = (self.marionette.find_element(By.ID, 'content')
|
||||
.find_element('anon attribute', {'label': label}))
|
||||
button.click()
|
||||
|
@ -42,7 +42,7 @@ class TestSSLDisabledErrorPage(PuppeteerMixin, MarionetteTestCase):
|
||||
|
||||
# Verify "Secure Connection Failed" error page title
|
||||
title = self.marionette.find_element(By.CLASS_NAME, 'title-text')
|
||||
nss_failure2title = self.browser.get_entity('nssFailure2.title')
|
||||
nss_failure2title = self.browser.localize_entity('nssFailure2.title')
|
||||
self.assertEquals(title.get_property('textContent'), nss_failure2title)
|
||||
|
||||
# Verify the error message is correct
|
||||
|
@ -112,7 +112,7 @@ class TestSSLStatusAfterRestart(PuppeteerMixin, MarionetteTestCase):
|
||||
if identity != '':
|
||||
owner = cert['organization']
|
||||
else:
|
||||
owner = page_info.get_property('securityNoOwner')
|
||||
owner = page_info.localize_property('securityNoOwner')
|
||||
|
||||
self.assertEqual(page_info.deck.security.owner.get_attribute('value'), owner,
|
||||
'Expected owner label found for ' + url)
|
||||
|
@ -38,7 +38,7 @@ class TestSubmitUnencryptedInfoWarning(PuppeteerMixin, MarionetteTestCase):
|
||||
button.click()
|
||||
|
||||
# Get the expected warning text and replace its two instances of "##" with "\n\n".
|
||||
message = self.browser.get_property('formPostSecureToInsecureWarning.message')
|
||||
message = self.browser.localize_property('formPostSecureToInsecureWarning.message')
|
||||
message = message.replace('##', '\n\n')
|
||||
|
||||
# Wait for the warning, verify the expected text matches warning, accept the warning
|
||||
|
@ -5,7 +5,7 @@
|
||||
from firefox_puppeteer import PuppeteerMixin
|
||||
from firefox_puppeteer.api.l10n import L10n
|
||||
from marionette_driver import By
|
||||
from marionette_driver.errors import MarionetteException
|
||||
from marionette_driver.errors import NoSuchElementException
|
||||
from marionette_harness import MarionetteTestCase
|
||||
|
||||
|
||||
@ -20,17 +20,18 @@ class TestL10n(PuppeteerMixin, MarionetteTestCase):
|
||||
dtds = ['chrome://global/locale/about.dtd',
|
||||
'chrome://browser/locale/baseMenuOverlay.dtd']
|
||||
|
||||
value = self.l10n.get_entity(dtds, 'helpSafeMode.label')
|
||||
value = self.l10n.localize_entity(dtds, 'helpSafeMode.label')
|
||||
elm = self.marionette.find_element(By.ID, 'helpSafeMode')
|
||||
self.assertEqual(value, elm.get_attribute('label'))
|
||||
|
||||
self.assertRaises(MarionetteException, self.l10n.get_entity, dtds, 'notExistent')
|
||||
self.assertRaises(NoSuchElementException,
|
||||
self.l10n.localize_entity, dtds, 'notExistent')
|
||||
|
||||
def test_dtd_entity_content(self):
|
||||
dtds = ['chrome://global/locale/about.dtd',
|
||||
'chrome://global/locale/aboutSupport.dtd']
|
||||
|
||||
value = self.l10n.get_entity(dtds, 'aboutSupport.pageTitle')
|
||||
value = self.l10n.localize_entity(dtds, 'aboutSupport.pageTitle')
|
||||
|
||||
self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
|
||||
self.marionette.navigate('about:support')
|
||||
@ -43,7 +44,8 @@ class TestL10n(PuppeteerMixin, MarionetteTestCase):
|
||||
'chrome://global/locale/findbar.properties']
|
||||
|
||||
# TODO: Find a way to verify the retrieved translated string
|
||||
value = self.l10n.get_property(properties, 'NotFound')
|
||||
value = self.l10n.localize_property(properties, 'NotFound')
|
||||
self.assertNotEqual(value, '')
|
||||
|
||||
self.assertRaises(MarionetteException, self.l10n.get_property, properties, 'notExistent')
|
||||
self.assertRaises(NoSuchElementException,
|
||||
self.l10n.localize_property, properties, 'notExistent')
|
||||
|
@ -82,7 +82,8 @@ class TestPageInfoWindow(PuppeteerMixin, MarionetteTestCase):
|
||||
def test_close_window(self):
|
||||
"""Test various closing strategies."""
|
||||
def closer(win):
|
||||
win.send_shortcut(win.get_entity('closeWindow.key'), accel=True)
|
||||
win.send_shortcut(win.localize_entity('closeWindow.key'),
|
||||
accel=True)
|
||||
|
||||
# Close a tab by each trigger method
|
||||
close_strategies = ('menu',
|
||||
|
@ -2,16 +2,44 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
# -----------------
|
||||
# DEPRECATED module
|
||||
# -----------------
|
||||
# Replace its use in tests when Firefox 45 ESR support ends with
|
||||
# marionette_driver.localization.L10n
|
||||
|
||||
import copy
|
||||
|
||||
from marionette_driver.errors import MarionetteException
|
||||
from marionette_driver.errors import (
|
||||
NoSuchElementException,
|
||||
UnknownCommandException,
|
||||
)
|
||||
from marionette_driver.localization import L10n as L10nMarionette
|
||||
|
||||
from firefox_puppeteer.base import BaseLib
|
||||
|
||||
|
||||
class L10n(BaseLib):
|
||||
"""An API which allows Marionette to handle localized content.
|
||||
|
||||
def get_entity(self, dtd_urls, entity_id):
|
||||
.. deprecated:: 52.2.0
|
||||
Use the localization module from :py:mod:`marionette_driver` instead.
|
||||
|
||||
The `localization`_ of UI elements in Gecko based applications is done via
|
||||
entities and properties. For static values entities are used, which are located
|
||||
in .dtd files. Whereby for dynamically updated content the values come from
|
||||
.property files. Both types of elements can be identifed via a unique id,
|
||||
and the translated content retrieved.
|
||||
|
||||
.. _localization: https://mzl.la/2eUMjyF
|
||||
"""
|
||||
|
||||
def __init__(self, marionette):
|
||||
super(L10n, self).__init__(marionette)
|
||||
|
||||
self._l10nMarionette = L10nMarionette(self.marionette)
|
||||
|
||||
def localize_entity(self, dtd_urls, entity_id):
|
||||
"""Returns the localized string for the specified DTD entity id.
|
||||
|
||||
To find the entity all given DTD files will be searched for the id.
|
||||
@ -21,39 +49,42 @@ class L10n(BaseLib):
|
||||
|
||||
:returns: The localized string for the requested entity.
|
||||
|
||||
:raises MarionetteException: When entity id is not found in dtd_urls.
|
||||
:raises NoSuchElementException: When entity id is not found in dtd_urls.
|
||||
"""
|
||||
# Add xhtml11.dtd to prevent missing entity errors with XHTML files
|
||||
dtds = copy.copy(dtd_urls)
|
||||
dtds.append("resource:///res/dtd/xhtml11.dtd")
|
||||
try:
|
||||
return self._l10nMarionette.localize_entity(dtd_urls, entity_id)
|
||||
except UnknownCommandException:
|
||||
dtds = copy.copy(dtd_urls)
|
||||
dtds.append("resource:///res/dtd/xhtml11.dtd")
|
||||
|
||||
dtd_refs = ''
|
||||
for index, item in enumerate(dtds):
|
||||
dtd_id = 'dtd_%s' % index
|
||||
dtd_refs += '<!ENTITY %% %s SYSTEM "%s">%%%s;' % \
|
||||
(dtd_id, item, dtd_id)
|
||||
dtd_refs = ''
|
||||
for index, item in enumerate(dtds):
|
||||
dtd_id = 'dtd_%s' % index
|
||||
dtd_refs += '<!ENTITY %% %s SYSTEM "%s">%%%s;' % \
|
||||
(dtd_id, item, dtd_id)
|
||||
|
||||
contents = """<?xml version="1.0"?>
|
||||
<!DOCTYPE elem [%s]>
|
||||
contents = """<?xml version="1.0"?>
|
||||
<!DOCTYPE elem [%s]>
|
||||
|
||||
<elem id="entity">&%s;</elem>""" % (dtd_refs, entity_id)
|
||||
<elem id="entity">&%s;</elem>""" % (dtd_refs, entity_id)
|
||||
|
||||
with self.marionette.using_context('chrome'):
|
||||
value = self.marionette.execute_script("""
|
||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMParser);
|
||||
var doc = parser.parseFromString(arguments[0], "text/xml");
|
||||
var node = doc.querySelector("elem[id='entity']");
|
||||
with self.marionette.using_context('chrome'):
|
||||
value = self.marionette.execute_script("""
|
||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMParser);
|
||||
var doc = parser.parseFromString(arguments[0], "text/xml");
|
||||
var node = doc.querySelector("elem[id='entity']");
|
||||
|
||||
return node ? node.textContent : null;
|
||||
""", script_args=[contents])
|
||||
return node ? node.textContent : null;
|
||||
""", script_args=[contents])
|
||||
|
||||
if not value:
|
||||
raise MarionetteException('DTD Entity not found: %s' % entity_id)
|
||||
if not value:
|
||||
raise NoSuchElementException('DTD Entity not found: %s' % entity_id)
|
||||
|
||||
return value
|
||||
return value
|
||||
|
||||
def get_property(self, property_urls, property_id):
|
||||
def localize_property(self, property_urls, property_id):
|
||||
"""Returns the localized string for the specified property id.
|
||||
|
||||
To find the property all given property files will be searched for
|
||||
@ -64,29 +95,31 @@ class L10n(BaseLib):
|
||||
|
||||
:returns: The localized string for the requested entity.
|
||||
|
||||
:raises MarionetteException: When property id is not found in
|
||||
:raises NoSuchElementException: When property id is not found in
|
||||
property_urls.
|
||||
"""
|
||||
try:
|
||||
return self._l10nMarionette.localize_property(property_urls, property_id)
|
||||
except UnknownCommandException:
|
||||
with self.marionette.using_context('chrome'):
|
||||
value = self.marionette.execute_script("""
|
||||
let property = null;
|
||||
let property_id = arguments[1];
|
||||
|
||||
with self.marionette.using_context('chrome'):
|
||||
value = self.marionette.execute_script("""
|
||||
let property = null;
|
||||
let property_id = arguments[1];
|
||||
arguments[0].some(aUrl => {
|
||||
let bundle = Services.strings.createBundle(aUrl);
|
||||
|
||||
arguments[0].some(aUrl => {
|
||||
let bundle = Services.strings.createBundle(aUrl);
|
||||
try {
|
||||
property = bundle.GetStringFromName(property_id);
|
||||
return true;
|
||||
}
|
||||
catch (ex) { }
|
||||
});
|
||||
|
||||
try {
|
||||
property = bundle.GetStringFromName(property_id);
|
||||
return true;
|
||||
}
|
||||
catch (ex) { }
|
||||
});
|
||||
return property;
|
||||
""", script_args=[property_urls, property_id])
|
||||
|
||||
return property;
|
||||
""", script_args=[property_urls, property_id])
|
||||
if not value:
|
||||
raise NoSuchElementException('Property not found: %s' % property_id)
|
||||
|
||||
if not value:
|
||||
raise MarionetteException('Property not found: %s' % property_id)
|
||||
|
||||
return value
|
||||
return value
|
||||
|
@ -133,7 +133,8 @@ class TabBar(UIBaseLib):
|
||||
self.window.menubar.select_by_id('file-menu',
|
||||
'menu_newNavigatorTab')
|
||||
elif trigger == 'shortcut':
|
||||
self.window.send_shortcut(self.window.get_entity('tabCmd.commandkey'), accel=True)
|
||||
self.window.send_shortcut(self.window.localize_entity('tabCmd.commandkey'),
|
||||
accel=True)
|
||||
# elif - need to add other cases
|
||||
else:
|
||||
raise ValueError('Unknown opening method: "%s"' % trigger)
|
||||
@ -312,7 +313,8 @@ class Tab(UIBaseLib):
|
||||
elif trigger == 'menu':
|
||||
self.window.menubar.select_by_id('file-menu', 'menu_close')
|
||||
elif trigger == 'shortcut':
|
||||
self.window.send_shortcut(self.window.get_entity('closeCmd.key'), accel=True)
|
||||
self.window.send_shortcut(self.window.localize_entity('closeCmd.key'),
|
||||
accel=True)
|
||||
else:
|
||||
raise ValueError('Unknown closing method: "%s"' % trigger)
|
||||
|
||||
|
@ -149,7 +149,7 @@ class LocationBar(UIBaseLib):
|
||||
if event == 'click':
|
||||
self.urlbar.click()
|
||||
elif event == 'shortcut':
|
||||
cmd_key = self.window.get_entity('openCmd.commandkey')
|
||||
cmd_key = self.window.localize_entity('openCmd.commandkey')
|
||||
self.window.send_shortcut(cmd_key, accel=True)
|
||||
else:
|
||||
raise ValueError("An unknown event type was passed: %s" % event)
|
||||
@ -263,7 +263,7 @@ class LocationBar(UIBaseLib):
|
||||
if trigger == 'button':
|
||||
self.reload_button.click()
|
||||
elif trigger == 'shortcut':
|
||||
cmd_key = self.window.get_entity('reloadCmd.commandkey')
|
||||
cmd_key = self.window.localize_entity('reloadCmd.commandkey')
|
||||
self.window.send_shortcut(cmd_key)
|
||||
elif trigger == 'shortcut2':
|
||||
self.window.send_shortcut(keys.Keys.F5)
|
||||
@ -604,7 +604,7 @@ class IdentityPopupSecurityView(IdentityPopupView):
|
||||
|
||||
:returns: Reference to the identity-popup more info button.
|
||||
"""
|
||||
label = self.window.get_entity('identity.moreInfoLinkText2')
|
||||
label = self.window.localize_entity('identity.moreInfoLinkText2')
|
||||
|
||||
return self.element.find_element(By.CSS_SELECTOR, u'button[label="{}"]'.format(label))
|
||||
|
||||
|
@ -161,7 +161,7 @@ class BrowserWindow(BaseWindow):
|
||||
elif trigger == 'menu':
|
||||
self.menubar.select_by_id('file-menu', 'menu_closeWindow')
|
||||
elif trigger == 'shortcut':
|
||||
win.send_shortcut(win.get_entity('closeCmd.key'),
|
||||
win.send_shortcut(win.localize_entity('closeCmd.key'),
|
||||
accel=True, shift=True)
|
||||
else:
|
||||
raise ValueError('Unknown closing method: "%s"' % trigger)
|
||||
@ -200,7 +200,7 @@ class BrowserWindow(BaseWindow):
|
||||
self.menubar.select_by_id('file-menu', menu_id)
|
||||
elif trigger == 'shortcut':
|
||||
cmd_key = 'privateBrowsingCmd.commandkey' if is_private else 'newNavigatorCmd.key'
|
||||
win.send_shortcut(win.get_entity(cmd_key),
|
||||
win.send_shortcut(win.localize_entity(cmd_key),
|
||||
accel=True, shift=is_private)
|
||||
else:
|
||||
raise ValueError('Unknown opening method: "%s"' % trigger)
|
||||
@ -245,7 +245,7 @@ class BrowserWindow(BaseWindow):
|
||||
elif trigger == 'shortcut':
|
||||
if win.marionette.session_capabilities['platformName'] == 'windows_nt':
|
||||
raise ValueError('Page info shortcut not available on Windows.')
|
||||
win.send_shortcut(win.get_entity('pageInfoCmd.commandkey'),
|
||||
win.send_shortcut(win.localize_entity('pageInfoCmd.commandkey'),
|
||||
accel=True)
|
||||
elif trigger == 'context_menu':
|
||||
# TODO: Add once we can do right clicks
|
||||
|
@ -50,7 +50,7 @@ class PageInfoWindow(BaseWindow):
|
||||
elif trigger == 'menu':
|
||||
self.menubar.select_by_id('file-menu', 'menu_close')
|
||||
elif trigger == 'shortcut':
|
||||
win.send_shortcut(win.get_entity('closeWindow.key'),
|
||||
win.send_shortcut(win.localize_entity('closeWindow.key'),
|
||||
accel=True)
|
||||
else:
|
||||
raise ValueError('Unknown closing method: "%s"' % trigger)
|
||||
|
@ -313,7 +313,7 @@ class BaseWindow(BaseLib):
|
||||
"""Sets the focus to the current chrome window."""
|
||||
return self._windows.focus(self.handle)
|
||||
|
||||
def get_entity(self, entity_id):
|
||||
def localize_entity(self, entity_id):
|
||||
"""Returns the localized string for the specified DTD entity id.
|
||||
|
||||
:param entity_id: The id to retrieve the value from.
|
||||
@ -322,9 +322,9 @@ class BaseWindow(BaseLib):
|
||||
|
||||
:raises MarionetteException: When entity id is not found.
|
||||
"""
|
||||
return self._l10n.get_entity(self.dtds, entity_id)
|
||||
return self._l10n.localize_entity(self.dtds, entity_id)
|
||||
|
||||
def get_property(self, property_id):
|
||||
def localize_property(self, property_id):
|
||||
"""Returns the localized string for the specified property id.
|
||||
|
||||
:param property_id: The id to retrieve the value from.
|
||||
@ -333,7 +333,7 @@ class BaseWindow(BaseLib):
|
||||
|
||||
:raises MarionetteException: When property id is not found.
|
||||
"""
|
||||
return self._l10n.get_property(self.properties, property_id)
|
||||
return self._l10n.localize_property(self.properties, property_id)
|
||||
|
||||
def open_window(self, callback=None, expected_window_class=None, focus=True):
|
||||
"""Opens a new top-level chrome window.
|
||||
|
Loading…
Reference in New Issue
Block a user