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