tor-browser

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

test_dedupe_prefix.js (8469B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_setup(() => {
      7  UrlbarPrefs.set("suggest.quickactions", false);
      8 });
      9 
     10 // Testing that we dedupe results that have the same URL and title as another
     11 // except for their prefix (e.g. http://www.).
     12 add_task(async function dedupe_prefix() {
     13  // We need to set the title or else we won't dedupe. We only dedupe when
     14  // titles match up to mitigate deduping when the www. version of a site is
     15  // completely different from it's www-less counterpart and thus presumably
     16  // has a different title.
     17  await PlacesTestUtils.addVisits([
     18    {
     19      uri: "http://example.com/foo/",
     20      title: "Example Page",
     21    },
     22    {
     23      uri: "http://www.example.com/foo/",
     24      title: "Example Page",
     25    },
     26    {
     27      uri: "https://example.com/foo/",
     28      title: "Example Page",
     29    },
     30    // Note that we add https://www.example.com/foo/ twice here.
     31    {
     32      uri: "https://www.example.com/foo/",
     33      title: "Example Page",
     34    },
     35    {
     36      uri: "https://www.example.com/foo/",
     37      title: "Example Page",
     38    },
     39  ]);
     40 
     41  // Expected results:
     42  //
     43  // Autofill result:
     44  //   https://www.example.com has the highest origin frecency since we added 2
     45  //   visits to https://www.example.com/foo/ and only one visit to the other
     46  //   URLs.
     47  // Other results:
     48  //   https://example.com/foo/ has the highest possible prefix rank, and it
     49  //   does not dupe the autofill result, so only it should be included.
     50  let context = createContext("example.com/foo/", { isPrivate: false });
     51  await check_results({
     52    context,
     53    autofilled: "example.com/foo/",
     54    completed: "https://www.example.com/foo/",
     55    matches: [
     56      makeVisitResult(context, {
     57        uri: "https://www.example.com/foo/",
     58        title: "Example Page",
     59        heuristic: true,
     60      }),
     61      makeVisitResult(context, {
     62        uri: "https://example.com/foo/",
     63        title: "Example Page",
     64      }),
     65    ],
     66  });
     67 
     68  // Add more visits to the lowest-priority prefix. It should be the heuristic
     69  // result but we should still show our highest-priority result. https://www.
     70  // should not appear at all.
     71  for (let i = 0; i < 3; i++) {
     72    await PlacesTestUtils.addVisits([
     73      {
     74        uri: "http://www.example.com/foo/",
     75        title: "Example Page",
     76      },
     77    ]);
     78  }
     79 
     80  // Expected results:
     81  //
     82  // Autofill result:
     83  //   http://www.example.com now has the highest origin frecency since we added
     84  //   4 visits to http://www.example.com/foo/
     85  // Other results:
     86  //   Same as before
     87  context = createContext("example.com/foo/", { isPrivate: false });
     88  await check_results({
     89    context,
     90    autofilled: "example.com/foo/",
     91    completed: "http://www.example.com/foo/",
     92    matches: [
     93      makeVisitResult(context, {
     94        uri: "http://www.example.com/foo/",
     95        title: "Example Page",
     96        heuristic: true,
     97      }),
     98      makeVisitResult(context, {
     99        uri: "https://example.com/foo/",
    100        title: "Example Page",
    101      }),
    102    ],
    103  });
    104 
    105  // Add enough https:// vists for it to have the highest frecency. It should
    106  // be the heuristic result. We should still get the https://www. result
    107  // because we still show results with the same key and protocol if they differ
    108  // from the heuristic result in having www.
    109  for (let i = 0; i < 5; i++) {
    110    await PlacesTestUtils.addVisits([
    111      {
    112        uri: "https://example.com/foo/",
    113        title: "Example Page",
    114      },
    115    ]);
    116  }
    117 
    118  // Expected results:
    119  //
    120  // Autofill result:
    121  //   https://example.com now has the highest origin frecency since we added
    122  //   6 visits to https://example.com/foo/
    123  // Other results:
    124  //   https://example.com/foo/ has the highest possible prefix rank, but it
    125  //   dupes the heuristic so it should not be included.
    126  //   https://www.example.com/foo/ has the next highest prefix rank, and it
    127  //   does not dupe the heuristic, so only it should be included.
    128  context = createContext("example.com/foo/", { isPrivate: false });
    129  await check_results({
    130    context,
    131    autofilled: "example.com/foo/",
    132    completed: "https://example.com/foo/",
    133    matches: [
    134      makeVisitResult(context, {
    135        uri: "https://example.com/foo/",
    136        title: "Example Page",
    137        heuristic: true,
    138      }),
    139    ],
    140  });
    141 
    142  await cleanupPlaces();
    143 });
    144 
    145 // This is the same as the previous task but with `experimental.hideHeuristic`
    146 // enabled.
    147 add_task(async function hideHeuristic() {
    148  UrlbarPrefs.set("experimental.hideHeuristic", true);
    149 
    150  // We need to set the title or else we won't dedupe. We only dedupe when
    151  // titles match up to mitigate deduping when the www. version of a site is
    152  // completely different from it's www-less counterpart and thus presumably
    153  // has a different title.
    154  await PlacesTestUtils.addVisits([
    155    {
    156      uri: "http://example.com/foo/",
    157      title: "Example Page",
    158    },
    159    {
    160      uri: "http://www.example.com/foo/",
    161      title: "Example Page",
    162    },
    163    {
    164      uri: "https://example.com/foo/",
    165      title: "Example Page",
    166    },
    167    // Note that we add https://www.example.com/foo/ twice here.
    168    {
    169      uri: "https://www.example.com/foo/",
    170      title: "Example Page",
    171    },
    172    {
    173      uri: "https://www.example.com/foo/",
    174      title: "Example Page",
    175    },
    176  ]);
    177 
    178  // Expected results:
    179  //
    180  // Autofill result:
    181  //   https://www.example.com has the highest origin frecency since we added 2
    182  //   visits to https://www.example.com/foo/ and only one visit to the other
    183  //   URLs.
    184  // Other results:
    185  //   https://example.com/foo/ has the highest possible prefix rank, and it
    186  //   does not dupe the autofill result, so only it should be included.
    187  let context = createContext("example.com/foo/", { isPrivate: false });
    188  await check_results({
    189    context,
    190    autofilled: "example.com/foo/",
    191    completed: "https://www.example.com/foo/",
    192    matches: [
    193      makeVisitResult(context, {
    194        uri: "https://www.example.com/foo/",
    195        title: "Example Page",
    196        heuristic: true,
    197      }),
    198      makeVisitResult(context, {
    199        uri: "https://example.com/foo/",
    200        title: "Example Page",
    201      }),
    202    ],
    203  });
    204 
    205  // Add more visits to the lowest-priority prefix. It should be the heuristic
    206  // result but we should still show our highest-priority result. https://www.
    207  // should not appear at all.
    208  for (let i = 0; i < 3; i++) {
    209    await PlacesTestUtils.addVisits([
    210      {
    211        uri: "http://www.example.com/foo/",
    212        title: "Example Page",
    213      },
    214    ]);
    215  }
    216 
    217  // Expected results:
    218  //
    219  // Autofill result:
    220  //   http://www.example.com now has the highest origin frecency since we added
    221  //   4 visits to http://www.example.com/foo/
    222  // Other results:
    223  //   Same as before
    224  context = createContext("example.com/foo/", { isPrivate: false });
    225  await check_results({
    226    context,
    227    autofilled: "example.com/foo/",
    228    completed: "http://www.example.com/foo/",
    229    matches: [
    230      makeVisitResult(context, {
    231        uri: "http://www.example.com/foo/",
    232        title: "Example Page",
    233        heuristic: true,
    234      }),
    235      makeVisitResult(context, {
    236        uri: "https://example.com/foo/",
    237        title: "Example Page",
    238      }),
    239    ],
    240  });
    241 
    242  // Add enough https:// vists for it to have the highest frecency.
    243  for (let i = 0; i < 5; i++) {
    244    await PlacesTestUtils.addVisits([
    245      {
    246        uri: "https://example.com/foo/",
    247        title: "Example Page",
    248      },
    249    ]);
    250  }
    251 
    252  // Expected results:
    253  //
    254  // Autofill result:
    255  //   https://example.com now has the highest origin frecency since we added
    256  //   6 visits to https://example.com/foo/
    257  // Other results:
    258  //   https://example.com/foo/ has the highest possible prefix rank. It dupes
    259  //   the heuristic so ordinarily it should not be included, but because the
    260  //   heuristic is hidden, only it should appear.
    261  context = createContext("example.com/foo/", { isPrivate: false });
    262  await check_results({
    263    context,
    264    autofilled: "example.com/foo/",
    265    completed: "https://example.com/foo/",
    266    matches: [
    267      makeVisitResult(context, {
    268        uri: "https://example.com/foo/",
    269        title: "Example Page",
    270        heuristic: true,
    271      }),
    272      makeVisitResult(context, {
    273        uri: "https://example.com/foo/",
    274        title: "Example Page",
    275      }),
    276    ],
    277  });
    278 
    279  await cleanupPlaces();
    280  UrlbarPrefs.clear("experimental.hideHeuristic");
    281 });