Bug 1331037 - Fix failures in test_localization.py for Fennec. r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Wed, 18 Jan 2017 09:47:58 +0100
changeset 353662 ed6e5d97950a01e80679a17e7abd4a3ed28e8f6b
parent 353661 ec7bc68407bc15224201ece596ae0a0ec4b53e6c
child 353663 6a4a8a59c816e7732bc8840a7207ef291328e2c5
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1331037
milestone52.0a2
Bug 1331037 - Fix failures in test_localization.py for Fennec. r=ato, a=test-only Fennec uses a different set of DTD and properties files. As such the current entity and property names do not work. To fix the tests a DTD and properties file gets added for the test_dialog.xul example dialog, which means that we have identical resources for every supported application. MozReview-Commit-ID: LXDeADHlxja
testing/marionette/chrome/test_dialog.dtd
testing/marionette/chrome/test_dialog.properties
testing/marionette/chrome/test_dialog.xul
testing/marionette/harness/marionette_harness/tests/unit/test_localization.py
testing/marionette/jar.mn
testing/marionette/l10n.js
new file mode 100644
--- /dev/null
+++ b/testing/marionette/chrome/test_dialog.dtd
@@ -0,0 +1,7 @@
+<!-- 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/. -->
+
+<!ENTITY testDialog.title "Test Dialog">
+
+<!ENTITY settings.label "Settings">
new file mode 100644
--- /dev/null
+++ b/testing/marionette/chrome/test_dialog.properties
@@ -0,0 +1,7 @@
+# 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/.
+
+testDialog.title=Test Dialog
+
+settings.label=Settings
--- a/testing/marionette/chrome/test_dialog.xul
+++ b/testing/marionette/chrome/test_dialog.xul
@@ -1,23 +1,28 @@
 <?xml version="1.0"?>
 <!-- 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/. -->
 
+<!DOCTYPE testdialog [
+<!ENTITY % dialogDTD SYSTEM "chrome://marionette/content/test_dialog.dtd" >
+%dialogDTD;
+]>
+
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
 
 <dialog id="testDialog"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        title="Test Dialog"
+        title="&testDialog.title;"
         buttons="accept,cancel">
 
   <vbox flex="1" style="min-width: 300px; min-height: 500px;">
-    <label>Settings</label>
+    <label>&settings.label;</label>
     <separator class="thin"/>
     <richlistbox id="test-list" flex="1">
         <richlistitem id="item-choose" orient="horizontal" selected="true">
             <label id="choose-label" value="First Entry" flex="1"/>
             <button id="choose-button" oncommand="" label="Choose..."/>
         </richlistitem>
     </richlistbox>
     <separator class="thin"/>
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_localization.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_localization.py
@@ -1,61 +1,51 @@
 # 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 InvalidArgumentException, NoSuchElementException
+from marionette_driver.errors import (
+    InvalidArgumentException,
+    NoSuchElementException,
+    UnknownException
+)
 from marionette_driver.localization import L10n
 
 from marionette_harness import MarionetteTestCase
 
 
 class TestL10n(MarionetteTestCase):
 
     def setUp(self):
         super(TestL10n, self).setUp()
 
         self.l10n = L10n(self.marionette)
 
-    def test_localize_entity_chrome(self):
-        dtds = ['chrome://global/locale/about.dtd',
-                'chrome://browser/locale/baseMenuOverlay.dtd']
-
-        with self.marionette.using_context('chrome'):
-            value = self.l10n.localize_entity(dtds, 'helpSafeMode.label')
-            element = self.marionette.find_element(By.ID, 'helpSafeMode')
-            self.assertEqual(value, element.get_attribute('label'))
+    def test_localize_entity(self):
+        dtds = ['chrome://marionette/content/test_dialog.dtd']
+        value = self.l10n.localize_entity(dtds, 'testDialog.title')
 
-    def test_localize_entity_content(self):
-        dtds = ['chrome://global/locale/about.dtd',
-                'chrome://global/locale/aboutSupport.dtd']
-
-        value = self.l10n.localize_entity(dtds, 'aboutSupport.pageTitle')
-        self.marionette.navigate('about:support')
-        element = self.marionette.find_element(By.TAG_NAME, 'title')
-        self.assertEqual(value, element.text)
+        self.assertEqual(value, 'Test Dialog')
 
     def test_localize_entity_invalid_arguments(self):
-        dtds = ['chrome://global/locale/about.dtd']
+        dtds = ['chrome://marionette/content/test_dialog.dtd']
 
         self.assertRaises(NoSuchElementException,
                           self.l10n.localize_entity, dtds, 'notExistent')
         self.assertRaises(InvalidArgumentException,
                           self.l10n.localize_entity, dtds[0], 'notExistent')
         self.assertRaises(InvalidArgumentException,
                           self.l10n.localize_entity, dtds, True)
 
     def test_localize_property(self):
-        properties = ['chrome://global/locale/filepicker.properties',
-                      'chrome://global/locale/findbar.properties']
+        properties = ['chrome://marionette/content/test_dialog.properties']
 
-        # TODO: Find a way to verify the retrieved localized value
-        value = self.l10n.localize_property(properties, 'CaseSensitive')
-        self.assertNotEqual(value, '')
+        value = self.l10n.localize_property(properties, 'testDialog.title')
+        self.assertEqual(value, 'Test Dialog')
 
         self.assertRaises(NoSuchElementException,
                           self.l10n.localize_property, properties, 'notExistent')
 
     def test_localize_property_invalid_arguments(self):
         properties = ['chrome://global/locale/filepicker.properties']
 
         self.assertRaises(NoSuchElementException,
--- a/testing/marionette/jar.mn
+++ b/testing/marionette/jar.mn
@@ -30,12 +30,14 @@ marionette.jar:
   content/navigate.js (navigate.js)
   content/l10n.js (l10n.js)
   content/assert.js (assert.js)
   content/addon.js (addon.js)
   content/session.js (session.js)
 #ifdef ENABLE_TESTS
   content/test.xul (chrome/test.xul)
   content/test2.xul (chrome/test2.xul)
+  content/test_dialog.dtd (chrome/test_dialog.dtd)
+  content/test_dialog.properties (chrome/test_dialog.properties)
   content/test_dialog.xul (chrome/test_dialog.xul)
   content/test_nested_iframe.xul (chrome/test_nested_iframe.xul)
   content/test_anonymous_content.xul (chrome/test_anonymous_content.xul)
 #endif
--- a/testing/marionette/l10n.js
+++ b/testing/marionette/l10n.js
@@ -38,19 +38,16 @@ this.l10n = {};
  *     Array of .dtd URLs.
  * @param {string} id
  *     The ID of the entity to retrieve the localized string for.
  *
  * @return {string}
  *     The localized string for the requested entity.
  */
 l10n.localizeEntity = function (urls, id) {
-  // Add xhtml11.dtd to prevent missing entity errors with XHTML files
-  urls.push("resource:///res/dtd/xhtml11.dtd");
-
   // Build a string which contains all possible entity locations
   let locations = [];
   urls.forEach((url, index) => {
     locations.push(`<!ENTITY % dtd_${index} SYSTEM "${url}">%dtd_${index};`);
   })
 
   // Use the DOM parser to resolve the entity and extract its real value
   let header = `<?xml version="1.0"?><!DOCTYPE elem [${locations.join("")}]>`;