WebKit.ResponsivenessTimerCrash sometimes fails.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Jul 2018 03:45:50 +0000 (03:45 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Jul 2018 03:45:50 +0000 (03:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187314

Reviewed by Tim Horton.

Actually unregister observers from objects we're about to destroy before destroying them.

* TestWebKitAPI/Tests/WebKit/ResponsivenessTimerCrash.mm:
(-[ResponsivenessTimerObserver observeValueForKeyPath:ofObject:change:context:]):

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

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit/ResponsivenessTimerCrash.mm

index 60379e0..18c57ed 100644 (file)
@@ -1,3 +1,15 @@
+2018-07-03  Brady Eidson  <beidson@apple.com>
+
+        WebKit.ResponsivenessTimerCrash sometimes fails.
+        https://bugs.webkit.org/show_bug.cgi?id=187314
+
+        Reviewed by Tim Horton.
+
+        Actually unregister observers from objects we're about to destroy before destroying them.
+
+        * TestWebKitAPI/Tests/WebKit/ResponsivenessTimerCrash.mm:
+        (-[ResponsivenessTimerObserver observeValueForKeyPath:ofObject:change:context:]): 
+
 2018-07-03  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         update-webkitgtk-flatpak fails if running with python2
index d8c22e1..2d90685 100644 (file)
 #import "TestWKWebView.h"
 #import <WebKit/WKPagePrivateMac.h>
 #import <WebKit/WKWebViewPrivate.h>
+#import <wtf/HashSet.h>
 #import <wtf/RetainPtr.h>
-#import <wtf/Vector.h>
 
 static bool didBecomeUnresponsive;
 static RetainPtr<TestWKWebView> webView;
-static Vector<RetainPtr<id>> observableStates;
+static HashSet<RetainPtr<id>> observableStates;
 static bool webViewSeen;
 
 @interface ResponsivenessTimerObserver : NSObject
@@ -49,10 +49,16 @@ static bool webViewSeen;
 {
     if (object == webView.get())
         webViewSeen = true;
+    else {
+        [object removeObserver:self forKeyPath:@"_webProcessIsResponsive"];
+        observableStates.remove(object);
+    }
+
+    if (!observableStates.isEmpty()) {
+        [observableStates.begin()->get() removeObserver:self forKeyPath:@"_webProcessIsResponsive"];
+        observableStates.remove(observableStates.begin());
+    }
 
-    if (!observableStates.isEmpty())
-        observableStates.removeLast();
-    
     if (webViewSeen && observableStates.isEmpty())
         didBecomeUnresponsive = true;
 }
@@ -71,10 +77,10 @@ TEST(WebKit, ResponsivenessTimerCrash)
 
         auto pageRef = [webView _pageRefForTransitionToWKWebView];
         
-        for (size_t i = 0; i < 10; ++i) {
+        for (size_t i = 0; i < 50; ++i) {
             RetainPtr<id> observableState = adoptNS(WKPageCreateObservableState(pageRef));
             [observableState.get() addObserver:observer.get() forKeyPath:@"_webProcessIsResponsive" options:0 context:nullptr];
-            observableStates.append(WTFMove(observableState));
+            observableStates.add(WTFMove(observableState));
         }
 
         [webView synchronouslyLoadHTMLString:@"<script>document.addEventListener('keydown', function(){while(1){}});</script>"];
@@ -82,6 +88,8 @@ TEST(WebKit, ResponsivenessTimerCrash)
     }
     
     Util::run(&didBecomeUnresponsive);
+
+    [webView removeObserver:observer.get() forKeyPath:@"_webProcessIsResponsive"];
 }
 
 } // namespace TestWebKitAPI