test_interactions_blocklist.js (2460B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Tests that blocked sites are caught by InteractionsBlocklist. 6 */ 7 8 ChromeUtils.defineESModuleGetters(this, { 9 InteractionsBlocklist: 10 "moz-src:///browser/components/places/InteractionsBlocklist.sys.mjs", 11 }); 12 13 let BLOCKED_URLS = [ 14 "https://www.bing.com/search?q=mozilla", 15 "https://duckduckgo.com/?q=a+test&kp=1&t=ffab", 16 "https://www.google.com/search?q=mozilla", 17 "https://www.google.ca/search?q=test", 18 "https://mozilla.zoom.us/j/123456789", 19 "https://yandex.az/search/?text=mozilla", 20 "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&ch=&tn=baidu&bar=&wd=mozilla&rn=&fenlei=256&oq=&rsv_pq=970f2b8f001757b9&rsv_t=1f5d2V2o80HPdZtZnhodwkc7nZXTvDI1zwdPy%2FAeomnvFFGIrU1F3D9WoK4&rqlang=cn", 21 "https://accounts.google.com/o/oauth2/v2/auth/identifier/foobar", 22 "https://auth.mozilla.auth0.com/login/foobar", 23 "https://accounts.google.com/signin/oauth/consent/foobar", 24 "https://accounts.google.com/o/oauth2/v2/auth?client_id=ZZZ", 25 "https://login.microsoftonline.com/common/oauth2/v2.0/authorize/foobar", 26 ]; 27 28 let ALLOWED_URLS = [ 29 "https://example.com", 30 "https://zoom.us/pricing", 31 "https://www.google.ca/maps/place/Toronto,+ON/@43.7181557,-79.5181414,11z/data=!3m1!4b1!4m5!3m4!1s0x89d4cb90d7c63ba5:0x323555502ab4c477!8m2!3d43.653226!4d-79.3831843", 32 "https://example.com/https://auth.mozilla.auth0.com/login/foobar", 33 ]; 34 35 // Tests that initializing InteractionsBlocklist loads the regexes from the 36 // customBlocklist pref on initialization. This subtest should always be the 37 // first one in this file. 38 add_task(async function blockedOnInit() { 39 Services.prefs.setStringPref( 40 "places.interactions.customBlocklist", 41 '["^(https?:\\\\/\\\\/)?mochi.test"]' 42 ); 43 Assert.ok( 44 InteractionsBlocklist.isUrlBlocklisted("https://mochi.test"), 45 "mochi.test is blocklisted." 46 ); 47 InteractionsBlocklist.removeRegexFromBlocklist("^(https?:\\/\\/)?mochi.test"); 48 Assert.ok( 49 !InteractionsBlocklist.isUrlBlocklisted("https://mochi.test"), 50 "mochi.test is not blocklisted." 51 ); 52 }); 53 54 add_task(async function test() { 55 for (let url of BLOCKED_URLS) { 56 Assert.ok( 57 InteractionsBlocklist.isUrlBlocklisted(url), 58 `${url} is blocklisted.` 59 ); 60 } 61 62 for (let url of ALLOWED_URLS) { 63 Assert.ok( 64 !InteractionsBlocklist.isUrlBlocklisted(url), 65 `${url} is not blocklisted.` 66 ); 67 } 68 });