Bug 1540170 - release assert if something tries to start the history service before profile startup, r=mak
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 26 Mar 2019 15:17:42 +0000
changeset 468196 c36ad62407f38e7d8c2bcba0250dfceb5c02d728
parent 468195 c2298e57e803a6bd901d6db4f8155202aec220eb
child 468197 c54533bd0e045f72faa9e355eb4c01f02fe0d25a
push id82442
push userbtara@mozilla.com
push dateFri, 05 Apr 2019 16:22:06 +0000
treeherderautoland@5f3cae719797 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1540170
milestone68.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 1540170 - release assert if something tries to start the history service before profile startup, r=mak Differential Revision: https://phabricator.services.mozilla.com/D24910
parser/xml/test/unit/test_sanitizer.js
toolkit/components/places/History.cpp
--- a/parser/xml/test/unit/test_sanitizer.js
+++ b/parser/xml/test/unit/test_sanitizer.js
@@ -1,13 +1,34 @@
+const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
+if (AppConstants.platform != "android") {
+  // We load HTML documents, which try to track link state, which requires
+  // the history service, which requires a profile.
+  do_get_profile();
+}
+
 function run_test() {
   // vectors by the html5security project (https://code.google.com/p/html5security/ & Creative Commons 3.0 BY), see CC-BY-LICENSE for the full license
   load("results.js"); // gives us a `vectors' array
   /* import-globals-from ./results.js */
 
+  if (AppConstants.platform != "android") {
+    // xpcshell tests are weird. They fake shutdown after the test finishes. This upsets this test
+    // because it will try to create the history service to check for visited state on the links
+    // we're parsing.
+    // Creating the history service midway through shutdown breaks.
+    // We can't catch this in the history component because we're not *actually* shutting down,
+    // and so the app startup's service's `shuttingDown` bool is false, even though normally that
+    // is set to true *before* profile-change-teardown notifications are fired.
+    // To work around this, just force the history service to be created earlier:
+
+    let {PlacesUtils} = ChromeUtils.import("resource://gre/modules/PlacesUtils.jsm");
+    Assert.ok(PlacesUtils.history.databaseStatus <= 1, "ensure places database is successfully initialized.");
+  }
+
   var ParserUtils =  Cc["@mozilla.org/parserutils;1"].getService(Ci.nsIParserUtils);
   var sanitizeFlags = ParserUtils.SanitizerCidEmbedsOnly | ParserUtils.SanitizerDropForms | ParserUtils.SanitizerDropNonCSSPresentation;
   // flags according to
   // http://mxr.mozilla.org/comm-central/source/mailnews/mime/src/mimemoz2.cpp#2218
   // and default settings
 
 
   for (var item in vectors) {
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -1440,16 +1440,26 @@ void StoreAndNotifyEmbedVisit(VisitData&
 History* History::gService = nullptr;
 
 History::History()
     : mShuttingDown(false),
       mShutdownMutex("History::mShutdownMutex"),
       mObservers(VISIT_OBSERVERS_INITIAL_CACHE_LENGTH),
       mRecentlyVisitedURIs(RECENTLY_VISITED_URIS_SIZE) {
   NS_ASSERTION(!gService, "Ruh-roh!  This service has already been created!");
+  if (XRE_IsParentProcess()) {
+    nsCOMPtr<nsIProperties> dirsvc = services::GetDirectoryService();
+    bool haveProfile = false;
+    MOZ_RELEASE_ASSERT(
+        dirsvc &&
+            NS_SUCCEEDED(
+                dirsvc->Has(NS_APP_USER_PROFILE_50_DIR, &haveProfile)) &&
+            haveProfile,
+        "Can't construct history service if there is no profile.");
+  }
   gService = this;
 
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
   NS_WARNING_ASSERTION(os, "Observer service was not found!");
   if (os) {
     (void)os->AddObserver(this, TOPIC_PLACES_SHUTDOWN, false);
   }
 }