Bug 1204147 - Prevent content preferences being written when they shouldn't (test). r=roc
authorJorg K <mozilla@jorgk.com>
Mon, 14 Sep 2015 02:35:00 +0200
changeset 294917 361c6d3c4678973ecf0fec2ae94769210d160c44
parent 294916 a3994f4ac9df331302de2a4a7fb421ae8bbe2024
child 294918 d60ded82663580e8d06ab904a3b673ee7f0af117
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1204147
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1204147 - Prevent content preferences being written when they shouldn't (test). r=roc
editor/composer/test/bug1204147_subframe.html
editor/composer/test/bug1204147_subframe2.html
editor/composer/test/chrome.ini
editor/composer/test/mochitest.ini
editor/composer/test/test_bug1204147.html
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/bug1204147_subframe.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<textarea id="en-GB" lang="en-GB">element en-GB</textarea>
+<textarea id="en-US" lang="testing-XX">element should default to en-US</textarea>
+
+<div id="trouble-maker" contenteditable>the presence of this div triggers the faulty code path</div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/bug1204147_subframe2.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<textarea id="en-GB" lang="en-GB">element en-GB</textarea>
+<textarea id="en-US" lang="testing-XX">element should default to en-US</textarea>
+</body>
+</html>
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -1,9 +1,10 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 
 [test_async_UpdateCurrentDictionary.html]
 [test_bug338427.html]
 [test_bug434998.xul]
 [test_bug678842.html]
 [test_bug717433.html]
+[test_bug1204147.html]
 [test_bug1200533.html]
--- a/editor/composer/test/mochitest.ini
+++ b/editor/composer/test/mochitest.ini
@@ -1,14 +1,16 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || buildapp == 'mulet'
 support-files =
   bug678842_subframe.html
   bug717433_subframe.html
   bug1200533_subframe.html
+  bug1204147_subframe.html
+  bug1204147_subframe2.html
   en-GB/en_GB.dic
   en-GB/en_GB.aff
   en-AU/en_AU.dic
   en-AU/en_AU.aff
   de-DE/de_DE.dic
   de-DE/de_DE.aff
 
 [test_bug348497.html]
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/test_bug1204147.html
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1204147
+-->
+<head>
+  <title>Test for Bug 1204147</title>
+  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1204147">Mozilla Bug 1204147</a>
+<p id="display"></p>
+<iframe id="content"></iframe>
+</div>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 1204147 **/
+SimpleTest.waitForExplicitFinish();
+var content = document.getElementById('content');
+// Load a subframe containing an editor with using "en-GB". At first
+// load, it will set the dictionary to "en-GB". The bug was that a content preference
+// was also created. At second load, we check the dictionary for another element,
+// one that should use "en-US". With the bug corrected, we get "en-US", before
+// we got "en-GB" from the content preference.
+
+var firstLoad = true;
+var en_GB;
+var hunspell;
+
+var loadListener = function(evt) {
+  Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
+
+  if (firstLoad) {
+    var dir = Components.classes["@mozilla.org/file/directory_service;1"]
+                        .getService(Components.interfaces.nsIProperties)
+                        .get("CurWorkD", Components.interfaces.nsIFile);
+    dir.append("tests");
+    dir.append("editor");
+    dir.append("composer");
+    dir.append("test");
+
+    hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
+                         .getService(Components.interfaces.mozISpellCheckingEngine);
+
+    // Install en-GB dictionary.
+    en_GB = dir.clone();
+    en_GB.append("en-GB");
+    is(en_GB.exists(), true, "true expected (en-GB directory should exist)");
+    hunspell.addDirectory(en_GB);
+  }
+
+  var doc = evt.target.contentDocument;
+  var elem;
+  if (firstLoad) {
+    elem = doc.getElementById('en-GB');
+  } else {
+    elem = doc.getElementById('en-US');
+  }
+
+  var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
+  editor.setSpellcheckUserOverride(true);
+  var inlineSpellChecker = editor.getInlineSpellChecker(true);
+
+  onSpellCheck(elem, function () {
+    var spellchecker = inlineSpellChecker.spellChecker;
+    try {
+      var currentDictonary = spellchecker.GetCurrentDictionary();
+    } catch(e) {}
+
+    if (firstLoad) {
+      firstLoad = false;
+
+       // First time around, the element's language should be used.
+      is (currentDictonary, "en-GB", "unexpected lang " + currentDictonary + " instead of en-GB");
+
+      // Note that on second load, we load a different page, which does NOT have the trouble-causing
+      // contenteditable in it. Sadly, loading the same page with the trouble-maker in it
+      // doesn't allow the retrieval of the spell check dictionary used for the element,
+      // because the trouble-maker causes the 'global' spell check dictionary to be set to "en-GB"
+      // (since it picks the first one from the list) before we have the chance to retrieve
+      // the dictionary for the element (which happens asynchonously after the spell check has completed).
+      content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1204147_subframe2.html?firstload=false';
+    } else {
+      // Second time around, the element should default to en-US.
+      // Without the fix, the first run sets the content preference to en-GB for the whole site.
+      is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
+      content.removeEventListener('load', loadListener, false);
+
+      // Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
+      hunspell.removeDirectory(en_GB);
+
+      // Reset the preference, so the last value we set doesn't collide with the next test.
+      SimpleTest.finish();
+    }
+  });
+}
+
+content.addEventListener('load', loadListener, false);
+
+content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1204147_subframe.html?firstload=true';
+
+</script>
+</pre>
+</body>
+</html>