LCOV - code coverage report
Current view: directory - toolkit/components/places/tests/cpp - test_IHistory.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 274 271 98.9 %
Date: 2012-06-02 Functions: 32 31 96.9 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is places test code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "places_test_harness.h"
      41                 : #include "nsIBrowserHistory.h"
      42                 : #include "nsIPrefService.h"
      43                 : #include "nsIPrefBranch.h"
      44                 : 
      45                 : #include "mock_Link.h"
      46                 : using namespace mozilla::dom;
      47                 : 
      48                 : /**
      49                 :  * This file tests the IHistory interface.
      50                 :  */
      51                 : 
      52                 : ////////////////////////////////////////////////////////////////////////////////
      53                 : //// Helper Methods
      54                 : 
      55                 : void
      56               5 : expect_visit(nsLinkState aState)
      57                 : {
      58               5 :   do_check_true(aState == eLinkState_Visited);
      59               5 : }
      60                 : 
      61                 : void
      62               0 : expect_no_visit(nsLinkState aState)
      63                 : {
      64               0 :   do_check_true(aState == eLinkState_Unvisited);
      65               0 : }
      66                 : 
      67                 : already_AddRefed<nsIURI>
      68              22 : new_test_uri()
      69                 : {
      70                 :   // Create a unique spec.
      71                 :   static PRInt32 specNumber = 0;
      72              44 :   nsCAutoString spec = NS_LITERAL_CSTRING("http://mozilla.org/");
      73              22 :   spec.AppendInt(specNumber++);
      74                 : 
      75                 :   // Create the URI for the spec.
      76              44 :   nsCOMPtr<nsIURI> testURI;
      77              22 :   nsresult rv = NS_NewURI(getter_AddRefs(testURI), spec);
      78              22 :   do_check_success(rv);
      79              22 :   return testURI.forget();
      80                 : }
      81                 : 
      82                 : class VisitURIObserver : public nsIObserver
      83                 : {
      84                 : public:
      85                 :   NS_DECL_ISUPPORTS
      86                 : 
      87               9 :   VisitURIObserver(int aExpectedVisits = 1) :
      88                 :     mVisits(0),
      89               9 :     mExpectedVisits(aExpectedVisits)
      90                 :   {
      91                 :     nsCOMPtr<nsIObserverService> observerService =
      92              18 :       do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
      93               9 :     do_check_true(observerService);
      94               9 :     (void)observerService->AddObserver(this,
      95                 :                                        "uri-visit-saved",
      96               9 :                                        false);
      97               9 :   }
      98                 : 
      99               9 :   void WaitForNotification()
     100                 :   {
     101              32 :     while (mVisits < mExpectedVisits) {
     102              14 :       (void)NS_ProcessNextEvent();
     103                 :     }
     104               9 :   }
     105                 : 
     106              10 :   NS_IMETHOD Observe(nsISupports* aSubject,
     107                 :                      const char* aTopic,
     108                 :                      const PRUnichar* aData)
     109                 :   {
     110              10 :     mVisits++;
     111                 : 
     112              10 :     if (mVisits == mExpectedVisits) {
     113                 :       nsCOMPtr<nsIObserverService> observerService =
     114              18 :         do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
     115               9 :       (void)observerService->RemoveObserver(this, "uri-visit-saved");
     116                 :     }
     117                 : 
     118              10 :     return NS_OK;
     119                 :   }
     120                 : private:
     121                 :   int mVisits;
     122                 :   int mExpectedVisits;
     123                 : };
     124             130 : NS_IMPL_ISUPPORTS1(
     125                 :   VisitURIObserver,
     126                 :   nsIObserver
     127                 : )
     128                 : 
     129                 : ////////////////////////////////////////////////////////////////////////////////
     130                 : //// Test Functions
     131                 : 
     132                 : void
     133               1 : test_set_places_enabled()
     134                 : {
     135                 :   // Ensure places is enabled for everyone.
     136                 :   nsresult rv;
     137                 :   nsCOMPtr<nsIPrefBranch> prefBranch =
     138               2 :     do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
     139               1 :   do_check_success(rv);
     140                 : 
     141               1 :   rv = prefBranch->SetBoolPref("places.history.enabled", true);
     142               1 :   do_check_success(rv);
     143                 : 
     144                 :   // Run the next test.
     145               1 :   run_next_test();
     146               1 : }
     147                 : 
     148                 : // These variables are shared between part 1 and part 2 of the test.  Part 2
     149                 : // sets the nsCOMPtr's to nsnull, freeing the reference.
     150                 : namespace test_unvisited_does_not_notify {
     151               1 :   nsCOMPtr<nsIURI> testURI;
     152               1 :   nsRefPtr<Link> testLink;
     153                 : }
     154                 : void
     155               1 : test_unvisited_does_not_notify_part1()
     156                 : {
     157                 :   using namespace test_unvisited_does_not_notify;
     158                 : 
     159                 :   // This test is done in two parts.  The first part registers for a URI that
     160                 :   // should not be visited.  We then run another test that will also do a
     161                 :   // lookup and will be notified.  Since requests are answered in the order they
     162                 :   // are requested (at least as long as the same URI isn't asked for later), we
     163                 :   // will know that the Link was not notified.
     164                 : 
     165                 :   // First, we need a test URI.
     166               1 :   testURI = new_test_uri();
     167                 : 
     168                 :   // Create our test Link.
     169               1 :   testLink = new mock_Link(expect_no_visit);
     170                 : 
     171                 :   // Now, register our Link to be notified.
     172               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     173               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, testLink);
     174               1 :   do_check_success(rv);
     175                 : 
     176                 :   // Run the next test.
     177               1 :   run_next_test();
     178               1 : }
     179                 : 
     180                 : void
     181               1 : test_visited_notifies()
     182                 : {
     183                 :   // First, we add our test URI to history.
     184               2 :   nsCOMPtr<nsIURI> testURI = new_test_uri();
     185               1 :   addURI(testURI);
     186                 : 
     187                 :   // Create our test Link.  The callback function will release the reference we
     188                 :   // have on the Link.
     189               2 :   nsRefPtr<Link> link = new mock_Link(expect_visit);
     190                 : 
     191                 :   // Now, register our Link to be notified.
     192               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     193               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, link);
     194               1 :   do_check_success(rv);
     195                 : 
     196                 :   // Note: test will continue upon notification.
     197               1 : }
     198                 : 
     199                 : void
     200               1 : test_unvisited_does_not_notify_part2()
     201                 : {
     202                 :   using namespace test_unvisited_does_not_notify;
     203                 : 
     204                 :   // We would have had a failure at this point had the content node been told it
     205                 :   // was visited.  Therefore, it is safe to unregister our content node.
     206               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     207               1 :   nsresult rv = history->UnregisterVisitedCallback(testURI, testLink);
     208               1 :   do_check_success(rv);
     209                 : 
     210                 :   // Clear the stored variables now.
     211               1 :   testURI = nsnull;
     212               1 :   testLink = nsnull;
     213                 : 
     214                 :   // Run the next test.
     215               1 :   run_next_test();
     216               1 : }
     217                 : 
     218                 : void
     219               1 : test_same_uri_notifies_both()
     220                 : {
     221                 :   // First, we add our test URI to history.
     222               2 :   nsCOMPtr<nsIURI> testURI = new_test_uri();
     223               1 :   addURI(testURI);
     224                 : 
     225                 :   // Create our two test Links.  The callback function will release the
     226                 :   // reference we have on the Links.  Only the second Link should run the next
     227                 :   // test!
     228               2 :   nsRefPtr<Link> link1 = new mock_Link(expect_visit, false);
     229               2 :   nsRefPtr<Link> link2 = new mock_Link(expect_visit);
     230                 : 
     231                 :   // Now, register our Link to be notified.
     232               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     233               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, link1);
     234               1 :   do_check_success(rv);
     235               1 :   rv = history->RegisterVisitedCallback(testURI, link2);
     236               1 :   do_check_success(rv);
     237                 : 
     238                 :   // Note: test will continue upon notification.
     239               1 : }
     240                 : 
     241                 : void
     242               1 : test_unregistered_visited_does_not_notify()
     243                 : {
     244                 :   // This test must have a test that has a successful notification after it.
     245                 :   // The Link would have been notified by now if we were buggy and notified
     246                 :   // unregistered Links (due to request serialization).
     247                 : 
     248               2 :   nsCOMPtr<nsIURI> testURI = new_test_uri();
     249               2 :   nsRefPtr<Link> link = new mock_Link(expect_no_visit);
     250                 : 
     251                 :   // Now, register our Link to be notified.
     252               2 :   nsCOMPtr<IHistory> history(do_get_IHistory());
     253               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, link);
     254               1 :   do_check_success(rv);
     255                 : 
     256                 :   // Unregister the Link.
     257               1 :   rv = history->UnregisterVisitedCallback(testURI, link);
     258               1 :   do_check_success(rv);
     259                 : 
     260                 :   // And finally add a visit for the URI.
     261               1 :   addURI(testURI);
     262                 : 
     263                 :   // If history tries to notify us, we'll either crash because the Link will
     264                 :   // have been deleted (we are the only thing holding a reference to it), or our
     265                 :   // expect_no_visit call back will produce a failure.  Either way, the test
     266                 :   // will be reported as a failure.
     267                 : 
     268                 :   // Run the next test.
     269               1 :   run_next_test();
     270               1 : }
     271                 : 
     272                 : void
     273               1 : test_new_visit_notifies_waiting_Link()
     274                 : {
     275                 :   // Create our test Link.  The callback function will release the reference we
     276                 :   // have on the link.
     277               2 :   nsRefPtr<Link> link = new mock_Link(expect_visit);
     278                 : 
     279                 :   // Now, register our content node to be notified.
     280               2 :   nsCOMPtr<nsIURI> testURI = new_test_uri();
     281               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     282               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, link);
     283               1 :   do_check_success(rv);
     284                 : 
     285                 :   // Add ourselves to history.
     286               1 :   addURI(testURI);
     287                 : 
     288                 :   // Note: test will continue upon notification.
     289               1 : }
     290                 : 
     291                 : void
     292               1 : test_RegisterVisitedCallback_returns_before_notifying()
     293                 : {
     294                 :   // Add a URI so that it's already in history.
     295               2 :   nsCOMPtr<nsIURI> testURI = new_test_uri();
     296               1 :   addURI(testURI);
     297                 : 
     298                 :   // Create our test Link.
     299               2 :   nsRefPtr<Link> link = new mock_Link(expect_no_visit);
     300                 : 
     301                 :   // Now, register our content node to be notified.  It should not be notified.
     302               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     303               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, link);
     304               1 :   do_check_success(rv);
     305                 : 
     306                 :   // Remove ourselves as an observer.  We would have failed if we had been
     307                 :   // notified.
     308               1 :   rv = history->UnregisterVisitedCallback(testURI, link);
     309               1 :   do_check_success(rv);
     310                 : 
     311               1 :   run_next_test();
     312               1 : }
     313                 : 
     314                 : namespace test_observer_topic_dispatched_helpers {
     315                 :   #define URI_VISITED "visited"
     316                 :   #define URI_NOT_VISITED "not visited"
     317                 :   #define URI_VISITED_RESOLUTION_TOPIC "visited-status-resolution"
     318                 :   class statusObserver : public nsIObserver
     319               2 :   {
     320                 :   public:
     321                 :     NS_DECL_ISUPPORTS
     322                 : 
     323               2 :     statusObserver(nsIURI* aURI,
     324                 :                    const bool aExpectVisit,
     325                 :                    bool& _notified)
     326                 :     : mURI(aURI)
     327                 :     , mExpectVisit(aExpectVisit)
     328               2 :     , mNotified(_notified)
     329                 :     {
     330                 :       nsCOMPtr<nsIObserverService> observerService =
     331               4 :         do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
     332               2 :       do_check_true(observerService);
     333               2 :       (void)observerService->AddObserver(this,
     334                 :                                          URI_VISITED_RESOLUTION_TOPIC,
     335               2 :                                          false);
     336               2 :     }
     337                 : 
     338               3 :     NS_IMETHOD Observe(nsISupports* aSubject,
     339                 :                        const char* aTopic,
     340                 :                        const PRUnichar* aData)
     341                 :     {
     342                 :       // Make sure we got notified of the right topic.
     343               3 :       do_check_false(strcmp(aTopic, URI_VISITED_RESOLUTION_TOPIC));
     344                 : 
     345                 :       // If this isn't for our URI, do not do anything.
     346               6 :       nsCOMPtr<nsIURI> notifiedURI = do_QueryInterface(aSubject);
     347               3 :       do_check_true(notifiedURI);
     348                 : 
     349                 :       bool isOurURI;
     350               3 :       nsresult rv = notifiedURI->Equals(mURI, &isOurURI);
     351               3 :       do_check_success(rv);
     352               3 :       if (!isOurURI) {
     353               1 :         return NS_OK;
     354                 :       }
     355                 : 
     356                 :       // Check that we have either the visited or not visited string.
     357               2 :       bool visited = !!NS_LITERAL_STRING(URI_VISITED).Equals(aData);
     358               2 :       bool notVisited = !!NS_LITERAL_STRING(URI_NOT_VISITED).Equals(aData);
     359               2 :       do_check_true(visited || notVisited);
     360                 : 
     361                 :       // Check to make sure we got the state we expected.
     362               2 :       do_check_eq(visited, mExpectVisit);
     363                 : 
     364                 :       // Indicate that we've been notified.
     365               2 :       mNotified = true;
     366                 : 
     367                 :       // Remove ourselves as an observer.
     368                 :       nsCOMPtr<nsIObserverService> observerService =
     369               4 :         do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
     370               2 :       (void)observerService->RemoveObserver(this,
     371               2 :                                             URI_VISITED_RESOLUTION_TOPIC);
     372               2 :       return NS_OK;
     373                 :     }
     374                 :   private:
     375                 :     nsCOMPtr<nsIURI> mURI;
     376                 :     const bool mExpectVisit;
     377                 :     bool& mNotified;
     378                 :   };
     379              38 :   NS_IMPL_ISUPPORTS1(
     380                 :     statusObserver,
     381                 :     nsIObserver
     382                 :   )
     383                 : }
     384                 : void
     385               1 : test_observer_topic_dispatched()
     386                 : {
     387                 :   using namespace test_observer_topic_dispatched_helpers;
     388                 : 
     389                 :   // Create two URIs, making sure only one is in history.
     390               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     391               2 :   nsCOMPtr<nsIURI> notVisitedURI = new_test_uri();
     392                 :   bool urisEqual;
     393               1 :   nsresult rv = visitedURI->Equals(notVisitedURI, &urisEqual);
     394               1 :   do_check_success(rv);
     395               1 :   do_check_false(urisEqual);
     396               1 :   addURI(visitedURI);
     397                 : 
     398                 :   // Need two Link objects as well - one for each URI.
     399               2 :   nsRefPtr<Link> visitedLink = new mock_Link(expect_visit, false);
     400               2 :   nsRefPtr<Link> visitedLinkCopy = visitedLink;
     401               2 :   nsRefPtr<Link> notVisitedLink = new mock_Link(expect_no_visit);
     402                 : 
     403                 :   // Add the right observers for the URIs to check results.
     404               1 :   bool visitedNotified = false;
     405                 :   nsCOMPtr<nsIObserver> visitedObs =
     406               3 :     new statusObserver(visitedURI, true, visitedNotified);
     407               1 :   bool notVisitedNotified = false;
     408                 :   nsCOMPtr<nsIObserver> unvisitedObs =
     409               3 :     new statusObserver(notVisitedURI, false, notVisitedNotified);
     410                 : 
     411                 :   // Register our Links to be notified.
     412               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     413               1 :   rv = history->RegisterVisitedCallback(visitedURI, visitedLink);
     414               1 :   do_check_success(rv);
     415               1 :   rv = history->RegisterVisitedCallback(notVisitedURI, notVisitedLink);
     416               1 :   do_check_success(rv);
     417                 : 
     418                 :   // Spin the event loop as long as we have not been properly notified.
     419               5 :   while (!visitedNotified || !notVisitedNotified) {
     420               3 :     (void)NS_ProcessNextEvent();
     421                 :   }
     422                 : 
     423                 :   // Unregister our observer that would not have been released.
     424               1 :   rv = history->UnregisterVisitedCallback(notVisitedURI, notVisitedLink);
     425               1 :   do_check_success(rv);
     426                 : 
     427               1 :   run_next_test();
     428               1 : }
     429                 : 
     430                 : void
     431               1 : test_visituri_inserts()
     432                 : {
     433               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     434               2 :   nsCOMPtr<nsIURI> lastURI = new_test_uri();
     435               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     436                 : 
     437               1 :   history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
     438                 : 
     439               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
     440               1 :   finisher->WaitForNotification();
     441                 : 
     442               2 :   PlaceRecord place;
     443               1 :   do_get_place(visitedURI, place);
     444                 : 
     445               1 :   do_check_true(place.id > 0);
     446               1 :   do_check_false(place.hidden);
     447               1 :   do_check_false(place.typed);
     448               1 :   do_check_eq(place.visitCount, 1);
     449                 : 
     450               1 :   run_next_test();
     451               1 : }
     452                 : 
     453                 : void
     454               1 : test_visituri_updates()
     455                 : {
     456               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     457               2 :   nsCOMPtr<nsIURI> lastURI = new_test_uri();
     458               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     459               2 :   nsRefPtr<VisitURIObserver> finisher;
     460                 : 
     461               1 :   history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
     462               1 :   finisher = new VisitURIObserver();
     463               1 :   finisher->WaitForNotification();
     464                 : 
     465               1 :   history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
     466               1 :   finisher = new VisitURIObserver();
     467               1 :   finisher->WaitForNotification();
     468                 : 
     469               2 :   PlaceRecord place;
     470               1 :   do_get_place(visitedURI, place);
     471                 : 
     472               1 :   do_check_eq(place.visitCount, 2);
     473                 : 
     474               1 :   run_next_test();
     475               1 : }
     476                 : 
     477                 : void
     478               1 : test_visituri_preserves_shown_and_typed()
     479                 : {
     480               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     481               2 :   nsCOMPtr<nsIURI> lastURI = new_test_uri();
     482               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     483                 : 
     484               1 :   history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
     485                 :   // this simulates the uri visit happening in a frame.  Normally frame
     486                 :   // transitions would be hidden unless it was previously loaded top-level
     487               1 :   history->VisitURI(visitedURI, lastURI, 0);
     488                 : 
     489               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver(2);
     490               1 :   finisher->WaitForNotification();
     491                 : 
     492               2 :   PlaceRecord place;
     493               1 :   do_get_place(visitedURI, place);
     494               1 :   do_check_false(place.hidden);
     495                 : 
     496               1 :   run_next_test();
     497               1 : }
     498                 : 
     499                 : void
     500               1 : test_visituri_creates_visit()
     501                 : {
     502               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     503               2 :   nsCOMPtr<nsIURI> lastURI = new_test_uri();
     504               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     505                 : 
     506               1 :   history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
     507               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
     508               1 :   finisher->WaitForNotification();
     509                 : 
     510               2 :   PlaceRecord place;
     511                 :   VisitRecord visit;
     512               1 :   do_get_place(visitedURI, place);
     513               1 :   do_get_lastVisit(place.id, visit);
     514                 : 
     515               1 :   do_check_true(visit.id > 0);
     516               1 :   do_check_eq(visit.lastVisitId, 0);
     517               1 :   do_check_eq(visit.transitionType, nsINavHistoryService::TRANSITION_LINK);
     518                 : 
     519               1 :   run_next_test();
     520               1 : }
     521                 : 
     522                 : void
     523               1 : test_visituri_transition_typed()
     524                 : {
     525               2 :   nsCOMPtr<nsINavHistoryService> navHistory = do_get_NavHistory();
     526               2 :   nsCOMPtr<nsIBrowserHistory> browserHistory = do_QueryInterface(navHistory);
     527               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     528               2 :   nsCOMPtr<nsIURI> lastURI = new_test_uri();
     529               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     530                 : 
     531               1 :   browserHistory->MarkPageAsTyped(visitedURI);
     532               1 :   history->VisitURI(visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL);
     533               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
     534               1 :   finisher->WaitForNotification();
     535                 : 
     536               2 :   PlaceRecord place;
     537                 :   VisitRecord visit;
     538               1 :   do_get_place(visitedURI, place);
     539               1 :   do_get_lastVisit(place.id, visit);
     540                 : 
     541               1 :   do_check_true(visit.transitionType == nsINavHistoryService::TRANSITION_TYPED);
     542                 : 
     543               1 :   run_next_test();
     544               1 : }
     545                 : 
     546                 : void
     547               1 : test_visituri_transition_embed()
     548                 : {
     549               2 :   nsCOMPtr<nsINavHistoryService> navHistory = do_get_NavHistory();
     550               2 :   nsCOMPtr<nsIBrowserHistory> browserHistory = do_QueryInterface(navHistory);
     551               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     552               2 :   nsCOMPtr<nsIURI> lastURI = new_test_uri();
     553               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     554                 : 
     555               1 :   history->VisitURI(visitedURI, lastURI, 0);
     556               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
     557               1 :   finisher->WaitForNotification();
     558                 : 
     559               2 :   PlaceRecord place;
     560                 :   VisitRecord visit;
     561               1 :   do_get_place(visitedURI, place);
     562               1 :   do_get_lastVisit(place.id, visit);
     563                 : 
     564               1 :   do_check_eq(place.id, 0);
     565               1 :   do_check_eq(visit.id, 0);
     566                 : 
     567               1 :   run_next_test();
     568               1 : }
     569                 : 
     570                 : void
     571               1 : test_new_visit_adds_place_guid()
     572                 : {
     573                 :   // First, add a visit and wait.  This will also add a place.
     574               2 :   nsCOMPtr<nsIURI> visitedURI = new_test_uri();
     575               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     576               1 :   nsresult rv = history->VisitURI(visitedURI, NULL,
     577               1 :                                   mozilla::IHistory::TOP_LEVEL);
     578               1 :   do_check_success(rv);
     579               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
     580               1 :   finisher->WaitForNotification();
     581                 : 
     582                 :   // Check that we have a guid for our visit.
     583               2 :   PlaceRecord place;
     584               1 :   do_get_place(visitedURI, place);
     585               1 :   do_check_eq(place.visitCount, 1);
     586               1 :   do_check_eq(place.guid.Length(), 12);
     587                 : 
     588               1 :   run_next_test();
     589               1 : }
     590                 : 
     591                 : ////////////////////////////////////////////////////////////////////////////////
     592                 : //// IPC-only Tests
     593                 : 
     594                 : void
     595               1 : test_two_null_links_same_uri()
     596                 : {
     597                 :   // Tests that we do not crash when we have had two NULL Links passed to
     598                 :   // RegisterVisitedCallback and then the visit occurs (bug 607469).  This only
     599                 :   // happens in IPC builds.
     600               2 :   nsCOMPtr<nsIURI> testURI = new_test_uri();
     601                 : 
     602               2 :   nsCOMPtr<IHistory> history = do_get_IHistory();
     603               1 :   nsresult rv = history->RegisterVisitedCallback(testURI, NULL);
     604               1 :   do_check_success(rv);
     605               1 :   rv = history->RegisterVisitedCallback(testURI, NULL);
     606               1 :   do_check_success(rv);
     607                 : 
     608               1 :   rv = history->VisitURI(testURI, NULL, mozilla::IHistory::TOP_LEVEL);
     609               1 :   do_check_success(rv);
     610                 : 
     611               2 :   nsRefPtr<VisitURIObserver> finisher = new VisitURIObserver();
     612               1 :   finisher->WaitForNotification();
     613                 : 
     614               1 :   run_next_test();
     615               1 : }
     616                 : 
     617                 : ////////////////////////////////////////////////////////////////////////////////
     618                 : //// Test Harness
     619                 : 
     620                 : /**
     621                 :  * Note: for tests marked "Order Important!", please see the test for details.
     622                 :  */
     623                 : Test gTests[] = {
     624                 :   TEST(test_set_places_enabled), // Must come first!
     625                 :   TEST(test_unvisited_does_not_notify_part1), // Order Important!
     626                 :   TEST(test_visited_notifies),
     627                 :   TEST(test_unvisited_does_not_notify_part2), // Order Important!
     628                 :   TEST(test_same_uri_notifies_both),
     629                 :   TEST(test_unregistered_visited_does_not_notify), // Order Important!
     630                 :   TEST(test_new_visit_notifies_waiting_Link),
     631                 :   TEST(test_RegisterVisitedCallback_returns_before_notifying),
     632                 :   TEST(test_observer_topic_dispatched),
     633                 :   TEST(test_visituri_inserts),
     634                 :   TEST(test_visituri_updates),
     635                 :   TEST(test_visituri_preserves_shown_and_typed),
     636                 :   TEST(test_visituri_creates_visit),
     637                 :   TEST(test_visituri_transition_typed),
     638                 :   TEST(test_visituri_transition_embed),
     639                 :   TEST(test_new_visit_adds_place_guid),
     640                 : 
     641                 :   // The rest of these tests are tests that are only run in IPC builds.
     642                 :   TEST(test_two_null_links_same_uri),
     643                 : };
     644                 : 
     645                 : const char* file = __FILE__;
     646                 : #define TEST_NAME "IHistory"
     647                 : #define TEST_FILE file
     648                 : #include "places_test_harness_tail.h"

Generated by: LCOV version 1.7