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
|
add_task(function*() {
registerCleanupFunction(() => {
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
});
function* addTagItem(tagName) {
let uri = NetUtil.newURI(`http://example.com/this/is/tagged/${tagName}`);
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
uri,
PlacesUtils.bookmarks.DEFAULT_INDEX,
`test ${tagName}`);
PlacesUtils.tagging.tagURI(uri, [tagName]);
yield PlacesTestUtils.addVisits([{uri: uri, title: `Test page with tag ${tagName}`}]);
}
// We use different tags for each part of the test, as otherwise the
// autocomplete code tries to be smart by using the previously cached element
// without updating it (since all parameters it knows about are the same).
let testcases = [{
description: "Test with suggest.bookmark=true",
tagName: "tagtest1",
prefs: {
"suggest.bookmark": true,
},
input: "tagtest1",
expected: {
type: "bookmark",
typeImageVisible: true,
},
}, {
description: "Test with suggest.bookmark=false",
tagName: "tagtest2",
prefs: {
"suggest.bookmark": false,
},
input: "tagtest2",
expected: {
type: "tag",
typeImageVisible: false,
},
}, {
description: "Test with suggest.bookmark=true (again)",
tagName: "tagtest3",
prefs: {
"suggest.bookmark": true,
},
input: "tagtest3",
expected: {
type: "bookmark",
typeImageVisible: true,
},
}, {
description: "Test with bookmark restriction token",
tagName: "tagtest4",
prefs: {
"suggest.bookmark": true,
},
input: "* tagtest4",
expected: {
type: "bookmark",
typeImageVisible: true,
},
}, {
description: "Test with history restriction token",
tagName: "tagtest5",
prefs: {
"suggest.bookmark": true,
},
input: "^ tagtest5",
expected: {
type: "tag",
typeImageVisible: false,
},
}];
for (let testcase of testcases) {
info(`Test case: ${testcase.description}`);
yield addTagItem(testcase.tagName);
for (let prefName of Object.keys(testcase.prefs)) {
Services.prefs.setBoolPref(`browser.urlbar.${prefName}`, testcase.prefs[prefName]);
}
yield promiseAutocompleteResultPopup(testcase.input);
let result = gURLBar.popup.richlistbox.children[1];
ok(result && !result.collasped, "Should have result");
is(result.getAttribute("type"), testcase.expected.type, "Result should have expected type");
let typeIconStyle = window.getComputedStyle(result._typeIcon);
let imageURL = typeIconStyle.listStyleImage;
if (testcase.expected.typeImageVisible) {
ok(/^url\(.+\)$/.test(imageURL), "Type image should be visible");
} else {
is(imageURL, "none", "Type image should be hidden");
}
gURLBar.popup.hidePopup();
yield promisePopupHidden(gURLBar.popup);
}
});
|