Bug 982800 - Browser API: Add a mozbrowsermanifestchange event to detect <link rel="manifest"> elements, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 13 Mar 2014 15:30:03 +0000
changeset 191636 68b0f7e79ceb9fab9ebfa37d219697fdc5cb48d4
parent 191635 c5854c288bcfe859e919c3af7e4ce2e7915bb246
child 191637 16d6b2e332e09ebba1fa623e300b28ceddd9c858
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs982800
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 982800 - Browser API: Add a mozbrowsermanifestchange event to detect <link rel="manifest"> elements, r=ehsan
dom/browser-element/BrowserElementChildPreload.js
dom/browser-element/BrowserElementParent.jsm
dom/browser-element/mochitest/browserElement_Manifestchange.js
dom/browser-element/mochitest/mochitest-oop.ini
dom/browser-element/mochitest/mochitest.ini
dom/browser-element/mochitest/test_browserElement_inproc_Manifestchange.html
dom/browser-element/mochitest/test_browserElement_oop_Manifestchange.html
--- a/dom/browser-element/BrowserElementChildPreload.js
+++ b/dom/browser-element/BrowserElementChildPreload.js
@@ -475,29 +475,37 @@ BrowserElementChild.prototype = {
       return;
     }
 
     sendAsyncMsg('opensearch', { title: e.target.title,
                                  href: e.target.href });
 
   },
 
+  _manifestChangedHandler: function(e) {
+    debug('Got manifestchanged: (' + e.target.href + ')');
+    let manifest = { href: e.target.href };
+    sendAsyncMsg('manifestchange', manifest);
+
+  },
+
   // Processes the "rel" field in <link> tags and forward to specific handlers.
   _linkAddedHandler: function(e) {
     let win = e.target.ownerDocument.defaultView;
     // Ignore links which don't come from the top-level
     // <iframe mozbrowser> window.
     if (win != content) {
       debug('Not top level!');
       return;
     }
 
     let handlers = {
       'icon': this._iconChangedHandler,
-      'search': this._openSearchHandler
+      'search': this._openSearchHandler,
+      'manifest': this._manifestChangedHandler
     };
 
     debug('Got linkAdded: (' + e.target.href + ') ' + e.target.rel);
     e.target.rel.split(' ').forEach(function(x) {
       let token = x.toLowerCase();
       if (handlers[token]) {
         handlers[token](e);
       }
--- a/dom/browser-element/BrowserElementParent.jsm
+++ b/dom/browser-element/BrowserElementParent.jsm
@@ -253,16 +253,17 @@ BrowserElementParent.prototype = {
     let mmCalls = {
       "hello": this._recvHello,
       "contextmenu": this._fireCtxMenuEvent,
       "locationchange": this._fireEventFromMsg,
       "loadstart": this._fireEventFromMsg,
       "loadend": this._fireEventFromMsg,
       "titlechange": this._fireEventFromMsg,
       "iconchange": this._fireEventFromMsg,
+      "manifestchange": this._fireEventFromMsg,
       "metachange": this._fireEventFromMsg,
       "close": this._fireEventFromMsg,
       "resize": this._fireEventFromMsg,
       "activitydone": this._fireEventFromMsg,
       "opensearch": this._fireEventFromMsg,
       "securitychange": this._fireEventFromMsg,
       "error": this._fireEventFromMsg,
       "scroll": this._fireEventFromMsg,
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_Manifestchange.js
@@ -0,0 +1,96 @@
+/* Any copyright is dedicated to the public domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test that the onmozbrowsermanifestchange event works.
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+
+function createHtml(manifest) {
+  return 'data:text/html,<html xmlns:xml="http://www.w3.org/XML/1998/namespace"><head>' + manifest + '<body></body></html>';
+}
+
+function createManifest(href) {
+  return '<link rel="manifest" href="' + href + '">';
+}
+
+function runTest() {
+  var iframe1 = document.createElement('iframe');
+  SpecialPowers.wrap(iframe1).mozbrowser = true;
+  document.body.appendChild(iframe1);
+
+  // iframe2 is a red herring; we modify its manifest link elements but don't
+  // listen for manifestchanges; we want to make sure that its manifestchange
+  // events aren't picked up by the listener on iframe1.
+  var iframe2 = document.createElement('iframe');
+  SpecialPowers.wrap(iframe2).mozbrowser = true;
+  document.body.appendChild(iframe2);
+
+  // iframe3 is another red herring.  It's not a mozbrowser, so we shouldn't
+  // get any manifestchange events on it.
+  var iframe3 = document.createElement('iframe');
+  document.body.appendChild(iframe3);
+
+  var numManifestChanges = 0;
+
+  iframe1.addEventListener('mozbrowsermanifestchange', function(e) {
+
+    numManifestChanges++;
+
+    if (numManifestChanges == 1) {
+      is(e.detail.href, 'manifest.1', 'manifest.1 matches');
+
+      // We should recieve manifestchange events when the user creates new
+      // manifests
+      SpecialPowers.getBrowserFrameMessageManager(iframe1)
+                   .loadFrameScript("data:,content.document.title='New title';",
+                                    /* allowDelayedLoad = */ false);
+
+      SpecialPowers.getBrowserFrameMessageManager(iframe1)
+                   .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')",
+                                    /* allowDelayedLoad = */ false);
+
+      SpecialPowers.getBrowserFrameMessageManager(iframe2)
+                   .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')",
+                                    /* allowDelayedLoad = */ false);
+    }
+    else if (numManifestChanges == 2) {
+      is(e.detail.href, 'manifest.2', 'manifest.2 matches');
+
+      // Full new pages should trigger manifestchange events
+      iframe1.src = createHtml(createManifest('manifest.3'));
+    }
+    else if (numManifestChanges == 3) {
+      is(e.detail.href, 'manifest.3', 'manifest.3 matches');
+
+      // Test setting a page with multiple manifest link elements
+      iframe1.src = createHtml(createManifest('manifest.4a') + createManifest('manifest.4b'));
+    }
+    else if (numManifestChanges == 4) {
+      is(e.detail.href, 'manifest.4a', 'manifest.4a matches');
+      // 2 events will be triggered by previous test, wait for next
+    }
+    else if (numManifestChanges == 5) {
+      is(e.detail.href, 'manifest.4b', 'manifest.4b matches');
+      SimpleTest.finish();
+    } else {
+      ok(false, 'Too many manifestchange events.');
+    }
+  });
+
+  iframe3.addEventListener('mozbrowsermanifestchange', function(e) {
+    ok(false, 'Should not get a manifestchange event for iframe3.');
+  });
+
+
+  iframe1.src = createHtml(createManifest('manifest.1'));
+  // We should not recieve manifest change events for either of the below iframes
+  iframe2.src = createHtml(createManifest('manifest.1'));
+  iframe3.src = createHtml(createManifest('manifest.1'));
+
+}
+
+addEventListener('testready', runTest);
+
--- a/dom/browser-element/mochitest/mochitest-oop.ini
+++ b/dom/browser-element/mochitest/mochitest-oop.ini
@@ -35,16 +35,17 @@ skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_oop_FirstPaint.html]
 [test_browserElement_oop_ForwardName.html]
 [test_browserElement_oop_FrameWrongURI.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_oop_GetScreenshot.html]
 [test_browserElement_oop_GetScreenshotDppx.html]
 [test_browserElement_oop_Iconchange.html]
 [test_browserElement_oop_LoadEvents.html]
+[test_browserElement_oop_Manifestchange.html]
 [test_browserElement_oop_Metachange.html]
 [test_browserElement_oop_OpenMixedProcess.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_oop_OpenNamed.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_oop_OpenWindow.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_oop_OpenWindowDifferentOrigin.html]
--- a/dom/browser-element/mochitest/mochitest.ini
+++ b/dom/browser-element/mochitest/mochitest.ini
@@ -26,16 +26,17 @@ support-files =
   browserElement_FirstPaint.js
   browserElement_ForwardName.js
   browserElement_FrameWrongURI.js
   browserElement_GetScreenshot.js
   browserElement_GetScreenshotDppx.js
   browserElement_Iconchange.js
   browserElement_KeyEvents.js
   browserElement_LoadEvents.js
+  browserElement_Manifestchange.js
   browserElement_Metachange.js
   browserElement_NextPaint.js
   browserElement_OpenNamed.js
   browserElement_OpenWindow.js
   browserElement_OpenWindowDifferentOrigin.js
   browserElement_OpenWindowInFrame.js
   browserElement_OpenWindowRejected.js
   browserElement_Opensearch.js
@@ -139,16 +140,17 @@ skip-if = buildapp == 'b2g'
 [test_browserElement_inproc_FrameWrongURI.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_inproc_GetScreenshot.html]
 [test_browserElement_inproc_GetScreenshotDppx.html]
 [test_browserElement_inproc_Iconchange.html]
 [test_browserElement_inproc_KeyEvents.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_inproc_LoadEvents.html]
+[test_browserElement_inproc_Manifestchange.html]
 [test_browserElement_inproc_Metachange.html]
 [test_browserElement_inproc_NextPaint.html]
 [test_browserElement_inproc_OpenNamed.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_inproc_OpenWindow.html]
 skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_inproc_OpenWindowDifferentOrigin.html]
 skip-if = (toolkit == 'gonk' && !debug)
copy from dom/browser-element/mochitest/test_browserElement_inproc_Iconchange.html
copy to dom/browser-element/mochitest/test_browserElement_inproc_Manifestchange.html
--- a/dom/browser-element/mochitest/test_browserElement_inproc_Iconchange.html
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_Manifestchange.html
@@ -1,19 +1,19 @@
 <!DOCTYPE HTML>
 <html>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=719461
+https://bugzilla.mozilla.org/show_bug.cgi?id=982800
 -->
 <head>
-  <title>Test for Bug 719461</title>
+  <title>Test for Bug 982800</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="browserElementTestHelpers.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=719461">Mozilla Bug 719461</a>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=982800">Mozilla Bug 982800</a>
 
-<script type="application/javascript;version=1.7" src="browserElement_Iconchange.js">
+<script type="application/javascript;version=1.7" src="browserElement_Manifestchange.js">
 </script>
 
 </body>
 </html>
copy from dom/browser-element/mochitest/test_browserElement_oop_Iconchange.html
copy to dom/browser-element/mochitest/test_browserElement_oop_Manifestchange.html
--- a/dom/browser-element/mochitest/test_browserElement_oop_Iconchange.html
+++ b/dom/browser-element/mochitest/test_browserElement_oop_Manifestchange.html
@@ -1,19 +1,19 @@
 <!DOCTYPE HTML>
 <html>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=719461
+https://bugzilla.mozilla.org/show_bug.cgi?id=982800
 -->
 <head>
-  <title>Test for Bug 719461</title>
+  <title>Test for Bug 982800</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="browserElementTestHelpers.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=719461">Mozilla Bug 719461</a>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=982800">Mozilla Bug 982800</a>
 
-<script type="application/javascript;version=1.7" src="browserElement_Iconchange.js">
+<script type="application/javascript;version=1.7" src="browserElement_Manifestchange.js">
 </script>
 
 </body>
 </html>