Windowless WebView not firing JavaScript load event if there is a media element
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Jul 2012 21:26:51 +0000 (21:26 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Jul 2012 21:26:51 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91331

Reviewed by Eric Carlson.

Source/WebCore:

In prepareForLoad we start deferring the load event. If we fall into this
clause where the page can not start loading media we bail, potentially
indefinitely waiting until we can start loading media. Since we can not
be certain this will ever happen, we should stop deferring the page's
load event.

Test: WebKit1.WindowlessWebViewWithMedia TestWebKitAPI test. The only
way this path was reachable right now is on the mac port.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::loadInternal):

Tools:

Test a windowless WebView loading a page with a media element. The load
event should happen on the next spin of the run loop, but we spin check
the page, with a timeout of 250ms.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.html: Added.
* TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.mm: Added.
(-[WindowlessWebViewWithMediaFrameLoadDelegate webView:didFinishLoadForFrame:]):
(TestWebKitAPI::spinLoop): Spin check with timeout. Runs a block each spin to early bail.
(TestWebKitAPI::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.mm [new file with mode: 0644]

index 97f0b3f..970fcff 100644 (file)
@@ -1,3 +1,22 @@
+2012-07-15  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Windowless WebView not firing JavaScript load event if there is a media element
+        https://bugs.webkit.org/show_bug.cgi?id=91331
+
+        Reviewed by Eric Carlson.
+
+        In prepareForLoad we start deferring the load event. If we fall into this
+        clause where the page can not start loading media we bail, potentially
+        indefinitely waiting until we can start loading media. Since we can not
+        be certain this will ever happen, we should stop deferring the page's
+        load event.
+
+        Test: WebKit1.WindowlessWebViewWithMedia TestWebKitAPI test. The only
+        way this path was reachable right now is on the mac port.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::loadInternal):
+
 2012-07-15  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/11875795> REGRESSION (tiled drawing): Page’s scroll bars flash with each character you type in a textarea (affects Wikipedia and YouTube)
index 31d46df..5a4efbe 100644 (file)
@@ -759,6 +759,7 @@ void HTMLMediaElement::loadInternal()
     // If we can't start a load right away, start it later.
     Page* page = document()->page();
     if (pageConsentRequiredForLoad() && page && !page->canStartMedia()) {
+        setShouldDelayLoadEvent(false);
         if (m_isWaitingUntilMediaCanStart)
             return;
         document()->addMediaCanStartListener(this);
index f40f69e..0c5db51 100644 (file)
@@ -1,3 +1,21 @@
+2012-07-15  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Windowless WebView not firing JavaScript load event if there is a media element
+        https://bugs.webkit.org/show_bug.cgi?id=91331
+
+        Reviewed by Eric Carlson.
+
+        Test a windowless WebView loading a page with a media element. The load
+        event should happen on the next spin of the run loop, but we spin check
+        the page, with a timeout of 250ms.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.html: Added.
+        * TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.mm: Added.
+        (-[WindowlessWebViewWithMediaFrameLoadDelegate webView:didFinishLoadForFrame:]):
+        (TestWebKitAPI::spinLoop): Spin check with timeout. Runs a block each spin to early bail.
+        (TestWebKitAPI::TEST):
+
 2012-07-14  Benjamin Poulain  <bpoulain@apple.com>
 
         [Mac] Do not try to update the cache model for every WebPreferences change
index 50045f3..26384e3 100644 (file)
@@ -79,6 +79,8 @@
                9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
                9B4F8FA4159D52B1002D9F94 /* HTMLCollectionNamedItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */; };
                9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; };
+               A5E2027315B2181900C13E14 /* WindowlessWebViewWithMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */; };
+               A5E2027515B21F6E00C13E14 /* WindowlessWebViewWithMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */; };
                A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
                B55F11A01516834F00915916 /* AttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = B55F119F1516834F00915916 /* AttributedString.mm */; };
                B55F11B71517D03300915916 /* attributedStringCustomFont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = B55F11B01517A2C400915916 /* attributedStringCustomFont.html */; };
                                9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */,
                                E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */,
                                517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */,
+                               A5E2027515B21F6E00C13E14 /* WindowlessWebViewWithMedia.html in Copy Resources */,
                                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
                                33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */,
                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
                9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLFormCollectionNamedItem.html; sourceTree = "<group>"; };
                9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; };
                9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLCollectionNamedItem.html; sourceTree = "<group>"; };
+               A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WindowlessWebViewWithMedia.html; sourceTree = "<group>"; };
+               A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowlessWebViewWithMedia.mm; sourceTree = "<group>"; };
                A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedArithmeticOperations.cpp; path = WTF/CheckedArithmeticOperations.cpp; sourceTree = "<group>"; };
                B55F119F1516834F00915916 /* AttributedString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedString.mm; sourceTree = "<group>"; };
                B55F11B01517A2C400915916 /* attributedStringCustomFont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = attributedStringCustomFont.html; sourceTree = "<group>"; };
                                37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */,
                                E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */,
                                51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */,
+                               A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */,
                                C07E6CB113FD738A0038B22B /* devicePixelRatio.html */,
                                C540F783152E5A7800A40C8C /* verboseMarkup.html */,
+                               A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */,
                        );
                        name = Resources;
                        sourceTree = "<group>";
                                F660AA1315A619C9003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp in Sources */,
                                0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
                                261516D615B0E60500A2C201 /* SetAndUpdateCacheModel.mm in Sources */,
+                               A5E2027315B2181900C13E14 /* WindowlessWebViewWithMedia.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.html b/Tools/TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.html
new file mode 100644 (file)
index 0000000..db064fb
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+    We want to make sure the page sends its onload event even if it has media in a windowless WebView.
+    <audio src="invalid.mp3"></audio>
+    <script>
+    var didTriggerLoad = false;
+    window.addEventListener('load', function(event) {
+        didTriggerLoad = true;
+    }, false);
+    </script>
+</body>
+</html>
diff --git a/Tools/TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.mm b/Tools/TestWebKitAPI/Tests/mac/WindowlessWebViewWithMedia.mm
new file mode 100644 (file)
index 0000000..bf593e6
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JavaScriptTest.h"
+#include "PlatformUtilities.h"
+#include <wtf/RetainPtr.h>
+
+
+static bool didFinishLoad;
+
+@interface WindowlessWebViewWithMediaFrameLoadDelegate : NSObject
+@end
+
+@implementation WindowlessWebViewWithMediaFrameLoadDelegate
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+
+@end
+
+
+namespace TestWebKitAPI {
+
+static void spinLoop(NSTimeInterval timeout, BOOL (^block)())
+{
+    if (timeout <= 0)
+        return;
+
+    NSTimeInterval end = [[NSDate date] timeIntervalSinceReferenceDate] + timeout;
+    NSDate *endDate = [NSDate dateWithTimeIntervalSinceReferenceDate:end];
+
+    while (!block()) {
+        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate];
+        if ([[NSDate date] timeIntervalSinceReferenceDate] > end)
+            break;
+    }
+}
+
+TEST(WebKit1, WindowlessWebViewWithMedia)
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+    RetainPtr<WindowlessWebViewWithMediaFrameLoadDelegate> testController(AdoptNS, [WindowlessWebViewWithMediaFrameLoadDelegate new]);
+    webView.get().frameLoadDelegate = testController.get();
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"WindowlessWebViewWithMedia" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    EXPECT_EQ(nil, [webView.get() window]);
+
+    Util::run(&didFinishLoad);    
+
+    spinLoop(0.25, ^{
+        return [[webView.get() stringByEvaluatingJavaScriptFromString:@"window.didTriggerLoad"] isEqualToString:@"true"];
+    });
+
+    EXPECT_JS_EQ(webView.get(), "window.didTriggerLoad", "true");
+
+    [pool drain];
+}
+
+} // namespace TestWebKitAPI