Bug 396649: Assert that content viewers aren't where they shouldn't be (debug-only), r+sr=bzbarsky, a=mtschrep
authorajschult@verizon.net
Fri, 16 Nov 2007 22:28:56 -0800
changeset 8115 ec5a37d4238a2631d8f670ec33e4cf91d8e3f178
parent 8114 e97fe496b71ab032c72cd0d1e0e7f2e63d202663
child 8116 ec4f1cff5e744e7af0c5cb16e9eabeb267e0a182
push idunknown
push userunknown
push dateunknown
reviewersmtschrep
bugs396649
milestone1.9b2pre
Bug 396649: Assert that content viewers aren't where they shouldn't be (debug-only), r+sr=bzbarsky, a=mtschrep
docshell/shistory/src/nsSHistory.cpp
--- a/docshell/shistory/src/nsSHistory.cpp
+++ b/docshell/shistory/src/nsSHistory.cpp
@@ -790,17 +790,41 @@ nsSHistory::EvictWindowContentViewers(PR
     startIndex = PR_MAX(0, aFromIndex - gHistoryMaxViewers);
   } else { // going backward
     startIndex = aToIndex + gHistoryMaxViewers + 1;
     if (startIndex >= mLength) {
       return;
     }
     endIndex = PR_MIN(mLength, aFromIndex + gHistoryMaxViewers + 1);
   }
-  
+
+#ifdef DEBUG
+  nsCOMPtr<nsISHTransaction> trans;
+  GetTransactionAtIndex(0, getter_AddRefs(trans));
+
+  // Walk the full session history and check that entries outside the window
+  // around aFromIndex have no content viewers
+  for (PRInt32 i = 0; i < mLength; ++i) {
+    if (i < aFromIndex - gHistoryMaxViewers || 
+        i > aFromIndex + gHistoryMaxViewers) {
+      nsCOMPtr<nsISHEntry> entry;
+      trans->GetSHEntry(getter_AddRefs(entry));
+      nsCOMPtr<nsIContentViewer> viewer;
+      nsCOMPtr<nsISHEntry> ownerEntry;
+      entry->GetAnyContentViewer(getter_AddRefs(ownerEntry),
+                                 getter_AddRefs(viewer));
+      NS_ASSERTION(!viewer,
+                   "ContentViewer exists outside gHistoryMaxViewer range");
+    }
+
+    nsISHTransaction *temp = trans;
+    temp->GetNext(getter_AddRefs(trans));
+  }
+#endif
+
   EvictContentViewersInRange(startIndex, endIndex);
 }
 
 void
 nsSHistory::EvictContentViewersInRange(PRInt32 aStart, PRInt32 aEnd)
 {
   nsCOMPtr<nsISHTransaction> trans;
   GetTransactionAtIndex(aStart, getter_AddRefs(trans));