Commit 43358768 authored by dimich@chromium.org's avatar dimich@chromium.org

WebCore: Timers from cached pages fire instantly rather than the after the specified timeout delay

https://bugs.webkit.org/show_bug.cgi?id=28683

Reviewed by Brady Eidson.

Test: fast/dom/Window/timer-resume-on-navigation-back.html

* history/CachedPage.cpp:
(WebCore::CachedPage::restore): Remove duplicated Frame::restore() call, since
    it should be done only once in FrameLoader::open(cachedFrame)
* page/DOMTimer.cpp: Added a debug-only flag and ASSERT to catch out-of-order suspense/restore.
(WebCore::DOMTimer::DOMTimer): Ditto.
(WebCore::DOMTimer::suspend): Ditto.
(WebCore::DOMTimer::resume): Ditto.
* page/DOMTimer.h: Ditto.

LayoutTests: Timers from cached pages fire instantly rather than the specified timeout delay
https://bugs.webkit.org/show_bug.cgi?id=28683

Reviewed by Brady Eidson.

Added test to verify the fix - it uses page cache and measures the timer callback fire time.

* fast/dom/Window/timer-resume-on-navigation-back-expected.txt: Added.
* fast/dom/Window/timer-resume-on-navigation-back.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47772 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7821e45e
2009-08-25 Dmitry Titov <dimich@chromium.org>
Reviewed by Brady Eidson.
Timers from cached pages fire instantly rather than the specified timeout delay
https://bugs.webkit.org/show_bug.cgi?id=28683
Added test to verify the fix - it uses page cache and measures the timer callback fire time.
* fast/dom/Window/timer-resume-on-navigation-back-expected.txt: Added.
* fast/dom/Window/timer-resume-on-navigation-back.html: Added.
2009-08-25 Kent Tamura <tkent@chromium.org>
Reviewed by Eric Seidel.
......
This test verifies that when page is loaded from the page cache on navigation back, the suspended timers are resumed for a duration left when they were suspended. This is a test for https://bugs.webkit.org/show_bug.cgi?id=28683.
The test navigates to a page, starts a timer and then navigates to another page and back. It then measures time when the timer is actually fired and makes sure that it is at least the time set at the beginning. If successful, it outputs 'PASS' below.
PASS
<html>
<script>
var timeoutValue = 100; //ms
var timestamp;
function verify() {
var actualTimerDelay = new Date().getTime() - timestamp;
document.getElementById("result").innerHTML =
actualTimerDelay >= timeoutValue ? 'PASS' : 'FAIL with ' + actualTimerDelay + ' ms delay.';
if (window.layoutTestController)
layoutTestController.notifyDone();
}
function runTest() {
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
layoutTestController.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
}
window.setTimeout("verify()", timeoutValue);
timestamp = new Date().getTime();
window.location.href = "data:text/html,<body onload='history.back()'></body>";
}
</script>
<body onload='runTest()'>
This test verifies that when page is loaded from the page cache on navigation back, the suspended timers are resumed for a duration left when they were suspended. This is a test for https://bugs.webkit.org/show_bug.cgi?id=28683.<br>
The test navigates to a page, starts a timer and then navigates to another page and back. It then measures time when the timer is actually fired and makes sure that it is at least the time set at the beginning. If successful, it outputs 'PASS' below.
<div id="result"></div>
</body>
</html>
2009-08-25 Dmitry Titov <dimich@chromium.org>
Reviewed by Brady Eidson.
Timers from cached pages fire instantly rather than the after the specified timeout delay
https://bugs.webkit.org/show_bug.cgi?id=28683
Test: fast/dom/Window/timer-resume-on-navigation-back.html
* history/CachedPage.cpp:
(WebCore::CachedPage::restore): Remove duplicated Frame::restore() call, since
it should be done only once in FrameLoader::open(cachedFrame)
* page/DOMTimer.cpp: Added a debug-only flag and ASSERT to catch out-of-order suspense/restore.
(WebCore::DOMTimer::DOMTimer): Ditto.
(WebCore::DOMTimer::suspend): Ditto.
(WebCore::DOMTimer::resume): Ditto.
* page/DOMTimer.h: Ditto.
2009-08-25 Eric Carlson <eric.carlson@apple.com>
Reviewed by Simon Fraser.
......@@ -67,7 +67,6 @@ CachedPage::~CachedPage()
void CachedPage::restore(Page* page)
{
ASSERT(page && page->mainFrame() && page->mainFrame() == m_cachedMainFrame->view()->frame());
m_cachedMainFrame->restore();
// Restore the focus appearance for the focused element.
// FIXME: Right now we don't support pages w/ frames in the b/f cache. This may need to be tweaked when we add support for that.
......
......@@ -47,6 +47,9 @@ DOMTimer::DOMTimer(ScriptExecutionContext* context, ScheduledAction* action, int
, m_action(action)
, m_nextFireInterval(0)
, m_repeatInterval(0)
#if !ASSERT_DISABLED
, m_suspended(false)
#endif
{
static int lastUsedTimeoutId = 0;
++lastUsedTimeoutId;
......@@ -148,7 +151,10 @@ void DOMTimer::stop()
void DOMTimer::suspend()
{
ASSERT(!m_nextFireInterval && !m_repeatInterval);
#if !ASSERT_DISABLED
ASSERT(!m_suspended);
m_suspended = true;
#endif
m_nextFireInterval = nextFireInterval();
m_repeatInterval = repeatInterval();
TimerBase::stop();
......@@ -156,9 +162,11 @@ void DOMTimer::suspend()
void DOMTimer::resume()
{
#if !ASSERT_DISABLED
ASSERT(m_suspended);
m_suspended = false;
#endif
start(m_nextFireInterval, m_repeatInterval);
m_nextFireInterval = 0;
m_repeatInterval = 0;
}
......
......@@ -66,6 +66,9 @@ namespace WebCore {
OwnPtr<ScheduledAction> m_action;
double m_nextFireInterval;
double m_repeatInterval;
#if !ASSERT_DISABLED
bool m_suspended;
#endif
static double s_minTimerInterval;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment