tor-browser

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

test_text_preprocessing.js (2721B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const { SmartTabGroupingManager } = ChromeUtils.importESModule(
      5  "moz-src:///browser/components/tabbrowser/SmartTabGrouping.sys.mjs"
      6 );
      7 
      8 add_task(function test_text_processing_basic_cases() {
      9  // trailing domain-like text should be removed
     10  Assert.equal(
     11    SmartTabGroupingManager.preprocessText("Some Title - Random Mail"),
     12    "Some Title",
     13    "Should remove '- Random Mail' suffix and lowercase result"
     14  );
     15 
     16  // trailing domain-like text with '|'
     17  Assert.equal(
     18    SmartTabGroupingManager.preprocessText(
     19      "Another Title | Some Video Website"
     20    ),
     21    "Another Title",
     22    "Should remove '| Some Video Website' suffix and lowercase result"
     23  );
     24 
     25  // no delimiter
     26  Assert.equal(
     27    SmartTabGroupingManager.preprocessText("Simple Title"),
     28    "Simple Title",
     29    "Should only be lowercased since there's no recognized delimiter"
     30  );
     31 
     32  // not enough info in first part
     33  Assert.equal(
     34    SmartTabGroupingManager.preprocessText("AB - Mail"),
     35    "AB - Mail",
     36    "Should not remove '- Mail' because the first part is too short"
     37  );
     38 
     39  // should not match for texts such as 'check-in'
     40  Assert.equal(
     41    SmartTabGroupingManager.preprocessText("Check-in for flight"),
     42    "Check-in for flight",
     43    "Should not remove '-in'"
     44  );
     45 });
     46 
     47 add_task(function test_text_processing_edge_cases() {
     48  // empty string
     49  Assert.equal(
     50    SmartTabGroupingManager.preprocessText(""),
     51    "",
     52    "Empty string returns empty string"
     53  );
     54 
     55  // exactly 20 chars
     56  const domain20Chars = "12345678901234567890"; // 20 characters
     57  Assert.equal(
     58    SmartTabGroupingManager.preprocessText(`My Title - ${domain20Chars}`),
     59    `My Title - ${domain20Chars}`,
     60    "Should not remove suffix because it’s exactly 20 chars long, not < 20"
     61  );
     62 
     63  // multiple delimiters, remove last only
     64  Assert.equal(
     65    SmartTabGroupingManager.preprocessText("Complex - Title - SomethingSmall"),
     66    "Complex Title",
     67    "Should remove only the last '- SomethingSmall', ignoring earlier delimiters"
     68  );
     69 
     70  // repeated delimiters
     71  Assert.equal(
     72    SmartTabGroupingManager.preprocessText("Title --- Domain"),
     73    "Title",
     74    "Should remove the last chunk and filter out empty strings"
     75  );
     76 
     77  Assert.equal(
     78    SmartTabGroupingManager.preprocessText("Title || Domain"),
     79    "Title",
     80    "Should remove the last chunk with double pipe delimiters too"
     81  );
     82 
     83  // long trailing text
     84  const longDomain = "Useful information is present";
     85  Assert.equal(
     86    SmartTabGroupingManager.preprocessText(`Some Title - ${longDomain}`),
     87    `Some Title - ${longDomain}`,
     88    "Should not remove suffix if it's >= 20 characters"
     89  );
     90 });