1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This test checks that search values longer than
* SearchSuggestionController.SEARCH_HISTORY_MAX_VALUE_LENGTH are not added to
* search history.
*/
"use strict";
const { SearchSuggestionController } = ChromeUtils.importESModule(
"resource://gre/modules/SearchSuggestionController.sys.mjs"
);
let gEngine;
add_setup(async function () {
await SearchTestUtils.installSearchExtension({}, { setAsDefault: true });
gEngine = Services.search.getEngineByName("Example");
await UrlbarTestUtils.formHistory.clear();
registerCleanupFunction(async function () {
await UrlbarTestUtils.formHistory.clear();
});
});
add_task(async function sanityCheckShortString() {
const shortString = new Array(
SearchSuggestionController.SEARCH_HISTORY_MAX_VALUE_LENGTH
)
.fill("a")
.join("");
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: shortString,
});
let url = gEngine.getSubmission(shortString).uri.spec;
let loadPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
url
);
let addPromise = UrlbarTestUtils.formHistory.promiseChanged("add");
EventUtils.synthesizeKey("VK_RETURN");
await Promise.all([loadPromise, addPromise]);
let formHistory = (
await UrlbarTestUtils.formHistory.search({ source: gEngine.name })
).map(entry => entry.value);
Assert.deepEqual(
formHistory,
[shortString],
"Should find form history after adding it"
);
await UrlbarTestUtils.formHistory.clear();
});
add_task(async function urlbar_checkLongString() {
const longString = new Array(
SearchSuggestionController.SEARCH_HISTORY_MAX_VALUE_LENGTH + 1
)
.fill("a")
.join("");
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: longString,
});
let url = gEngine.getSubmission(longString).uri.spec;
let loadPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
url
);
EventUtils.synthesizeKey("VK_RETURN");
await loadPromise;
// There's nothing we can wait for, since addition should not be happening.
/* eslint-disable mozilla/no-arbitrary-setTimeout */
await new Promise(resolve => setTimeout(resolve, 500));
let formHistory = (
await UrlbarTestUtils.formHistory.search({ source: gEngine.name })
).map(entry => entry.value);
Assert.deepEqual(formHistory, [], "Should not find form history");
await UrlbarTestUtils.formHistory.clear();
});
|