Bug 1313580 - Part 3: Remove web content access to Battery API. r=baku
authorChris Peterson <cpeterson@mozilla.com>
Fri, 28 Oct 2016 18:45:36 -0700
changeset 320111 6069dc9afe31c75b809df062af362df76faf25cc
parent 320110 585f52662d697ca95cb679246cc59ce28fefe60b
child 320112 f408d5bef95d9dce2cbbc1251e40a360f2a4cc01
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1313580
milestone52.0a1
Bug 1313580 - Part 3: Remove web content access to Battery API. r=baku
dom/battery/moz.build
dom/battery/test/chrome.ini
dom/battery/test/mochitest.ini
dom/battery/test/test_battery_basics.html
dom/battery/test/test_battery_charging.html
dom/battery/test/test_battery_discharging.html
dom/battery/test/test_battery_unprivileged.html
dom/webidl/Navigator.webidl
testing/web-platform/meta/battery-status/battery-charging-manual.html.ini
testing/web-platform/meta/battery-status/battery-discharging-manual.html.ini
testing/web-platform/meta/battery-status/battery-full-manual.html.ini
testing/web-platform/meta/battery-status/battery-interface-idlharness.html.ini
testing/web-platform/meta/battery-status/battery-plugging-in-manual.html.ini
testing/web-platform/meta/battery-status/battery-promise-iframe.html.ini
testing/web-platform/meta/battery-status/battery-promise-window.html.ini
testing/web-platform/meta/battery-status/battery-promise.html.ini
testing/web-platform/meta/battery-status/battery-unplugging-manual.html.ini
testing/web-platform/meta/battery-status/support-iframe-initial.html.ini
testing/web-platform/meta/battery-status/support-iframe.html.ini
testing/web-platform/meta/battery-status/support-window-open.html.ini
--- a/dom/battery/moz.build
+++ b/dom/battery/moz.build
@@ -12,9 +12,10 @@ EXPORTS.mozilla.dom.battery += [
 SOURCES += [
     'BatteryManager.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
+MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
 MOCHITEST_MANIFESTS += ['test/mochitest.ini']
copy from dom/battery/test/mochitest.ini
copy to dom/battery/test/chrome.ini
--- a/dom/battery/test/mochitest.ini
+++ b/dom/battery/test/mochitest.ini
@@ -1,3 +1,1 @@
-[test_battery_basics.html]
-[test_battery_charging.html]
-[test_battery_discharging.html]
+[test_battery_unprivileged.html]
--- a/dom/battery/test/test_battery_basics.html
+++ b/dom/battery/test/test_battery_basics.html
@@ -1,14 +1,14 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for Battery API</title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
--- a/dom/battery/test/test_battery_charging.html
+++ b/dom/battery/test/test_battery_charging.html
@@ -1,22 +1,24 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for Battery API</title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
+"use strict";
+
 SimpleTest.waitForExplicitFinish();
 
 /** Test for Battery API **/
 navigator.getBattery().then(function (battery) {
   ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");
 
   SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.charging", true]]}, function () {
     is(battery.charging, true, "Battery should be charging");
--- a/dom/battery/test/test_battery_discharging.html
+++ b/dom/battery/test/test_battery_discharging.html
@@ -1,22 +1,24 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for Battery API</title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
+"use strict";
+
 SimpleTest.waitForExplicitFinish();
 
 /** Test for Battery API **/
 navigator.getBattery().then(function (battery) {
   ok(battery.level >= 0.0 && battery.level <= 1.0, "Battery level " + battery.level + " should be in the range [0.0, 1.0]");
 
   SpecialPowers.pushPrefEnv({"set": [["dom.battery.test.discharging", true]]}, function () {
     is(battery.charging, false, "Battery should be discharging");
new file mode 100644
--- /dev/null
+++ b/dom/battery/test/test_battery_unprivileged.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for Battery API</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+"use strict";
+
+/** Test for Battery API **/
+ok(!("getBattery" in navigator), "navigator.getBattery should not exist for unprivileged web content");
+ok(!("battery" in navigator), "navigator.battery should not exist");
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -122,17 +122,18 @@ partial interface Navigator {
 interface NavigatorGeolocation {
   [Throws, Pref="geo.enabled"]
   readonly attribute Geolocation geolocation;
 };
 Navigator implements NavigatorGeolocation;
 
 // http://www.w3.org/TR/battery-status/#navigatorbattery-interface
 partial interface Navigator {
-  [Throws, Pref="dom.battery.enabled"]
+  // ChromeOnly to prevent web content from fingerprinting users' batteries.
+  [Throws, ChromeOnly, Pref="dom.battery.enabled"]
   Promise<BatteryManager> getBattery();
 };
 
 partial interface Navigator {
   [NewObject, Pref="dom.flyweb.enabled"]
   Promise<FlyWebPublishedServer> publishServer(DOMString name,
                                                optional FlyWebPublishOptions options);
 };
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-charging-manual.html.ini
@@ -0,0 +1,4 @@
+[battery-charging-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-charging-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-discharging-manual.html.ini
@@ -0,0 +1,4 @@
+[battery-discharging-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-discharging-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-full-manual.html.ini
@@ -0,0 +1,4 @@
+[battery-full-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-full-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
--- a/testing/web-platform/meta/battery-status/battery-interface-idlharness.html.ini
+++ b/testing/web-platform/meta/battery-status/battery-interface-idlharness.html.ini
@@ -1,50 +1,4 @@
 [battery-interface-idlharness.html]
   type: testharness
-  [BatteryManager must be primary interface of navigator.getBattery()]
-    expected: FAIL
-
-  [Stringification of navigator.getBattery()]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "charging" with the proper type (0)]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "chargingTime" with the proper type (1)]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "dischargingTime" with the proper type (2)]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "level" with the proper type (3)]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "onchargingchange" with the proper type (4)]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "onchargingtimechange" with the proper type (5)]
+  [Battery test: IDL]
     expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "ondischargingtimechange" with the proper type (6)]
-    expected: FAIL
-
-  [BatteryManager interface: navigator.getBattery() must inherit property "onlevelchange" with the proper type (7)]
-    expected: FAIL
-
-  [EventTarget interface: navigator.getBattery() must inherit property "addEventListener" with the proper type (0)]
-    expected: FAIL
-
-  [EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on navigator.getBattery() with too few arguments must throw TypeError]
-    expected: FAIL
-
-  [EventTarget interface: navigator.getBattery() must inherit property "removeEventListener" with the proper type (1)]
-    expected: FAIL
-
-  [EventTarget interface: calling removeEventListener(DOMString,EventListener,boolean) on navigator.getBattery() with too few arguments must throw TypeError]
-    expected: FAIL
-
-  [EventTarget interface: navigator.getBattery() must inherit property "dispatchEvent" with the proper type (2)]
-    expected: FAIL
-
-  [EventTarget interface: calling dispatchEvent(Event) on navigator.getBattery() with too few arguments must throw TypeError]
-    expected: FAIL
-
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-plugging-in-manual.html.ini
@@ -0,0 +1,4 @@
+[battery-plugging-in-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-plugging-in-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-promise-iframe.html.ini
@@ -0,0 +1,4 @@
+[battery-promise-iframe.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-promise-iframe.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-promise-window.html.ini
@@ -0,0 +1,4 @@
+[battery-promise-window.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-promise-window.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
--- a/testing/web-platform/meta/battery-status/battery-promise.html.ini
+++ b/testing/web-platform/meta/battery-status/battery-promise.html.ini
@@ -1,5 +1,2 @@
 [battery-promise.html]
-  type: testharness
-  [setting iframe's src makes its Navigator object vary thus getting another battery promise]
-    expected: FAIL
-
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/battery-unplugging-manual.html.ini
@@ -0,0 +1,4 @@
+[battery-unplugging-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[battery-unplugging-manual.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/support-iframe-initial.html.ini
@@ -0,0 +1,4 @@
+[support-iframe-initial.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[support-iframe-initial.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/support-iframe.html.ini
@@ -0,0 +1,4 @@
+[support-iframe.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[support-iframe.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/battery-status/support-window-open.html.ini
@@ -0,0 +1,4 @@
+[support-window-open.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580
+[support-window-open.html]
+  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1313580