Bug 628805 - Add tests for invalid referrerURI and invalid sessionId to test_async_history_api.js [r=sdwilsh, a=blocking-final]
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 25 Jan 2011 14:26:29 -0800
changeset 62167 175623f0113a5a428eb6950710bf3936bd3b5e9f
parent 62166 0b4c13e87e5a2ff707882409661ec06e7f913085
child 62168 ef4d491f9ba0fbece23448cfce69710e1d639680
push id18626
push usermleibovic@mozilla.com
push dateTue, 08 Feb 2011 21:15:39 +0000
treeherdermozilla-central@ef4d491f9ba0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh, blocking-final
bugs628805
milestone2.0b12pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 628805 - Add tests for invalid referrerURI and invalid sessionId to test_async_history_api.js [r=sdwilsh, a=blocking-final]
toolkit/components/places/tests/unit/test_async_history_api.js
--- a/toolkit/components/places/tests/unit/test_async_history_api.js
+++ b/toolkit/components/places/tests/unit/test_async_history_api.js
@@ -388,16 +388,121 @@ function test_non_addable_uri_errors()
 
     // If we have had all of our callbacks, continue running tests.
     if (++callbackCount == places.length) {
       run_next_test();
     }
   });
 }
 
+function test_invalid_referrerURI_ignored()
+{
+  let place = {
+    uri: NetUtil.newURI(TEST_DOMAIN +
+                        "test_invalid_referrerURI_ignored"),
+    visits: [
+      new VisitInfo(),
+    ],
+  };
+  place.visits[0].referrerURI = NetUtil.newURI(place.uri.spec + "_unvisistedURI");
+  do_check_false(gGlobalHistory.isVisited(place.uri));
+  do_check_false(gGlobalHistory.isVisited(place.visits[0].referrerURI));
+
+  gHistory.updatePlaces(place, function(aResultCode, aPlaceInfo) {
+    do_check_true(Components.isSuccessCode(aResultCode));
+    let uri = aPlaceInfo.uri;
+    do_check_true(gGlobalHistory.isVisited(uri));
+
+    // Check to make sure we do not visit the invalid referrer.
+    let visit = aPlaceInfo.visits[0];
+    do_check_false(gGlobalHistory.isVisited(visit.referrerURI));
+
+    // Check to make sure from_visit is zero in database.
+    let stmt = DBConn().createStatement(
+      "SELECT from_visit " +
+      "FROM moz_historyvisits " +
+      "WHERE id = :visit_id"
+    );
+    stmt.params.visit_id = aPlaceInfo.visits[0].visitId;
+    do_check_true(stmt.executeStep());
+    do_check_eq(stmt.row.from_visit, 0);
+    stmt.finalize();
+
+    run_next_test();
+  });
+}
+
+function test_nonnsIURI_referrerURI_ignored()
+{
+  let place = {
+    uri: NetUtil.newURI(TEST_DOMAIN +
+                        "test_nonnsIURI_referrerURI_ignored"),
+    visits: [
+      new VisitInfo(),
+    ],
+  };
+  place.visits[0].referrerURI = place.uri.spec + "_nonnsIURI";
+  do_check_false(gGlobalHistory.isVisited(place.uri));
+
+  gHistory.updatePlaces(place, function(aResultCode, aPlaceInfo) {
+    do_check_true(Components.isSuccessCode(aResultCode));
+    let uri = aPlaceInfo.uri;
+    do_check_true(gGlobalHistory.isVisited(uri));
+
+    // Check to make sure from_visit is zero in database.
+    let stmt = DBConn().createStatement(
+      "SELECT from_visit " +
+      "FROM moz_historyvisits " +
+      "WHERE id = :visit_id"
+    );
+    stmt.params.visit_id = aPlaceInfo.visits[0].visitId;
+    do_check_true(stmt.executeStep());
+    do_check_eq(stmt.row.from_visit, 0);
+    stmt.finalize();
+
+    run_next_test();
+  });
+}
+
+function test_invalid_sessionId_ignored()
+{
+  let place = {
+    uri: NetUtil.newURI(TEST_DOMAIN +
+                        "test_invalid_sessionId_ignored"),
+    visits: [
+      new VisitInfo(),
+    ],
+  };
+  place.visits[0].sessionId = -1;
+  do_check_false(gGlobalHistory.isVisited(place.uri));
+
+  gHistory.updatePlaces(place, function(aResultCode, aPlaceInfo) {
+    do_check_true(Components.isSuccessCode(aResultCode));
+    let uri = aPlaceInfo.uri;
+    do_check_true(gGlobalHistory.isVisited(uri));
+
+    // Check to make sure we do not persist bogus sessionId with the visit.
+    let visit = aPlaceInfo.visits[0];
+    do_check_neq(visit.sessionId, place.visits[0].sessionId);
+
+    // Check to make sure we do not persist bogus sessionId in database.
+    let stmt = DBConn().createStatement(
+      "SELECT session " +
+      "FROM moz_historyvisits " +
+      "WHERE id = :visit_id"
+    );
+    stmt.params.visit_id = visit.visitId;
+    do_check_true(stmt.executeStep());
+    do_check_neq(stmt.row.session, place.visits[0].sessionId);
+    stmt.finalize();
+
+    run_next_test();
+  });
+}
+
 function test_observer_topic_dispatched_when_complete()
 {
   // We test a normal visit, and embeded visit, and a uri that would fail
   // the canAddURI test to make sure that the notification happens after *all*
   // of them have had a callback.
   let places = [
     { uri: NetUtil.newURI(TEST_DOMAIN +
                           "test_observer_topic_dispatched_when_complete"),
@@ -859,16 +964,19 @@ let gTests = [
   test_invalid_uri_throws,
   test_invalid_places_throws,
   test_invalid_guid_throws,
   test_no_visits_throws,
   test_add_visit_no_date_throws,
   test_add_visit_no_transitionType_throws,
   test_add_visit_invalid_transitionType_throws,
   test_non_addable_uri_errors,
+  test_invalid_referrerURI_ignored,
+  test_nonnsIURI_referrerURI_ignored,
+  test_invalid_sessionId_ignored,
   test_observer_topic_dispatched_when_complete,
   test_add_visit,
   test_properties_saved,
   test_guid_saved,
   test_referrer_saved,
   test_sessionId_saved,
   test_guid_change_saved,
   test_title_change_saved,