Commit e8ea8344 authored by Tim Huang's avatar Tim Huang Committed by Georg Koppen
Browse files

Bug 1330882 - Part 5: Add more test cases for rounded windows test. r=arthuredelstein,smaug

This patch adds two more test cases, browser_roundedWindow_open.js and
browser_roundedWindow_windowSetting.js. The browser_roundedWindow_open.js tests
the window.open() with window features, it will test window.open() with numbers
of window features to see that whether the opened window is correctly rounded.

The browser_roundedWindow_windowSetting.js tests the setting of
innerWidth/Height and outerWidth/Height. To see that the window is correctly
rounded or not after the setting.

This patch also adds a head.js and rename the browser_roundedWindow.js to
browser_roundedWindow_newWindow.js. The head.js carries two helper functions
that calculate the maximum available content size and the chrome UI size of
the pop up window.

MozReview-Commit-ID: LxJ2h2qAanY

--HG--
extra : rebase_source : b3744155fda93bd9e1650d07db7105092a2e5260
parent 95d3d105
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@

module.exports = {
  "extends": [
    "../../../../../testing/mochitest/browser.eslintrc.js"
  ]
    "plugin:mozilla/browser-test"
  ],

  "rules": {
    "no-undef": "error"
  }
};
+8 −1
Original line number Diff line number Diff line
@@ -2,5 +2,12 @@
tags = resistfingerprinting
support-files =
  file_dummy.html
  head.js

[browser_roundedWindow.js]
[browser_roundedWindow_newWindow.js]
[browser_roundedWindow_open_max.js]
[browser_roundedWindow_open_mid.js]
[browser_roundedWindow_open_min.js]
[browser_roundedWindow_windowSetting_max.js]
[browser_roundedWindow_windowSetting_mid.js]
[browser_roundedWindow_windowSetting_min.js]
+49 −0
Original line number Diff line number Diff line
@@ -8,74 +8,38 @@ const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
const TEST_DOMAIN = "http://example.net/";
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";

let desiredWidth;
let desiredHeight;
let gMaxAvailWidth;
let gMaxAvailHeight;

add_task(function* setup() {
  yield SpecialPowers.pushPrefEnv({"set":
    [["privacy.resistFingerprinting", true]]
  });
  // Calculate the desire window size which is depending on the available screen
  // space.
  let chromeUIWidth = window.outerWidth - window.innerWidth;
  let chromeUIHeight = window.outerHeight - window.innerHeight;

  let availWidth = window.screen.availWidth;
  let availHeight = window.screen.availHeight;
  // Calculate the maximum available size.
  let maxAvailSize = yield calcMaximumAvailSize();

  // Ideally, we would round the window size as 1000x1000.
  let availContentWidth = Math.min(1000, availWidth - chromeUIWidth);
  let availContentHeight = Math.min(1000, 0.95 * availHeight - chromeUIHeight);

  // Rounded the desire size to the nearest 200x100.
  desiredWidth = availContentWidth - (availContentWidth % 200);
  desiredHeight = availContentHeight - (availContentHeight % 100);
  gMaxAvailWidth = maxAvailSize.maxAvailWidth;
  gMaxAvailHeight = maxAvailSize.maxAvailHeight;
});

add_task(function* () {
  // Open a tab to test window.open().
  let tab = yield BrowserTestUtils.openNewForegroundTab(
    gBrowser, TEST_PATH + "file_dummy.html");

  yield ContentTask.spawn(tab.linkedBrowser, {desiredWidth, desiredHeight},
    function* (obj) {
      // Create a new window with the size which is not rounded.
      let win = content.open("http://example.net/", "", "width=1030,height=1025");

      win.onresize = () => {
        is(win.screen.width, obj.desiredWidth,
          "The screen.width has a correct rounded value");
        is(win.screen.height, obj.desiredHeight,
          "The screen.height has a correct rounded value");
        is(win.innerWidth, obj.desiredWidth,
          "The window.innerWidth has a correct rounded value");
        is(win.innerHeight, obj.desiredHeight,
          "The window.innerHeight has a correct rounded value");
      };

      win.onload = () => win.close();
    }
  );

  yield BrowserTestUtils.removeTab(tab);


add_task(function* test_new_window() {
  // Open a new window.
  let win = yield BrowserTestUtils.openNewBrowserWindow();

  // Load a page and verify its window size.
  tab = yield BrowserTestUtils.openNewForegroundTab(
  let tab = yield BrowserTestUtils.openNewForegroundTab(
    win.gBrowser, TEST_PATH + "file_dummy.html");

  yield ContentTask.spawn(tab.linkedBrowser, {desiredWidth, desiredHeight},
    function* (obj) {
      is(content.screen.width, obj.desiredWidth,
  yield ContentTask.spawn(tab.linkedBrowser, {gMaxAvailWidth, gMaxAvailHeight},
    function* (input) {
      is(content.screen.width, input.gMaxAvailWidth,
        "The screen.width has a correct rounded value");
      is(content.screen.height, obj.desiredHeight,
      is(content.screen.height, input.gMaxAvailHeight,
        "The screen.height has a correct rounded value");
      is(content.innerWidth, obj.desiredWidth,
      is(content.innerWidth, input.gMaxAvailWidth,
        "The window.innerWidth has a correct rounded value");
      is(content.innerHeight, obj.desiredHeight,
      is(content.innerHeight, input.gMaxAvailHeight,
        "The window.innerHeight has a correct rounded value");
    }
  );
+62 −0
Original line number Diff line number Diff line
/*
 * Bug 1330882 - A test case for opening new windows through window.open() as
 *   rounded size when fingerprinting resistance is enabled. This test is for
 *   maximum values.
 */

const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;

const TEST_DOMAIN = "http://example.net/";
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";

let gMaxAvailWidth;
let gMaxAvailHeight;

// We need the chrome UI size of popup windows for testing outerWidth/Height.
let gPopupChromeUIWidth;
let gPopupChromeUIHeight;

const TESTCASES = [
  { settingWidth: 1025, settingHeight: 1050, targetWidth: 1000, targetHeight: 1000 },
  { settingWidth: 9999, settingHeight: 9999, targetWidth: 1000, targetHeight: 1000 },
  { settingWidth: 999, settingHeight: 999, targetWidth: 1000, targetHeight: 1000 },
];

add_task(function* setup() {
  yield SpecialPowers.pushPrefEnv({"set":
    [["privacy.resistFingerprinting", true]]
  });

  // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
  let popUpChromeUISize = yield calcPopUpWindowChromeUISize();

  gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
  gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;

  // Calculate the maximum available size.
  let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
                                                gPopupChromeUIHeight);

  gMaxAvailWidth = maxAvailSize.maxAvailWidth;
  gMaxAvailHeight = maxAvailSize.maxAvailHeight;
});

add_task(function* test_window_open() {
  // Open a tab to test window.open().
  let tab = yield BrowserTestUtils.openNewForegroundTab(
    gBrowser, TEST_PATH + "file_dummy.html");

  for (let test of TESTCASES) {
    // Test 'width' and 'height' of window features.
    yield testWindowOpen(tab.linkedBrowser, test.settingWidth, test.settingHeight,
                         test.targetWidth, test.targetHeight, false, gMaxAvailWidth,
                         gMaxAvailHeight, gPopupChromeUIWidth, gPopupChromeUIHeight);

    // test 'outerWidth' and 'outerHeight' of window features.
    yield testWindowOpen(tab.linkedBrowser, test.settingWidth, test.settingHeight,
                         test.targetWidth, test.targetHeight, true, gMaxAvailWidth,
                         gMaxAvailHeight, gPopupChromeUIWidth, gPopupChromeUIHeight);
  }

  yield BrowserTestUtils.removeTab(tab);
});
+62 −0
Original line number Diff line number Diff line
/*
 * Bug 1330882 - A test case for opening new windows through window.open() as
 *   rounded size when fingerprinting resistance is enabled. This test is for
 *   middle values.
 */

const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;

const TEST_DOMAIN = "http://example.net/";
const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";

let gMaxAvailWidth;
let gMaxAvailHeight;

// We need the chrome UI size of popup windows for testing outerWidth/Height.
let gPopupChromeUIWidth;
let gPopupChromeUIHeight;

const TESTCASES = [
  { settingWidth: 600, settingHeight: 600, targetWidth: 600, targetHeight: 600 },
  { settingWidth: 599, settingHeight: 599, targetWidth: 600, targetHeight: 600 },
  { settingWidth: 401, settingHeight: 501, targetWidth: 600, targetHeight: 600 },
];

add_task(function* setup() {
  yield SpecialPowers.pushPrefEnv({"set":
    [["privacy.resistFingerprinting", true]]
  });

  // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
  let popUpChromeUISize = yield calcPopUpWindowChromeUISize();

  gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
  gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;

  // Calculate the maximum available size.
  let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
                                                gPopupChromeUIHeight);

  gMaxAvailWidth = maxAvailSize.maxAvailWidth;
  gMaxAvailHeight = maxAvailSize.maxAvailHeight;
});

add_task(function* test_window_open() {
  // Open a tab to test window.open().
  let tab = yield BrowserTestUtils.openNewForegroundTab(
    gBrowser, TEST_PATH + "file_dummy.html");

  for (let test of TESTCASES) {
    // Test 'width' and 'height' of window features.
    yield testWindowOpen(tab.linkedBrowser, test.settingWidth, test.settingHeight,
                         test.targetWidth, test.targetHeight, false, gMaxAvailWidth,
                         gMaxAvailHeight, gPopupChromeUIWidth, gPopupChromeUIHeight);

    // test 'outerWidth' and 'outerHeight' of window features.
    yield testWindowOpen(tab.linkedBrowser, test.settingWidth, test.settingHeight,
                         test.targetWidth, test.targetHeight, true, gMaxAvailWidth,
                         gMaxAvailHeight, gPopupChromeUIWidth, gPopupChromeUIHeight);
  }

  yield BrowserTestUtils.removeTab(tab);
});
Loading