tor-browser

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

navigator.any.js (3169B)


      1  var compatibilityMode;
      2  if (navigator.userAgent.includes("Chrome")) {
      3    compatibilityMode = "Chrome";
      4  } else if (navigator.userAgent.includes("WebKit")) {
      5    compatibilityMode = "WebKit";
      6  } else {
      7    compatibilityMode = "Gecko";
      8  }
      9 
     10  test(function() {
     11    assert_equals(navigator.appCodeName, "Mozilla");
     12  }, "appCodeName");
     13 
     14  test(function() {
     15    assert_equals(navigator.appName, "Netscape");
     16  }, "appName");
     17 
     18  test(function() {
     19    assert_equals(typeof navigator.appVersion, "string",
     20                  "navigator.appVersion should be a string");
     21  }, "appVersion");
     22 
     23  test(function() {
     24    assert_equals(typeof navigator.platform, "string",
     25                  "navigator.platform should be a string");
     26  }, "platform");
     27 
     28  test(function() {
     29    assert_equals(navigator.product, "Gecko");
     30  }, "product");
     31 
     32  test(function() {
     33    if ("window" in self) {
     34      if (compatibilityMode == "Gecko") {
     35        assert_equals(navigator.productSub, "20100101");
     36      } else {
     37        assert_equals(navigator.productSub, "20030107");
     38      }
     39    } else {
     40      assert_false("productSub" in navigator);
     41    }
     42  }, "productSub");
     43 
     44  test(function() {
     45    assert_equals(typeof navigator.userAgent, "string",
     46                  "navigator.userAgent should be a string");
     47  }, "userAgent type");
     48 
     49  async_test(function() {
     50    var request = new XMLHttpRequest();
     51    request.onload = this.step_func_done(function() {
     52      assert_equals("User-Agent: " + navigator.userAgent + "\n",
     53                    request.response,
     54                    "userAgent should return the value sent in the " +
     55                    "User-Agent header");
     56    });
     57    request.open("GET", "/xhr/resources/inspect-headers.py?" +
     58                        "filter_name=User-Agent");
     59    request.send();
     60  }, "userAgent value");
     61 
     62  test(function() {
     63    if ("window" in self) {
     64      if (compatibilityMode == "Chrome") {
     65        assert_equals(navigator.vendor, "Google Inc.");
     66      } else if (compatibilityMode == "WebKit") {
     67        assert_equals(navigator.vendor, "Apple Computer, Inc.");
     68      } else {
     69        assert_equals(navigator.vendor, "");
     70      }
     71    } else {
     72      assert_false("vendor" in navigator);
     73    }
     74  }, "vendor");
     75 
     76  test(function() {
     77    if ("window" in self) {
     78      assert_equals(navigator.vendorSub, "");
     79    } else {
     80      assert_false("vendorSub" in navigator);
     81    }
     82  }, "vendorSub");
     83 
     84  // "If the navigator compatibility mode is Gecko, then the user agent must
     85  // also support the following partial interface" (taintEnabled() and oscpu)
     86  // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=22555 and
     87  // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27820
     88 
     89  test(function() {
     90    if ("window" in self && compatibilityMode == "Gecko") {
     91      assert_false(navigator.taintEnabled());
     92    } else {
     93      assert_false("taintEnabled" in navigator);
     94    }
     95  }, "taintEnabled");
     96 
     97  test(function() {
     98    if ("window" in self && compatibilityMode == "Gecko") {
     99      assert_equals(typeof navigator.oscpu, "string",
    100                    "navigator.oscpu should be a string");
    101    } else {
    102      assert_false("oscpu" in navigator);
    103    }
    104  }, "oscpu");
    105 
    106 done()