/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"places_test_harness:SpinEventLoopUntil(placesIHistory )_ns, #nclude n.h #include"nsIPrefService.h" #includejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #include"mozilla/SpinEventLoopUntil.h" #include"mozilla/StackWalk.h" #include"mozilla/StaticPrefs_layout.h" #include"nsNetUtil.h"
// Create the URI for the spec.
nsCOMPtr<nsIURI> testURI;
nsresult rv = NS_NewURI(getter_AddRefs(testURI), spec);
do_check_success(rv); return testURI.forget();
}
class VisitURIObserver final : public nsIObserver {
~VisitURIObserver() = default;
void test_wait_checkpoint() { // This "fake" test is here to wait for the initial WAL checkpoint we force // after creating the database schema, since that may happen at any time, // and cause concurrent readers to access an older checkpoint.
nsCOMPtr<mozIStorageConnection> db = do_get_db();
nsCOMPtr<mozIStorageAsyncStatement> stmt;
db->CreateAsyncStatement("SELECT 1"_ns, getter_AddRefs(stmt));
RefPtr<PlacesAsyncStatementSpinner> spinner = new PlacesAsyncStatementSpinner();
nsCOMPtr<mozIStoragePendingStatement> pending;
(void)stmt->ExecuteAsync(spinner, getter_AddRefs(pending));
spinner->SpinUntilCompleted();
// Run the next test.
run_next_test();
}
// These variables are shared between part 1 and part 2 of the test. Part 2 // sets the nsCOMPtr's to nullptr, freeing the reference. namespace test_unvisited_does_not_notify {
constinit nsCOMPtr<nsIURI> testURI;
constinit RefPtr<mock_Link> testLink;
} // namespace test_unvisited_does_not_notify void test_unvisited_does_not_notify_part1() { usingnamespace test_unvisited_does_not_notify;
// This test is done in two parts. The first part registers for a URI that // should not be visited. We then run another test that will also do a // lookup and will be notified. Since requests are answered in the order they // are requested (at least as long as the same URI isn't asked for later), we // will know that the Link was not notified.
// First, we need a test URI.
testURI = new_test_uri();
// Create our test Link.
testLink = new mock_Link(expect_no_visit);
// Now, register our Link to be notified.
nsCOMPtr<IHistory> history = do_get_IHistory();
history->RegisterVisitedCallback(testURI, testLink);
// Run the next test.
run_next_test();
}
void test_visited_notifies() { // First, we add our test URI to history.
nsCOMPtr<nsIURI> testURI = new_test_uri();
addURI(testURI);
// Create our test Link. The callback function will release the reference we // have on the Link.
RefPtr<Link> link = new mock_Link(expect_visit);
// Now, register our Link to be notified.
nsCOMPtr<IHistory> history = do_get_IHistory();
history->RegisterVisitedCallback(testURI, link);
// We would have had a failure at this point had the content node been told it // was visited. Therefore, now we change it so that it expects a visited // notification, and unregisters itself after addURI.
testLink->AwaitNewNotification(expect_visit);
addURI(testURI);
void test_same_uri_notifies_both() { // First, we add our test URI to history.
nsCOMPtr<nsIURI> testURI = new_test_uri();
addURI(testURI);
// Create our two test Links. The callback function will release the // reference we have on the Links. Only the second Link should run the next // test!
RefPtr<Link> link1 = new mock_Link(expect_visit, false);
RefPtr<Link> link2 = new mock_Link(expect_visit);
// Now, register our Link to be notified.
nsCOMPtr<IHistory> history = do_get_IHistory();
history->RegisterVisitedCallback(testURI, link1);
history->RegisterVisitedCallback(testURI, link2);
// Note: test will continue upon notification.
}
void test_unregistered_visited_does_not_notify() { // This test must have a test that has a successful notification after it. // The Link would have been notified by now if we were buggy and notified // unregistered Links (due to request serialization).
nsCOMPtr<nsIURI> testURI = new_test_uri();
RefPtr<Link> link = new mock_Link(expect_no_visit, false);
nsCOMPtr<IHistory> history(do_get_IHistory());
history->RegisterVisitedCallback(testURI, link);
// Unregister the Link.
history->UnregisterVisitedCallback(testURI, link);
// And finally add a visit for the URI.
addURI(testURI);
// If history tries to notify us, we'll either crash because the Link will // have been deleted (we are the only thing holding a reference to it), or our // expect_no_visit call back will produce a failure. Either way, the test // will be reported as a failure.
// Run the next test.
run_next_test();
}
void test_new_visit_notifies_waiting_Link() { // Create our test Link. The callback function will release the reference we // have on the link. // // Note that this will query the database and we'll get an _unvisited_ // notification, then (after we addURI) a _visited_ one.
RefPtr<mock_Link> link = new mock_Link(expect_no_visit);
// Now, register our content node to be notified.
nsCOMPtr<nsIURI> testURI = new_test_uri();
nsCOMPtr<IHistory> history = do_get_IHistory();
history->RegisterVisitedCallback(testURI, link);
void test_RegisterVisitedCallback_returns_before_notifying() { // Add a URI so that it's already in history.
nsCOMPtr<nsIURI> testURI = new_test_uri();
addURI(testURI);
// Create our test Link.
RefPtr<Link> link = new mock_Link(expect_no_visit, false);
// Now, register our content node to be notified. It should not be notified.
nsCOMPtr<IHistory> history = do_get_IHistory();
history->RegisterVisitedCallback(testURI, link);
// Remove ourselves as an observer. We would have failed if we had been // notified.
history->UnregisterVisitedCallback(testURI, link);
history->VisitURI(nullptr, visitedURI, lastURI, mozilla::IHistory::TOP_LEVEL, 0); // this simulates the uri visit happening in a frame. Normally frame // transitions would be hidden unless it was previously loaded top-level
history->VisitURI(nullptr, visitedURI, lastURI, 0, 0);
RefPtr<VisitURIObserver> finisher = new VisitURIObserver(2);
finisher->WaitForNotification();
void test_new_visit_adds_place_guid() { // First, add a visit and wait. This will also add a place.
nsCOMPtr<nsIURI> visitedURI = new_test_uri();
nsCOMPtr<IHistory> history = do_get_IHistory();
nsresult rv = history->VisitURI(nullptr, visitedURI, nullptr,
mozilla::IHistory::TOP_LEVEL, 0);
do_check_success(rv);
RefPtr<VisitURIObserver> finisher = new VisitURIObserver();
finisher->WaitForNotification();
// Check that we have a guid for our visit.
PlaceRecord place;
do_get_place(visitedURI, place);
do_check_eq(place.visitCount, 1);
do_check_eq(place.guid.Length(), 12u);
run_next_test();
}
//////////////////////////////////////////////////////////////////////////////// //// Test Harness
/** *Note:fortestsmarked"OrderImportant!",pleaseseethetestfordetails.
*/
Test gTests[] = {
PTEST(test_set_places_enabled), // Must come first!
PTEST(test_wait_checkpoint), // Must come second!
PTEST(test_unvisited_does_not_notify_part1), // Order Important!
PTEST(test_visited_notifies),
PTEST(test_unvisited_does_not_notify_part2), // Order Important!
PTEST(test_same_uri_notifies_both),
PTEST(test_unregistered_visited_does_not_notify), // Order Important!
PTEST(test_new_visit_adds_place_guid),
PTEST(test_new_visit_notifies_waiting_Link),
PTEST(test_RegisterVisitedCallback_returns_before_notifying),
PTEST(test_visituri_inserts),
PTEST(test_visituri_updates),
PTEST(test_visituri_preserves_shown_and_typed),
PTEST(test_visituri_creates_visit),
PTEST(test_visituri_frecency),
PTEST(test_visituri_hidden),
PTEST(test_visituri_transition_typed),
PTEST(test_visituri_transition_embed),
};
int gTestsIndex = 0;
class RunNextTest : public mozilla::Runnable { public:
RunNextTest() : mozilla::Runnable("RunNextTest") {}
NS_IMETHOD Run() override {
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Not running on the main thread?"); if (gTestsIndex < int(std::size(gTests))) {
do_test_pending();
Test& test = gTests[gTestsIndex++];
(void)fprintf(stderr, TEST_INFO_STR "Running %s.\n", test.name);
test.func();
}
do_test_finished(); return NS_OK;
}
};
staticconstbool kDebugRunNextTest = false;
void run_next_test() { if (kDebugRunNextTest) {
printf_stderr("run_next_test()\n");
MozWalkTheStack(stderr);
}
nsCOMPtr<nsIRunnable> event = new RunNextTest();
do_check_success(NS_DispatchToCurrentThread(event));
}
int gPendingTests = 0;
void do_test_pending() {
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Not running on the main thread?"); if (kDebugRunNextTest) {
printf_stderr("do_test_pending()\n");
MozWalkTheStack(stderr);
}
gPendingTests++;
}
void do_test_finished() {
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Not running on the main thread?");
MOZ_RELEASE_ASSERT(gPendingTests > 0, "Invalid pending test count!");
gPendingTests--;
}
TEST(IHistory, Test)
{
RefPtr<WaitForConnectionClosed> spinClose = new WaitForConnectionClosed();
// Tinderboxes are constantly on idle. Since idle tasks can interact with // tests, causing random failures, disable the idle service.
disable_idle_service();
do_test_pending();
run_next_test();
// Spin the event loop until we've run out of tests to run.
mozilla::SpinEventLoopUntil("places:TEST(IHistory, Test)"_ns,
[&]() { return !gPendingTests; });
// And let any other events finish before we quit.
(void)NS_ProcessPendingEvents(nullptr);
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.9Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.