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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Tests we clear interactions when history is cleared.
*/
"use strict";
const TEST_URL =
"https://example.com/browser/browser/components/places/tests/browser/keyword_form.html";
const TEST_URL_2 =
"https://example.org/browser/browser/components/places/tests/browser/keyword_form.html";
const TEST_URL_AWAY = "https://example.com/browser";
const sentence = "The quick brown fox jumps over the lazy dog.";
async function sendTextToInput(browser, text) {
// Reset to later verify that the provided text matches the value.
await SpecialPowers.spawn(browser, [], function () {
const input = content.document.querySelector(
"#form1 > input[name='search']"
);
input.focus();
input.value = "";
});
EventUtils.sendString(text);
await SpecialPowers.spawn(browser, [{ text }], async function (args) {
await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector("#form1 > input[name='search']").value ==
args.text,
"Text has been set on input"
);
});
}
add_setup(async function () {
await Interactions.reset();
await PlacesUtils.bookmarks.insert({
url: TEST_URL,
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
});
registerCleanupFunction(async () => {
await Interactions.reset();
await PlacesUtils.bookmarks.eraseEverything();
});
});
add_task(async function test_clear_history() {
await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
await sendTextToInput(browser, sentence);
BrowserTestUtils.startLoadingURIString(browser, TEST_URL_2);
await BrowserTestUtils.browserLoaded(browser, false, TEST_URL_2);
await sendTextToInput(browser, sentence);
BrowserTestUtils.startLoadingURIString(browser, "about:blank");
await BrowserTestUtils.browserLoaded(browser, false, "about:blank");
});
Assert.ok(
await PlacesUtils.history.hasVisits(TEST_URL),
"Check visits were added"
);
Assert.ok(
await PlacesUtils.history.hasVisits(TEST_URL_2),
"Check visits were added"
);
info("Check interactions were added");
await assertDatabaseValues([
{
url: TEST_URL,
keypresses: sentence.length,
typingTimeIsGreaterThan: 0,
},
{
url: TEST_URL_2,
keypresses: sentence.length,
typingTimeIsGreaterThan: 0,
},
]);
await PlacesUtils.history.clear();
Assert.ok(
await PlacesTestUtils.isPageInDB(TEST_URL),
"Bookmarked page remains in the database"
);
Assert.ok(
!(await PlacesUtils.history.hasVisits(TEST_URL)),
"Check visits were removed"
);
Assert.ok(
!(await PlacesTestUtils.isPageInDB(TEST_URL_2)),
"Non bookmarked page was removed from the database"
);
info("Check all interactions have been removed.");
await assertDatabaseValues([]);
});
|