diff --git a/layout/reftests/bugs/371925-1-ref.html b/layout/reftests/bugs/371925-1-ref.html
new file mode 100644
index 00000000000..0d3e2761c98
--- /dev/null
+++ b/layout/reftests/bugs/371925-1-ref.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
diff --git a/layout/reftests/bugs/371925-1a.html b/layout/reftests/bugs/371925-1a.html
new file mode 100644
index 00000000000..fd1d69da37a
--- /dev/null
+++ b/layout/reftests/bugs/371925-1a.html
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/layout/reftests/bugs/371925-1b.html b/layout/reftests/bugs/371925-1b.html
new file mode 100644
index 00000000000..8db15e968be
--- /dev/null
+++ b/layout/reftests/bugs/371925-1b.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list
index 78a331a75fa..32e192ce9f0 100644
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -157,3 +157,5 @@ fails == 368020-4.html 368020-4-ref.html # bug 368085
== 370629-1.html 370629-1-ref.html
== 370629-2.html 370629-2-ref.html
== 370692-1.xhtml 370692-1-ref.xhtml
+== 371925-1a.html 371925-1-ref.html
+== 371925-1b.html 371925-1-ref.html
diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp
index 19fd37661bf..b244d64af7b 100644
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -2284,8 +2284,12 @@ nsTableFrame::InsertFrames(nsIAtom* aListName,
const nsStyleDisplay* display = aFrameList->GetStyleDisplay();
if (aPrevFrame) {
const nsStyleDisplay* prevDisplay = aPrevFrame->GetStyleDisplay();
- if (display->mDisplay != prevDisplay->mDisplay) {
+ // Make sure they belong on the same frame list
+ if ((display->mDisplay == NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP) !=
+ (prevDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP)) {
// the previous frame is not valid, see comment at ::AppendFrames
+ // XXXbz Using content indices here means XBL will get screwed
+ // over... Oh, well.
nsIFrame* pseudoFrame = aFrameList;
nsIContent* parentContent = GetContent();
nsIContent* content;
@@ -2305,7 +2309,8 @@ nsTableFrame::InsertFrames(nsIAtom* aListName,
else {
kidFrame = mFrames.FirstChild();
}
- PRInt32 lastIndex = 0;
+ // Important: need to start at a value smaller than all valid indices
+ PRInt32 lastIndex = -1;
while (kidFrame) {
if (isColGroup) {
nsTableColGroupType groupType =