author Zibi Braniecki <>
Thu, 14 Sep 2017 15:21:33 -0700
changeset 424146 48109fce6741a2448a9d71f48deccbd72f732003
parent 414688 4f7877809d7973fbc9e7d37f74039d4598ec384a
child 457640 b38d59f71915f78922b46a7c7bc65a48488c45f1
permissions -rw-r--r--
Bug 1400006 - Extend language negotiation in LocaleService to support looking for the best likelySubtag for the locale with region stripped. r=Pike, a=lizzard Add additional logic to our language negotation to do apply likelySubtags when a direct match is not available. Currently, if the user specifies the locale with region, and we do not have a direct for that region, we pick all locales for the same language and other regions in no order. The example of where it returns suboptimal results: 1) Requested locale "en-CA" 2) Available locales ["en-ZA", "en-GB", "en-US"] 3) Negotiated locales ["en-ZA", "en-GB", "en-US"] This would not happen, if the user requested a generic "de", "en" etc.: 1) Requested locale "en" 2) Available locales ["en-ZA", "en-GB", "en-US"] 3) Negotiated locales ["en-US", "en-ZA", "en-GB"] because after not finding a direct match, we would use likelySubtags to extend "en" to "en-Latn-US" and then find the priority match in "en-US". This patch extends this logic to "en-US" or "de-LU" by adding a step which strips the region tag and then applies likelySubtag on the result. This means that in absence of direct match the following fallbacks would happen: "de-LU" -> "de-DE" "es-CL" -> "es-ES" "en-CA" -> "en-US" This does not affect languages that use multiple scripts, so ar, sr and zh are not affected. MozReview-Commit-ID: BR1WrgXSf6a

  <meta charset="utf-8">
  <title>Test for Bug 987877</title>

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  <script type="application/javascript">
"use strict";

const { utils: Cu } = Components;
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const CssLogic = require("devtools/shared/inspector/css-logic");

const _tests = [];
function addTest(test) {

function runNextTest() {
  if (_tests.length == 0) {

window.onload = function () {

addTest(function getXPathForUnattachedElement() {
  let unattached = document.createElement("div"); = "unattached";
  try {
    ok(false, "Unattached node did not throw");
  } catch (e) {
    ok(e, "Unattached node throws an exception");

  let unattachedChild = document.createElement("div");
  try {
    ok(false, "Unattached child node did not throw");
  } catch (e) {
    ok(e, "Unattached child node throws an exception");

  let unattachedBody = document.createElement("body");
  try {
    ok(false, "Unattached body node did not throw");
  } catch (e) {
    ok(e, "Unattached body node throws an exception");


addTest(function getXPath() {
  let data = [{
    // Target elements that have an ID get a short XPath.
    selector: "#i-have-an-id",
    path: "//*[@id=\"i-have-an-id\"]"
  }, {
    selector: "html",
    path: "/html"
  }, {
    selector: "body",
    path: "/html/body"
  }, {
    selector: "body > div:nth-child(2) > div > div:nth-child(4)",
    path: "/html/body/div[2]/div/div[4]"
  }, {
    // XPath should support namespace.
    selector: "namespace\\:body",
    path: "/html/body/namespace:test/namespace:body"

  for (let {selector, path} of data) {
    let node = document.querySelector(selector);
    is(CssLogic.getXPath(node), path, `Full css path is correct for ${selector}`);

  <div id="i-have-an-id">find me</div>
      <div>me too!</div>
    <namespace:body>and me</namespace:body>