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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
requestLongerTimeout(2);
const PRELOAD_PREF = "browser.newtab.preload";
var suggestedLink = {
url: "http://example1.com/2",
imageURI: "data:image/png;base64,helloWORLD3",
title: "title2",
type: "affiliate",
adgroup_name: "Technology",
frecent_sites: ["classroom.google.com", "codeacademy.org", "codecademy.com", "codeschool.com", "codeyear.com", "elearning.ut.ac.id", "how-to-build-websites.com", "htmlcodetutorial.com", "htmldog.com", "htmlplayground.com", "learn.jquery.com", "quackit.com", "roseindia.net", "teamtreehouse.com", "tizag.com", "tutorialspoint.com", "udacity.com", "w3schools.com", "webdevelopersnotes.com"]
};
gDirectorySource = "data:application/json," + JSON.stringify({
"enhanced": [{
url: "http://example.com/",
enhancedImageURI: "data:image/png;base64,helloWORLD",
title: "title",
type: "organic",
}],
"directory": [{
url: "http://example1.com/",
enhancedImageURI: "data:image/png;base64,helloWORLD2",
title: "title1",
type: "organic"
}],
"suggested": [suggestedLink]
});
add_task(function* () {
let origEnhanced = NewTabUtils.allPages.enhanced;
registerCleanupFunction(() => {
NewTabUtils.allPages.enhanced = origEnhanced;
});
yield pushPrefs([PRELOAD_PREF, false]);
function getData(cellNum) {
return performOnCell(cellNum, cell => {
if (!cell.site)
return null;
let siteNode = cell.site.node;
return {
type: siteNode.getAttribute("type"),
enhanced: siteNode.querySelector(".enhanced-content").style.backgroundImage,
title: siteNode.querySelector(".newtab-title").textContent,
suggested: siteNode.querySelector(".newtab-suggested").innerHTML
};
});
}
// Make the page have a directory link, enhanced link, and history link
yield setLinks("-1");
// Test with enhanced = false
yield* addNewTabPageTab();
yield customizeNewTabPage("classic");
yield customizeNewTabPage("enhanced"); // Toggle enhanced off
let {type, enhanced, title, suggested} = yield getData(0);
isnot(type, "enhanced", "history link is not enhanced");
is(enhanced, "", "history link has no enhanced image");
is(title, "example.com");
is(suggested, "", "There is no suggested explanation");
let data = yield getData(1);
is(data, null, "there is only one link and it's a history link");
// Test with enhanced = true
yield* addNewTabPageTab();
yield customizeNewTabPage("enhanced"); // Toggle enhanced on
({type, enhanced, title, suggested} = yield getData(0));
is(type, "organic", "directory link is organic");
isnot(enhanced, "", "directory link has enhanced image");
is(title, "title1");
is(suggested, "", "There is no suggested explanation");
({type, enhanced, title, suggested} = yield getData(1));
is(type, "enhanced", "history link is enhanced");
isnot(enhanced, "", "history link has enhanced image");
is(title, "title");
is(suggested, "", "There is no suggested explanation");
data = yield getData(2);
is(data, null, "there are only 2 links, directory and enhanced history");
// Test with a pinned link
setPinnedLinks("-1");
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
is(type, "enhanced", "pinned history link is enhanced");
isnot(enhanced, "", "pinned history link has enhanced image");
is(title, "title");
is(suggested, "", "There is no suggested explanation");
({type, enhanced, title, suggested} = yield getData(1));
is(type, "organic", "directory link is organic");
isnot(enhanced, "", "directory link has enhanced image");
is(title, "title1");
is(suggested, "", "There is no suggested explanation");
data = yield getData(2);
is(data, null, "directory link pushed out by pinned history link");
// Test pinned link with enhanced = false
yield* addNewTabPageTab();
yield customizeNewTabPage("enhanced"); // Toggle enhanced off
({type, enhanced, title, suggested} = yield getData(0));
isnot(type, "enhanced", "history link is not enhanced");
is(enhanced, "", "history link has no enhanced image");
is(title, "example.com");
is(suggested, "", "There is no suggested explanation");
data = yield getData(1);
is(data, null, "directory link still pushed out by pinned history link");
yield unpinCell(0);
// Test that a suggested tile is not enhanced by a directory tile
NewTabUtils.isTopPlacesSite = () => true;
yield setLinks("-1,2,3,4,5,6,7,8");
// Test with enhanced = false
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
isnot(type, "enhanced", "history link is not enhanced");
is(enhanced, "", "history link has no enhanced image");
is(title, "example.com");
is(suggested, "", "There is no suggested explanation");
data = yield getData(7);
isnot(data, null, "there are 8 history links");
data = yield getData(8);
is(data, null, "there are 8 history links");
// Test with enhanced = true
yield* addNewTabPageTab();
yield customizeNewTabPage("enhanced");
// Suggested link was not enhanced by directory link with same domain
({type, enhanced, title, suggested} = yield getData(0));
is(type, "affiliate", "suggested link is affiliate");
is(enhanced, "", "suggested link has no enhanced image");
is(title, "title2");
ok(suggested.indexOf("Suggested for <strong> Technology </strong> visitors") > -1, "Suggested for 'Technology'");
// Enhanced history link shows up second
({type, enhanced, title, suggested} = yield getData(1));
is(type, "enhanced", "pinned history link is enhanced");
isnot(enhanced, "", "pinned history link has enhanced image");
is(title, "title");
is(suggested, "", "There is no suggested explanation");
data = yield getData(9);
is(data, null, "there is a suggested link followed by an enhanced history link and the remaining history links");
// Test no override category/adgroup name.
let linksChangedPromise = watchLinksChangeOnce();
yield pushPrefs([PREF_NEWTAB_DIRECTORYSOURCE,
"data:application/json," + JSON.stringify({"suggested": [suggestedLink]})]);
yield linksChangedPromise;
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
Cu.reportError("SUGGEST " + suggested);
ok(suggested.indexOf("Suggested for <strong> Technology </strong> visitors") > -1, "Suggested for 'Technology'");
// Test server provided explanation string.
suggestedLink.explanation = "Suggested for %1$S enthusiasts who visit sites like %2$S";
linksChangedPromise = watchLinksChangeOnce();
yield pushPrefs([PREF_NEWTAB_DIRECTORYSOURCE,
"data:application/json," + encodeURIComponent(JSON.stringify({"suggested": [suggestedLink]}))]);
yield linksChangedPromise;
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
Cu.reportError("SUGGEST " + suggested);
ok(suggested.indexOf("Suggested for <strong> Technology </strong> enthusiasts who visit sites like <strong> classroom.google.com </strong>") > -1, "Suggested for 'Technology' enthusiasts");
// Test server provided explanation string with category override.
suggestedLink.adgroup_name = "webdev education";
linksChangedPromise = watchLinksChangeOnce();
yield pushPrefs([PREF_NEWTAB_DIRECTORYSOURCE,
"data:application/json," + encodeURIComponent(JSON.stringify({"suggested": [suggestedLink]}))]);
yield linksChangedPromise;
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
Cu.reportError("SUGGEST " + suggested);
ok(suggested.indexOf("Suggested for <strong> webdev education </strong> enthusiasts who visit sites like <strong> classroom.google.com </strong>") > -1, "Suggested for 'webdev education' enthusiasts");
// Test with xml entities in category name
suggestedLink.url = "http://example1.com/3";
suggestedLink.adgroup_name = ">angles< & \"quotes\'";
linksChangedPromise = watchLinksChangeOnce();
yield pushPrefs([PREF_NEWTAB_DIRECTORYSOURCE,
"data:application/json," + encodeURIComponent(JSON.stringify({"suggested": [suggestedLink]}))]);
yield linksChangedPromise;
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
Cu.reportError("SUGGEST " + suggested);
ok(suggested.indexOf("Suggested for <strong> >angles< & \"quotes\' </strong> enthusiasts who visit sites like <strong> classroom.google.com </strong>") > -1, "Suggested for 'xml entities' enthusiasts");
// Test with xml entities in explanation.
suggestedLink.explanation = "Testing junk explanation &<>\"'";
linksChangedPromise = watchLinksChangeOnce();
yield pushPrefs([PREF_NEWTAB_DIRECTORYSOURCE,
"data:application/json," + encodeURIComponent(JSON.stringify({"suggested": [suggestedLink]}))]);
yield linksChangedPromise;
yield* addNewTabPageTab();
({type, enhanced, title, suggested} = yield getData(0));
Cu.reportError("SUGGEST " + suggested);
ok(suggested.indexOf("Testing junk explanation &<>\"'") > -1, "Junk test");
});
|