tor-browser

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

HighlightRegistry-iteration-with-modifications.html (8523B)


      1 <!doctype html>
      2 <title>HighlightRegistry iteration with insertions and deletions inbetween</title>
      3 <link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script>
      7  'use strict';
      8  let customHighlight1 = new Highlight();
      9  let customHighlight2 = new Highlight();
     10  let highlightName1 = "example1";
     11  let highlightName2 = "example2";
     12 
     13  // Test insertions using .add
     14  test(() => {
     15    let iterator = CSS.highlights[Symbol.iterator]();
     16    CSS.highlights.set(highlightName1, customHighlight1);
     17    let element = iterator.next();
     18    assert_true(element.done, 'The iteration ends although we added a new Highlight after starting the iteration');
     19    assert_equals(element.value, undefined, 'A Highlight added after starting the iteration is not found during the current iteration');
     20  }, 'HighlightRegistry iteration is not modified when a new Highlight is added after starting the iteration');
     21 
     22  CSS.highlights.clear();
     23 
     24  test(() => {
     25    CSS.highlights.set(highlightName1, customHighlight1);
     26    let iterator = CSS.highlights[Symbol.iterator]();
     27    CSS.highlights.set(highlightName2, customHighlight2);
     28    let element = iterator.next();
     29    assert_false(element.done, 'The iteration doesn\'t end although there was a second Highlight added to the HighlightRegistry after starting the iteration');
     30    assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned although a second Highlight was added after starting the iteration');
     31    assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned although a second Highlight was added after starting the iteration');
     32    element = iterator.next();
     33    assert_true(element.done, 'The iteration ends after going through all the Highlights that were in the HighlightRegistry when the iteration started although there was a Highlight addition after starting the iteration');
     34    assert_equals(element.value, undefined, 'A Highlight added after starting the iteration is not found during the current iteration');
     35  }, 'HighlightRegistry iteration is not modified when a new Highlight is added after starting the iteration with one Highlight in the HighlightRegistry');
     36 
     37  CSS.highlights.clear();
     38 
     39  // Test deletions using .delete
     40  test(() => {
     41    CSS.highlights.set(highlightName1, customHighlight1);
     42    let iterator = CSS.highlights[Symbol.iterator]();
     43    CSS.highlights.delete(highlightName1);
     44    let element = iterator.next();
     45    assert_false(element.done, 'The iteration doesn\'t end although the Highlight that was pointed to by the iterator was deleted');
     46    assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned although it was deleted after starting the iteration');
     47    assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned although it was deleted after starting the iteration');
     48    element = iterator.next();
     49    assert_true(element.done, 'The iteration ends after going through all the highlights although the Highlight that was pointed to by the iterator was deleted after starting the iteration');
     50    assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
     51  }, 'HighlightRegistry iteration is not modified when the Highlight that was pointed to by the iterator was deleted after starting the iteration');
     52 
     53  CSS.highlights.clear();
     54 
     55  test(() => {
     56    CSS.highlights.set(highlightName1, customHighlight1);
     57    CSS.highlights.set(highlightName2, customHighlight2);
     58    let iterator = CSS.highlights[Symbol.iterator]();
     59    CSS.highlights.delete(highlightName2);
     60    let element = iterator.next();
     61    assert_false(element.done, 'The iteration doesn\'t end although the Highlight following to the one that was pointed to by the iterator was deleted');
     62    assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned as it should although the next Highlight was deleted immediately after starting the iteration');
     63    assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned as it should although the next Highlight was deleted immediately after starting the iteration');
     64    element = iterator.next();
     65    assert_false(element.done, 'The iteration doesn\'t end when you call .next twice since the beginning of the iteration although the second Highlight was deleted');
     66    assert_equals(element.value[0], highlightName2, 'The highlight name that was pointed to by the iterator is returned as it should although the next Highlight was deleted immediately after starting the iteration');
     67    assert_equals(element.value[1], customHighlight2, 'The Highlight that was pointed to by the iterator is returned as it should although the next Highlight was deleted immediately after starting the iteration');
     68    element = iterator.next();
     69    assert_true(element.done, 'The iteration ends after going through all the highlights although the second Highlight was deleted immediately after starting the iteration');
     70    assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
     71  }, 'HighlightRegistry iteration is not modified when the Highlight that was immediately after the one pointed to by the iterator was deleted after starting the iteration');
     72 
     73  CSS.highlights.clear();
     74 
     75  test(() => {
     76    CSS.highlights.set(highlightName1, customHighlight1);
     77    CSS.highlights.set(highlightName2, customHighlight2);
     78    let iterator = CSS.highlights[Symbol.iterator]();
     79    let element = iterator.next();
     80    assert_false(element.done, 'The iteration doesn\'t end when there are still two Highlights to visit');
     81    assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned as it should');
     82    assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned as it should');
     83    CSS.highlights.delete(highlightName1);
     84    element = iterator.next();
     85    assert_false(element.done, 'The iteration doesn\'t end when the Highlight previously visited is deleted and there is still a Highlight to visit');
     86    assert_equals(element.value[0], highlightName2, 'The highlight name that was pointed to by the iterator is returned as it should although the previous Highlight was deleted after calling .next');
     87    assert_equals(element.value[1], customHighlight2, 'The Highlight that was pointed to by the iterator is returned as it should although the previous Highlight was deleted after calling .next');
     88    element = iterator.next();
     89    assert_true(element.done, 'The iteration ends after going through all the highlights although the first Highlight was deleted after the first call to .next');
     90    assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
     91  }, 'HighlightRegistry iteration is not modified when a Highlight that was already visited is deleted and there are still Highlights to visit');
     92 
     93  CSS.highlights.clear();
     94 
     95  // Test deletions using .clear
     96  test(() => {
     97    CSS.highlights.set(highlightName1, customHighlight1);
     98    let iterator = CSS.highlights[Symbol.iterator]();
     99    CSS.highlights.clear();
    100    let element = iterator.next();
    101    assert_false(element.done, 'The iteration doesn\'t end although the Highlight that was pointed to by the iterator was deleted using .clear()');
    102    assert_equals(element.value[0], highlightName1, 'The highlight name that was pointed to by the iterator is returned although it was deleted using .clear() after starting the iteration');
    103    assert_equals(element.value[1], customHighlight1, 'The Highlight that was pointed to by the iterator is returned although it was deleted using .clear() after starting the iteration');
    104    element = iterator.next();
    105    assert_true(element.done, 'The iteration ends after going through all the highlights although the Highlight that was pointed to by the iterator was deleted using .clear() after starting the iteration');
    106    assert_equals(element.value, undefined, '.next() returns undefined when the iteration ends');
    107  }, 'HighlightRegistry iteration is not modified when the Highlight that was pointed to by the iterator was deleted using .clear() after starting the iteration');
    108 
    109 </script>