Bug 1061469 - part 8: Encoding for Imports. r=mrbkap
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Mon, 06 Oct 2014 11:43:58 +0200
changeset 209001 52b510bad6a746e390b835a354f6c082ef7ee243
parent 209000 cda7419a220b5c10e9ed84835c677f461b6c4707
child 209002 e210c7768dfd2e05d9f79236084c89dac52a2cf8
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmrbkap
bugs1061469
milestone35.0a1
Bug 1061469 - part 8: Encoding for Imports. r=mrbkap
content/base/src/nsDocument.cpp
content/html/content/test/imports/file_encoding.html
content/html/content/test/imports/mochitest.ini
content/html/content/test/imports/test_encoding.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -3515,16 +3515,20 @@ nsDocument::GetBaseTarget(nsAString &aBa
 
 void
 nsDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
 {
   // XXX it would be a good idea to assert the sanity of the argument,
   // but before we figure out what to do about non-Encoding Standard
   // encodings in the charset menu and in mailnews, assertions are futile.
   if (!mCharacterSet.Equals(aCharSetID)) {
+    if (mMasterDocument && !aCharSetID.EqualsLiteral("UTF-8")) {
+      // Imports are always UTF-8
+      return;
+    }
     mCharacterSet = aCharSetID;
 
     int32_t n = mCharSetObservers.Length();
 
     for (int32_t i = 0; i < n; i++) {
       nsIObserver* observer = mCharSetObservers.ElementAt(i);
 
       observer->Observe(static_cast<nsIDocument *>(this), "charset",
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/imports/file_encoding.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<head>
+<meta charset="EUC-KR">
+</head>
+<body>Ignore my encoding</body>
\ No newline at end of file
--- a/content/html/content/test/imports/mochitest.ini
+++ b/content/html/content/test/imports/mochitest.ini
@@ -30,19 +30,21 @@ support-files =
   file_cycle_4_B.html
   file_cycle_4_C.html
   file_cycle_4_D.html
   file_cycle_4_E.html
   file_cycle_5_A.html
   file_cycle_5_B.html
   file_cycle_5_C.html
   file_cycle_5_D.html
+  file_encoding.html
 
 [test_cycle_1.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_2.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_3.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_4.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_5.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
+[test_encoding.html]
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/imports/test_encoding.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1061469
+-->
+<head>
+  <title>Test for Bug 1061469</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+</head>
+<body>
+  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1061469">Mozilla Bug 1061469</a>
+  <script type="text/javascript">
+    SimpleTest.waitForExplicitFinish();
+    var success = false;
+    function loaded() {
+      success = true;
+    }
+    function failed() {
+      ok(false, "Import loading failed");
+    }
+  </script>
+  <link rel="import" href="file_encoding.html" id="import" onload="loaded()" onerror="failed()"></link>
+  <script type="text/javascript">
+    is(document.getElementById("import").import.characterSet, "UTF-8", "characterSet should be UTF-8 for imports");
+    SimpleTest.finish();
+  </script>
+</body>
+</html>
\ No newline at end of file