summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/test/browser/browser_viewport_resizing_after_reload.js
blob: 22dbdff5279127ef05291d4f2f491712cb9ee1c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test viewport resizing, with and without meta viewport support.

const TEST_URL =
  "data:text/html;charset=utf-8," +
  '<head><meta name="viewport" content="width=device-width"/></head>' +
  '<body style="margin:0px;min-width:600px">' +
  '<div style="width:100%;height:100px;background-color:black"></div>' +
  '<div style="width:100%;height:1100px;background-color:lightblue"></div>' +
  "</body>";

addRDMTask(TEST_URL, async function ({ ui, manager }) {
  info("--- Starting viewport test output ---");

  // We're going to take a 300,600 viewport (before), reload it,
  // then resize it to 600,300 (after) and then resize it back.
  // At the before and after points, we'll measure zoom and the
  // layout viewport width and height.
  const expected = [
    {
      metaSupport: false,
      before: [0.5, 300, 600],
      after: [1.0, 600, 300],
    },
    {
      metaSupport: true,
      before: [0.5, 300, 600],
      after: [1.0, 600, 300],
    },
  ];

  for (const e of expected) {
    const b = e.before;
    const a = e.after;

    const message = "Meta Viewport " + (e.metaSupport ? "ON" : "OFF");

    // Ensure meta viewport is set.
    info(message + " setting meta viewport support.");
    await setTouchAndMetaViewportSupport(ui, e.metaSupport);

    // Get to the initial size and check values.
    await setViewportSizeAndAwaitReflow(ui, manager, 300, 600);
    await testViewportZoomWidthAndHeight(
      message + " before resize",
      ui,
      b[0],
      b[1],
      b[2]
    );

    // Force a reload.
    await reloadBrowser();

    // Check initial values again.
    await testViewportZoomWidthAndHeight(
      message + " after reload",
      ui,
      b[0],
      b[1],
      b[2]
    );

    // Move to the smaller size.
    await setViewportSizeAndAwaitReflow(ui, manager, 600, 300);
    await testViewportZoomWidthAndHeight(
      message + " after resize",
      ui,
      a[0],
      a[1],
      a[2]
    );

    // Go back to the initial size and check again.
    await setViewportSizeAndAwaitReflow(ui, manager, 300, 600);
    await testViewportZoomWidthAndHeight(
      message + " return to initial size",
      ui,
      b[0],
      b[1],
      b[2]
    );
  }
});