summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive.html/test/browser/browser_device_width.js
blob: 9489d8f0bb3a5b702e6019084c208c1dd0186025 (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
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_URL = "data:text/html;charset=utf-8,";

addRDMTask(TEST_URL, function* ({ ui, manager }) {
  ok(ui, "An instance of the RDM should be attached to the tab.");
  yield setViewportSize(ui, manager, 110, 500);

  info("Checking initial width/height properties.");
  yield doInitialChecks(ui);

  info("Changing the RDM size");
  yield setViewportSize(ui, manager, 90, 500);

  info("Checking for screen props");
  yield checkScreenProps(ui);

  info("Setting docShell.deviceSizeIsPageSize to false");
  yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
    let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIWebNavigation)
                          .QueryInterface(Ci.nsIDocShell);
    docShell.deviceSizeIsPageSize = false;
  });

  info("Checking for screen props once again.");
  yield checkScreenProps2(ui);
});

function* doInitialChecks(ui) {
  let { innerWidth, matchesMedia } = yield grabContentInfo(ui);
  is(innerWidth, 110, "initial width should be 110px");
  ok(!matchesMedia, "media query shouldn't match.");
}

function* checkScreenProps(ui) {
  let { matchesMedia, screen } = yield grabContentInfo(ui);
  ok(matchesMedia, "media query should match");
  isnot(window.screen.width, screen.width,
        "screen.width should not be the size of the screen.");
  is(screen.width, 90, "screen.width should be the page width");
  is(screen.height, 500, "screen.height should be the page height");
}

function* checkScreenProps2(ui) {
  let { matchesMedia, screen } = yield grabContentInfo(ui);
  ok(!matchesMedia, "media query should be re-evaluated.");
  is(window.screen.width, screen.width,
     "screen.width should be the size of the screen.");
}

function grabContentInfo(ui) {
  return ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
    return {
      screen: {
        width: content.screen.width,
        height: content.screen.height
      },
      innerWidth: content.innerWidth,
      matchesMedia: content.matchMedia("(max-device-width:100px)").matches
    };
  });
}