tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_bug92473.js (2449B)


      1 /* The test text as octets for reference
      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
      3 */
      4 
      5 function testContent(text) {
      6  return SpecialPowers.spawn(gBrowser.selectedBrowser, [text], text => {
      7    Assert.equal(
      8      content.document.getElementById("testpar").innerHTML,
      9      text,
     10      "<p> contains expected text"
     11    );
     12    Assert.equal(
     13      content.document.getElementById("testtextarea").innerHTML,
     14      text,
     15      "<textarea> contains expected text"
     16    );
     17    Assert.equal(
     18      content.document.getElementById("testinput").value,
     19      text,
     20      "<input> contains expected text"
     21    );
     22  });
     23 }
     24 
     25 function afterOpen() {
     26  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(
     27    afterChangeCharset
     28  );
     29 
     30  /* The test text decoded incorrectly as Windows-1251. This is the "right" wrong
     31   text; anything else is unexpected. */
     32  const wrongText =
     33    "\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";
     34 
     35  /* Test that the content on load is the expected wrong decoding */
     36  testContent(wrongText).then(() => {
     37    BrowserCommands.forceEncodingDetection();
     38  });
     39 }
     40 
     41 function afterChangeCharset() {
     42  /* The test text decoded correctly as Shift_JIS */
     43  const rightText =
     44    "\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";
     45 
     46  /* test that the content is decoded correctly */
     47  testContent(rightText).then(() => {
     48    gBrowser.removeCurrentTab();
     49    finish();
     50  });
     51 }
     52 
     53 function test() {
     54  waitForExplicitFinish();
     55 
     56  // Get the local directory. This needs to be a file: URI because chrome: URIs
     57  // are always UTF-8 (bug 617339) and we are testing decoding from other
     58  // charsets.
     59  var jar = getJar(getRootDirectory(gTestPath));
     60  var dir = jar
     61    ? extractJarToTmp(jar)
     62    : getChromeDir(getResolvedURI(gTestPath));
     63  var rootDir = Services.io.newFileURI(dir).spec;
     64 
     65  gBrowser.selectedTab = BrowserTestUtils.addTab(
     66    gBrowser,
     67    rootDir + "test-form_sjis.html"
     68  );
     69  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterOpen);
     70 }