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 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // shell.js |
michael@0 | 7 | // This file sets up the unit test environment by building an array of files |
michael@0 | 8 | // to be tested. It assumes it lives in a folder adjacent to the a folder |
michael@0 | 9 | // called 'xml', where the testcases live. |
michael@0 | 10 | // |
michael@0 | 11 | // The directory layout looks something like this: |
michael@0 | 12 | // |
michael@0 | 13 | // tests/ *shell.js* |
michael@0 | 14 | // | |
michael@0 | 15 | // - test.js |
michael@0 | 16 | // | |
michael@0 | 17 | // - xml/ -- rss1/... |
michael@0 | 18 | // | |
michael@0 | 19 | // -- rss2/... |
michael@0 | 20 | // | |
michael@0 | 21 | // -- atom/testcase.xml |
michael@0 | 22 | |
michael@0 | 23 | function trimString(s) |
michael@0 | 24 | { |
michael@0 | 25 | return(s.replace(/^\s+/,'').replace(/\s+$/,'')); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | var tests = new Array(); |
michael@0 | 29 | const ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService); |
michael@0 | 30 | |
michael@0 | 31 | // find the directory containing our test XML |
michael@0 | 32 | |
michael@0 | 33 | if (0 < arguments.length) { |
michael@0 | 34 | |
michael@0 | 35 | // dir is specified on the command line |
michael@0 | 36 | |
michael@0 | 37 | var topDir = Components.classes["@mozilla.org/file/local;1"] |
michael@0 | 38 | .createInstance(Components.interfaces.nsILocalFile); |
michael@0 | 39 | |
michael@0 | 40 | topDir.initWithPath(arguments[0]); |
michael@0 | 41 | } |
michael@0 | 42 | else { |
michael@0 | 43 | const nsIDirectoryServiceProvider |
michael@0 | 44 | = Components.interfaces.nsIDirectoryServiceProvider; |
michael@0 | 45 | const nsIDirectoryServiceProvider_CONTRACTID |
michael@0 | 46 | = "@mozilla.org/file/directory_service;1"; |
michael@0 | 47 | |
michael@0 | 48 | var dirServiceProvider |
michael@0 | 49 | = Components.classes[nsIDirectoryServiceProvider_CONTRACTID] |
michael@0 | 50 | .getService(nsIDirectoryServiceProvider); |
michael@0 | 51 | |
michael@0 | 52 | var persistent = new Object(); |
michael@0 | 53 | |
michael@0 | 54 | var topDir = dirServiceProvider.getFile("CurWorkD", persistent); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | var entries = topDir.directoryEntries; |
michael@0 | 58 | var xmlDir; |
michael@0 | 59 | while(entries.hasMoreElements()){ |
michael@0 | 60 | xmlDir = entries.getNext(); |
michael@0 | 61 | xmlDir.QueryInterface(Components.interfaces.nsILocalFile); |
michael@0 | 62 | if(xmlDir.leafName == "xml") |
michael@0 | 63 | break; |
michael@0 | 64 | else |
michael@0 | 65 | xmlDir = null; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // if we got our xmldir, find our testcases |
michael@0 | 69 | var testDir; |
michael@0 | 70 | if(xmlDir){ |
michael@0 | 71 | entries = xmlDir.directoryEntries; |
michael@0 | 72 | while(entries.hasMoreElements()){ |
michael@0 | 73 | testDir = entries.getNext(); |
michael@0 | 74 | testDir.QueryInterface(Components.interfaces.nsILocalFile); |
michael@0 | 75 | if(testDir.exists() && testDir.isDirectory()){ |
michael@0 | 76 | var testfiles = testDir.directoryEntries; |
michael@0 | 77 | while(testfiles.hasMoreElements()){ // inside an individual testdir, like "rss2" |
michael@0 | 78 | var test = testfiles.getNext(); |
michael@0 | 79 | test.QueryInterface(Components.interfaces.nsILocalFile); |
michael@0 | 80 | if(test.exists() && test.isFile()){ |
michael@0 | 81 | |
michael@0 | 82 | // Got a feed file, now we need to add it to our tests |
michael@0 | 83 | // and parse out the Description and Expect headers. |
michael@0 | 84 | // That lets us write one test.js file and keep the |
michael@0 | 85 | // tests with the XML. Convenient method learned from |
michael@0 | 86 | // Mark Pilgrim. |
michael@0 | 87 | |
michael@0 | 88 | var istream = Components.classes["@mozilla.org/network/file-input-stream;1"] |
michael@0 | 89 | .createInstance(Components.interfaces.nsIFileInputStream); |
michael@0 | 90 | |
michael@0 | 91 | try{ |
michael@0 | 92 | // open an input stream from file |
michael@0 | 93 | istream.init(test, 0x01, 0444, 0); |
michael@0 | 94 | istream.QueryInterface(Components.interfaces.nsILineInputStream); |
michael@0 | 95 | var line = {}, hasmore, testcase = {}, expectIndex, descIndex; |
michael@0 | 96 | |
michael@0 | 97 | do { |
michael@0 | 98 | hasmore = istream.readLine(line); |
michael@0 | 99 | expectIndex = line.value.indexOf('Expect:'); |
michael@0 | 100 | descIndex = line.value.indexOf('Description:'); |
michael@0 | 101 | baseIndex = line.value.indexOf('Base:'); |
michael@0 | 102 | if(descIndex > -1) |
michael@0 | 103 | testcase.desc = trimString(line.value.substring(line.value.indexOf(':')+1)); |
michael@0 | 104 | if(expectIndex > -1) |
michael@0 | 105 | testcase.expect = trimString(line.value.substring(line.value.indexOf(':')+1)); |
michael@0 | 106 | if(baseIndex > -1) |
michael@0 | 107 | testcase.base = ioService.newURI(trimString(line.value.substring(line.value.indexOf(':')+1)),null,null); |
michael@0 | 108 | if(testcase.expect && testcase.desc){ |
michael@0 | 109 | // got our fields, let's add it to our array and break |
michael@0 | 110 | testcase.path = xmlDir.leafName + '/' + testDir.leafName + '/' + test.leafName; |
michael@0 | 111 | testcase.file = test; |
michael@0 | 112 | tests.push(testcase); |
michael@0 | 113 | break; // out of do-while |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | } while(hasmore); |
michael@0 | 117 | |
michael@0 | 118 | }catch(e){ |
michael@0 | 119 | dump("FAILED! Error reading test case in file " + test.leafName + " " + e + "\n"); |
michael@0 | 120 | }finally{ |
michael@0 | 121 | istream.close(); |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | load(topDir.path+'/test.js'); |