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.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 var current_test = 0;
9 function AutoCompleteInput(aSearches) {
10 this.searches = aSearches;
11 }
12 AutoCompleteInput.prototype = {
13 constructor: AutoCompleteInput,
15 searches: null,
17 minResultsForPopup: 0,
18 timeout: 10,
19 searchParam: "",
20 textValue: "",
21 disableAutoComplete: false,
22 completeDefaultIndex: false,
24 get searchCount() {
25 return this.searches.length;
26 },
28 getSearchAt: function(aIndex) {
29 return this.searches[aIndex];
30 },
32 onSearchBegin: function() {},
33 onSearchComplete: function() {},
35 popupOpen: false,
37 popup: {
38 setSelectedIndex: function(aIndex) {},
39 invalidate: function() {},
41 // nsISupports implementation
42 QueryInterface: function(iid) {
43 if (iid.equals(Ci.nsISupports) ||
44 iid.equals(Ci.nsIAutoCompletePopup))
45 return this;
47 throw Components.results.NS_ERROR_NO_INTERFACE;
48 }
49 },
51 // nsISupports implementation
52 QueryInterface: function(iid) {
53 if (iid.equals(Ci.nsISupports) ||
54 iid.equals(Ci.nsIAutoCompleteInput))
55 return this;
57 throw Components.results.NS_ERROR_NO_INTERFACE;
58 }
59 }
61 // Get tagging service
62 try {
63 var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
64 getService(Ci.nsITaggingService);
65 } catch(ex) {
66 do_throw("Could not get tagging service\n");
67 }
69 function ensure_tag_results(uris, searchTerm)
70 {
71 var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
72 getService(Components.interfaces.nsIAutoCompleteController);
74 // Make an AutoCompleteInput that uses our searches
75 // and confirms results on search complete
76 var input = new AutoCompleteInput(["history"]);
78 controller.input = input;
80 // Search is asynchronous, so don't let the test finish immediately
81 do_test_pending();
83 var numSearchesStarted = 0;
84 input.onSearchBegin = function() {
85 numSearchesStarted++;
86 do_check_eq(numSearchesStarted, 1);
87 };
89 input.onSearchComplete = function() {
90 do_check_eq(numSearchesStarted, 1);
91 do_check_eq(controller.searchStatus,
92 Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
93 do_check_eq(controller.matchCount, uris.length);
94 let vals = [];
95 for (var i=0; i<controller.matchCount; i++) {
96 // Keep the URL for later because order of tag results is undefined
97 vals.push(controller.getValueAt(i));
98 do_check_eq(controller.getStyleAt(i), "tag");
99 }
100 // Sort the results then check if we have the right items
101 vals.sort().forEach(function(val, i) do_check_eq(val, uris[i].spec))
103 if (current_test < (tests.length - 1)) {
104 current_test++;
105 tests[current_test]();
106 }
108 do_test_finished();
109 };
111 controller.startSearch(searchTerm);
112 }
114 var uri1 = uri("http://site.tld/1");
115 var uri2 = uri("http://site.tld/2");
116 var uri3 = uri("http://site.tld/3");
117 var uri4 = uri("http://site.tld/4");
118 var uri5 = uri("http://site.tld/5");
119 var uri6 = uri("http://site.tld/6");
121 var tests = [function() { ensure_tag_results([uri1, uri2, uri3], "foo"); },
122 function() { ensure_tag_results([uri1, uri2, uri3], "Foo"); },
123 function() { ensure_tag_results([uri1, uri2, uri3], "foO"); },
124 function() { ensure_tag_results([uri4, uri5, uri6], "bar mud"); },
125 function() { ensure_tag_results([uri4, uri5, uri6], "BAR MUD"); },
126 function() { ensure_tag_results([uri4, uri5, uri6], "Bar Mud"); }];
128 /**
129 * Properly tags a uri adding it to bookmarks.
130 *
131 * @param aURI
132 * The nsIURI to tag.
133 * @param aTags
134 * The tags to add.
135 */
136 function tagURI(aURI, aTags) {
137 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
138 aURI,
139 PlacesUtils.bookmarks.DEFAULT_INDEX,
140 "A title");
141 tagssvc.tagURI(aURI, aTags);
142 }
144 /**
145 * Test bug #408221
146 */
147 function run_test() {
148 // always search in history + bookmarks, no matter what the default is
149 var prefs = Cc["@mozilla.org/preferences-service;1"].
150 getService(Ci.nsIPrefBranch);
151 prefs.setIntPref("browser.urlbar.search.sources", 3);
152 prefs.setIntPref("browser.urlbar.default.behavior", 0);
154 tagURI(uri1, ["Foo"]);
155 tagURI(uri2, ["FOO"]);
156 tagURI(uri3, ["foO"]);
157 tagURI(uri4, ["BAR"]);
158 tagURI(uri4, ["MUD"]);
159 tagURI(uri5, ["bar"]);
160 tagURI(uri5, ["mud"]);
161 tagURI(uri6, ["baR"]);
162 tagURI(uri6, ["muD"]);
164 tests[0]();
165 }