From 29905dad37b6ad5f83b451ed18bf23da195226af Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Wed, 24 Jun 2009 13:12:37 -0400 Subject: [PATCH] Bug 499912, crash activating window with no root element, r+sr=smaug --- dom/base/nsGlobalWindow.cpp | 12 +++++++----- dom/tests/mochitest/chrome/window_focus.xul | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index e248c74150c7..cc137f543292 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -6654,11 +6654,13 @@ nsGlobalWindow::ActivateOrDeactivate(PRBool aActivate) nsCOMPtr chromeWin = do_QueryInterface(topLevelWindow); if (xulDoc && chromeWin) { nsCOMPtr rootElem = doc->GetRootContent(); - if (aActivate) - rootElem->SetAttr(kNameSpaceID_None, nsGkAtoms::active, - NS_LITERAL_STRING("true"), PR_TRUE); - else - rootElem->UnsetAttr(kNameSpaceID_None, nsGkAtoms::active, PR_TRUE); + if (rootElem) { + if (aActivate) + rootElem->SetAttr(kNameSpaceID_None, nsGkAtoms::active, + NS_LITERAL_STRING("true"), PR_TRUE); + else + rootElem->UnsetAttr(kNameSpaceID_None, nsGkAtoms::active, PR_TRUE); + } } } } diff --git a/dom/tests/mochitest/chrome/window_focus.xul b/dom/tests/mochitest/chrome/window_focus.xul index e6502e341b2a..6d26e68480c6 100644 --- a/dom/tests/mochitest/chrome/window_focus.xul +++ b/dom/tests/mochitest/chrome/window_focus.xul @@ -1119,13 +1119,29 @@ function switchWindowTest(otherWindow, framesetWindow) otherWindow.close(); framesetWindow.close(); + gRefocusCallback = doWindowNoRootTest; +} + +// open a window with no root element +var noRootWindow = null; +function doWindowNoRootTest() +{ + var data = "data:application/vnd.mozilla.xul+xml," + unescape( + "" + + ""); + gRefocusCallback = doFrameSwitchingTests; + noRootWindow = window.open(data, "_blank", "chrome,width=100,height=100"); } // these tests check when focus is moved between a tree of frames to ensure // that the focus is in the right place at each event step. function doFrameSwitchingTests() { + noRootWindow.close(); gRefocusCallback = null; var framea = document.getElementById("ifa");