toolkit/components/places/tests/cpp/test_IHistory.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/cpp/test_IHistory.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,634 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "places_test_harness.h"
    1.11 +#include "nsIPrefService.h"
    1.12 +#include "nsIPrefBranch.h"
    1.13 +#include "mozilla/Attributes.h"
    1.14 +
    1.15 +#include "mock_Link.h"
    1.16 +using namespace mozilla;
    1.17 +using namespace mozilla::dom;
    1.18 +
    1.19 +/**
    1.20 + * This file tests the IHistory interface.
    1.21 + */
    1.22 +
    1.23 +////////////////////////////////////////////////////////////////////////////////
    1.24 +//// Helper Methods
    1.25 +
    1.26 +void
    1.27 +expect_visit(nsLinkState aState)
    1.28 +{
    1.29 +  do_check_true(aState == eLinkState_Visited);
    1.30 +}
    1.31 +
    1.32 +void
    1.33 +expect_no_visit(nsLinkState aState)
    1.34 +{
    1.35 +  do_check_true(aState == eLinkState_Unvisited);
    1.36 +}
    1.37 +
    1.38 +already_AddRefed<nsIURI>
    1.39 +new_test_uri()
    1.40 +{
    1.41 +  // Create a unique spec.
    1.42 +  static int32_t specNumber = 0;
    1.43 +  nsAutoCString spec = NS_LITERAL_CSTRING("http://mozilla.org/");
    1.44 +  spec.AppendInt(specNumber++);
    1.45 +
    1.46 +  // Create the URI for the spec.
    1.47 +  nsCOMPtr<nsIURI> testURI;
    1.48 +  nsresult rv = NS_NewURI(getter_AddRefs(testURI), spec);
    1.49 +  do_check_success(rv);
    1.50 +  return testURI.forget();
    1.51 +}
    1.52 +
    1.53 +class VisitURIObserver MOZ_FINAL : public nsIObserver
    1.54 +{
    1.55 +public:
    1.56 +  NS_DECL_ISUPPORTS
    1.57 +
    1.58 +  VisitURIObserver(int aExpectedVisits = 1) :
    1.59 +    mVisits(0),
    1.60 +    mExpectedVisits(aExpectedVisits)
    1.61 +  {
    1.62 +    nsCOMPtr<nsIObserverService> observerService =
    1.63 +      do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
    1.64 +    do_check_true(observerService);
    1.65 +    (void)observerService->AddObserver(this,
    1.66 +                                       "uri-visit-saved",
    1.67 +                                       false);
    1.68 +  }
    1.69 +
    1.70 +  void WaitForNotification()
    1.71 +  {
    1.72 +    while (mVisits < mExpectedVisits) {
    1.73 +      (void)NS_ProcessNextEvent();
    1.74 +    }
    1.75 +  }
    1.76 +
    1.77 +  NS_IMETHOD Observe(nsISupports* aSubject,
    1.78 +                     const char* aTopic,
    1.79 +                     const char16_t* aData)
    1.80 +  {
    1.81 +    mVisits++;
    1.82 +
    1.83 +    if (mVisits == mExpectedVisits) {
    1.84 +      nsCOMPtr<nsIObserverService> observerService =
    1.85 +        do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
    1.86 +      (void)observerService->RemoveObserver(this, "uri-visit-saved");
    1.87 +    }
    1.88 +
    1.89 +    return NS_OK;
    1.90 +  }
    1.91 +private:
    1.92 +  int mVisits;
    1.93 +  int mExpectedVisits;
    1.94 +};
    1.95 +NS_IMPL_ISUPPORTS(
    1.96 +  VisitURIObserver,
    1.97 +  nsIObserver
    1.98 +)
    1.99 +
   1.100 +////////////////////////////////////////////////////////////////////////////////
   1.101 +//// Test Functions
   1.102 +
   1.103 +void
   1.104 +test_set_places_enabled()
   1.105 +{
   1.106 +  // Ensure places is enabled for everyone.
   1.107 +  nsresult rv;
   1.108 +  nsCOMPtr<nsIPrefBranch> prefBranch =
   1.109 +    do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   1.110 +  do_check_success(rv);
   1.111 +
   1.112 +  rv = prefBranch->SetBoolPref("places.history.enabled", true);
   1.113 +  do_check_success(rv);
   1.114 +
   1.115 +  // Run the next test.
   1.116 +  run_next_test();
   1.117 +}
   1.118 +
   1.119 +
   1.120 +void
   1.121 +test_wait_checkpoint()
   1.122 +{
   1.123 +  // This "fake" test is here to wait for the initial WAL checkpoint we force
   1.124 +  // after creating the database schema, since that may happen at any time,
   1.125 +  // and cause concurrent readers to access an older checkpoint.
   1.126 +  nsCOMPtr<mozIStorageConnection> db = do_get_db();
   1.127 +  nsCOMPtr<mozIStorageAsyncStatement> stmt;
   1.128 +  db->CreateAsyncStatement(NS_LITERAL_CSTRING("SELECT 1"),
   1.129 +                           getter_AddRefs(stmt));
   1.130 +  nsRefPtr<AsyncStatementSpinner> spinner = new AsyncStatementSpinner();
   1.131 +  nsCOMPtr<mozIStoragePendingStatement> pending;
   1.132 +  (void)stmt->ExecuteAsync(spinner, getter_AddRefs(pending));
   1.133 +  spinner->SpinUntilCompleted();
   1.134 +
   1.135 +  // Run the next test.
   1.136 +  run_next_test();
   1.137 +}
   1.138 +
   1.139 +// These variables are shared between part 1 and part 2 of the test.  Part 2
   1.140 +// sets the nsCOMPtr's to nullptr, freeing the reference.
   1.141 +namespace test_unvisited_does_not_notify {
   1.142 +  nsCOMPtr<nsIURI> testURI;
   1.143 +  nsRefPtr<Link> testLink;
   1.144 +}
   1.145 +void
   1.146 +test_unvisited_does_not_notify_part1()
   1.147 +{
   1.148 +  using namespace test_unvisited_does_not_notify;
   1.149 +
   1.150 +  // This test is done in two parts.  The first part registers for a URI that
   1.151 +  // should not be visited.  We then run another test that will also do a
   1.152 +  // lookup and will be notified.  Since requests are answered in the order they
   1.153 +  // are requested (at least as long as the same URI isn't asked for later), we
   1.154 +  // will know that the Link was not notified.
   1.155 +
   1.156 +  // First, we need a test URI.
   1.157 +  testURI = new_test_uri();
   1.158 +
   1.159 +  // Create our test Link.
   1.160 +  testLink = new mock_Link(expect_no_visit);
   1.161 +
   1.162 +  // Now, register our Link to be notified.
   1.163 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.164 +  nsresult rv = history->RegisterVisitedCallback(testURI, testLink);
   1.165 +  do_check_success(rv);
   1.166 +
   1.167 +  // Run the next test.
   1.168 +  run_next_test();
   1.169 +}
   1.170 +
   1.171 +void
   1.172 +test_visited_notifies()
   1.173 +{
   1.174 +  // First, we add our test URI to history.
   1.175 +  nsCOMPtr<nsIURI> testURI = new_test_uri();
   1.176 +  addURI(testURI);
   1.177 +
   1.178 +  // Create our test Link.  The callback function will release the reference we
   1.179 +  // have on the Link.
   1.180 +  nsRefPtr<Link> link = new mock_Link(expect_visit);
   1.181 +
   1.182 +  // Now, register our Link to be notified.
   1.183 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.184 +  nsresult rv = history->RegisterVisitedCallback(testURI, link);
   1.185 +  do_check_success(rv);
   1.186 +
   1.187 +  // Note: test will continue upon notification.
   1.188 +}
   1.189 +
   1.190 +void
   1.191 +test_unvisited_does_not_notify_part2()
   1.192 +{
   1.193 +  using namespace test_unvisited_does_not_notify;
   1.194 +
   1.195 +  // We would have had a failure at this point had the content node been told it
   1.196 +  // was visited.  Therefore, it is safe to unregister our content node.
   1.197 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.198 +  nsresult rv = history->UnregisterVisitedCallback(testURI, testLink);
   1.199 +  do_check_success(rv);
   1.200 +
   1.201 +  // Clear the stored variables now.
   1.202 +  testURI = nullptr;
   1.203 +  testLink = nullptr;
   1.204 +
   1.205 +  // Run the next test.
   1.206 +  run_next_test();
   1.207 +}
   1.208 +
   1.209 +void
   1.210 +test_same_uri_notifies_both()
   1.211 +{
   1.212 +  // First, we add our test URI to history.
   1.213 +  nsCOMPtr<nsIURI> testURI = new_test_uri();
   1.214 +  addURI(testURI);
   1.215 +
   1.216 +  // Create our two test Links.  The callback function will release the
   1.217 +  // reference we have on the Links.  Only the second Link should run the next
   1.218 +  // test!
   1.219 +  nsRefPtr<Link> link1 = new mock_Link(expect_visit, false);
   1.220 +  nsRefPtr<Link> link2 = new mock_Link(expect_visit);
   1.221 +
   1.222 +  // Now, register our Link to be notified.
   1.223 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.224 +  nsresult rv = history->RegisterVisitedCallback(testURI, link1);
   1.225 +  do_check_success(rv);
   1.226 +  rv = history->RegisterVisitedCallback(testURI, link2);
   1.227 +  do_check_success(rv);
   1.228 +
   1.229 +  // Note: test will continue upon notification.
   1.230 +}
   1.231 +
   1.232 +void
   1.233 +test_unregistered_visited_does_not_notify()
   1.234 +{
   1.235 +  // This test must have a test that has a successful notification after it.
   1.236 +  // The Link would have been notified by now if we were buggy and notified
   1.237 +  // unregistered Links (due to request serialization).
   1.238 +
   1.239 +  nsCOMPtr<nsIURI> testURI = new_test_uri();
   1.240 +  nsRefPtr<Link> link = new mock_Link(expect_no_visit);
   1.241 +
   1.242 +  // Now, register our Link to be notified.
   1.243 +  nsCOMPtr<IHistory> history(do_get_IHistory());
   1.244 +  nsresult rv = history->RegisterVisitedCallback(testURI, link);
   1.245 +  do_check_success(rv);
   1.246 +
   1.247 +  // Unregister the Link.
   1.248 +  rv = history->UnregisterVisitedCallback(testURI, link);
   1.249 +  do_check_success(rv);
   1.250 +
   1.251 +  // And finally add a visit for the URI.
   1.252 +  addURI(testURI);
   1.253 +
   1.254 +  // If history tries to notify us, we'll either crash because the Link will
   1.255 +  // have been deleted (we are the only thing holding a reference to it), or our
   1.256 +  // expect_no_visit call back will produce a failure.  Either way, the test
   1.257 +  // will be reported as a failure.
   1.258 +
   1.259 +  // Run the next test.
   1.260 +  run_next_test();
   1.261 +}
   1.262 +
   1.263 +void
   1.264 +test_new_visit_notifies_waiting_Link()
   1.265 +{
   1.266 +  // Create our test Link.  The callback function will release the reference we
   1.267 +  // have on the link.
   1.268 +  nsRefPtr<Link> link = new mock_Link(expect_visit);
   1.269 +
   1.270 +  // Now, register our content node to be notified.
   1.271 +  nsCOMPtr<nsIURI> testURI = new_test_uri();
   1.272 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.273 +  nsresult rv = history->RegisterVisitedCallback(testURI, link);
   1.274 +  do_check_success(rv);
   1.275 +
   1.276 +  // Add ourselves to history.
   1.277 +  addURI(testURI);
   1.278 +
   1.279 +  // Note: test will continue upon notification.
   1.280 +}
   1.281 +
   1.282 +void
   1.283 +test_RegisterVisitedCallback_returns_before_notifying()
   1.284 +{
   1.285 +  // Add a URI so that it's already in history.
   1.286 +  nsCOMPtr<nsIURI> testURI = new_test_uri();
   1.287 +  addURI(testURI);
   1.288 +
   1.289 +  // Create our test Link.
   1.290 +  nsRefPtr<Link> link = new mock_Link(expect_no_visit);
   1.291 +
   1.292 +  // Now, register our content node to be notified.  It should not be notified.
   1.293 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.294 +  nsresult rv = history->RegisterVisitedCallback(testURI, link);
   1.295 +  do_check_success(rv);
   1.296 +
   1.297 +  // Remove ourselves as an observer.  We would have failed if we had been
   1.298 +  // notified.
   1.299 +  rv = history->UnregisterVisitedCallback(testURI, link);
   1.300 +  do_check_success(rv);
   1.301 +
   1.302 +  run_next_test();
   1.303 +}
   1.304 +
   1.305 +namespace test_observer_topic_dispatched_helpers {
   1.306 +  #define URI_VISITED "visited"
   1.307 +  #define URI_NOT_VISITED "not visited"
   1.308 +  #define URI_VISITED_RESOLUTION_TOPIC "visited-status-resolution"
   1.309 +  class statusObserver MOZ_FINAL : public nsIObserver
   1.310 +  {
   1.311 +  public:
   1.312 +    NS_DECL_ISUPPORTS
   1.313 +
   1.314 +    statusObserver(nsIURI* aURI,
   1.315 +                   const bool aExpectVisit,
   1.316 +                   bool& _notified)
   1.317 +    : mURI(aURI)
   1.318 +    , mExpectVisit(aExpectVisit)
   1.319 +    , mNotified(_notified)
   1.320 +    {
   1.321 +      nsCOMPtr<nsIObserverService> observerService =
   1.322 +        do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
   1.323 +      do_check_true(observerService);
   1.324 +      (void)observerService->AddObserver(this,
   1.325 +                                         URI_VISITED_RESOLUTION_TOPIC,
   1.326 +                                         false);
   1.327 +    }
   1.328 +
   1.329 +    NS_IMETHOD Observe(nsISupports* aSubject,
   1.330 +                       const char* aTopic,
   1.331 +                       const char16_t* aData)
   1.332 +    {
   1.333 +      // Make sure we got notified of the right topic.
   1.334 +      do_check_false(strcmp(aTopic, URI_VISITED_RESOLUTION_TOPIC));
   1.335 +
   1.336 +      // If this isn't for our URI, do not do anything.
   1.337 +      nsCOMPtr<nsIURI> notifiedURI = do_QueryInterface(aSubject);
   1.338 +      do_check_true(notifiedURI);
   1.339 +
   1.340 +      bool isOurURI;
   1.341 +      nsresult rv = notifiedURI->Equals(mURI, &isOurURI);
   1.342 +      do_check_success(rv);
   1.343 +      if (!isOurURI) {
   1.344 +        return NS_OK;
   1.345 +      }
   1.346 +
   1.347 +      // Check that we have either the visited or not visited string.
   1.348 +      bool visited = !!NS_LITERAL_STRING(URI_VISITED).Equals(aData);
   1.349 +      bool notVisited = !!NS_LITERAL_STRING(URI_NOT_VISITED).Equals(aData);
   1.350 +      do_check_true(visited || notVisited);
   1.351 +
   1.352 +      // Check to make sure we got the state we expected.
   1.353 +      do_check_eq(visited, mExpectVisit);
   1.354 +
   1.355 +      // Indicate that we've been notified.
   1.356 +      mNotified = true;
   1.357 +
   1.358 +      // Remove ourselves as an observer.
   1.359 +      nsCOMPtr<nsIObserverService> observerService =
   1.360 +        do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
   1.361 +      (void)observerService->RemoveObserver(this,
   1.362 +                                            URI_VISITED_RESOLUTION_TOPIC);
   1.363 +      return NS_OK;
   1.364 +    }
   1.365 +  private:
   1.366 +    nsCOMPtr<nsIURI> mURI;
   1.367 +    const bool mExpectVisit;
   1.368 +    bool& mNotified;
   1.369 +  };
   1.370 +  NS_IMPL_ISUPPORTS(
   1.371 +    statusObserver,
   1.372 +    nsIObserver
   1.373 +  )
   1.374 +}
   1.375 +void
   1.376 +test_observer_topic_dispatched()
   1.377 +{
   1.378 +  using namespace test_observer_topic_dispatched_helpers;
   1.379 +
   1.380 +  // Create two URIs, making sure only one is in history.
   1.381 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.382 +  nsCOMPtr<nsIURI> notVisitedURI = new_test_uri();
   1.383 +  bool urisEqual;
   1.384 +  nsresult rv = visitedURI->Equals(notVisitedURI, &urisEqual);
   1.385 +  do_check_success(rv);
   1.386 +  do_check_false(urisEqual);
   1.387 +  addURI(visitedURI);
   1.388 +
   1.389 +  // Need two Link objects as well - one for each URI.
   1.390 +  nsRefPtr<Link> visitedLink = new mock_Link(expect_visit, false);
   1.391 +  nsRefPtr<Link> visitedLinkCopy = visitedLink;
   1.392 +  nsRefPtr<Link> notVisitedLink = new mock_Link(expect_no_visit);
   1.393 +
   1.394 +  // Add the right observers for the URIs to check results.
   1.395 +  bool visitedNotified = false;
   1.396 +  nsCOMPtr<nsIObserver> visitedObs =
   1.397 +    new statusObserver(visitedURI, true, visitedNotified);
   1.398 +  bool notVisitedNotified = false;
   1.399 +  nsCOMPtr<nsIObserver> unvisitedObs =
   1.400 +    new statusObserver(notVisitedURI, false, notVisitedNotified);
   1.401 +
   1.402 +  // Register our Links to be notified.
   1.403 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.404 +  rv = history->RegisterVisitedCallback(visitedURI, visitedLink);
   1.405 +  do_check_success(rv);
   1.406 +  rv = history->RegisterVisitedCallback(notVisitedURI, notVisitedLink);
   1.407 +  do_check_success(rv);
   1.408 +
   1.409 +  // Spin the event loop as long as we have not been properly notified.
   1.410 +  while (!visitedNotified || !notVisitedNotified) {
   1.411 +    (void)NS_ProcessNextEvent();
   1.412 +  }
   1.413 +
   1.414 +  // Unregister our observer that would not have been released.
   1.415 +  rv = history->UnregisterVisitedCallback(notVisitedURI, notVisitedLink);
   1.416 +  do_check_success(rv);
   1.417 +
   1.418 +  run_next_test();
   1.419 +}
   1.420 +
   1.421 +void
   1.422 +test_visituri_inserts()
   1.423 +{
   1.424 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.425 +  nsCOMPtr<nsIURI> lastURI = new_test_uri();
   1.426 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.427 +
   1.428 +  history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
   1.429 +
   1.430 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
   1.431 +  finisher->WaitForNotification();
   1.432 +
   1.433 +  PlaceRecord place;
   1.434 +  do_get_place(visitedURI, place);
   1.435 +
   1.436 +  do_check_true(place.id > 0);
   1.437 +  do_check_false(place.hidden);
   1.438 +  do_check_false(place.typed);
   1.439 +  do_check_eq(place.visitCount, 1);
   1.440 +
   1.441 +  run_next_test();
   1.442 +}
   1.443 +
   1.444 +void
   1.445 +test_visituri_updates()
   1.446 +{
   1.447 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.448 +  nsCOMPtr<nsIURI> lastURI = new_test_uri();
   1.449 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.450 +  nsRefPtr<VisitURIObserver> finisher;
   1.451 +
   1.452 +  history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
   1.453 +  finisher = new VisitURIObserver();
   1.454 +  finisher->WaitForNotification();
   1.455 +
   1.456 +  history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
   1.457 +  finisher = new VisitURIObserver();
   1.458 +  finisher->WaitForNotification();
   1.459 +
   1.460 +  PlaceRecord place;
   1.461 +  do_get_place(visitedURI, place);
   1.462 +
   1.463 +  do_check_eq(place.visitCount, 2);
   1.464 +
   1.465 +  run_next_test();
   1.466 +}
   1.467 +
   1.468 +void
   1.469 +test_visituri_preserves_shown_and_typed()
   1.470 +{
   1.471 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.472 +  nsCOMPtr<nsIURI> lastURI = new_test_uri();
   1.473 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.474 +
   1.475 +  history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
   1.476 +  // this simulates the uri visit happening in a frame.  Normally frame
   1.477 +  // transitions would be hidden unless it was previously loaded top-level
   1.478 +  history->VisitURI(visitedURI, lastURI, 0);
   1.479 +
   1.480 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver(2);
   1.481 +  finisher->WaitForNotification();
   1.482 +
   1.483 +  PlaceRecord place;
   1.484 +  do_get_place(visitedURI, place);
   1.485 +  do_check_false(place.hidden);
   1.486 +
   1.487 +  run_next_test();
   1.488 +}
   1.489 +
   1.490 +void
   1.491 +test_visituri_creates_visit()
   1.492 +{
   1.493 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.494 +  nsCOMPtr<nsIURI> lastURI = new_test_uri();
   1.495 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.496 +
   1.497 +  history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
   1.498 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
   1.499 +  finisher->WaitForNotification();
   1.500 +
   1.501 +  PlaceRecord place;
   1.502 +  VisitRecord visit;
   1.503 +  do_get_place(visitedURI, place);
   1.504 +  do_get_lastVisit(place.id, visit);
   1.505 +
   1.506 +  do_check_true(visit.id > 0);
   1.507 +  do_check_eq(visit.lastVisitId, 0);
   1.508 +  do_check_eq(visit.transitionType, nsINavHistoryService::TRANSITION_LINK);
   1.509 +
   1.510 +  run_next_test();
   1.511 +}
   1.512 +
   1.513 +void
   1.514 +test_visituri_transition_typed()
   1.515 +{
   1.516 +  nsCOMPtr<nsINavHistoryService> navHistory = do_get_NavHistory();
   1.517 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.518 +  nsCOMPtr<nsIURI> lastURI = new_test_uri();
   1.519 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.520 +
   1.521 +  navHistory->MarkPageAsTyped(visitedURI);
   1.522 +  history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
   1.523 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
   1.524 +  finisher->WaitForNotification();
   1.525 +
   1.526 +  PlaceRecord place;
   1.527 +  VisitRecord visit;
   1.528 +  do_get_place(visitedURI, place);
   1.529 +  do_get_lastVisit(place.id, visit);
   1.530 +
   1.531 +  do_check_true(visit.transitionType == nsINavHistoryService::TRANSITION_TYPED);
   1.532 +
   1.533 +  run_next_test();
   1.534 +}
   1.535 +
   1.536 +void
   1.537 +test_visituri_transition_embed()
   1.538 +{
   1.539 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.540 +  nsCOMPtr<nsIURI> lastURI = new_test_uri();
   1.541 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.542 +
   1.543 +  history->VisitURI(visitedURI, lastURI, 0);
   1.544 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
   1.545 +  finisher->WaitForNotification();
   1.546 +
   1.547 +  PlaceRecord place;
   1.548 +  VisitRecord visit;
   1.549 +  do_get_place(visitedURI, place);
   1.550 +  do_get_lastVisit(place.id, visit);
   1.551 +
   1.552 +  do_check_eq(place.id, 0);
   1.553 +  do_check_eq(visit.id, 0);
   1.554 +
   1.555 +  run_next_test();
   1.556 +}
   1.557 +
   1.558 +void
   1.559 +test_new_visit_adds_place_guid()
   1.560 +{
   1.561 +  // First, add a visit and wait.  This will also add a place.
   1.562 +  nsCOMPtr<nsIURI> visitedURI = new_test_uri();
   1.563 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.564 +  nsresult rv = history->VisitURI(visitedURI, nullptr,
   1.565 +                                  mozilla::IHistory::TOP_LEVEL);
   1.566 +  do_check_success(rv);
   1.567 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
   1.568 +  finisher->WaitForNotification();
   1.569 +
   1.570 +  // Check that we have a guid for our visit.
   1.571 +  PlaceRecord place;
   1.572 +  do_get_place(visitedURI, place);
   1.573 +  do_check_eq(place.visitCount, 1);
   1.574 +  do_check_eq(place.guid.Length(), 12);
   1.575 +
   1.576 +  run_next_test();
   1.577 +}
   1.578 +
   1.579 +////////////////////////////////////////////////////////////////////////////////
   1.580 +//// IPC-only Tests
   1.581 +
   1.582 +void
   1.583 +test_two_null_links_same_uri()
   1.584 +{
   1.585 +  // Tests that we do not crash when we have had two nullptr Links passed to
   1.586 +  // RegisterVisitedCallback and then the visit occurs (bug 607469).  This only
   1.587 +  // happens in IPC builds.
   1.588 +  nsCOMPtr<nsIURI> testURI = new_test_uri();
   1.589 +
   1.590 +  nsCOMPtr<IHistory> history = do_get_IHistory();
   1.591 +  nsresult rv = history->RegisterVisitedCallback(testURI, nullptr);
   1.592 +  do_check_success(rv);
   1.593 +  rv = history->RegisterVisitedCallback(testURI, nullptr);
   1.594 +  do_check_success(rv);
   1.595 +
   1.596 +  rv = history->VisitURI(testURI, nullptr, mozilla::IHistory::TOP_LEVEL);
   1.597 +  do_check_success(rv);
   1.598 +
   1.599 +  nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
   1.600 +  finisher->WaitForNotification();
   1.601 +
   1.602 +  run_next_test();
   1.603 +}
   1.604 +
   1.605 +////////////////////////////////////////////////////////////////////////////////
   1.606 +//// Test Harness
   1.607 +
   1.608 +/**
   1.609 + * Note: for tests marked "Order Important!", please see the test for details.
   1.610 + */
   1.611 +Test gTests[] = {
   1.612 +  TEST(test_set_places_enabled), // Must come first!
   1.613 +  TEST(test_wait_checkpoint), // Must come second!
   1.614 +  TEST(test_unvisited_does_not_notify_part1), // Order Important!
   1.615 +  TEST(test_visited_notifies),
   1.616 +  TEST(test_unvisited_does_not_notify_part2), // Order Important!
   1.617 +  TEST(test_same_uri_notifies_both),
   1.618 +  TEST(test_unregistered_visited_does_not_notify), // Order Important!
   1.619 +  TEST(test_new_visit_notifies_waiting_Link),
   1.620 +  TEST(test_RegisterVisitedCallback_returns_before_notifying),
   1.621 +  TEST(test_observer_topic_dispatched),
   1.622 +  TEST(test_visituri_inserts),
   1.623 +  TEST(test_visituri_updates),
   1.624 +  TEST(test_visituri_preserves_shown_and_typed),
   1.625 +  TEST(test_visituri_creates_visit),
   1.626 +  TEST(test_visituri_transition_typed),
   1.627 +  TEST(test_visituri_transition_embed),
   1.628 +  TEST(test_new_visit_adds_place_guid),
   1.629 +
   1.630 +  // The rest of these tests are tests that are only run in IPC builds.
   1.631 +  TEST(test_two_null_links_same_uri),
   1.632 +};
   1.633 +
   1.634 +const char* file = __FILE__;
   1.635 +#define TEST_NAME "IHistory"
   1.636 +#define TEST_FILE file
   1.637 +#include "places_test_harness_tail.h"

mercurial