Title: [92982] trunk
Revision
92982
Author
[email protected]
Date
2011-08-12 12:56:56 -0700 (Fri, 12 Aug 2011)

Log Message

Cancel in onbeforeunload dialog sometime causes a button to stop working.
https://bugs.webkit.org/show_bug.cgi?id=26211

Reviewed by Alexey Proskuryakov.

Source/WebCore:

Test: fast/loader/form-submission-after-beforeunload-cancel.html

If an onbeforeunload handler cancels a navigation that was triggered by
a form submission, WebCore's multiple form submission protection
prevents the form from being submitted a second time even though no
first submission actually took place. Fix this by clearing
m_submittedFormURL if the onbeforeunload handler cancels the load. This
allows the submission to be retried.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::shouldClose): Set m_submittedFormURL to KURL()
if shouldClose() will return false.

Tools:

Implement a new LayoutTestController method that a test can call to set
the return value of DumpRenderTree's beforeunload UI delegate.

* DumpRenderTree/LayoutTestController.cpp:
(LayoutTestController::LayoutTestController): Initialize
m_shouldStayOnPageAfterHandlingBeforeUnload.
(setShouldStayOnPageAfterHandlingBeforeUnloadCallback): Call
LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload().
(LayoutTestController::staticFunctions): Register
'setShouldStayOnPageAfterHandlingBeforeUnload' as a static function.
* DumpRenderTree/LayoutTestController.h:
(LayoutTestController::shouldStayOnPageAfterHandlingBeforeUnload):
(LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload):
* DumpRenderTree/chromium/LayoutTestController.cpp:
(LayoutTestController::LayoutTestController): Initialize
m_shouldStayOnPageAfterHandlingBeforeUnload and bind
'setShouldStayOnPageAfterHandlingBeforeUnload' to its c++ setter.
(LayoutTestController::reset): Reset
m_shouldStayOnPageAfterHandlingBeforeUnload to false.
(LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload):
Set m_shouldStayOnPageAfterHandlingBeforeUnload to the value passed in
from _javascript_.
* DumpRenderTree/chromium/LayoutTestController.h:
(LayoutTestController::shouldStayOnPageAfterHandlingBeforeUnload):
* DumpRenderTree/chromium/WebViewHost.cpp:
(WebViewHost::runModalBeforeUnloadDialog): Add the correct logging and
return the inverse of
LayoutTestController::shouldStayOnPageAfterHandlingBeforeUnload().
* DumpRenderTree/mac/UIDelegate.mm:
(-[UIDelegate webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:]): Ditto.
* DumpRenderTree/win/UIDelegate.cpp:
(UIDelegate::runBeforeUnloadConfirmPanelWithMessage): Ditto.
* WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl:
Define setShouldStayOnPageAfterHandlingBeforeUnload().
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::postNewBeforeUnloadReturnValue): Post a message
to the Test Controller telling it what value it should return in its
onbeforeunload UI delegate.
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
* WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
(WTR::LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload):
Call InjectedBundle::postNewBeforeUnloadReturnValue().
* WebKitTestRunner/InjectedBundle/LayoutTestController.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::TestController): Initialize
m_beforeUnloadReturnValue to true.
(WTR::runBeforeUnloadConfirmPanel): Add the correct logging and return
the value of TestController::beforeUnloadReturnValue().
(WTR::TestController::resetStateToConsistentValues): Reset
m_beforeUnloadReturnValue to true.
* WebKitTestRunner/TestController.h:
(WTR::TestController::beforeUnloadReturnValue):
(WTR::TestController::setBeforeUnloadReturnValue):
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Handle the
message posted from the injected bundle by retrieving the message body
as a WKBoolean and calling TestController::setBeforeUnloadReturnValue().

LayoutTests:

* fast/loader/form-submission-after-beforeunload-cancel-expected.txt: Added.
* fast/loader/form-submission-after-beforeunload-cancel.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92981 => 92982)


--- trunk/LayoutTests/ChangeLog	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/LayoutTests/ChangeLog	2011-08-12 19:56:56 UTC (rev 92982)
@@ -1,3 +1,13 @@
+2011-08-12  Andy Estes  <[email protected]>
+
+        Cancel in onbeforeunload dialog sometime causes a button to stop working.
+        https://bugs.webkit.org/show_bug.cgi?id=26211
+
+        Reviewed by Alexey Proskuryakov.
+
+        * fast/loader/form-submission-after-beforeunload-cancel-expected.txt: Added.
+        * fast/loader/form-submission-after-beforeunload-cancel.html: Added.
+
 2011-08-12  David Hyatt  <[email protected]>
 
         https://bugs.webkit.org/show_bug.cgi?id=66130

Added: trunk/LayoutTests/fast/loader/form-submission-after-beforeunload-cancel-expected.txt (0 => 92982)


--- trunk/LayoutTests/fast/loader/form-submission-after-beforeunload-cancel-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/loader/form-submission-after-beforeunload-cancel-expected.txt	2011-08-12 19:56:56 UTC (rev 92982)
@@ -0,0 +1,3 @@
+CONFIRM NAVIGATION: Click 'Stay on Page'
+CONFIRM NAVIGATION: Click 'Leave Page'
+PASS

Added: trunk/LayoutTests/fast/loader/form-submission-after-beforeunload-cancel.html (0 => 92982)


--- trunk/LayoutTests/fast/loader/form-submission-after-beforeunload-cancel.html	                        (rev 0)
+++ trunk/LayoutTests/fast/loader/form-submission-after-beforeunload-cancel.html	2011-08-12 19:56:56 UTC (rev 92982)
@@ -0,0 +1,43 @@
+<script>
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone();
+    layoutTestController.dumpAsText();
+    layoutTestController.setShouldStayOnPageAfterHandlingBeforeUnload(true);
+}
+
+_confirmationDialogDisplayedOnce = false;
+
+window.addEventListener("beforeunload", function() {
+
+    if (window._confirmationDialogDisplayedOnce)
+        return "Click 'Leave Page'";
+
+    window.setTimeout(function() {
+        if (window.layoutTestController)
+            layoutTestController.setShouldStayOnPageAfterHandlingBeforeUnload(false);
+
+        window.setTimeout(function() {
+            document.getElementById("console").innerHTML = "FAIL";
+            if (window.layoutTestController)
+                layoutTestController.notifyDone();
+        }, 0);
+
+        document.forms[0].submit();
+    }, 0);
+    
+    window._confirmationDialogDisplayedOnce = true;
+    
+    return "Click 'Stay on Page'";
+});
+</script>
+
+<p>This tests that submitting a form a second time after canceling the first submission in a onbeforeunload handler is allowed. To test manually, follow the instructions in the _javascript_ confirmation dialogs.</p>
+
+<div id="console"></div>
+
+<form action="" method="POST">
+</form>
+
+<script>
+document.forms[0].submit();
+</script>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (92981 => 92982)


--- trunk/Source/WebCore/ChangeLog	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Source/WebCore/ChangeLog	2011-08-12 19:56:56 UTC (rev 92982)
@@ -1,3 +1,23 @@
+2011-08-12  Andy Estes  <[email protected]>
+
+        Cancel in onbeforeunload dialog sometime causes a button to stop working.
+        https://bugs.webkit.org/show_bug.cgi?id=26211
+
+        Reviewed by Alexey Proskuryakov.
+
+        Test: fast/loader/form-submission-after-beforeunload-cancel.html
+
+        If an onbeforeunload handler cancels a navigation that was triggered by
+        a form submission, WebCore's multiple form submission protection
+        prevents the form from being submitted a second time even though no
+        first submission actually took place. Fix this by clearing
+        m_submittedFormURL if the onbeforeunload handler cancels the load. This
+        allows the submission to be retried.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::shouldClose): Set m_submittedFormURL to KURL()
+        if shouldClose() will return false.
+
 2011-08-12  David Hyatt  <[email protected]>
 
         https://bugs.webkit.org/show_bug.cgi?id=66130

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (92981 => 92982)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -2732,6 +2732,9 @@
             shouldClose = true;
     }
 
+    if (!shouldClose)
+        m_submittedFormURL = KURL();
+
     return shouldClose;
 }
 

Modified: trunk/Tools/ChangeLog (92981 => 92982)


--- trunk/Tools/ChangeLog	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/ChangeLog	2011-08-12 19:56:56 UTC (rev 92982)
@@ -1,3 +1,68 @@
+2011-08-12  Andy Estes  <[email protected]>
+
+        Cancel in onbeforeunload dialog sometime causes a button to stop working.
+        https://bugs.webkit.org/show_bug.cgi?id=26211
+
+        Reviewed by Alexey Proskuryakov.
+
+        Implement a new LayoutTestController method that a test can call to set
+        the return value of DumpRenderTree's beforeunload UI delegate.
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (LayoutTestController::LayoutTestController): Initialize
+        m_shouldStayOnPageAfterHandlingBeforeUnload.
+        (setShouldStayOnPageAfterHandlingBeforeUnloadCallback): Call
+        LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload().
+        (LayoutTestController::staticFunctions): Register
+        'setShouldStayOnPageAfterHandlingBeforeUnload' as a static function.
+        * DumpRenderTree/LayoutTestController.h: 
+        (LayoutTestController::shouldStayOnPageAfterHandlingBeforeUnload):
+        (LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload):
+        * DumpRenderTree/chromium/LayoutTestController.cpp:
+        (LayoutTestController::LayoutTestController): Initialize
+        m_shouldStayOnPageAfterHandlingBeforeUnload and bind
+        'setShouldStayOnPageAfterHandlingBeforeUnload' to its c++ setter.
+        (LayoutTestController::reset): Reset
+        m_shouldStayOnPageAfterHandlingBeforeUnload to false.
+        (LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload):
+        Set m_shouldStayOnPageAfterHandlingBeforeUnload to the value passed in
+        from _javascript_.
+        * DumpRenderTree/chromium/LayoutTestController.h:
+        (LayoutTestController::shouldStayOnPageAfterHandlingBeforeUnload):
+        * DumpRenderTree/chromium/WebViewHost.cpp:
+        (WebViewHost::runModalBeforeUnloadDialog): Add the correct logging and
+        return the inverse of
+        LayoutTestController::shouldStayOnPageAfterHandlingBeforeUnload().
+        * DumpRenderTree/mac/UIDelegate.mm:
+        (-[UIDelegate webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:]): Ditto.
+        * DumpRenderTree/win/UIDelegate.cpp:
+        (UIDelegate::runBeforeUnloadConfirmPanelWithMessage): Ditto.
+        * WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl:
+        Define setShouldStayOnPageAfterHandlingBeforeUnload().
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::postNewBeforeUnloadReturnValue): Post a message
+        to the Test Controller telling it what value it should return in its
+        onbeforeunload UI delegate.
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+        * WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
+        (WTR::LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload):
+        Call InjectedBundle::postNewBeforeUnloadReturnValue().
+        * WebKitTestRunner/InjectedBundle/LayoutTestController.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::TestController): Initialize
+        m_beforeUnloadReturnValue to true.
+        (WTR::runBeforeUnloadConfirmPanel): Add the correct logging and return
+        the value of TestController::beforeUnloadReturnValue().
+        (WTR::TestController::resetStateToConsistentValues): Reset
+        m_beforeUnloadReturnValue to true.
+        * WebKitTestRunner/TestController.h:
+        (WTR::TestController::beforeUnloadReturnValue):
+        (WTR::TestController::setBeforeUnloadReturnValue):
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Handle the
+        message posted from the injected bundle by retrieving the message body
+        as a WKBoolean and calling TestController::setBeforeUnloadReturnValue().
+
 2011-08-12  Sam Weinig  <[email protected]>
 
         Move compiler specific macros to their own header

Modified: trunk/Tools/DumpRenderTree/LayoutTestController.cpp (92981 => 92982)


--- trunk/Tools/DumpRenderTree/LayoutTestController.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/LayoutTestController.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -87,6 +87,7 @@
     , m_isPrinting(false)
     , m_deferMainResourceDataLoad(true)
     , m_shouldPaintBrokenImage(true)
+    , m_shouldStayOnPageAfterHandlingBeforeUnload(false)
     , m_testPathOrURL(testPathOrURL)
     , m_expectedPixelHash(expectedPixelHash)
 {
@@ -2140,6 +2141,16 @@
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef setShouldStayOnPageAfterHandlingBeforeUnloadCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    
+    if (argumentCount == 1)
+        controller->setShouldStayOnPageAfterHandlingBeforeUnload(JSValueToBoolean(context, arguments[0]));
+
+    return JSValueMakeUndefined(context);
+}
+
 // Static Values
 
 static JSValueRef getGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
@@ -2414,6 +2425,7 @@
         { "setShouldPaintBrokenImage", setShouldPaintBrokenImageCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setTextDirection", setTextDirectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "allowRoundingHacks", allowRoundingHacksCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "setShouldStayOnPageAfterHandlingBeforeUnload", setShouldStayOnPageAfterHandlingBeforeUnloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { 0, 0, 0 }
     };
 

Modified: trunk/Tools/DumpRenderTree/LayoutTestController.h (92981 => 92982)


--- trunk/Tools/DumpRenderTree/LayoutTestController.h	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/LayoutTestController.h	2011-08-12 19:56:56 UTC (rev 92982)
@@ -307,6 +307,9 @@
     void evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script);
     void allowRoundingHacks();
 
+    bool shouldStayOnPageAfterHandlingBeforeUnload() const { return m_shouldStayOnPageAfterHandlingBeforeUnload; }
+    void setShouldStayOnPageAfterHandlingBeforeUnload(bool shouldStayOnPageAfterHandlingBeforeUnload) { m_shouldStayOnPageAfterHandlingBeforeUnload = shouldStayOnPageAfterHandlingBeforeUnload; }
+
     void setPOSIXLocale(JSStringRef locale);
 
     void setWebViewEditable(bool);
@@ -398,6 +401,7 @@
     bool m_isPrinting;
     bool m_deferMainResourceDataLoad;
     bool m_shouldPaintBrokenImage;
+    bool m_shouldStayOnPageAfterHandlingBeforeUnload;
 
     std::string m_authenticationUsername;
     std::string m_authenticationPassword; 

Modified: trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp (92981 => 92982)


--- trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -77,6 +77,7 @@
     , m_deferMainResourceDataLoad(false)
     , m_showDebugLayerTree(false)
     , m_workQueue(this)
+    , m_shouldStayOnPageAfterHandlingBeforeUnload(false)
 {
 
     // Initialize the map that associates methods of this class with the names
@@ -219,6 +220,7 @@
     bindMethod("deleteLocalStorageForOrigin", &LayoutTestController::deleteLocalStorageForOrigin);
     bindMethod("observeStorageTrackerNotifications", &LayoutTestController::observeStorageTrackerNotifications);
     bindMethod("syncLocalStorage", &LayoutTestController::syncLocalStorage);
+    bindMethod("setShouldStayOnPageAfterHandlingBeforeUnload", &LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload);
     
     // The fallback method is called when an unknown method is invoked.
     bindFallbackMethod(&LayoutTestController::fallbackMethod);
@@ -611,6 +613,7 @@
         m_closeRemainingWindows = true;
     m_workQueue.reset();
     m_taskList.revokeAll();
+    m_shouldStayOnPageAfterHandlingBeforeUnload = false;
 }
 
 void LayoutTestController::locationChangeDone()
@@ -1806,6 +1809,14 @@
     // Not Implemented
 }
 
+void LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload(const CppArgumentList& arguments, CppVariant* result)
+{
+    if (arguments.size() == 1 && arguments[0].isBool())
+        m_shouldStayOnPageAfterHandlingBeforeUnload = arguments[0].toBoolean();
+
+    result->setNull();
+}
+
 void LayoutTestController::setPluginsEnabled(const CppArgumentList& arguments, CppVariant* result)
 {
     if (arguments.size() > 0 && arguments[0].isBool()) {

Modified: trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h (92981 => 92982)


--- trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h	2011-08-12 19:56:56 UTC (rev 92982)
@@ -394,6 +394,8 @@
     // Changes the direction of the focused element.
     void setTextDirection(const CppArgumentList&, CppVariant*);
 
+    void setShouldStayOnPageAfterHandlingBeforeUnload(const CppArgumentList&, CppVariant*);
+
 public:
     // The following methods are not exposed to _javascript_.
     void setWorkQueueFrozen(bool frozen) { m_workQueue.setFrozen(frozen); }
@@ -455,6 +457,8 @@
 
     TaskList* taskList() { return &m_taskList; }
 
+    bool shouldStayOnPageAfterHandlingBeforeUnload() const { return m_shouldStayOnPageAfterHandlingBeforeUnload; }
+
 private:
     friend class WorkItem;
     friend class WorkQueue;
@@ -623,6 +627,8 @@
 
     // WAV audio data is stored here.
     WebKit::WebArrayBufferView m_audioData;
+
+    bool m_shouldStayOnPageAfterHandlingBeforeUnload;
 };
 
 #endif // LayoutTestController_h

Modified: trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp (92981 => 92982)


--- trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -481,9 +481,10 @@
     return true;
 }
 
-bool WebViewHost::runModalBeforeUnloadDialog(WebFrame*, const WebString&)
+bool WebViewHost::runModalBeforeUnloadDialog(WebFrame*, const WebString& message)
 {
-    return true; // Allow window closure.
+    printf("CONFIRM NAVIGATION: %s\n", message.utf8().data());
+    return !layoutTestController()->shouldStayOnPageAfterHandlingBeforeUnload();
 }
 
 void WebViewHost::showContextMenu(WebFrame*, const WebContextMenuData& contextMenuData)

Modified: trunk/Tools/DumpRenderTree/mac/UIDelegate.mm (92981 => 92982)


--- trunk/Tools/DumpRenderTree/mac/UIDelegate.mm	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/mac/UIDelegate.mm	2011-08-12 19:56:56 UTC (rev 92982)
@@ -107,7 +107,8 @@
 {
     if (!done)
         printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]);
-    return YES;
+    
+    return !gLayoutTestController->shouldStayOnPageAfterHandlingBeforeUnload();
 }
 
 

Modified: trunk/Tools/DumpRenderTree/win/UIDelegate.cpp (92981 => 92982)


--- trunk/Tools/DumpRenderTree/win/UIDelegate.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/DumpRenderTree/win/UIDelegate.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -465,14 +465,15 @@
 
 HRESULT STDMETHODCALLTYPE UIDelegate::runBeforeUnloadConfirmPanelWithMessage( 
     /* [in] */ IWebView* /*sender*/,
-    /* [in] */ BSTR /*message*/,
+    /* [in] */ BSTR message,
     /* [in] */ IWebFrame* /*initiatedByFrame*/,
     /* [retval][out] */ BOOL* result)
 {
     if (!result)
         return E_POINTER;
-    *result = TRUE;
-    return E_NOTIMPL;
+    printf("CONFIRM NAVIGATION: %S\n", message ? message : L"");
+    *result = !gLayoutTestController->shouldStayOnPageAfterHandlingBeforeUnload();
+    return S_OK;
 }
 
 HRESULT STDMETHODCALLTYPE UIDelegate::webViewAddMessageToConsole( 

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl	2011-08-12 19:56:56 UTC (rev 92982)
@@ -112,6 +112,8 @@
         void setTextDirection(in DOMString direction);
 
         void setWillSendRequestReturnsNull(in boolean flag);
+        
+        void setShouldStayOnPageAfterHandlingBeforeUnload(in boolean flag);
     };
 
 }

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -232,5 +232,12 @@
     for (size_t i = 0; i < size; ++i)
         m_pages[i]->dumpBackForwardList();
 }
+    
+void InjectedBundle::postNewBeforeUnloadReturnValue(bool value)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("BeforeUnloadReturnValue"));
+    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
+    WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
+}
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2011-08-12 19:56:56 UTC (rev 92982)
@@ -71,6 +71,8 @@
     void setTopLoadingFrame(WKBundleFrameRef frame) { m_topLoadingFrame = frame; }
 
     bool shouldDumpPixels() const { return m_dumpPixels; }
+    
+    void postNewBeforeUnloadReturnValue(bool);
 
 private:
     InjectedBundle();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -493,5 +493,10 @@
     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
     return WKBundleFrameSetTextDirection(mainFrame, toWK(direction).get());
 }
+    
+void LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload(bool shouldStayOnPage)
+{
+    InjectedBundle::shared().postNewBeforeUnloadReturnValue(!shouldStayOnPage);
+}
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.h (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.h	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.h	2011-08-12 19:56:56 UTC (rev 92982)
@@ -168,6 +168,8 @@
 
     void setTextDirection(JSStringRef);
 
+    void setShouldStayOnPageAfterHandlingBeforeUnload(bool);
+
 private:
     static const double waitToDumpWatchdogTimerInterval;
 

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -68,6 +68,7 @@
     , m_shortTimeout(defaultShortTimeout)
     , m_didPrintWebProcessCrashedMessage(false)
     , m_shouldExitWhenWebProcessCrashes(true)
+    , m_beforeUnloadReturnValue(true)
 {
     initialize(argc, argv);
     controller = this;
@@ -105,8 +106,9 @@
 
 static bool runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo)
 {
-    printf("%s\n", toSTD(message).c_str());
-    return true;
+    TestController* testController = static_cast<TestController*>(const_cast<void*>(clientInfo));
+    printf("CONFIRM NAVIGATION: %s\n", toSTD(message).c_str());
+    return testController->beforeUnloadReturnValue();
 }
 
 static unsigned long long exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKStringRef, WKStringRef, unsigned long long, unsigned long long, unsigned long long, unsigned long long, const void*)
@@ -358,6 +360,8 @@
 bool TestController::resetStateToConsistentValues()
 {
     m_state = Resetting;
+    
+    m_beforeUnloadReturnValue = true;
 
     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset"));
     WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate());

Modified: trunk/Tools/WebKitTestRunner/TestController.h (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/TestController.h	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2011-08-12 19:56:56 UTC (rev 92982)
@@ -56,6 +56,9 @@
     enum TimeoutDuration { ShortTimeout, LongTimeout };
     void runUntil(bool& done, TimeoutDuration);
     void notifyDone();
+    
+    bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
+    void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
 
 private:
     void initialize(int argc, const char* argv[]);
@@ -121,6 +124,8 @@
 
     bool m_didPrintWebProcessCrashedMessage;
     bool m_shouldExitWhenWebProcessCrashes;
+    
+    bool m_beforeUnloadReturnValue;
 };
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (92981 => 92982)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2011-08-12 19:53:24 UTC (rev 92981)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2011-08-12 19:56:56 UTC (rev 92982)
@@ -238,6 +238,13 @@
         TestController::shared().notifyDone();
         return;
     }
+    
+    if (WKStringIsEqualToUTF8CString(messageName, "BeforeUnloadReturnValue")) {
+        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
+        WKBooleanRef beforeUnloadReturnValue = static_cast<WKBooleanRef>(messageBody);
+        TestController::shared().setBeforeUnloadReturnValue(WKBooleanGetValue(beforeUnloadReturnValue));
+        return;
+    }
 
     ASSERT_NOT_REACHED();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to