Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* The test text as octets for reference |
michael@0 | 2 | * %83%86%83%6a%83%52%81%5b%83%68%82%cd%81%41%82%b7%82%d7%82%c4%82%cc%95%b6%8e%9a%82%c9%8c%c5%97%4c%82%cc%94%d4%8d%86%82%f0%95%74%97%5e%82%b5%82%dc%82%b7 |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | /* The test text decoded correctly as Shift_JIS */ |
michael@0 | 6 | const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059"; |
michael@0 | 7 | |
michael@0 | 8 | /* The test text decoded incorrectly as Windows-1251. This is the "right" wrong |
michael@0 | 9 | text; anything else is unexpected. */ |
michael@0 | 10 | const wrongText="\u0453\u2020\u0453\u006A\u0453\u0052\u0403\u005B\u0453\u0068\u201A\u041D\u0403\u0041\u201A\u00B7\u201A\u0427\u201A\u0414\u201A\u041C\u2022\u00B6\u040B\u0459\u201A\u0419\u040A\u0415\u2014\u004C\u201A\u041C\u201D\u0424\u040C\u2020\u201A\u0440\u2022\u0074\u2014\u005E\u201A\u00B5\u201A\u042C\u201A\u00B7"; |
michael@0 | 11 | |
michael@0 | 12 | function testContent(text) { |
michael@0 | 13 | is(gBrowser.contentDocument.getElementById("testpar").innerHTML, text, |
michael@0 | 14 | "<p> contains expected text"); |
michael@0 | 15 | is(gBrowser.contentDocument.getElementById("testtextarea").innerHTML, text, |
michael@0 | 16 | "<textarea> contains expected text"); |
michael@0 | 17 | is(gBrowser.contentDocument.getElementById("testinput").value, text, |
michael@0 | 18 | "<input> contains expected text"); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function afterOpen() { |
michael@0 | 22 | gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true); |
michael@0 | 23 | gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true); |
michael@0 | 24 | |
michael@0 | 25 | /* Test that the content on load is the expected wrong decoding */ |
michael@0 | 26 | testContent(wrongText); |
michael@0 | 27 | |
michael@0 | 28 | /* Force the page encoding to Shift_JIS */ |
michael@0 | 29 | BrowserSetForcedCharacterSet("Shift_JIS"); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function afterChangeCharset() { |
michael@0 | 33 | gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true); |
michael@0 | 34 | |
michael@0 | 35 | /* test that the content is decoded correctly */ |
michael@0 | 36 | testContent(rightText); |
michael@0 | 37 | gBrowser.removeCurrentTab(); |
michael@0 | 38 | finish(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function test() { |
michael@0 | 42 | waitForExplicitFinish(); |
michael@0 | 43 | |
michael@0 | 44 | // Get the local directory. This needs to be a file: URI because chrome: URIs |
michael@0 | 45 | // are always UTF-8 (bug 617339) and we are testing decoding from other |
michael@0 | 46 | // charsets. |
michael@0 | 47 | var jar = getJar(getRootDirectory(gTestPath)); |
michael@0 | 48 | var dir = jar ? |
michael@0 | 49 | extractJarToTmp(jar) : |
michael@0 | 50 | getChromeDir(getResolvedURI(gTestPath)); |
michael@0 | 51 | var rootDir = Services.io.newFileURI(dir).spec; |
michael@0 | 52 | |
michael@0 | 53 | gBrowser.selectedTab = gBrowser.addTab(rootDir + "test-form_sjis.html"); |
michael@0 | 54 | gBrowser.selectedBrowser.addEventListener("load", afterOpen, true); |
michael@0 | 55 | } |