Title: [217574] trunk/Tools
Revision
217574
Author
[email protected]
Date
2017-05-30 14:12:53 -0700 (Tue, 30 May 2017)

Log Message

Add unit test for WebKit2 C SPI runBeforeUnloadConfirmPanel()
https://bugs.webkit.org/show_bug.cgi?id=172671

Reviewed by Alex Christensen.

We should add a unit test to ensure we do not regress the WKPageUIClient runBeforeUnloadConfirmPanel() callback.
For completeness, the callback runBeforeUnloadConfirmPanel() existed since inception of WKPageUIClient (WKPageUIClientV0).

* TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp:
(TestWebKitAPI::analyzeDialogArguments): Test the runBeforeUnloadConfirmPanel() callback last as we need
to trigger a navigation to test it.
(TestWebKitAPI::runBeforeUnloadConfirmPanel): Added.
(TestWebKitAPI::createNewPage): Wire up the runBeforeUnloadConfirmPanel callback.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (217573 => 217574)


--- trunk/Tools/ChangeLog	2017-05-30 21:08:18 UTC (rev 217573)
+++ trunk/Tools/ChangeLog	2017-05-30 21:12:53 UTC (rev 217574)
@@ -1,3 +1,19 @@
+2017-05-30  Daniel Bates  <[email protected]>
+
+        Add unit test for WebKit2 C SPI runBeforeUnloadConfirmPanel()
+        https://bugs.webkit.org/show_bug.cgi?id=172671
+
+        Reviewed by Alex Christensen.
+
+        We should add a unit test to ensure we do not regress the WKPageUIClient runBeforeUnloadConfirmPanel() callback.
+        For completeness, the callback runBeforeUnloadConfirmPanel() existed since inception of WKPageUIClient (WKPageUIClientV0).
+
+        * TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp:
+        (TestWebKitAPI::analyzeDialogArguments): Test the runBeforeUnloadConfirmPanel() callback last as we need
+        to trigger a navigation to test it.
+        (TestWebKitAPI::runBeforeUnloadConfirmPanel): Added.
+        (TestWebKitAPI::createNewPage): Wire up the runBeforeUnloadConfirmPanel callback.
+
 2017-05-30  Jonathan Bedard  <[email protected]>
 
         webkitpy: Start servers before setting-up for testing

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp (217573 => 217574)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp	2017-05-30 21:08:18 UTC (rev 217573)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/ModalAlertsSPI.cpp	2017-05-30 21:12:53 UTC (rev 217574)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,9 +38,12 @@
 
 static bool done;
 static unsigned dialogsSeen;
-static const unsigned dialogsExpected = 3;
+static const unsigned dialogsExpected = 4;
+static const unsigned dialogsBeforeUnloadConfirmPanel = dialogsExpected - 1;
 
-static void analyzeDialogArguments(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef securityOrigin)
+static std::unique_ptr<PlatformWebView> openedWebView;
+
+static void analyzeDialogArguments(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef securityOrigin = nullptr)
 {
     EXPECT_EQ(page, WKFrameGetPage(frame));
 
@@ -48,15 +51,28 @@
     WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(url.get()));
     EXPECT_WK_STREQ("about:blank", urlString.get());
 
-    WKRetainPtr<WKStringRef> protocol = adoptWK(WKSecurityOriginCopyProtocol(securityOrigin));
-    EXPECT_WK_STREQ("file", protocol.get());
+    if (securityOrigin) {
+        WKRetainPtr<WKStringRef> protocol = adoptWK(WKSecurityOriginCopyProtocol(securityOrigin));
+        EXPECT_WK_STREQ("file", protocol.get());
 
-    WKRetainPtr<WKStringRef> host = adoptWK(WKSecurityOriginCopyHost(securityOrigin));
-    EXPECT_WK_STREQ("", host.get());
+        WKRetainPtr<WKStringRef> host = adoptWK(WKSecurityOriginCopyHost(securityOrigin));
+        EXPECT_WK_STREQ("", host.get());
 
-    EXPECT_EQ(WKSecurityOriginGetPort(securityOrigin), 0);
+        EXPECT_EQ(WKSecurityOriginGetPort(securityOrigin), 0);
+    }
 
-    if (++dialogsSeen == dialogsExpected)
+    ++dialogsSeen;
+
+    // Test beforeunload last as we need to navigate the window to trigger it.
+    if (dialogsSeen == dialogsBeforeUnloadConfirmPanel) {
+        // User interaction is required to show the beforeunload prompt.
+        openedWebView->simulateButtonClick(kWKEventMouseButtonLeftButton, 5, 5, 0);
+        WKRetainPtr<WKURLRef> blankDataURL = adoptWK(WKURLCreateWithUTF8CString("data:text/html"));
+        WKPageLoadURL(page, blankDataURL.get());
+        return;
+    }
+
+    if (dialogsSeen == dialogsExpected)
         done = true;
 }
 
@@ -77,7 +93,11 @@
     return nullptr;
 }
 
-static std::unique_ptr<PlatformWebView> openedWebView;
+static bool runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef, WKFrameRef frame, const void*)
+{
+    analyzeDialogArguments(page, frame);
+    return false;
+}
 
 static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef urlRequest, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo)
 {
@@ -92,6 +112,7 @@
     uiClient.runJavaScriptAlert = runJavaScriptAlert;
     uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
     uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
+    uiClient.runBeforeUnloadConfirmPanel = runBeforeUnloadConfirmPanel;
 
     WKPageSetPageUIClient(openedWebView->page(), &uiClient.base);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to