testing/firefox-ui/tests/puppeteer/test_l10n.py
author Nicholas Nethercote <nnethercote@mozilla.com>
Wed, 27 Apr 2016 14:16:50 +1000
changeset 336387 3d67e45f994a3ae1ae43479c32c2ed63bbf1a7c8
parent 329944 7e807a003ea4c3a4680f2f0c7bbab8883a1a4db7
child 360370 4b5a9f8b52d493e4b867b666433fe2aae254c100
permissions -rw-r--r--
Bug 1267550 (part 2) - Rename MOZ_WARN_UNUSED_RESULT as MOZ_MUST_USE. r=froydnj. It's an annotation that is used a lot, and should be used even more, so a shorter name is better. MozReview-Commit-ID: 1VS4Dney4WX

# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.

from marionette_driver import By
from marionette_driver.errors import MarionetteException

from firefox_puppeteer.api.l10n import L10n
from firefox_ui_harness.testcases import FirefoxTestCase


class TestL10n(FirefoxTestCase):

    def setUp(self):
        FirefoxTestCase.setUp(self)
        self.l10n = L10n(lambda: self.marionette)

    def tearDown(self):
        FirefoxTestCase.tearDown(self)

    def test_dtd_entity_chrome(self):
        dtds = ['chrome://global/locale/filepicker.dtd',
                'chrome://browser/locale/baseMenuOverlay.dtd']

        value = self.l10n.get_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')

    def test_dtd_entity_content(self):
        dtds = ['chrome://global/locale/filepicker.dtd',
                'chrome://global/locale/aboutSupport.dtd']

        value = self.l10n.get_entity(dtds, 'aboutSupport.pageTitle')

        self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
        self.marionette.navigate('about:support')

        elm = self.marionette.find_element(By.TAG_NAME, 'title')
        self.assertEqual(value, elm.text)

    def test_properties(self):
        properties = ['chrome://global/locale/filepicker.properties',
                      'chrome://global/locale/findbar.properties']

        # TODO: Find a way to verify the retrieved translated string
        value = self.l10n.get_property(properties, 'NotFound')
        self.assertNotEqual(value, '')

        self.assertRaises(MarionetteException, self.l10n.get_property, properties, 'notExistent')