tor-browser

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

test_missing_variables.js (1133B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Disable `xpc::IsInAutomation()` so that missing variables don't throw
      5 // errors.
      6 Services.prefs.setBoolPref(
      7  "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer",
      8  false
      9 );
     10 
     11 /**
     12 * The following test demonstrates crashing behavior.
     13 */
     14 add_task(function test_missing_variables() {
     15  const l10nReg = new L10nRegistry();
     16 
     17  const fs = [
     18    { path: "/localization/en-US/browser/test.ftl", source: "welcome-message = Welcome { $user }\n" }
     19  ]
     20  const locales = ["en-US"];
     21  const source = L10nFileSource.createMock("test", "app", locales, "/localization/{locale}", fs);
     22  l10nReg.registerSources([source]);
     23  const l10n = new Localization(["/browser/test.ftl"], true, l10nReg, locales);
     24 
     25  {
     26    const [message] = l10n.formatValuesSync([{ id: "welcome-message", args: { user: "Greg" } }]);
     27    equal(message, "Welcome Greg");
     28  }
     29 
     30  {
     31    // This will crash in debug builds.
     32    const [message] = l10n.formatValuesSync([{ id: "welcome-message" }]);
     33    equal(message, "Welcome {$user}");
     34  }
     35 });