tor-browser

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

opaque-ad-sizes-utils.js (1982B)


      1 async function runOpaqueAdSizesTest(input_width, input_height, output_width, output_height) {
      2  // Attach a FLEDGE fenced frame whose outer container has dimensions
      3  // `input_width` by `input_height`.
      4  const frame = await attachFencedFrameContext({
      5      generator_api: "fledge", resolve_to_config: true, attributes: [
      6      ["width", input_width], ["height", input_height]]});
      7 
      8  const assert_dimensions =
      9      (label, input_width, input_height, output_width, output_height) => {
     10    assert_equals(getComputedStyle(document.documentElement).width,
     11        output_width+"px",
     12        label + " the computed width coerces to " + output_width);
     13    assert_equals(window.innerWidth, output_width,
     14        label + " the innerWidth " + input_width + " coerces to " + output_width);
     15    assert_equals(window.innerHeight, output_height,
     16        label + " the innerHeight " + input_height + " coerces to " + output_height);
     17  }
     18 
     19  // Assert that the fenced frame sees its dimensions rounded to the nearest
     20  // ad size.
     21  await frame.execute(assert_dimensions,
     22      ["After navigation", input_width, input_height, output_width, output_height]);
     23 
     24  // Assert that the embedder sees the fenced frame's original dimensions.
     25  assert_equals(frame.width, input_width.toString(),
     26      "The outer container width is the requested width.");
     27  assert_equals(frame.height, input_height.toString(),
     28      "The outer container height is the requested height.");
     29 
     30  // Resize the fenced frame's outer container.
     31  const new_size_x = 320;
     32  const new_size_y = 50;
     33  frame.width = new_size_x;
     34  frame.height = new_size_y;
     35 
     36  // Refresh the fenced frame.
     37  await frame.execute(() => {
     38    window.executor.suspend(() => {
     39      location.href = location.href;
     40    });
     41  });
     42 
     43  // Observe that navigations after the first don't change the fenced frame's
     44  // inner dimensions.
     45  await frame.execute(assert_dimensions,
     46      ["After resizing", input_width, input_height, output_width, output_height]);
     47 }