Bug 1330882 - Part 5: Add more test cases for rounded windows test. r?smaug,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Wed, 29 Mar 2017 15:43:57 +0800
changeset 552918 cf173a53a757d670bb4cd4edc2414644d51b0b80
parent 552917 568572562f91ccb6e13e2bc4500e9ec7d6e5428c
child 621947 8d4a0cc6f60dd530bbc1cc02399f96e536eb6317
push id51508
push userbmo:tihuang@mozilla.com
push dateWed, 29 Mar 2017 07:44:26 +0000
reviewerssmaug, arthuredelstein
bugs1330882
milestone55.0a1
Bug 1330882 - Part 5: Add more test cases for rounded windows test. r?smaug,arthuredelstein 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
browser/components/resistfingerprinting/test/browser/.eslintrc.js
browser/components/resistfingerprinting/test/browser/browser.ini
browser/components/resistfingerprinting/test/browser/browser_roundedWindow.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
browser/components/resistfingerprinting/test/browser/head.js
--- a/browser/components/resistfingerprinting/test/browser/.eslintrc.js
+++ b/browser/components/resistfingerprinting/test/browser/.eslintrc.js
@@ -1,7 +1,11 @@
 "use strict";
 
 module.exports = {
   "extends": [
-    "../../../../../testing/mochitest/browser.eslintrc.js"
-  ]
+    "plugin:mozilla/browser-test"
+  ],
+
+  "rules": {
+    "no-undef": "error"
+  }
 };
--- a/browser/components/resistfingerprinting/test/browser/browser.ini
+++ b/browser/components/resistfingerprinting/test/browser/browser.ini
@@ -1,6 +1,13 @@
 [DEFAULT]
 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]
deleted file mode 100644
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow.js
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Bug 1330882 - A test case for opening new windows as rounded size when
- *   fingerprinting resistance is enabled.
- */
-
-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;
-
-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;
-
-  // 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);
-});
-
-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);
-
-
-  // Open a new window.
-  let win = yield BrowserTestUtils.openNewBrowserWindow();
-
-  // Load a page and verify its window size.
-  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,
-        "The screen.width has a correct rounded value");
-      is(content.screen.height, obj.desiredHeight,
-        "The screen.height has a correct rounded value");
-      is(content.innerWidth, obj.desiredWidth,
-        "The window.innerWidth has a correct rounded value");
-      is(content.innerHeight, obj.desiredHeight,
-        "The window.innerHeight has a correct rounded value");
-    }
-  );
-
-  yield BrowserTestUtils.removeTab(tab);
-  yield BrowserTestUtils.closeWindow(win);
-});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
@@ -0,0 +1,49 @@
+/*
+ * Bug 1330882 - A test case for opening new windows as rounded size when
+ *   fingerprinting resistance is enabled.
+ */
+
+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;
+
+add_task(function* setup() {
+  yield SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", true]]
+  });
+
+  // Calculate the maximum available size.
+  let maxAvailSize = yield calcMaximumAvailSize();
+
+  gMaxAvailWidth = maxAvailSize.maxAvailWidth;
+  gMaxAvailHeight = maxAvailSize.maxAvailHeight;
+});
+
+add_task(function* test_new_window() {
+  // Open a new window.
+  let win = yield BrowserTestUtils.openNewBrowserWindow();
+
+  // Load a page and verify its window size.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(
+    win.gBrowser, TEST_PATH + "file_dummy.html");
+
+  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, input.gMaxAvailHeight,
+        "The screen.height has a correct rounded value");
+      is(content.innerWidth, input.gMaxAvailWidth,
+        "The window.innerWidth has a correct rounded value");
+      is(content.innerHeight, input.gMaxAvailHeight,
+        "The window.innerHeight has a correct rounded value");
+    }
+  );
+
+  yield BrowserTestUtils.removeTab(tab);
+  yield BrowserTestUtils.closeWindow(win);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
@@ -0,0 +1,62 @@
+/*
+ * 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);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
@@ -0,0 +1,62 @@
+/*
+ * 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);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
@@ -0,0 +1,61 @@
+/*
+ * Bug 1330882 - A test case for opening new windows through window.open() as
+ *   rounded size when fingerprinting resistance is enabled. This test is for
+ *   minimum 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: 199, settingHeight: 99, targetWidth: 200, targetHeight: 100 },
+  { settingWidth: 10, settingHeight: 10, targetWidth: 200, targetHeight: 100 },
+];
+
+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);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
@@ -0,0 +1,67 @@
+/*
+ * Bug 1330882 - A test case for setting window size through window.innerWidth/Height
+ *   and window.outerWidth/Height 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,
+    initWidth: 200, initHeight: 100 },
+  { settingWidth: 9999, settingHeight: 9999, targetWidth: 1000, targetHeight: 1000,
+    initWidth: 200, initHeight: 100  },
+  { settingWidth: 999, settingHeight: 999, targetWidth: 1000, targetHeight: 1000,
+    initWidth: 200, initHeight: 100  },
+];
+
+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_size_setting() {
+  // Open a tab to test.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(
+    gBrowser, TEST_PATH + "file_dummy.html");
+
+  for (let test of TESTCASES) {
+    // Test window.innerWidth and window.innerHeight.
+    yield testWindowSizeSetting(tab.linkedBrowser, test.settingWidth, test.settingHeight,
+                                test.targetWidth, test.targetHeight, test.initWidth,
+                                test.initHeight, false, gMaxAvailWidth, gMaxAvailHeight,
+                                gPopupChromeUIWidth, gPopupChromeUIHeight);
+
+    // test window.outerWidth and window.outerHeight.
+    yield testWindowSizeSetting(tab.linkedBrowser, test.settingWidth, test.settingHeight,
+                                test.targetWidth, test.targetHeight, test.initWidth,
+                                test.initHeight, true, gMaxAvailWidth, gMaxAvailHeight,
+                                gPopupChromeUIWidth, gPopupChromeUIHeight);
+  }
+
+  yield BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
@@ -0,0 +1,67 @@
+/*
+ * Bug 1330882 - A test case for setting window size through window.innerWidth/Height
+ *   and window.outerWidth/Height 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,
+    initWidth: 200, initHeight: 100  },
+  { settingWidth: 599, settingHeight: 599, targetWidth: 600, targetHeight: 600,
+    initWidth: 200, initHeight: 100  },
+  { settingWidth: 401, settingHeight: 501, targetWidth: 600, targetHeight: 600,
+    initWidth: 200, initHeight: 100  },
+];
+
+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_size_setting() {
+  // Open a tab to test.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(
+    gBrowser, TEST_PATH + "file_dummy.html");
+
+  for (let test of TESTCASES) {
+    // Test window.innerWidth and window.innerHeight.
+    yield testWindowSizeSetting(tab.linkedBrowser, test.settingWidth, test.settingHeight,
+                                test.targetWidth, test.targetHeight, test.initWidth,
+                                test.initHeight, false, gMaxAvailWidth, gMaxAvailHeight,
+                                gPopupChromeUIWidth, gPopupChromeUIHeight);
+
+    // test window.outerWidth and window.outerHeight.
+    yield testWindowSizeSetting(tab.linkedBrowser, test.settingWidth, test.settingHeight,
+                                test.targetWidth, test.targetHeight, test.initWidth,
+                                test.initHeight, true, gMaxAvailWidth, gMaxAvailHeight,
+                                gPopupChromeUIWidth, gPopupChromeUIHeight);
+  }
+
+  yield BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
@@ -0,0 +1,65 @@
+/*
+ * Bug 1330882 - A test case for setting window size through window.innerWidth/Height
+ *   and window.outerWidth/Height when fingerprinting resistance is enabled. This
+ *   test is for minimum 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: 199, settingHeight: 99, targetWidth: 200, targetHeight: 100,
+    initWidth: 1000, initHeight: 1000  },
+  { settingWidth: 10, settingHeight: 10, targetWidth: 200, targetHeight: 100,
+    initWidth: 1000, initHeight: 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_size_setting() {
+  // Open a tab to test.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(
+    gBrowser, TEST_PATH + "file_dummy.html");
+
+  for (let test of TESTCASES) {
+    // Test window.innerWidth and window.innerHeight.
+    yield testWindowSizeSetting(tab.linkedBrowser, test.settingWidth, test.settingHeight,
+                                test.targetWidth, test.targetHeight, test.initWidth,
+                                test.initHeight, false, gMaxAvailWidth, gMaxAvailHeight,
+                                gPopupChromeUIWidth, gPopupChromeUIHeight);
+
+    // test window.outerWidth and window.outerHeight.
+    yield testWindowSizeSetting(tab.linkedBrowser, test.settingWidth, test.settingHeight,
+                                test.targetWidth, test.targetHeight, test.initWidth,
+                                test.initHeight, true, gMaxAvailWidth, gMaxAvailHeight,
+                                gPopupChromeUIWidth, gPopupChromeUIHeight);
+  }
+
+  yield BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/head.js
@@ -0,0 +1,227 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+
+// This function calculates the maximum available window dimensions and returns
+// them as an object.
+function* calcMaximumAvailSize(aChromeWidth, aChromeHeight) {
+  let chromeUIWidth;
+  let chromeUIHeight;
+  let testPath = "http://example.net/browser/browser/" +
+                 "components/resistFingerprinting/test/browser/"
+
+  // If the chrome UI dimensions is not given, we will calculate it.
+  if (!aChromeWidth || !aChromeHeight) {
+    let tab = yield BrowserTestUtils.openNewForegroundTab(
+      gBrowser, testPath + "file_dummy.html");
+
+    let contentSize = yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
+      let result = {
+        width: content.innerWidth,
+        height: content.innerHeight
+      };
+
+      return result;
+    });
+
+    // Calculate the maximum available window size which is depending on the
+    // available screen space.
+    chromeUIWidth = window.outerWidth - contentSize.width;
+    chromeUIHeight = window.outerHeight - contentSize.height;
+
+    yield BrowserTestUtils.removeTab(tab);
+  } else {
+    chromeUIWidth = aChromeWidth;
+    chromeUIHeight = aChromeHeight;
+  }
+
+  let availWidth = window.screen.availWidth;
+  let availHeight = window.screen.availHeight;
+
+  // Ideally, we would round the window size as 1000x1000. But the available
+  // screen space might not suffice. So, we decide the size according to the
+  // available screen size.
+  let availContentWidth = Math.min(1000, availWidth - chromeUIWidth);
+  let availContentHeight;
+
+  // If it is GTK window, we would consider the system decorations when we
+  // calculating avail content height since the system decorations won't be
+  // reported when we get available screen dimensions.
+  if (AppConstants.MOZ_WIDGET_GTK) {
+    availContentHeight = Math.min(1000, -40 + availHeight - chromeUIHeight);
+  } else {
+    availContentHeight = Math.min(1000, availHeight - chromeUIHeight);
+  }
+
+  // Rounded the desire size to the nearest 200x100.
+  let maxAvailWidth = availContentWidth - (availContentWidth % 200);
+  let maxAvailHeight = availContentHeight - (availContentHeight % 100);
+
+  return {maxAvailWidth, maxAvailHeight};
+}
+
+function* calcPopUpWindowChromeUISize() {
+  let testPath = "http://example.net/browser/browser/" +
+                 "components/resistFingerprinting/test/browser/"
+  // open a popup window to acquire the chrome UI size of it.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(
+    gBrowser, testPath + "file_dummy.html");
+
+  let result = yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
+    let win;
+
+    yield new Promise(resolve => {
+      win = content.open("about:blank", "", "width=1000,height=1000");
+      win.onload = () => resolve();
+    });
+
+    let res = {
+      chromeWidth: win.outerWidth - win.innerWidth,
+      chromeHeight: win.outerHeight - win.innerHeight
+    };
+
+    win.close();
+
+    return res;
+  });
+
+  yield BrowserTestUtils.removeTab(tab);
+
+  return result;
+}
+
+function* testWindowOpen(aBrowser, aSettingWidth, aSettingHeight,
+                         aTargetWidth, aTargetHeight, aTestOuter,
+                         aMaxAvailWidth, aMaxAvailHeight, aPopupChromeUIWidth,
+                         aPopupChromeUIHeight) {
+  // If the target size is greater than the maximum available content size,
+  // we set the target size to it.
+  if (aTargetWidth > aMaxAvailWidth) {
+    aTargetWidth = aMaxAvailWidth;
+  }
+
+  if (aTargetHeight > aMaxAvailHeight) {
+    aTargetHeight = aMaxAvailHeight;
+  }
+
+  // Create the testing window features.
+  let winFeatures;
+
+  if (aTestOuter) {
+    winFeatures = "outerWidth=" + (aSettingWidth + aPopupChromeUIWidth) +
+                  ",outerHeight=" + (aSettingHeight + aPopupChromeUIHeight);
+  } else {
+    winFeatures = "width=" + aSettingWidth + ",height=" + aSettingHeight;
+  }
+
+  let testParams = {
+    winFeatures,
+    targetWidth:  aTargetWidth,
+    targetHeight: aTargetHeight,
+  };
+
+  yield ContentTask.spawn(aBrowser, testParams,
+    function* (input) {
+      // Call window.open() with window features.
+      yield new Promise(resolve => {
+        let win = content.open("http://example.net/", "", input.winFeatures);
+
+        win.onload = () => {
+          is(win.screen.width, input.targetWidth,
+            "The screen.width has a correct rounded value");
+          is(win.screen.height, input.targetHeight,
+            "The screen.height has a correct rounded value");
+          is(win.innerWidth, input.targetWidth,
+            "The window.innerWidth has a correct rounded value");
+          is(win.innerHeight, input.targetHeight,
+            "The window.innerHeight has a correct rounded value");
+
+          win.close()
+          resolve();
+        };
+      });
+    }
+  );
+}
+
+function* testWindowSizeSetting(aBrowser, aSettingWidth, aSettingHeight,
+                                aTargetWidth, aTargetHeight, aInitWidth,
+                                aInitHeight, aTestOuter, aMaxAvailWidth,
+                                aMaxAvailHeight, aPopupChromeUIWidth,
+                                aPopupChromeUIHeight) {
+  // If the target size is greater than the maximum available content size,
+  // we set the target size to it.
+  if (aTargetWidth > aMaxAvailWidth) {
+    aTargetWidth = aMaxAvailWidth;
+  }
+
+  if (aTargetHeight > aMaxAvailHeight) {
+    aTargetHeight = aMaxAvailHeight;
+  }
+
+  let testParams = {
+    initWidth: aInitWidth,
+    initHeight: aInitHeight,
+    settingWidth: aSettingWidth + (aTestOuter ? aPopupChromeUIWidth : 0),
+    settingHeight: aSettingHeight + (aTestOuter ? aPopupChromeUIHeight : 0),
+    targetWidth:  aTargetWidth,
+    targetHeight: aTargetHeight,
+    testOuter: aTestOuter
+  };
+
+  yield ContentTask.spawn(aBrowser, testParams,
+    function* (input) {
+
+      let win;
+      // Open a new window and wait until it loads.
+      yield new Promise(resolve => {
+        // Given a initial window size which should be different from target
+        // size. We need this to trigger 'onresize' event.
+        let initWinFeatures = "width=" + input.initWidth + ",height=" + input.initHeight;
+        win = content.open("http://example.net/", "", initWinFeatures);
+        win.onload = () => resolve();
+      });
+
+      // Test inner/outerWidth.
+      yield new Promise(resolve => {
+        win.onresize = () => {
+          is(win.screen.width, input.targetWidth,
+            "The screen.width has a correct rounded value");
+          is(win.innerWidth, input.targetWidth,
+            "The window.innerWidth has a correct rounded value");
+
+          resolve();
+        };
+
+        if (input.testOuter) {
+          win.outerWidth = input.settingWidth;
+        } else {
+          win.innerWidth = input.settingWidth;
+        }
+      });
+
+      // Test inner/outerHeight.
+      yield new Promise(resolve => {
+        win.onresize = () => {
+          is(win.screen.height, input.targetHeight,
+            "The screen.height has a correct rounded value");
+          is(win.innerHeight, input.targetHeight,
+            "The window.innerHeight has a correct rounded value");
+
+          resolve();
+        };
+
+        if (input.testOuter) {
+          win.outerHeight = input.settingHeight;
+        } else {
+          win.innerHeight = input.settingHeight;
+        }
+      });
+
+      win.close();
+    }
+  );
+}