Skip to content

Commit

Permalink
Bug 504837: Hashchange event should not be restricted to firing only …
Browse files Browse the repository at this point in the history
…when the document's readystate is 'complete'. r/sr=smaug
  • Loading branch information
Justin Lebar committed Jul 21, 2009
1 parent 4cbbbfb commit 3cf42d7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 100 deletions.
1 change: 0 additions & 1 deletion docshell/test/Makefile.in
Expand Up @@ -76,7 +76,6 @@ _TEST_FILES = \
file_bug385434_1.html \
file_bug385434_2.html \
file_bug385434_3.html \
file_bug385434_4.html \
$(NULL)

libs:: $(_TEST_FILES)
Expand Down
7 changes: 1 addition & 6 deletions docshell/test/file_bug385434_3.html
Expand Up @@ -7,14 +7,9 @@
<script type="application/javascript">
// Notify our parent if we have a hashchange and once we're done loading.
window.addEventListener("hashchange", parent.onIframeHashchange, false);
window.addEventListener("load", parent.onIframeLoad, false);

// This shouldn't trigger a hashchange, because we haven't finished loading
// the document.
window.location.hash = "1";

window.addEventListener("DOMContentLoaded", function() {
// This also shouldn't trigger a hashchange, becuase the readystate is
// This also should trigger a hashchange, becuase the readystate is
// "interactive", not "complete" during DOMContentLoaded.
window.location.hash = "2";
}, false);
Expand Down
36 changes: 0 additions & 36 deletions docshell/test/file_bug385434_4.html

This file was deleted.

58 changes: 7 additions & 51 deletions docshell/test/test_bug385434.html
Expand Up @@ -169,6 +169,7 @@
/*
* TEST 2 tests that:
* <frameset onhashchange = ... > works,
* the event is targeted at the window object
* the event's cancelable, bubbles settings are correct
*/
enableIframeLoadCallback();
Expand All @@ -180,6 +181,8 @@

eventExpected("frame onhashchange should fire events.");
// iframe should set gSampleEvent
is(gSampleEvent.target, frameCw,
"The hashchange event should be targeted to the window.");
is(gSampleEvent.type, "hashchange",
"Event type should be 'hashchange'.");
is(gSampleEvent.cancelable, false,
Expand All @@ -189,60 +192,13 @@

/*
* TEST 3 tests that:
* hashchange is not dispatched if the current document readyState is
* not "complete".
* hashchange is dispatched if the current document readyState is
* not "complete" (bug 504837).
*/
enableIframeLoadCallback();
frameCw.document.location = "file_bug385434_3.html";
yield;
noEventExpected("Hashchange shouldn't fire if the document " +
"hasn't finished loading.");

longWait();
yield;
noEventExpected("Hashchange shouldn't fire after longWait() if " +
"the document hasn't finished loading.");

/*
* TEST 4 tests that if we
*
* * Load a page A
* * Register a hashchange callback on A
* * Navigate to A#foo
* * Redirect to a different page, B, before the hashchange event triggered
* by redirecting to A#foo fires,
*
* a hashchange event is not fired on B.
*/
statusMsg("Starting test 4.");
frameCw.document.location = "file_bug385434_4.html";
longWait();
yield;
noEventExpected("Test 4 sequence shouldn't trigger a hashchange.");

/*
* TEST 5 tests that:
* document.window.addEventListener() works for hashchange,
* hashchange is dispatched to window, not to body
*/

// Make sure the current window doesn't have a hash, as would happen if we
// were running this test interactively and it hung right after we assigned a
// value to window.location.hash
window.location.hash = "";

window.addEventListener("hashchange", onIframeHashchange, false);
window.location.hash = "#foo";
yield;
eventExpected("addEventListener() should work for hashchange.");
window.removeEventListener("hashchange", onIframeHashchange, false);

document.body.addEventListener("hashchange", onIframeHashchange, false);
enableIframeLoadCallback();
window.location.hash = "#baz";
longWait();
yield;
noEventExpected("hashchange shouldn't be dispatched to <body>.");
eventExpected("Hashchange should fire even if the document " +
"hasn't finished loading.");

SimpleTest.finish();
yield;
Expand Down
6 changes: 0 additions & 6 deletions dom/base/nsGlobalWindow.cpp
Expand Up @@ -6735,12 +6735,6 @@ nsGlobalWindow::DispatchAsyncHashchange()
{
FORWARD_TO_INNER(DispatchAsyncHashchange, (), NS_OK);

nsIDocument::ReadyState readyState = mDoc->GetReadyStateEnum();

// We only queue up the event if the ready state is currently "complete"
if (readyState != nsIDocument::READYSTATE_COMPLETE)
return NS_OK;

nsCOMPtr<nsIRunnable> event =
NS_NEW_RUNNABLE_METHOD(nsGlobalWindow, this, FireHashchange);

Expand Down

0 comments on commit 3cf42d7

Please sign in to comment.