tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_match_javascript.js (4484B)


      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 /**
      6 * Test for bug 417798 to make sure javascript: URIs don't show up unless the
      7 * user searches for javascript: explicitly.
      8 */
      9 
     10 testEngine_setup();
     11 
     12 add_task(async function test_javascript_match() {
     13  Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
     14  Services.prefs.setBoolPref("browser.urlbar.suggest.engines", false);
     15  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
     16  registerCleanupFunction(() => {
     17    Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
     18    Services.prefs.clearUserPref("browser.urlbar.suggest.engines");
     19    Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
     20  });
     21 
     22  let uri1 = Services.io.newURI("http://abc/def");
     23  let uri2 = Services.io.newURI("javascript:5");
     24  await PlacesTestUtils.addBookmarkWithDetails({
     25    uri: uri2,
     26    title: "Title with javascript:",
     27  });
     28  await PlacesTestUtils.addVisits([
     29    { uri: uri1, title: "Title with javascript:" },
     30  ]);
     31 
     32  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();
     33 
     34  info("Match non-javascript: with plain search");
     35  let context = createContext("a", {
     36    isPrivate: false,
     37    allowAutofill: false /* avoid autofilling abc, as it's not necessary */,
     38  });
     39  await check_results({
     40    context,
     41    matches: [
     42      makeSearchResult(context, {
     43        engineName: SUGGESTIONS_ENGINE_NAME,
     44        heuristic: true,
     45      }),
     46      makeVisitResult(context, {
     47        uri: uri1.spec,
     48        title: "Title with javascript:",
     49      }),
     50    ],
     51  });
     52 
     53  info("Match non-javascript: with 'javascript'");
     54  context = createContext("javascript", { isPrivate: false });
     55  await check_results({
     56    context,
     57    matches: [
     58      makeSearchResult(context, {
     59        engineName: SUGGESTIONS_ENGINE_NAME,
     60        heuristic: true,
     61      }),
     62      makeVisitResult(context, {
     63        uri: uri1.spec,
     64        title: "Title with javascript:",
     65      }),
     66    ],
     67  });
     68 
     69  info("Match non-javascript with 'javascript:'");
     70  context = createContext("javascript:", { isPrivate: false });
     71  await check_results({
     72    context,
     73    matches: [
     74      makeSearchResult(context, {
     75        engineName: SUGGESTIONS_ENGINE_NAME,
     76        heuristic: true,
     77      }),
     78      makeVisitResult(context, {
     79        uri: uri1.spec,
     80        title: "Title with javascript:",
     81      }),
     82    ],
     83  });
     84 
     85  info("Match nothing with '5 javascript:'");
     86  context = createContext("5 javascript:", { isPrivate: false });
     87  await check_results({
     88    context,
     89    matches: [
     90      makeSearchResult(context, {
     91        engineName: SUGGESTIONS_ENGINE_NAME,
     92        heuristic: true,
     93      }),
     94    ],
     95  });
     96 
     97  info("Match non-javascript: with 'a javascript:'");
     98  context = createContext("a javascript:", { isPrivate: false });
     99  await check_results({
    100    context,
    101    matches: [
    102      makeSearchResult(context, {
    103        engineName: SUGGESTIONS_ENGINE_NAME,
    104        heuristic: true,
    105      }),
    106      makeVisitResult(context, {
    107        uri: uri1.spec,
    108        title: "Title with javascript:",
    109      }),
    110    ],
    111  });
    112 
    113  info("Match non-javascript: and javascript: with 'javascript: a'");
    114  context = createContext("javascript: a", { isPrivate: false });
    115  await check_results({
    116    context,
    117    matches: [
    118      makeVisitResult(context, {
    119        uri: "javascript: a",
    120        title: "javascript: a",
    121        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
    122        heuristic: true,
    123      }),
    124      makeBookmarkResult(context, {
    125        uri: uri2.spec,
    126        iconUri: "chrome://global/skin/icons/defaultFavicon.svg",
    127        title: "Title with javascript:",
    128      }),
    129      makeVisitResult(context, {
    130        uri: uri1.spec,
    131        title: "Title with javascript:",
    132      }),
    133    ],
    134  });
    135 
    136  info("Match javascript: with 'javascript: 5'");
    137  context = createContext("javascript: 5", { isPrivate: false });
    138  await check_results({
    139    context,
    140    matches: [
    141      makeVisitResult(context, {
    142        uri: "javascript: 5",
    143        title: "javascript: 5",
    144        source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
    145        heuristic: true,
    146      }),
    147      makeBookmarkResult(context, {
    148        uri: uri2.spec,
    149        iconUri: "chrome://global/skin/icons/defaultFavicon.svg",
    150        title: "Title with javascript:",
    151      }),
    152    ],
    153  });
    154 
    155  await cleanupPlaces();
    156 });