Debian Codegraph @

third_party/rust/suggest/src/testing/data.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 //! Test data that we use in many tests
6
7 use crate::{suggestion::FtsMatchInfo, suggestion::YelpSubjectType, testing::MockIcon, Suggestion};
8 use serde_json::json;
9 use serde_json::Value as JsonValue;
10
11 pub fn los_pollos_amp() -> JsonValue {
12 json!({
13 "id": 100,
14 "advertiser": "Los Pollos Hermanos",
15 "iab_category": "8 - Food & Drink",
16 "keywords": ["lo", "los", "los p", "los pollos", "los pollos h", "los pollos hermanos"],
17 "full_keywords": [("los pollos", 4), ("los pollos hermanos", 2)],
18 "title": "Los Pollos Hermanos - Albuquerque",
19 "url": "https://www.lph-nm.biz",
20 "icon": "los-pollos-favicon",
21 "impression_url": "https://example.com/impression_url",
22 "click_url": "https://example.com/click_url",
23 "score": 0.3
24 })
25 }
26
27 pub fn los_pollos_icon() -> MockIcon {
28 MockIcon {
29 id: "los-pollos-favicon",
30 data: "los-pollos-icon-data",
31 mimetype: "image/png",
32 }
33 }
34
35 pub fn los_pollos_suggestion(
36 full_keyword: &str,
37 fts_match_info: Option<FtsMatchInfo>,
38 ) -> Suggestion {
39 Suggestion::Amp {
40 title: "Los Pollos Hermanos - Albuquerque".into(),
41 url: "https://www.lph-nm.biz".into(),
42 raw_url: "https://www.lph-nm.biz".into(),
43 icon: Some("los-pollos-icon-data".as_bytes().to_vec()),
44 icon_mimetype: Some("image/png".into()),
45 block_id: 100,
46 advertiser: "Los Pollos Hermanos".into(),
47 iab_category: "8 - Food & Drink".into(),
48 impression_url: "https://example.com/impression_url".into(),
49 click_url: "https://example.com/click_url".into(),
50 raw_click_url: "https://example.com/click_url".into(),
51 score: 0.3,
52 full_keyword: full_keyword.to_string(),
53 fts_match_info,
54 }
55 }
56
57 pub fn good_place_eats_amp() -> JsonValue {
58 json!({
59 "id": 101,
60 "advertiser": "Good Place Eats",
61 "iab_category": "8 - Food & Drink",
62 "keywords": ["la", "las", "lasa", "lasagna", "lasagna come out tomorrow"],
63 "full_keywords": [("lasagna", 2), ("lasagna come out tomorrow", 2)],
64 "title": "Lasagna Come Out Tomorrow",
65 "url": "https://www.lasagna.restaurant",
66 "icon": "good-place-eats-favicon",
67 "impression_url": "https://example.com/impression_url",
68 "click_url": "https://example.com/click_url"
69 })
70 }
71
72 pub fn good_place_eats_icon() -> MockIcon {
73 MockIcon {
74 id: "good-place-eats-favicon",
75 data: "good-place-eats-icon-data",
76 mimetype: "image/gif",
77 }
78 }
79
80 pub fn good_place_eats_suggestion(
81 full_keyword: &str,
82 fts_match_info: Option<FtsMatchInfo>,
83 ) -> Suggestion {
84 Suggestion::Amp {
85 title: "Lasagna Come Out Tomorrow".into(),
86 url: "https://www.lasagna.restaurant".into(),
87 raw_url: "https://www.lasagna.restaurant".into(),
88 icon: Some("good-place-eats-icon-data".as_bytes().to_vec()),
89 icon_mimetype: Some("image/gif".into()),
90 full_keyword: full_keyword.into(),
91 block_id: 101,
92 advertiser: "Good Place Eats".into(),
93 iab_category: "8 - Food & Drink".into(),
94 impression_url: "https://example.com/impression_url".into(),
95 click_url: "https://example.com/click_url".into(),
96 raw_click_url: "https://example.com/click_url".into(),
97 score: 0.2,
98 fts_match_info,
99 }
100 }
101
102 pub fn california_wiki() -> JsonValue {
103 json!({
104 "id": 200,
105 "advertiser": "Wikipedia",
106 "iab_category": "5 - Education",
107 "keywords": ["cal", "cali", "california"],
108 "title": "California",
109 "url": "https://wikipedia.org/California",
110 "icon": "california-favicon",
111 })
112 }
113
114 pub fn california_icon() -> MockIcon {
115 MockIcon {
116 id: "california-favicon",
117 data: "california-icon-data",
118 mimetype: "image/png",
119 }
120 }
121
122 pub fn california_suggestion(full_keyword: &str) -> Suggestion {
123 Suggestion::Wikipedia {
124 title: "California".into(),
125 url: "https://wikipedia.org/California".into(),
126 icon: Some("california-icon-data".as_bytes().to_vec()),
127 icon_mimetype: Some("image/png".into()),
128 full_keyword: full_keyword.into(),
129 }
130 }
131
132 pub fn caltech_wiki() -> JsonValue {
133 json!({
134 "id": 2001,
135 "advertiser": "Wikipedia",
136 "iab_category": "5 - Education",
137 "keywords": ["cal", "cali", "california", "institute", "technology"],
138 "title": "California Institute of Technology",
139 "url": "https://wikipedia.org/California_Institute_of_Technology",
140 "icon": "caltech-favicon"
141 })
142 }
143
144 pub fn caltech_icon() -> MockIcon {
145 MockIcon {
146 id: "caltech-favicon",
147 data: "caltech-icon-data",
148 mimetype: "image/png",
149 }
150 }
151
152 pub fn caltech_suggestion(full_keyword: &str) -> Suggestion {
153 Suggestion::Wikipedia {
154 title: "California Institute of Technology".into(),
155 url: "https://wikipedia.org/California_Institute_of_Technology".into(),
156 icon: Some("caltech-icon-data".as_bytes().to_vec()),
157 icon_mimetype: Some("image/png".into()),
158 full_keyword: full_keyword.into(),
159 }
160 }
161
162 pub fn relay_amo() -> JsonValue {
163 json!({
164 "title": "Firefox Relay",
165 "description": "Firefox Relay -- Email masking",
166 "url": "https://example.org/amo-suggestion-1",
167 "guid": "{b9db16a4-6edc-47ec-a1f4-b86292ed211d}",
168 "keywords": ["relay", "spam", "masking email", "alias"],
169 "icon": "https://example.org/amo-suggestion-1/icon.png",
170 "rating": "4.9",
171 "number_of_ratings": 800,
172 "score": 0.25
173 })
174 }
175
176 pub fn dark_mode_amo() -> JsonValue {
177 json!({
178 "title": "Dark Mode",
179 "description": "Ease your eyes",
180 "url": "https://example.org/amo-suggestion-2",
181 "guid": "{6d24e3b8-1400-4d37-9440-c798f9b79b1a}",
182 "keywords": ["dark mode", "dark theme", "night mode"],
183 "icon": "https://example.org/amo-suggestion-2/icon.png",
184 "rating": "4.6",
185 "number_of_ratings": 750,
186 "score": 0.25
187 })
188 }
189
190 pub fn foxy_guestures_amo() -> JsonValue {
191 json!({
192 "title": "Foxy Guestures",
193 "description": "Mouse gestures for Firefox",
194 "url": "https://example.org/amo-suggestion-3",
195 "guid": "{1e9d493b-0498-48bb-9b9a-8b45a44df146}",
196 "keywords": ["grammar", "spelling", "edit"],
197 "icon": "https://example.org/amo-suggestion-3/icon.png",
198 "rating": "4.8",
199 "number_of_ratings": 900,
200 "score": 0.25
201 })
202 }
203
204 pub fn new_tab_override_amo() -> JsonValue {
205 json!({
206 "title": "New Tab Override",
207 "description": "New Tab Override allows you to set the page that shows whenever you open a new tab",
208 "url": "https://example.org/amo-suggestion-4",
209 "guid": "{1ea82ebd-a1ba-4f57-b8bb-3824ead837bd}",
210 "keywords": ["image search", "visual search"],
211 "icon": "https://example.org/amo-suggestion-4/icon.png",
212 "rating": "5.0",
213 "number_of_ratings": 100,
214 "score": 0.25
215 })
216 }
217
218 pub fn relay_suggestion() -> Suggestion {
219 Suggestion::Amo {
220 title: "Firefox Relay".into(),
221 url: "https://example.org/amo-suggestion-1".into(),
222 icon_url: "https://example.org/amo-suggestion-1/icon.png".into(),
223 description: "Firefox Relay -- Email masking".into(),
224 rating: Some("4.9".into()),
225 number_of_ratings: 800,
226 guid: "{b9db16a4-6edc-47ec-a1f4-b86292ed211d}".into(),
227 score: 0.25,
228 }
229 }
230
231 pub fn dark_mode_suggestion() -> Suggestion {
232 Suggestion::Amo {
233 title: "Dark Mode".into(),
234 url: "https://example.org/amo-suggestion-2".into(),
235 icon_url: "https://example.org/amo-suggestion-2/icon.png".into(),
236 description: "Ease your eyes".into(),
237 rating: Some("4.6".into()),
238 number_of_ratings: 750,
239 guid: "{6d24e3b8-1400-4d37-9440-c798f9b79b1a}".into(),
240 score: 0.25,
241 }
242 }
243
244 pub fn foxy_guestures_suggestion() -> Suggestion {
245 Suggestion::Amo {
246 title: "Foxy Guestures".into(),
247 url: "https://example.org/amo-suggestion-3".into(),
248 icon_url: "https://example.org/amo-suggestion-3/icon.png".into(),
249 description: "Mouse gestures for Firefox".into(),
250 rating: Some("4.8".into()),
251 number_of_ratings: 900,
252 guid: "{1e9d493b-0498-48bb-9b9a-8b45a44df146}".into(),
253 score: 0.25,
254 }
255 }
256
257 pub fn new_tab_override_suggestion() -> Suggestion {
258 Suggestion::Amo {
259 title: "New Tab Override".into(),
260 url: "https://example.org/amo-suggestion-4".into(),
261 icon_url: "https://example.org/amo-suggestion-4/icon.png".into(),
262 description:
263 "New Tab Override allows you to set the page that shows whenever you open a new tab"
264 .into(),
265 rating: Some("5.0".into()),
266 number_of_ratings: 100,
267 guid: "{1ea82ebd-a1ba-4f57-b8bb-3824ead837bd}".into(),
268 score: 0.25,
269 }
270 }
271
272 pub fn burnout_pocket() -> JsonValue {
273 json!({
274 "description": "pocket suggestion",
275 "url": "https://getpocket.com/collections/its-not-just-burnout-how-grind-culture-failed-women",
276 "lowConfidenceKeywords": ["soft life", "workaholism", "toxic work culture", "work-life balance"],
277 "highConfidenceKeywords": ["burnout women", "grind culture", "women burnout"],
278 "title": "‘It’s Not Just Burnout:’ How Grind Culture Fails Women",
279 "score": 0.25
280 })
281 }
282
283 pub fn burnout_suggestion(is_top_pick: bool) -> Suggestion {
284 Suggestion::Pocket {
285 title: "‘It’s Not Just Burnout:’ How Grind Culture Fails Women".into(),
286 url:
287 "https://getpocket.com/collections/its-not-just-burnout-how-grind-culture-failed-women"
288 .into(),
289 score: 0.25,
290 is_top_pick,
291 }
292 }
293
294 pub fn ramen_yelp() -> JsonValue {
295 json!({
296 "subjects": ["ramen", "spicy ramen", "spicy random ramen", "rats", "raven", "raccoon", "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789Z"],
297 "businessSubjects": ["the shop"],
298 "preModifiers": ["best", "super best", "same_modifier"],
299 "postModifiers": ["delivery", "super delivery", "same_modifier"],
300 "locationSigns": [
301 // V1 format also can be used as location sign.
302 { "keyword": "in", "needLocation": true },
303 { "keyword": "near by", "needLocation": false },
304 // V2 format.
305 "near",
306 "near me",
307 ],
308 "yelpModifiers": ["yelp", "yelp keyword"],
309 "icon": "yelp-favicon",
310 "score": 0.5
311 })
312 }
313
314 pub fn ramen_suggestion(title: &str, url: &str) -> Suggestion {
315 Suggestion::Yelp {
316 title: title.into(),
317 url: url.into(),
318 icon: Some("yelp-favicon-data".into()),
319 icon_mimetype: Some("image/svg+xml".into()),
320 score: 0.5,
321 has_location_sign: true,
322 subject_exact_match: true,
323 subject_type: YelpSubjectType::Service,
324 location_param: "find_loc".into(),
325 }
326 }
327
328 pub fn yelp_favicon() -> MockIcon {
329 MockIcon {
330 id: "yelp-favicon",
331 data: "yelp-favicon-data",
332 mimetype: "image/svg+xml",
333 }
334 }
335
336 pub fn array_mdn() -> JsonValue {
337 json!({
338 "description": "Javascript Array",
339 "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",
340 "keywords": ["array javascript", "javascript array", "wildcard"],
341 "title": "Array",
342 "score": 0.24
343 })
344 }
345
346 pub fn array_suggestion() -> Suggestion {
347 Suggestion::Mdn {
348 title: "Array".into(),
349 url:
350 "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"
351 .into(),
352 description: "Javascript Array".into(),
353 score: 0.24,
354 }
355 }
356
357 pub fn multimatch_wiki() -> JsonValue {
358 json!({
359 "id": 0,
360 "advertiser": "Wikipedia",
361 "iab_category": "5 - Education",
362 "keywords": ["multimatch"],
363 "title": "Multimatch",
364 "url": "https://wikipedia.org/Multimatch",
365 "icon": "multimatch-wiki-favicon"
366 })
367 }
368
369 pub fn multimatch_amo() -> JsonValue {
370 json!({
371 "description": "amo suggestion multi-match",
372 "url": "https://addons.mozilla.org/en-US/firefox/addon/multimatch",
373 "guid": "{b9db16a4-6edc-47ec-a1f4-b86292ed211d}",
374 "keywords": ["multimatch"],
375 "title": "Firefox Multimatch",
376 "icon": "https://addons.mozilla.org/user-media/addon_icons/2633/2633704-64.png?modified=2c11a80b",
377 "rating": "4.9",
378 "number_of_ratings": 888,
379 "score": 0.25
380 })
381 }
382
383 pub fn multimatch_pocket() -> JsonValue {
384 json!({
385 "description": "pocket suggestion multi-match",
386 "url": "https://getpocket.com/collections/multimatch",
387 "lowConfidenceKeywords": [],
388 "highConfidenceKeywords": ["multimatch"],
389 "title": "Multimatching",
390 "score": 0.88
391 })
392 }
393
394 pub fn multimatch_wiki_icon() -> MockIcon {
395 MockIcon {
396 id: "multimatch-wiki-favicon",
397 data: "multimatch-wiki-icon-data",
398 mimetype: "image/png",
399 }
400 }
401
402 pub fn multimatch_pocket_suggestion(is_top_pick: bool) -> Suggestion {
403 Suggestion::Pocket {
404 title: "Multimatching".into(),
405 url: "https://getpocket.com/collections/multimatch".into(),
406 score: 0.88,
407 is_top_pick,
408 }
409 }
410
411 pub fn multimatch_amo_suggestion() -> Suggestion {
412 Suggestion::Amo {
413 title: "Firefox Multimatch".into(),
414 url: "https://addons.mozilla.org/en-US/firefox/addon/multimatch".into(),
415 icon_url: "https://addons.mozilla.org/user-media/addon_icons/2633/2633704-64.png?modified=2c11a80b".into(),
416 description: "amo suggestion multi-match".into(),
417 rating: Some("4.9".into()),
418 number_of_ratings: 888,
419 guid: "{b9db16a4-6edc-47ec-a1f4-b86292ed211d}".into(),
420 score: 0.25,
421 }
422 }
423
424 pub fn multimatch_wiki_suggestion() -> Suggestion {
425 Suggestion::Wikipedia {
426 title: "Multimatch".into(),
427 url: "https://wikipedia.org/Multimatch".into(),
428 icon: Some("multimatch-wiki-icon-data".as_bytes().to_vec()),
429 icon_mimetype: Some("image/png".into()),
430 full_keyword: "multimatch".into(),
431 }
432 }
433
434 // Fakespot test data
435
436 pub fn snowglobe_fakespot() -> JsonValue {
437 json!({
438 "fakespot_grade": "B",
439 "product_id": "amazon-ABC",
440 "keywords": "",
441 "product_type": "snow globe",
442 "rating": 4.7,
443 "score": 0.8,
444 "title": "Make Your Own Glitter Snow Globes",
445 "total_reviews": 152,
446 "url": "http://amazon.com/dp/ABC"
447 })
448 }
449
450 pub fn snowglobe_suggestion(match_info: Option<FtsMatchInfo>) -> Suggestion {
451 Suggestion::Fakespot {
452 fakespot_grade: "B".into(),
453 product_id: "amazon-ABC".into(),
454 rating: 4.7,
455 title: "Make Your Own Glitter Snow Globes".into(),
456 total_reviews: 152,
457 url: "http://amazon.com/dp/ABC".into(),
458 score: 0.3 + 0.00008,
459 icon: Some("fakespot-icon-amazon-data".as_bytes().to_vec()),
460 icon_mimetype: Some("image/png".into()),
461 match_info,
462 }
463 }
464
465 pub fn simpsons_fakespot() -> JsonValue {
466 json!({
467 "fakespot_grade": "A",
468 // Use a product ID that doesn't match the ingested icons to test what happens. In this
469 // case, icon and icon_mimetype for the returned Suggestion should both be None.
470 "product_id": "vendorwithouticon-XYZ",
471 "keywords": "",
472 "product_type": "",
473 "rating": 4.9,
474 "score": 0.9,
475 "title": "The Simpsons: Skinner's Sense of Snow (DVD)",
476 "total_reviews": 14000,
477 "url": "http://vendorwithouticon.com/dp/XYZ"
478 })
479 }
480
481 pub fn simpsons_suggestion(match_info: Option<FtsMatchInfo>) -> Suggestion {
482 Suggestion::Fakespot {
483 fakespot_grade: "A".into(),
484 product_id: "vendorwithouticon-XYZ".into(),
485 rating: 4.9,
486 title: "The Simpsons: Skinner's Sense of Snow (DVD)".into(),
487 total_reviews: 14000,
488 url: "http://vendorwithouticon.com/dp/XYZ".into(),
489 score: 0.3 + 0.00009,
490 icon: None,
491 icon_mimetype: None,
492 match_info,
493 }
494 }
495
496 pub fn fakespot_amazon_icon() -> MockIcon {
497 MockIcon {
498 id: "fakespot-amazon",
499 data: "fakespot-icon-amazon-data",
500 mimetype: "image/png",
501 }
502 }