tor-browser

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

header-util.sub.js (1344B)


      1 const EMPTY_TOPICS_HEADER = '();p=P0000000000000000000000000000000';
      2 
      3 function test_topics_iframe_navigation_header(
      4    test, has_browsing_topics_attribute, is_same_origin, expect_topics_header_available_func) {
      5  const same_origin_src = '/browsing-topics/resources/check-topics-request-header-notify-parent.py';
      6  const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
      7    same_origin_src;
      8 
      9  let frame = document.createElement('iframe');
     10  frame.src = is_same_origin ? same_origin_src : cross_origin_src;
     11 
     12  if (has_browsing_topics_attribute) {
     13    frame.browsingTopics = true;
     14  }
     15 
     16  window.addEventListener('message', test.step_func(function handler(evt) {
     17    if (evt.source === frame.contentWindow) {
     18      expect_topics_header_available_func(evt.data);
     19 
     20      document.body.removeChild(frame);
     21      window.removeEventListener('message', handler);
     22      test.done();
     23    }
     24  }));
     25 
     26  document.body.appendChild(frame);
     27 }
     28 
     29 function expect_topics_header_unavailable(data) {
     30  assert_equals(data.topicsHeader, 'NO_TOPICS_HEADER');
     31 }
     32 
     33 function expect_topics_header_available(data) {
     34  // An empty result indicates that the request was eligible for topics.
     35  // Currently, the web-platform-tests framework does not support actually
     36  // handling the topics request.
     37  assert_equals(data.topicsHeader, EMPTY_TOPICS_HEADER);
     38 }