try: -b do -p all -u all -t all
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Fri, 20 Feb 2015 16:18:05 -0800
changeset 402746 f270fb202f5636ef911311e2c191aea9c0b87092
parent 402745 ed288392b7e381f0fd991640b9c048e66bc5a460
child 543807 c766770fcb0eee60782c5acaaf3d22842879883c
push id56543
push usermozilla@christophkerschbaumer.com
push dateMon, 02 Mar 2015 18:07:57 +0000
treeherdertry@f270fb202f56 [default view] [failures only]
milestone39.0a1
try: -b do -p all -u all -t all
browser/base/content/test/general/BrowserMetaReferrerTestUtils.jsm
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_meta_referrer_ctrl_click.js
browser/base/content/test/general/browser_meta_referrer_open_link_in_tab.js
browser/base/content/test/general/browser_meta_referrer_open_link_in_window.js
browser/base/content/test/general/browser_meta_referrer_simple_click.js
browser/base/content/test/general/file_meta_referrer_policyserver.sjs
browser/base/content/test/general/file_meta_referrer_testserver.sjs
browser/base/moz.build
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/BrowserMetaReferrerTestUtils.jsm
@@ -0,0 +1,218 @@
+/*
+ * Description of the tests for
+ *   Bug 1113431 - <meta name="referrer"> is ignored for navigations from the
+ *                 context menu and via a middle-click
+ *
+ * This file provides the shared testing infrastracture for the following tests:
+ *   1. browser_meta_referrer_simple_click.js  (simple left mouse click)
+ *   2. browser_meta_referrer_ctrl_click       (ctrl-click)
+ *   3. browser_meta_referrer_open_link_in_tab (right-click -> open in new tab)
+ *
+ */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = [
+  "BrowserMetaReferrerTestUtils",
+];
+
+const BASE_URL =
+  "test1.example.com/browser/browser/base/content/test/general/" +
+  "file_meta_referrer_policyserver.sjs";
+
+let tests = [
+  // ------------------------------ origin ----------
+  {  // http->http
+    policy: "origin",
+    fromScheme: "http://",
+    toScheme: "http://",
+    result: "http://test1.example.com"
+  },
+  { // http->https
+    policy: "origin",
+    fromScheme: "http://",
+    toScheme: "https://",
+    result: "http://test1.example.com"
+  },
+  { // https->https
+    policy: "origin",
+    fromScheme: "https://",
+    toScheme: "https://",
+    result: "https://test1.example.com"
+  },
+  { // https->http
+    policy: "origin",
+    fromScheme: "https://",
+    toScheme: "http://",
+    result: "https://test1.example.com"
+  },
+  // ------------------------------ no-referrer ----------
+  {  // http->http
+    policy: "no-referrer",
+    fromScheme: "http://",
+    toScheme: "http://",
+    result: "no referrer"
+  },
+  { // http->https
+    policy: "no-referrer",
+    fromScheme: "http://",
+    toScheme: "https://",
+    result: "no referrer"
+  },
+  { // https->https
+    policy: "no-referrer",
+    fromScheme: "https://",
+    toScheme: "https://",
+    result: "no referrer"
+  },
+  { // https->http
+    policy: "no-referrer",
+    fromScheme: "https://",
+    toScheme: "http://",
+    result: "no referrer"
+  },
+  // ------------------------------ no-referrer-when-downgrade ----------
+  {  // http->http
+    policy: "no-referrer-when-downgrade",
+    fromScheme: "http://",
+    toScheme: "http://",
+    result: "http://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=http://&amp;policy=no-referrer-when-downgrade"
+  },
+  { // http->https
+    policy: "no-referrer-when-downgrade",
+    fromScheme: "http://",
+    toScheme: "https://",
+    result: "http://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=https://&amp;policy=no-referrer-when-downgrade"
+  },
+  { // https->https
+    policy: "no-referrer-when-downgrade",
+    fromScheme: "https://",
+    toScheme: "https://",
+    result: "https://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=https://&amp;policy=no-referrer-when-downgrade"
+  },
+  { // https->http
+    policy: "no-referrer-when-downgrade",
+    fromScheme: "https://",
+    toScheme: "http://",
+    result: "no referrer"
+  },
+  // ------------------------------ origin-when-crossorigin ----------
+  {  // http->http
+    policy: "origin-when-crossorigin",
+    fromScheme: "http://",
+    toScheme: "http://",
+    result: "http://test1.example.com"
+  },
+  { // http->https
+    policy: "origin-when-crossorigin",
+    fromScheme: "http://",
+    toScheme: "https://",
+    result: "http://test1.example.com"
+  },
+  { // https->https
+    policy: "origin-when-crossorigin",
+    fromScheme: "https://",
+    toScheme: "https://",
+    result: "https://test1.example.com"
+  },
+  { // https->http
+    policy: "origin-when-crossorigin",
+    fromScheme: "https://",
+    toScheme: "http://",
+    result: "https://test1.example.com"
+  },
+  // ------------------------------ unsafe-url ----------
+  {  // http->http
+    policy: "unsafe-url",
+    fromScheme: "http://",
+    toScheme: "http://",
+    result: "http://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=http://&amp;policy=unsafe-url"
+  },
+  { // http->https
+    policy: "unsafe-url",
+    fromScheme: "http://",
+    toScheme: "https://",
+    result: "http://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=https://&amp;policy=unsafe-url"
+  },
+  { // https->https
+    policy: "unsafe-url",
+    fromScheme: "https://",
+    toScheme: "https://",
+    result: "https://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=https://&amp;policy=unsafe-url"
+  },
+  { // https->http
+    policy: "unsafe-url",
+    fromScheme: "https://",
+    toScheme: "http://",
+    result: "https://test1.example.com/browser/browser/base/content/" +
+            "test/general/file_meta_referrer_policyserver.sjs?" +
+            "scheme=http://&amp;policy=unsafe-url"
+  },
+];
+
+
+this.BrowserMetaReferrerTestUtils = {
+
+  /**
+   * Function to get the next test object.
+   *
+   * @param aIndex
+   *        the index of the next test
+   */
+  getNextMetaReferrerTest: function getNextMetaReferrerTest(aIndex) {
+    if (aIndex < tests.length) {
+      return tests[aIndex];
+    }
+    return null;
+  },
+
+  /**
+   * Waits for a load event somewhere in the browser but ignore events coming
+   * from <xul:browser>s without a tab assigned. That are most likely browsers
+   * that preload the new tab page.
+   *
+   * @param aWin
+   *        the window where tests are running in (e.g. gTestWin)
+   * @param aCallBack
+   *        the callback function once the tab loaded
+   */
+  waitForSomeTabToLoad: function waitForSomeTabToLoad(aWin, aCallback) {
+    aWin.gBrowser.addEventListener("load", function onLoad(event) {
+      let tab = aWin.gBrowser._getTabForContentWindow(event.target.defaultView.top);
+      if (tab) {
+        aWin.gBrowser.removeEventListener("load", onLoad, true);
+        aCallback();
+      }
+    }, true);
+  },
+
+  /*
+   * Sets up the next test.
+   *
+   * @param aCurTest
+   *        a test object from within tests[] defined above.
+   * @param aWin
+   *        the window where tests are running in (e.g. gTestWin)
+   * @param aCallBack
+   *        the callback function once the test is set up and
+   *        ready to run.
+   */
+  setUpTest: function setUpTest(aCurTest, aWin, aCallBack)  {
+    let query = "?scheme=" + aCurTest.toScheme + "&policy=" + aCurTest.policy;
+    aWin.gBrowser.addTab(aCurTest.fromScheme + BASE_URL + query);
+    aWin.gBrowser.selectTabAtIndex(1);
+    this.waitForSomeTabToLoad(aWin, aCallBack);
+  }
+};
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -52,16 +52,18 @@ support-files =
   file_bug970276_popup2.html
   file_bug970276_favicon1.ico
   file_bug970276_favicon2.ico
   file_dom_notifications.html
   file_double_close_tab.html
   file_favicon_change.html
   file_favicon_change_not_in_document.html
   file_fullscreen-window-open.html
+  file_meta_referrer_policyserver.sjs
+  file_meta_referrer_testserver.sjs
   get_user_media.html
   head.js
   healthreport_testRemoteCommands.html
   moz.png
   navigating_window_with_download.html
   offlineQuotaNotification.cacheManifest
   offlineQuotaNotification.html
   page_style_sample.html
@@ -334,16 +336,20 @@ skip-if = e10s # Bug 921957 - remote web
 [browser_lastAccessedTab.js]
 skip-if = toolkit == "windows" # Disabled on Windows due to frequent failures (bug 969405)
 [browser_locationBarCommand.js]
 skip-if = os == "linux" || e10s # Linux: Intermittent failures, bug 917535; e10s: Bug 1094252 - Focus issues (There should be no focused element - Got [object XULElement], expected null)
 [browser_locationBarExternalLoad.js]
 skip-if = e10s
 [browser_menuButtonFitts.js]
 skip-if = os != "win" # The Fitts Law menu button is only supported on Windows (bug 969376)
+[browser_meta_referrer_ctrl_click.js]
+[browser_meta_referrer_open_link_in_tab.js]
+[browser_meta_referrer_open_link_in_window.js]
+[browser_meta_referrer_simple_click.js]
 [browser_middleMouse_noJSPaste.js]
 skip-if = e10s # Bug 921952 - Content:Click event issues
 [browser_minimize.js]
 skip-if = e10s # Bug 1100664 - test directly access content docShells (TypeError: gBrowser.docShell is null)
 [browser_mixedcontent_securityflags.js]
 [browser_notification_tab_switching.js]
 skip-if = buildapp == 'mulet' || e10s # Bug 1100662 - content access causing uncaught exception - Error: cannot ipc non-cpow object at chrome://mochitests/content/browser/browser/base/content/test/general/browser_notification_tab_switching.js:32 (or in RemoteAddonsChild.jsm)
 [browser_offlineQuotaNotification.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_meta_referrer_ctrl_click.js
@@ -0,0 +1,91 @@
+
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserMetaReferrerTestUtils",
+                                  "resource://testing-common/BrowserMetaReferrerTestUtils.jsm");
+
+let gTestWin = null;
+let curClickHandler = null;
+let curTest = null;
+let testCounter = 0;
+
+const INITAL_TEST = function () { waitForFocus(ctrlClickTest, gTestWin.content) };
+
+// --------------- helper functions ---------------
+
+// The purpose of this function is to simulate |CTRL+CLICK|.
+// The clickHandler intercepts simulated user clicks and performs
+// the |contentAreaClick| which dispatches to handleLinkClick.
+let clickHandler = function (aEvent, aFunc) {
+  gTestWin.gBrowser.removeEventListener("click", curClickHandler, true);
+  gTestWin.contentAreaClick(aEvent, true);
+  var callback = function() { waitForFocus(aFunc, gTestWin.content) };
+  BrowserMetaReferrerTestUtils.waitForSomeTabToLoad(gTestWin, callback);
+  aEvent.preventDefault();
+  aEvent.stopPropagation();
+}
+
+// --------------- runCtrlClickTest ---------------
+
+function ctrlClickTest() {
+  info("runCtrlClickTest (policy = '" + curTest.policy + "' ("+
+        curTest.fromScheme + " -> " + curTest.toScheme + ") started...");
+
+  curClickHandler = function (e) { clickHandler(e, ctrlClickTestPart2) };
+  gTestWin.gBrowser.addEventListener("click", curClickHandler , true);
+
+  // simulating |CTRL-CLICK|
+  let targetElt = gTestWin.content.document.getElementById("testlink");
+  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
+}
+
+function ctrlClickTestPart2() {
+  gTestWin.gBrowser.selectTabAtIndex(2);
+  waitForFocus(ctrlClickTestPart3, gTestWin.content);
+}
+
+function ctrlClickTestPart3() {
+  var desc = "simple click [" + curTest.policy + "] (" +
+             curTest.fromScheme + " -> " + curTest.toScheme + ")";
+  try {
+    let targetElt = gTestWin.content.document.getElementById("testdiv");
+    is(targetElt.innerHTML, curTest.result, desc);
+  }
+  catch (e) {
+    ok(false, desc);
+  }
+
+  // sanity testing, make sure 3 tabs are open and remove them individually
+  // so we start out with the initial tab again
+  is(gTestWin.gBrowser.tabs.length, 3, "there are three tabs open");
+  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2]);
+  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1]);
+
+
+  testCounter++;
+  curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+  if (!curTest) {
+    // we are done; close the browser window
+    gTestWin.close();
+    finish();
+  }
+  else {
+    BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+  }
+}
+
+//------------------------ setup ------------------------------
+
+function test() {
+  info("test()...");
+  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
+  waitForExplicitFinish();
+
+  gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
+  whenDelayedStartupFinished(gTestWin, function () {
+    info("browser window opened...");
+    waitForFocus(function() {
+      info("browser window focused...");
+      curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+      BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+    }, gTestWin);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_meta_referrer_open_link_in_tab.js
@@ -0,0 +1,90 @@
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserMetaReferrerTestUtils",
+                                  "resource://testing-common/BrowserMetaReferrerTestUtils.jsm");
+
+let gTestWin = null;
+let curContextMenu = null;
+let curTest = null;
+let testCounter = 0;
+
+const INITAL_TEST = function () { waitForFocus(contextMenuClickTest, gTestWin.content) };
+
+// --------------- helper functions ---------------
+
+// The purpose of this function is to simulate |RIGHT-CLICK|->|OPEN LINK IN TAB|
+// Once the contextmenu opens, this functions selects 'open link in tab'
+// from the contextmenu which dispatches to the function openLinkInTab.
+let contextMenuOpenHandler = function(aEvent, aFunc) {
+  gTestWin.document.removeEventListener("popupshown", curContextMenu, false);
+  var callback = function() { waitForFocus(aFunc, gTestWin.content) };
+  BrowserMetaReferrerTestUtils.waitForSomeTabToLoad(gTestWin, callback);
+  var openLinkInTabCommand = gTestWin.document.getElementById("context-openlinkintab");
+  openLinkInTabCommand.doCommand();
+  aEvent.target.hidePopup();
+};
+
+// --------------- contextMenuClickTest ---------------
+
+function contextMenuClickTest() {
+  info("contextMenuClickTest (policy = '" + curTest.policy + "' ("+
+        curTest.fromScheme + " -> " + curTest.toScheme + ") started...");
+
+  curContextMenu = function (e) { contextMenuOpenHandler(e, contextMenuClickTestPart2) };
+  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
+
+  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
+  let targetElt = gTestWin.content.document.getElementById("testlink");
+  // button 2 is a right click, hence the context menu pops up
+  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
+}
+
+function contextMenuClickTestPart2() {
+  gTestWin.gBrowser.selectTabAtIndex(2);
+  waitForFocus(contextMenuClickTestPart3, gTestWin.content);
+}
+
+function contextMenuClickTestPart3() {
+  var desc = "open link in tab [" + curTest.policy + "] (" +
+             curTest.fromScheme + " -> " + curTest.toScheme + ")";
+  try {
+    let targetElt = gTestWin.content.document.getElementById("testdiv");
+    is(targetElt.innerHTML, curTest.result, desc);
+  }
+  catch (e) {
+    ok(false, desc);
+  }
+
+  // sanity testing, make sure 3 tabs are open and remove them individually
+  // so we start out with the initial tab again
+  is(gTestWin.gBrowser.tabs.length, 3, "there are three tabs open");
+  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2]);
+  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1]);
+
+  testCounter++;
+  curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+  if (!curTest) {
+    // we are done; close the browser window
+    gTestWin.close();
+    finish();
+  }
+  else {
+    BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+  }
+}
+
+//------------------------ setup ------------------------------
+
+function test() {
+  info("test()...");
+  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
+  waitForExplicitFinish();
+
+  gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
+  whenDelayedStartupFinished(gTestWin, function () {
+    info("browser window opened...");
+    waitForFocus(function() {
+      info("browser window focused...");
+      curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+      BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+    }, gTestWin);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_meta_referrer_open_link_in_window.js
@@ -0,0 +1,113 @@
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserMetaReferrerTestUtils",
+                                  "resource://testing-common/BrowserMetaReferrerTestUtils.jsm");
+
+let gTestWin = null;
+let gTestWin2 = null;
+let curContextMenu = null;
+let curTest = null;
+let testCounter = 0;
+
+const INITAL_TEST = function () { waitForFocus(openLinkInWindowTest, gTestWin.content) };
+
+// --------------- helper functions ---------------
+
+// The WindowListener waits for the new window to load and waits till the window has
+// the focus before checking the URL of the document and moving on to the next test.
+function addWindowListener() {
+  Services.wm.addListener({
+    onOpenWindow: function(aXULWindow) {
+      info("window opened, waiting for focus");
+      Services.wm.removeListener(this);
+
+      gTestWin2 = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                            .getInterface(Ci.nsIDOMWindow);
+
+      waitForFocus(function() {
+        // wait for the new tab to be loaded before we move on with the test
+        BrowserMetaReferrerTestUtils.waitForSomeTabToLoad(gTestWin2, openLinkInWindowTest2);
+      }, gTestWin2);
+    },
+    onCloseWindow: function(aXULWindow) { },
+    onWindowTitleChange: function(aXULWindow, aNewTitle) { }
+  });
+}
+
+// The purpose of this function is to simulate |RIGHT-CLICK|->|OPEN LINK IN WINDOW|
+// Once the contextmenu opens, this functions selects 'open link in window'
+// from the contextmenu which dispatches to the function openLink.
+let contextMenuOpenHandler = function(aEvent) {
+  gTestWin.document.removeEventListener("popupshown", curContextMenu, false);
+  //var callback = function() { waitForFocus(aFunc, gTestWin.content) };
+  //BrowserMetaReferrerTestUtils.waitForSomeTabToLoad(gTestWin, callback);
+  // pass the new URL to the window listener for sanity checking
+  addWindowListener(curTest.toScheme + "test1.example.com");
+  var openLinkInTabCommand = gTestWin.document.getElementById("context-openlink");
+  openLinkInTabCommand.doCommand();
+  aEvent.target.hidePopup();
+};
+
+// --------------- openLinkInWindowTest ---------------
+
+function openLinkInWindowTest() {
+  info("openLinkInWindowTest (policy = '" + curTest.policy + "' ("+
+        curTest.fromScheme + " -> " + curTest.toScheme + ") started...");
+
+  curContextMenu = function (e) { contextMenuOpenHandler(e) };
+  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
+
+  // simulating |RIGHT-CLICK -> OPEN LINK IN WINDOW|
+  let targetElt = gTestWin.content.document.getElementById("testlink");
+  // button 2 is a right click, hence the context menu pops up
+  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
+}
+
+function openLinkInWindowTest2() {
+  var desc = "open link in window [" + curTest.policy + "] (" +
+             curTest.fromScheme + " -> " + curTest.toScheme + ")";
+  try {
+    let targetElt = gTestWin2.content.document.getElementById("testdiv");
+    is(targetElt.innerHTML, curTest.result, desc);
+  }
+  catch (e) {
+    ok(false, desc);
+  }
+
+  // sanity testing, make sure the new test window has one open tab before closing
+  is(gTestWin2.gBrowser.tabs.length, 1, "there is one tab open in the new window");
+  gTestWin2.gBrowser.removeTab(gTestWin.gBrowser.tabs[0]);
+  gTestWin2.close();
+
+  // make sure there are two tabs in the inital window, close the test tab
+  // and move on to the next test.
+  is(gTestWin.gBrowser.tabs.length, 2, "there are two tabs open");
+  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1]);
+
+  testCounter++;
+  curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+  if (!curTest) {
+    // we are done; close the browser window
+    gTestWin.close();
+    finish();
+  }
+  else {
+    BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+  }
+}
+
+//------------------------ setup ------------------------------
+
+function test() {
+  info("test()...");
+  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
+  waitForExplicitFinish();
+
+  gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
+  whenDelayedStartupFinished(gTestWin, function () {
+    info("browser window opened...");
+    waitForFocus(function() {
+      info("browser window focused...");
+      curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+      BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+    }, gTestWin);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_meta_referrer_simple_click.js
@@ -0,0 +1,69 @@
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserMetaReferrerTestUtils",
+                                  "resource://testing-common/BrowserMetaReferrerTestUtils.jsm");
+
+let gTestWin = null;
+let curContextMenu = null;
+let curTest = null;
+let testCounter = 0;
+
+const INITAL_TEST = function () { waitForFocus(normalClickTest, gTestWin.content) };
+
+// --------------- normalClickTest ---------------
+
+function normalClickTest() {
+  info("simple click (policy = '" + curTest.policy + "' ("+
+        curTest.fromScheme + " -> " + curTest.toScheme + ") started...");
+
+  var callback = function() { waitForFocus(normalClickTestPart2, gTestWin.content) };
+  BrowserMetaReferrerTestUtils.waitForSomeTabToLoad(gTestWin, callback);
+
+  // simulating |CLICK|
+  let targetElt = gTestWin.content.document.getElementById("testlink");
+  EventUtils.synthesizeMouseAtCenter(targetElt, {}, gTestWin.content);
+}
+
+function normalClickTestPart2() {
+  var desc = "simple click [" + curTest.policy + "] (" +
+             curTest.fromScheme + " -> " + curTest.toScheme + ")";
+  try {
+    let targetElt = gTestWin.content.document.getElementById("testdiv");
+    is(targetElt.innerHTML, curTest.result, desc);
+  }
+  catch (e) {
+    ok(false, desc);
+  }
+
+  // sanity testing, make sure there are 2 tabs open and remove them individually
+  // so we start out with the initial tab again
+  is(gTestWin.gBrowser.tabs.length, 2, "there are two tabs open");
+  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1]);
+
+  testCounter++;
+  curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+  if (!curTest) {
+    // we are done; close the browser window
+    gTestWin.close();
+    finish();
+  }
+  else {
+    BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+  }
+}
+
+//------------------------ setup ------------------------------
+
+function test() {
+  info("test()...");
+  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
+  waitForExplicitFinish();
+
+  gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
+  whenDelayedStartupFinished(gTestWin, function () {
+    info("browser window opened...");
+    waitForFocus(function() {
+      info("browser window focused...");
+      curTest = BrowserMetaReferrerTestUtils.getNextMetaReferrerTest(testCounter);
+      BrowserMetaReferrerTestUtils.setUpTest(curTest, gTestWin, INITAL_TEST);
+    }, gTestWin);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/file_meta_referrer_policyserver.sjs
@@ -0,0 +1,40 @@
+/*
+ * Custom *.sjs file for Bug 1113431 which sends some
+ * html snippet using the provided meta_referrer policy
+ */
+
+function handleRequest(request, response)
+{
+  let query = {};
+
+  request.queryString.split('&').forEach(function(val) {
+    let [name, value] = val.split('=');
+    query[name] = unescape(value);
+  });
+
+  let policy = unescape(query['policy']);
+  let scheme = unescape(query['scheme']);
+
+  let base_url = "example.com/browser/browser/base/content/test/general/" +
+                 "file_meta_referrer_testserver.sjs";
+
+  let html = "<!DOCTYPE HTML>" +
+             "<html>" +
+             "<head>" +
+             "<meta charset='utf-8'>" +
+             "<meta name='referrer' content='" + policy + "'>" +
+             "<title>Test for meta referrer bug</title>" +
+             "</head>" +
+             "<body>" +
+             "<a id='testlink' href='" + scheme + base_url + "'>referrer test link</a>" +
+             "</body>" +
+             "</html>";
+
+  // avoid confusing cache behaviors
+  response.setHeader("Cache-Control", "no-cache", false);
+
+  // Send HTML to test allowed/blocked behaviors
+  response.setHeader("Content-Type", "text/html", false);
+
+  response.write(html);
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/file_meta_referrer_testserver.sjs
@@ -0,0 +1,33 @@
+/*
+ * Custom *.sjs file for Bug 1113431 to see if the referrer
+ * is sent correctly when using meta_referrer.
+ */
+
+function handleRequest(request, response)
+{
+  let referrer = "";
+  try {
+    referrer = request.getHeader("referer");
+  }
+  catch (e) {
+    referrer = "no referrer";
+  }
+
+  let html = "<!DOCTYPE HTML>" +
+             "<html>" +
+             "<head>" +
+             "<title>Test for meta referrer bug</title>" +
+             "</head>" +
+             "<body>" +
+             "<div id='testdiv'>" + referrer + "</div>" +
+             "</body>" +
+             "</html>";
+
+  // avoid confusing cache behaviors
+  response.setHeader("Cache-Control", "no-cache", false);
+
+  // Send HTML to test allowed/blocked behaviors
+  response.setHeader("Content-Type", "text/html", false);
+
+  response.write(html);
+}
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -3,16 +3,17 @@
 # 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/.
 
 SPHINX_TREES['sslerrorreport'] = 'content/docs/sslerrorreport'
 
 TESTING_JS_MODULES += [
     'content/test/BrowserUITestUtils.jsm',
+    'content/test/general/BrowserMetaReferrerTestUtils.jsm',
 ]
 
 MOCHITEST_MANIFESTS += [
     'content/test/general/mochitest.ini',
 ]
 
 MOCHITEST_CHROME_MANIFESTS += [
     'content/test/chrome/chrome.ini',