Throw Exception when test doesn't clean up HID Events properly
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Dec 2016 01:10:28 +0000 (01:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Dec 2016 01:10:28 +0000 (01:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166271

Patch by Megan Gardner <megan_gardner@apple.com> on 2016-12-20
Reviewed by Simon Fraser.

Add in a check when UIScriptController is deleted to make sure that the HID event
callback dictionary is empty. If it is not, and a HID event is hit, this will cause
the program to crash without any good information. Crashes are race-y, and will still
happen with malformed test, but the information will be much more helpful.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::checkForClean):
* TestRunnerShared/UIScriptContext/UIScriptContext.cpp:
(UIScriptContext::~UIScriptContext):
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::checkForClean):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/ios/HIDEventGenerator.h:
* WebKitTestRunner/ios/HIDEventGenerator.mm:
(-[HIDEventGenerator checkHIDCallbacksClear]):
* WebKitTestRunner/ios/TestControllerIOS.mm:
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::checkForClean):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210048 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/TestRunnerShared/UIScriptContext/UIScriptContext.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/ios/HIDEventGenerator.h
Tools/WebKitTestRunner/ios/HIDEventGenerator.mm
Tools/WebKitTestRunner/ios/TestControllerIOS.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

index b61d9f8..5a83a60 100644 (file)
@@ -1,3 +1,29 @@
+2016-12-20  Megan Gardner  <megan_gardner@apple.com>
+
+        Throw Exception when test doesn't clean up HID Events properly
+        https://bugs.webkit.org/show_bug.cgi?id=166271
+
+        Reviewed by Simon Fraser.
+
+        Add in a check when UIScriptController is deleted to make sure that the HID event
+        callback dictionary is empty. If it is not, and a HID event is hit, this will cause
+        the program to crash without any good information. Crashes are race-y, and will still
+        happen with malformed test, but the information will be much more helpful. 
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::checkForClean):
+        * TestRunnerShared/UIScriptContext/UIScriptContext.cpp:
+        (UIScriptContext::~UIScriptContext):
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::checkForClean):
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/ios/HIDEventGenerator.h:
+        * WebKitTestRunner/ios/HIDEventGenerator.mm:
+        (-[HIDEventGenerator checkHIDCallbacksClear]):
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::checkForClean):
+
 2016-12-20  Andy Estes  <aestes@apple.com>
 
         [Cocoa] REGRESSION (r209558): Calling decisionHandler multiple times in webView:decidePolicyForNavigationAction:decisionHandler: leads to a crash
index 5df26cf..472dde9 100644 (file)
@@ -37,6 +37,10 @@ extern DumpRenderTreeBrowserView *gWebBrowserView;
 extern DumpRenderTreeWebScrollView *gWebScrollView;
 
 namespace WTR {
+    
+void UIScriptController::checkForOutstandingCallbacks()
+{
+}
 
 void UIScriptController::doAsyncTask(JSValueRef callback)
 {
index 62d4f30..7f3896d 100644 (file)
@@ -52,6 +52,7 @@ UIScriptContext::UIScriptContext(UIScriptContextDelegate& delegate)
 
 UIScriptContext::~UIScriptContext()
 {
+    m_controller->checkForOutstandingCallbacks();
     m_controller->contextDestroyed();
 }
 
index 2b8cbdb..218c5eb 100644 (file)
@@ -37,6 +37,12 @@ UIScriptController::UIScriptController(UIScriptContext& context)
 {
 }
 
+#if !PLATFORM(IOS)
+void UIScriptController::checkForOutstandingCallbacks()
+{
+}
+#endif
+
 void UIScriptController::contextDestroyed()
 {
     m_context = nullptr;
index d1d54be..05dc500 100644 (file)
@@ -47,6 +47,7 @@ public:
     }
 
     void contextDestroyed();
+    void checkForOutstandingCallbacks();
 
     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     
index f3fbd6c..e732785 100644 (file)
@@ -98,6 +98,7 @@ extern NSString* const HIDEventPhaseCanceled;
 - (void)sendEventStream:(NSDictionary *)eventInfo completionBlock:(void (^)(void))completionBlock;
 
 - (void)markerEventReceived:(IOHIDEventRef)event;
+- (BOOL)checkForOutstandingCallbacks;
 
 // Keyboard
 - (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock;
index 1ddb780..73006ac 100644 (file)
@@ -769,6 +769,11 @@ static InterpolationType interpolationFromString(NSString *string)
     }
 }
 
+- (BOOL)checkForOutstandingCallbacks
+{
+    return !([_eventCallbacks count] > 0);
+}
+
 static inline bool shouldWrapWithShiftKeyEventForCharacter(NSString *key)
 {
     if (key.length != 1)
index b4cd287..a1bf6c8 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "TestController.h"
 
+#import "HIDEventGenerator.h"
 #import "PlatformWebView.h"
 #import "TestInvocation.h"
 #import "TestRunnerWKWebView.h"
index 3c3961c..20a1da5 100644 (file)
@@ -53,6 +53,12 @@ static NSDictionary *toNSDictionary(CGRect rect)
         @"height": @(rect.size.height)
     };
 }
+    
+void UIScriptController::checkForOutstandingCallbacks()
+{
+    if (![[HIDEventGenerator sharedHIDEventGenerator] checkForOutstandingCallbacks])
+        [NSException raise:@"WebKitTestRunnerTestProblem" format:@"The test completed before all synthesized events had been handled. Perhaps you're calling notifyDone() too early?"];
+}
 
 void UIScriptController::doAsyncTask(JSValueRef callback)
 {