Bug 1330882 - Part 3: Add a test case for opening new windows as rounded size when fingerprinting resistance is enabled. r?smaug,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Wed, 29 Mar 2017 15:43:56 +0800
changeset 552916 6f2a666fada773f5c06f425f4aeed260fb083ced
parent 552915 f1756926c1c8de17c7abb5bd6ac64dbca8c223f8
child 552917 568572562f91ccb6e13e2bc4500e9ec7d6e5428c
push id51508
push userbmo:tihuang@mozilla.com
push dateWed, 29 Mar 2017 07:44:26 +0000
reviewerssmaug, arthuredelstein
bugs1330882
milestone55.0a1
Bug 1330882 - Part 3: Add a test case for opening new windows as rounded size when fingerprinting resistance is enabled. r?smaug,arthuredelstein MozReview-Commit-ID: Gvksnh3cKHM
browser/components/moz.build
browser/components/resistfingerprinting/moz.build
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/file_dummy.html
--- a/browser/components/moz.build
+++ b/browser/components/moz.build
@@ -13,16 +13,17 @@ DIRS += [
     'extensions',
     'feeds',
     'migration',
     'newtab',
     'originattributes',
     'places',
     'preferences',
     'privatebrowsing',
+    'resistfingerprinting',
     'search',
     'sessionstore',
     'shell',
     'selfsupport',
     'syncedtabs',
     'uitour',
     'translation',
 ]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/moz.build
@@ -0,0 +1,9 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+BROWSER_CHROME_MANIFESTS += [
+    'test/browser/browser.ini',
+]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "../../../../../testing/mochitest/browser.eslintrc.js"
+  ]
+};
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+tags = resistfingerprinting
+support-files =
+  file_dummy.html
+
+[browser_roundedWindow.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow.js
@@ -0,0 +1,85 @@
+/*
+ * 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/file_dummy.html
@@ -0,0 +1,9 @@
+<html>
+<head>
+<title>Dummy test page</title>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
+</head>
+<body>
+<p>Dummy test page</p>
+</body>
+</html>