Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | var MANIFESTS = [ |
michael@0 | 7 | do_get_file("data/test_bug519468.manifest") |
michael@0 | 8 | ]; |
michael@0 | 9 | |
michael@0 | 10 | // Stub in the locale service so we can control what gets returned as the OS locale setting |
michael@0 | 11 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | let stubOSLocale = null; |
michael@0 | 14 | |
michael@0 | 15 | stubID = Components.ID("9d09d686-d913-414c-a1e6-4be8652d7d93"); |
michael@0 | 16 | localeContractID = "@mozilla.org/intl/nslocaleservice;1"; |
michael@0 | 17 | |
michael@0 | 18 | StubLocaleService = { |
michael@0 | 19 | classDescription: "Stub version of Locale service for testing", |
michael@0 | 20 | classID: stubID, |
michael@0 | 21 | contractID: localeContractID, |
michael@0 | 22 | QueryInterface: XPCOMUtils.generateQI([Ci.nsILocaleService, Ci.nsISupports, Ci.nsIFactory]), |
michael@0 | 23 | |
michael@0 | 24 | createInstance: function (outer, iid) { |
michael@0 | 25 | if (outer) |
michael@0 | 26 | throw Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 27 | return this.QueryInterface(iid); |
michael@0 | 28 | }, |
michael@0 | 29 | lockFactory: function (lock) { |
michael@0 | 30 | throw Components.results.NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 31 | }, |
michael@0 | 32 | |
michael@0 | 33 | getLocaleComponentForUserAgent: function SLS_getLocaleComponentForUserAgent() |
michael@0 | 34 | { |
michael@0 | 35 | return stubOSLocale; |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | let registrar = Components.manager.nsIComponentRegistrar; |
michael@0 | 40 | // Save original factory. |
michael@0 | 41 | let localeCID = registrar.contractIDToCID(localeContractID) |
michael@0 | 42 | let originalFactory = |
michael@0 | 43 | Components.manager.getClassObject(Components.classes[localeContractID], |
michael@0 | 44 | Components.interfaces.nsIFactory); |
michael@0 | 45 | |
michael@0 | 46 | registrar.registerFactory(stubID, "Unit test Locale Service", localeContractID, StubLocaleService); |
michael@0 | 47 | |
michael@0 | 48 | // Now fire up the test |
michael@0 | 49 | do_test_pending() |
michael@0 | 50 | registerManifests(MANIFESTS); |
michael@0 | 51 | |
michael@0 | 52 | var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"] |
michael@0 | 53 | .getService(Ci.nsIXULChromeRegistry) |
michael@0 | 54 | .QueryInterface(Ci.nsIToolkitChromeRegistry); |
michael@0 | 55 | chromeReg.checkForNewChrome(); |
michael@0 | 56 | |
michael@0 | 57 | var prefService = Cc["@mozilla.org/preferences-service;1"] |
michael@0 | 58 | .getService(Ci.nsIPrefService) |
michael@0 | 59 | .QueryInterface(Ci.nsIPrefBranch); |
michael@0 | 60 | var os = Cc["@mozilla.org/observer-service;1"] |
michael@0 | 61 | .getService(Ci.nsIObserverService); |
michael@0 | 62 | |
michael@0 | 63 | var testsLocale = [ |
michael@0 | 64 | // These tests cover when the OS local is included in our manifest |
michael@0 | 65 | {matchOS: false, selected: "en-US", osLocale: "xx-AA", locale: "en-US"}, |
michael@0 | 66 | {matchOS: true, selected: "en-US", osLocale: "xx-AA", locale: "xx-AA"}, |
michael@0 | 67 | {matchOS: false, selected: "fr-FR", osLocale: "xx-AA", locale: "fr-FR"}, |
michael@0 | 68 | {matchOS: true, selected: "fr-FR", osLocale: "xx-AA", locale: "xx-AA"}, |
michael@0 | 69 | {matchOS: false, selected: "de-DE", osLocale: "xx-AA", locale: "de-DE"}, |
michael@0 | 70 | {matchOS: true, selected: "de-DE", osLocale: "xx-AA", locale: "xx-AA"}, |
michael@0 | 71 | // these tests cover the case where the OS locale is not available in our manifest, but the |
michael@0 | 72 | // base language is (ie, substitute xx-AA which we have for xx-BB which we don't) |
michael@0 | 73 | {matchOS: false, selected: "en-US", osLocale: "xx-BB", locale: "en-US"}, |
michael@0 | 74 | {matchOS: true, selected: "en-US", osLocale: "xx-BB", locale: "xx-AA"}, |
michael@0 | 75 | {matchOS: false, selected: "fr-FR", osLocale: "xx-BB", locale: "fr-FR"}, |
michael@0 | 76 | {matchOS: true, selected: "fr-FR", osLocale: "xx-BB", locale: "xx-AA"}, |
michael@0 | 77 | // These tests cover where the language is not available |
michael@0 | 78 | {matchOS: false, selected: "en-US", osLocale: "xy-BB", locale: "en-US"}, |
michael@0 | 79 | {matchOS: true, selected: "en-US", osLocale: "xy-BB", locale: "en-US"}, |
michael@0 | 80 | {matchOS: false, selected: "fr-FR", osLocale: "xy-BB", locale: "fr-FR"}, |
michael@0 | 81 | {matchOS: true, selected: "fr-FR", osLocale: "xy-BB", locale: "en-US"}, |
michael@0 | 82 | ]; |
michael@0 | 83 | |
michael@0 | 84 | var observedLocale = null; |
michael@0 | 85 | |
michael@0 | 86 | function test_locale(aTest) { |
michael@0 | 87 | observedLocale = null; |
michael@0 | 88 | |
michael@0 | 89 | stubOSLocale = aTest.osLocale; |
michael@0 | 90 | prefService.setBoolPref("intl.locale.matchOS", aTest.matchOS); |
michael@0 | 91 | prefService.setCharPref("general.useragent.locale", aTest.selected); |
michael@0 | 92 | |
michael@0 | 93 | chromeReg.reloadChrome(); |
michael@0 | 94 | |
michael@0 | 95 | do_check_eq(observedLocale, aTest.locale); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | // Callback function for observing locale change. May be called more than once |
michael@0 | 99 | // per test iteration. |
michael@0 | 100 | function checkValidity() { |
michael@0 | 101 | observedLocale = chromeReg.getSelectedLocale("testmatchos"); |
michael@0 | 102 | dump("checkValidity called back with locale = " + observedLocale + "\n"); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | function run_test() { |
michael@0 | 106 | os.addObserver(checkValidity, "selected-locale-has-changed", false); |
michael@0 | 107 | |
michael@0 | 108 | for (let count = 0 ; count < testsLocale.length ; count++) { |
michael@0 | 109 | dump("count = " + count + " " + testsLocale[count].toSource() + "\n"); |
michael@0 | 110 | test_locale(testsLocale[count]); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | os.removeObserver(checkValidity, "selected-locale-has-changed"); |
michael@0 | 114 | do_test_finished(); |
michael@0 | 115 | } |