Bug 1255061 - [e10s] convert test_bug_411966.html to mochitest-browser. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 10 Mar 2016 16:19:23 +0100
changeset 339687 17c26f1208274831953821a0a0d23e8efc637afe
parent 339668 612013e2676d371df229abdd4819abe896cc310e
child 339688 b8efc6dc729ea6b1b5de4e6aca866ee52d7dccf9
push id12800
push usercmanchester@mozilla.com
push dateSat, 12 Mar 2016 21:33:31 +0000
reviewersadw
bugs1255061
milestone48.0a1
Bug 1255061 - [e10s] convert test_bug_411966.html to mochitest-browser. r=adw MozReview-Commit-ID: 5QCYC6uljKa
toolkit/components/places/tests/browser/browser.ini
toolkit/components/places/tests/browser/browser_double_redirect.js
toolkit/components/places/tests/browser/browser_redirect.js
toolkit/components/places/tests/browser/head.js
toolkit/components/places/tests/browser/redirect_once.sjs
toolkit/components/places/tests/chrome.ini
toolkit/components/places/tests/mochitest/bug_411966/.eslintrc
toolkit/components/places/tests/mochitest/bug_411966/ClickedPage.htm
toolkit/components/places/tests/mochitest/bug_411966/ClickedPage.htm^headers^
toolkit/components/places/tests/mochitest/bug_411966/PermRedirectPage.htm
toolkit/components/places/tests/mochitest/bug_411966/TempRedirectPage.htm
toolkit/components/places/tests/mochitest/bug_411966/TempRedirectPage.htm^headers^
toolkit/components/places/tests/mochitest/bug_411966/TypedPage.htm
toolkit/components/places/tests/mochitest/bug_411966/redirect.js
toolkit/components/places/tests/moz.build
toolkit/components/places/tests/test_bug_411966.html
--- a/toolkit/components/places/tests/browser/browser.ini
+++ b/toolkit/components/places/tests/browser/browser.ini
@@ -7,16 +7,17 @@ support-files =
   head.js
 
 [browser_bug248970.js]
 [browser_bug399606.js]
 [browser_bug646422.js]
 [browser_bug680727.js]
 skip-if = buildapp == 'mulet' # Bug ?????? - test times out on try on all platforms, but works locally for markh!
 [browser_colorAnalyzer.js]
+[browser_double_redirect.js]
 [browser_favicon_privatebrowsing_perwindowpb.js]
 [browser_favicon_setAndFetchFaviconForPage.js]
 [browser_favicon_setAndFetchFaviconForPage_failures.js]
 [browser_notfound.js]
 [browser_redirect.js]
 [browser_settitle.js]
 [browser_visited_notfound.js]
 [browser_visituri.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/browser/browser_double_redirect.js
@@ -0,0 +1,63 @@
+// Test for bug 411966.
+// When a page redirects multiple times, from_visit should point to the
+// previous visit in the chain, not to the first visit in the chain.
+
+add_task(function* () {
+  yield PlacesTestUtils.clearHistory();
+
+  const BASE_URL = "http://example.com/tests/toolkit/components/places/tests/browser/";
+  const TEST_URI = NetUtil.newURI(BASE_URL + "begin.html");
+  const FIRST_REDIRECTING_URI = NetUtil.newURI(BASE_URL + "redirect_twice.sjs");
+  const FINAL_URI = NetUtil.newURI(BASE_URL + "final.html");
+
+  let promiseVisits = new Promise(resolve => {
+    PlacesUtils.history.addObserver({
+      __proto__: NavHistoryObserver.prototype,
+      _notified: [],
+      onVisit: function (uri, id, time, sessionId, referrerId, transition) {
+        info("Received onVisit: " + uri.spec);
+        this._notified.push(uri);
+
+        if (!uri.equals(FINAL_URI)) {
+          return;
+        }
+
+        is(this._notified.length, 4);
+        PlacesUtils.history.removeObserver(this);
+
+        Task.spawn(function* () {
+          // Get all pages visited from the original typed one
+          let db = yield PlacesUtils.promiseDBConnection();
+          let rows = yield db.execute(
+            `SELECT url FROM moz_historyvisits
+             JOIN moz_places h ON h.id = place_id
+             WHERE from_visit IN
+                (SELECT v.id FROM moz_historyvisits v
+                 JOIN moz_places p ON p.id = v.place_id
+                 WHERE p.url = :url)
+            `, { url: TEST_URI.spec });
+
+          is(rows.length, 1, "Found right number of visits");
+          let visitedUrl = rows[0].getResultByName("url");
+          // Check that redirect from_visit is not from the original typed one
+          is(visitedUrl, FIRST_REDIRECTING_URI.spec, "Check referrer for " + visitedUrl);
+
+          resolve();
+        });
+      }
+    }, false);
+  });
+
+  PlacesUtils.history.markPageAsTyped(TEST_URI);
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: TEST_URI.spec,
+  }, function* (browser) {
+    // Load begin page, click link on page to record visits.
+    yield BrowserTestUtils.synthesizeMouseAtCenter("#clickme", {}, browser);
+
+    yield promiseVisits;
+  });
+
+  yield PlacesTestUtils.clearHistory();
+});
--- a/toolkit/components/places/tests/browser/browser_redirect.js
+++ b/toolkit/components/places/tests/browser/browser_redirect.js
@@ -1,15 +1,13 @@
 /* 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/. */
 
 add_task(function* () {
-  waitForExplicitFinish();
-
   const REDIRECT_URI = NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/browser/redirect.sjs");
   const TARGET_URI = NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/browser/redirect-target.html");
 
   // Create and add history observer.
   let visitedPromise = new Promise(resolve => {
     let historyObserver = {
       _redirectNotified: false,
       onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
--- a/toolkit/components/places/tests/browser/head.js
+++ b/toolkit/components/places/tests/browser/head.js
@@ -1,23 +1,24 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-const TRANSITION_LINK = Ci.nsINavHistoryService.TRANSITION_LINK;
-const TRANSITION_TYPED = Ci.nsINavHistoryService.TRANSITION_TYPED;
-const TRANSITION_BOOKMARK = Ci.nsINavHistoryService.TRANSITION_BOOKMARK;
-const TRANSITION_REDIRECT_PERMANENT = Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT;
-const TRANSITION_REDIRECT_TEMPORARY = Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY;
-const TRANSITION_EMBED = Ci.nsINavHistoryService.TRANSITION_EMBED;
-const TRANSITION_FRAMED_LINK = Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK;
-const TRANSITION_DOWNLOAD = Ci.nsINavHistoryService.TRANSITION_DOWNLOAD;
-
+Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
                                   "resource://testing-common/PlacesTestUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserTestUtils",
+                                  "resource://testing-common/BrowserTestUtils.jsm");
+
+const TRANSITION_LINK = PlacesUtils.history.TRANSITION_LINK;
+const TRANSITION_TYPED = PlacesUtils.history.TRANSITION_TYPED;
+const TRANSITION_BOOKMARK = PlacesUtils.history.TRANSITION_BOOKMARK;
+const TRANSITION_REDIRECT_PERMANENT = PlacesUtils.history.TRANSITION_REDIRECT_PERMANENT;
+const TRANSITION_REDIRECT_TEMPORARY = PlacesUtils.history.TRANSITION_REDIRECT_TEMPORARY;
+const TRANSITION_EMBED = PlacesUtils.history.TRANSITION_EMBED;
+const TRANSITION_FRAMED_LINK = PlacesUtils.history.TRANSITION_FRAMED_LINK;
+const TRANSITION_DOWNLOAD = PlacesUtils.history.TRANSITION_DOWNLOAD;
 
 /**
  * Returns a moz_places field value for a url.
  *
  * @param aURI
  *        The URI or spec to get field for.
  * param aCallback
  *        Callback function that will get the property value.
--- a/toolkit/components/places/tests/browser/redirect_once.sjs
+++ b/toolkit/components/places/tests/browser/redirect_once.sjs
@@ -1,9 +1,9 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 function handleRequest(request, response) {
-  response.setStatusLine("1.1", 302, "Found");
+  response.setStatusLine("1.1", 301, "Found");
   response.setHeader("Location", "final.html", false);
 }
--- a/toolkit/components/places/tests/chrome.ini
+++ b/toolkit/components/places/tests/chrome.ini
@@ -1,3 +1,2 @@
 [test_bug_94514.html]
-[test_bug_411966.html]
 [test_bug_461710_perwindowpb.html]
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/.eslintrc
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "extends": [
-    "../../../../../../testing/mochitest/mochitest.eslintrc"
-  ]
-}
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/ClickedPage.htm
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Bug 411966</title>
-  </head>
-  </body>
-    Clicked link page!
-  </body>
-</html>
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/ClickedPage.htm^headers^
+++ /dev/null
@@ -1,2 +0,0 @@
-HTTP 302 Moved Temporarily
-Location: http://localhost:8888/tests/toolkit/components/places/tests/bug_411966/TempRedirectPage.htm
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/PermRedirectPage.htm
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Bug 411966</title>
-  </head>
-  </body>
-    Permanently redirected!
-  </body>
-</html>
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/TempRedirectPage.htm
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Bug 411966</title>
-  </head>
-  </body>
-    Temporarly redirected!
-  </body>
-</html>
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/TempRedirectPage.htm^headers^
+++ /dev/null
@@ -1,2 +0,0 @@
-HTTP 301 Moved Permanently
-Location: http://localhost:8888/tests/toolkit/components/places/tests/bug_411966/PermRedirectPage.htm
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/TypedPage.htm
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <head>
-    <title>Bug 411966</title>
-  </head>
-  </body>
-    Typed in page!
-  </body>
-</html>
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_411966/redirect.js
+++ /dev/null
@@ -1,183 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et: */
-/* 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/. */
-
-var Ci = Components.interfaces;
-var Cc = Components.classes;
-var Cu = Components.utils;
-
-var PlacesUtils = Cu.import("resource://gre/modules/PlacesUtils.jsm").PlacesUtils;
-
-// Get Services.
-var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
-              getService(Ci.nsINavHistoryService);
-ok(histsvc != null, "Could not get History Service");
-var bhist = histsvc.QueryInterface(Ci.nsIBrowserHistory);
-ok(bhist != null, "Could not get Browser History Service");
-var ios = Cc["@mozilla.org/network/io-service;1"].
-          getService(Components.interfaces.nsIIOService);
-ok(ios != null, "Could not get IO Service");
-var storage = Cc["@mozilla.org/storage/service;1"].
-              getService(Ci.mozIStorageService);
-ok(storage != null, "Could not get Storage Service");
-
-// Get database connection.
-var mDBConn = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
-ok(mDBConn != null, "Could not get Database Connection");
-
-function uri(URIString) {
-  return ios.newURI(URIString, null, null);
-}
-
-var typedURI = uri("http://localhost:8888/tests/toolkit/components/places/tests/mochitest/bug_411966/TypedPage.htm");
-var clickedLinkURI = uri("http://localhost:8888/tests/toolkit/components/places/tests/mochitest/bug_411966/ClickedPage.htm");
-var temporaryRedirectURI = uri("http://localhost:8888/tests/toolkit/components/places/tests/mochitest/bug_411966/TempRedirectPage.htm");
-var permanentRedirectURI = uri("http://localhost:8888/tests/toolkit/components/places/tests/mochitest/bug_411966/PermRedirectPage.htm");
-
-// Stream Listener
-function StreamListener(aChannel, aCallbackFunc) {
-  this.mChannel = aChannel;
-  this.mCallbackFunc = aCallbackFunc;
-}
-
-StreamListener.prototype = {
-  mData: "",
-  mChannel: null,
-
-  // nsIStreamListener
-  onStartRequest: function (aRequest, aContext) {
-    this.mData = "";
-  },
-
-  onDataAvailable: function (aRequest, aContext, aStream, aSourceOffset, aLength) {
-    // We actually don't need received data
-    var scriptableInputStream =
-      Components.classes["@mozilla.org/scriptableinputstream;1"]
-                .createInstance(Components.interfaces.nsIScriptableInputStream);
-    scriptableInputStream.init(aStream);
-
-    this.mData += scriptableInputStream.read(aLength);
-  },
-
-  onStopRequest: function (aRequest, aContext, aStatus) {
-    if (Components.isSuccessCode(aStatus))
-      this.mCallbackFunc(this.mData);
-    else
-      throw("Could not get page.");
-
-    this.mChannel = null;
-  },
-
-  // nsIChannelEventSink
-  asyncOnChannelRedirect: function (aOldChannel, aNewChannel, aFlags, callback) {
-    // If redirecting, store the new channel
-    this.mChannel = aNewChannel;
-    callback.onRedirectVerifyCallback(Components.results.NS_OK);
-  },
-
-  // nsIInterfaceRequestor
-  getInterface: function (aIID) {
-    try {
-      return this.QueryInterface(aIID);
-    } catch (e) {
-      throw Components.results.NS_NOINTERFACE;
-    }
-  },
-
-  // nsIProgressEventSink (not implementing will cause annoying exceptions)
-  onProgress : function (aRequest, aContext, aProgress, aProgressMax) { },
-  onStatus : function (aRequest, aContext, aStatus, aStatusArg) { },
-
-  // nsIHttpEventSink (not implementing will cause annoying exceptions)
-  onRedirect : function (aOldChannel, aNewChannel) { },
-
-  // we are faking an XPCOM interface, so we need to implement QI
-  QueryInterface : function(aIID) {
-    if (aIID.equals(Components.interfaces.nsISupports) ||
-        aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
-        aIID.equals(Components.interfaces.nsIChannelEventSink) ||
-        aIID.equals(Components.interfaces.nsIProgressEventSink) ||
-        aIID.equals(Components.interfaces.nsIHttpEventSink) ||
-        aIID.equals(Components.interfaces.nsIStreamListener))
-      return this;
-
-    throw Components.results.NS_NOINTERFACE;
-  }
-};
-
-// Check Callback.
-function checkDB(data){
-  var referrer = this.mChannel.QueryInterface(Ci.nsIHttpChannel).referrer;
-
-  addVisits(
-    {uri: this.mChannel.URI,
-      transition: Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT,
-      referrer: referrer},
-    function() {
-      // Get all pages visited from the original typed one
-      var sql = `SELECT url FROM moz_historyvisits
-                 JOIN moz_places h ON h.id = place_id
-                 WHERE from_visit IN
-                    (SELECT v.id FROM moz_historyvisits v
-                    JOIN moz_places p ON p.id = v.place_id
-                    WHERE p.url = ?1)`;
-      var stmt = mDBConn.createStatement(sql);
-      stmt.bindByIndex(0, typedURI.spec);
-
-      var empty = true;
-      while (stmt.executeStep()) {
-        empty = false;
-        var visitedURI = stmt.getUTF8String(0);
-        // Check that redirect from_visit is not from the original typed one
-        ok(visitedURI == clickedLinkURI.spec, "Got wrong referrer for " + visitedURI);
-      }
-      // Ensure that we got some result
-      ok(!empty, "empty table");
-
-      SimpleTest.finish();
-    }
-  );
-}
-
-// Asynchronously adds visits to a page, invoking a callback function when done.
-function addVisits(aPlaceInfo, aCallback) {
-  var places = [];
-  if (aPlaceInfo instanceof Ci.nsIURI) {
-    places.push({ uri: aPlaceInfo });
-  } else if (Array.isArray(aPlaceInfo)) {
-    places = places.concat(aPlaceInfo);
-  } else {
-    places.push(aPlaceInfo);
-  }
-
-  // Create mozIVisitInfo for each entry.
-  var now = Date.now();
-  for (var i = 0; i < places.length; i++) {
-    if (!places[i].title) {
-      places[i].title = "test visit for " + places[i].uri.spec;
-    }
-    places[i].visits = [{
-      transitionType: places[i].transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK
-                                                         : places[i].transition,
-      visitDate: places[i].visitDate || (now++) * 1000,
-      referrerURI: places[i].referrer
-    }];
-  }
-
-  PlacesUtils.asyncHistory.updatePlaces(
-    places,
-    {
-      handleError: function AAV_handleError() {
-        throw("Unexpected error in adding visit.");
-      },
-      handleResult: function () {},
-      handleCompletion: function UP_handleCompletion() {
-        if (aCallback)
-          aCallback();
-      }
-    }
-  );
-}
-
--- a/toolkit/components/places/tests/moz.build
+++ b/toolkit/components/places/tests/moz.build
@@ -62,26 +62,16 @@ TEST_HARNESS_FILES.testing.mochitest.tes
     'chrome/rss_as_html.rss^headers^',
     'chrome/sample_feed.atom',
 ]
 
 TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests += [
     'bug94514-postpage.html',
 ]
 
-TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests.mochitest.bug_411966 += [
-    'mochitest/bug_411966/ClickedPage.htm',
-    'mochitest/bug_411966/ClickedPage.htm^headers^',
-    'mochitest/bug_411966/PermRedirectPage.htm',
-    'mochitest/bug_411966/redirect.js',
-    'mochitest/bug_411966/TempRedirectPage.htm',
-    'mochitest/bug_411966/TempRedirectPage.htm^headers^',
-    'mochitest/bug_411966/TypedPage.htm',
-]
-
 TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests.mochitest.bug_461710 += [
     'mochitest/bug_461710/iframe.html',
     'mochitest/bug_461710/link_page-2.html',
     'mochitest/bug_461710/link_page-3.html',
     'mochitest/bug_461710/link_page.html',
     'mochitest/bug_461710/visited_page.html',
 ]
 
deleted file mode 100644
--- a/toolkit/components/places/tests/test_bug_411966.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-  <!--
-    https://bugzilla.mozilla.org/show_bug.cgi?id=411966
-  -->
-  <head>
-    <title>Test for Bug 411966</title>
-    <script type="text/javascript" src="http://mochi.test:8888/tests/SimpleTest/SimpleTest.js"></script>
-    <script type="text/javascript" src="http://mochi.test:8888/tests/toolkit/components/places/tests/mochitest/bug_411966/redirect.js"></script>
-    <link rel="stylesheet" type="text/css" href="http://mochi.test:8888/tests/SimpleTest/test.css" />
-  </head>
-  <body>
-    <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=411966">
-      Mozilla Bug 411966</a>
-    <p id="display"></p>
-    <div id="content" style="display: none">
-      <iframe id="iframe"></iframe>
-    </div>
-    <pre id="test">
-      <script class="testbody" type="text/javascript">
-
-      Cu.import("resource://gre/modules/NetUtil.jsm");
-
-      /** Test for Bug 411966 **/
-      addVisits(typedURI, function() {
-        histsvc.markPageAsTyped(typedURI);
-
-        var clickedLinkChannel = NetUtil.newChannel({
-                                   uri: clickedLinkURI,
-                                   loadUsingSystemPrincipal: true
-                                });
-        clickedLinkChannel.QueryInterface(Ci.nsIHttpChannel).referrer = typedURI;
-        var listener = new StreamListener(clickedLinkChannel, checkDB);
-        clickedLinkChannel.notificationCallbacks = listener;
-        clickedLinkChannel.asyncOpen2(listener);
-      });
-
-      SimpleTest.waitForExplicitFinish();
-
-     </script>
-   </pre>
- </body>
-</html>