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 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | // Get history service |
michael@0 | 8 | try { |
michael@0 | 9 | var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService); |
michael@0 | 10 | } catch(ex) { |
michael@0 | 11 | do_throw("Could not get history service\n"); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. |
michael@0 | 15 | getService(Ci.nsINavBookmarksService); |
michael@0 | 16 | |
michael@0 | 17 | // main |
michael@0 | 18 | function run_test() { |
michael@0 | 19 | // add a folder |
michael@0 | 20 | var folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX); |
michael@0 | 21 | |
michael@0 | 22 | // add a bookmark to the folder |
michael@0 | 23 | var b1 = bmsvc.insertBookmark(folder, uri("http://a1.com/"), |
michael@0 | 24 | bmsvc.DEFAULT_INDEX, "1 title"); |
michael@0 | 25 | // add a subfolder |
michael@0 | 26 | var sf1 = bmsvc.createFolder(folder, "subfolder 1", bmsvc.DEFAULT_INDEX); |
michael@0 | 27 | |
michael@0 | 28 | // add a bookmark to the subfolder |
michael@0 | 29 | var b2 = bmsvc.insertBookmark(sf1, uri("http://a2.com/"), |
michael@0 | 30 | bmsvc.DEFAULT_INDEX, "2 title"); |
michael@0 | 31 | |
michael@0 | 32 | // add a subfolder to the subfolder |
michael@0 | 33 | var sf2 = bmsvc.createFolder(sf1, "subfolder 2", bmsvc.DEFAULT_INDEX); |
michael@0 | 34 | |
michael@0 | 35 | // add a bookmark to the subfolder of the subfolder |
michael@0 | 36 | var b3 = bmsvc.insertBookmark(sf2, uri("http://a3.com/"), |
michael@0 | 37 | bmsvc.DEFAULT_INDEX, "3 title"); |
michael@0 | 38 | |
michael@0 | 39 | // bookmark query that should result in the "hierarchical" result |
michael@0 | 40 | // because there is one query, one folder, |
michael@0 | 41 | // no begin time, no end time, no domain, no uri, no search term |
michael@0 | 42 | // and no max results. See GetSimpleBookmarksQueryFolder() |
michael@0 | 43 | // for more details. |
michael@0 | 44 | var options = histsvc.getNewQueryOptions(); |
michael@0 | 45 | options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; |
michael@0 | 46 | var query = histsvc.getNewQuery(); |
michael@0 | 47 | query.setFolders([folder], 1); |
michael@0 | 48 | var result = histsvc.executeQuery(query, options); |
michael@0 | 49 | var root = result.root; |
michael@0 | 50 | root.containerOpen = true; |
michael@0 | 51 | do_check_eq(root.childCount, 2); |
michael@0 | 52 | do_check_eq(root.getChild(0).itemId, b1); |
michael@0 | 53 | do_check_eq(root.getChild(1).itemId, sf1); |
michael@0 | 54 | |
michael@0 | 55 | // check the contents of the subfolder |
michael@0 | 56 | var sf1Node = root.getChild(1); |
michael@0 | 57 | sf1Node = sf1Node.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 58 | sf1Node.containerOpen = true; |
michael@0 | 59 | do_check_eq(sf1Node.childCount, 2); |
michael@0 | 60 | do_check_eq(sf1Node.getChild(0).itemId, b2); |
michael@0 | 61 | do_check_eq(sf1Node.getChild(1).itemId, sf2); |
michael@0 | 62 | |
michael@0 | 63 | // check the contents of the subfolder's subfolder |
michael@0 | 64 | var sf2Node = sf1Node.getChild(1); |
michael@0 | 65 | sf2Node = sf2Node.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 66 | sf2Node.containerOpen = true; |
michael@0 | 67 | do_check_eq(sf2Node.childCount, 1); |
michael@0 | 68 | do_check_eq(sf2Node.getChild(0).itemId, b3); |
michael@0 | 69 | |
michael@0 | 70 | sf2Node.containerOpen = false; |
michael@0 | 71 | sf1Node.containerOpen = false; |
michael@0 | 72 | root.containerOpen = false; |
michael@0 | 73 | |
michael@0 | 74 | // bookmark query that should result in a flat list |
michael@0 | 75 | // because we specified max results |
michael@0 | 76 | var options = histsvc.getNewQueryOptions(); |
michael@0 | 77 | options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; |
michael@0 | 78 | options.maxResults = 10; |
michael@0 | 79 | var query = histsvc.getNewQuery(); |
michael@0 | 80 | query.setFolders([folder], 1); |
michael@0 | 81 | var result = histsvc.executeQuery(query, options); |
michael@0 | 82 | var root = result.root; |
michael@0 | 83 | root.containerOpen = true; |
michael@0 | 84 | do_check_eq(root.childCount, 3); |
michael@0 | 85 | do_check_eq(root.getChild(0).itemId, b1); |
michael@0 | 86 | do_check_eq(root.getChild(1).itemId, b2); |
michael@0 | 87 | do_check_eq(root.getChild(2).itemId, b3); |
michael@0 | 88 | root.containerOpen = false; |
michael@0 | 89 | |
michael@0 | 90 | // XXX TODO |
michael@0 | 91 | // test that if we have: more than one query, |
michael@0 | 92 | // multiple folders, a begin time, an end time, a domain, a uri |
michael@0 | 93 | // or a search term, that we get the (correct) flat list results |
michael@0 | 94 | // (like we do when specified maxResults) |
michael@0 | 95 | } |