diff options
author | joepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | 2013-01-28 22:38:26 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-08 17:35:16 +0200 |
commit | 412ec5284b300668101a1db137e08a729008d164 (patch) | |
tree | be76826e8200e642448c585bad98fc74e60486d9 /Tools/TestWebKitAPI | |
parent | 0dd9e57645d192fca388abe8f04e93ca7bef6ad6 (diff) | |
download | qtwebkit-412ec5284b300668101a1db137e08a729008d164.tar.gz |
[Mac] Update PageVisibilityState when WebView is hidden / visible
https://bugs.webkit.org/show_bug.cgi?id=107509
Source/WebKit/mac:
Reviewed by NOBODY (OOPS!).
* WebView/WebView.mm:
* WebView/WebViewPrivate.h:
(-[WebView _commonInitializationWithFrameName:groupName:]):
Set the initial visibility of the page.
(-[WebView addWindowObserversForWindow:]):
(-[WebView removeWindowObservers]):
(-[WebView _isViewVisible]):
(-[WebView _updateVisibilityState]):
(-[WebView viewDidMoveToWindow]):
(-[WebView _windowVisibilityChanged:]):
Update visibility state in the same ways WK2 does. This involves
listening for some new NSWindow delegates.
Tools:
Add a test that PageVisibility of WK1 WebViews and WK2 WKViews
automatically changes between hidden and visible as the view is added
and removed from window, or when it is in a window that changes
visibility, for instance by minimizing / deminimizing.
Reviewed by NOBODY (OOPS!).
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html: Added.
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm: Added.
(-[PageVisibilityStateDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]):
(runJavaScriptAlert):
(PageVisibilityStateWithWindowChanges):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::initializeView):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::deinitializeView):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::runTest):
(TestWebKitAPI::TEST_F):
Test visibility state of a page in a WebView/WKView with different window states.
* TestWebKitAPI/mac/WebKitAgnosticTest.h:
* TestWebKitAPI/mac/WebKitAgnosticTest.mm:
(TestWebKitAPI::WebKitAgnosticTest::deinitializeView):
(TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test):
(TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test):
Add a WK1 and WK2 deinitializeView to balance initializeView.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@141011 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Change-Id: Ie9ef191e55f69ee32b01a0e7220820be038ac8a4
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Tools/TestWebKitAPI')
6 files changed, 180 insertions, 1 deletions
diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj index cfda4b91d..4c0925f17 100644 --- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj +++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj @@ -96,6 +96,8 @@ 9B4F8FA4159D52B1002D9F94 /* HTMLCollectionNamedItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */; }; 9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; }; A51B650916ADF9B1007AA5D9 /* PageVisibilityState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A51B650816ADF9B1007AA5D9 /* PageVisibilityState.cpp */; }; + A57A34F016AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm in Sources */ = {isa = PBXBuildFile; fileRef = A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */; }; + A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.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 */; }; @@ -235,6 +237,7 @@ 93AF4ED11506F130007FD57E /* lots-of-images.html in Copy Resources */, 930AD402150698D00067970F /* lots-of-text.html in Copy Resources */, 33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */, + A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */, F6FDDDD614241C6F004F1729 /* push-state.html in Copy Resources */, BCBD3737125ABBEB00D2C29F /* icon.png in Copy Resources */, 1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */, @@ -343,6 +346,8 @@ 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>"; }; A51B650816ADF9B1007AA5D9 /* PageVisibilityState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageVisibilityState.cpp; sourceTree = "<group>"; }; + A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageVisibilityStateWithWindowChanges.mm; sourceTree = "<group>"; }; + A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = PageVisibilityStateWithWindowChanges.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>"; }; @@ -759,6 +764,7 @@ C507E8A614C6545B005D6B3B /* InspectorBar.mm */, E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */, 517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */, + A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */, 3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */, 261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */, 52B8CF9515868CF000281053 /* SetDocumentURI.mm */, @@ -788,6 +794,7 @@ E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */, 517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */, C07E6CB113FD738A0038B22B /* devicePixelRatio.html */, + A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */, C540F783152E5A7800A40C8C /* verboseMarkup.html */, A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */, ); @@ -977,6 +984,7 @@ BC90977A125571AB00083756 /* PageLoadBasic.cpp in Sources */, BC2D004912A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */, A51B650916ADF9B1007AA5D9 /* PageVisibilityState.cpp in Sources */, + A57A34F016AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm in Sources */, 52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */, BC575BC0126F5752006F0F12 /* PlatformUtilities.cpp in Sources */, BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */, diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp index 00c79ce3a..8aa7495b5 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp @@ -100,7 +100,7 @@ TEST(WebKit2, PageVisibilityState) WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); // Pass the PlatformWebView webView on as the context of the evals, so we can continue to eval on it. - PlatformWebView webView(context.get()); + PlatformWebView webView(context.get()); setPageVisibilityStateWithEvalContinuation(&webView, kWKPageVisibilityStateVisible, didRunStep1StateChangeVisibleToHidden); Util::run(&testDone); diff --git a/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html b/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html new file mode 100644 index 000000000..8a2bdc6a2 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html @@ -0,0 +1,6 @@ +<script> +document.addEventListener("webkitvisibilitychange", function(event) { + // Send a signal to the test controller via alert. + alert('webkitvisibilitychange'); +}); +</script> diff --git a/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm b/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm new file mode 100644 index 000000000..cec138cb7 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2013 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. + */ + +#import "config.h" +#import "JavaScriptTest.h" +#import "Test.h" +#import "WebKitAgnosticTest.h" +#import <WebKit/WebView.h> +#import <WebKit2/WKViewPrivate.h> +#import <wtf/RetainPtr.h> + +static bool didGetPageSignalToContinue; + +// WebKit1 WebUIDelegate + +@interface PageVisibilityStateDelegate : NSObject +@end + +@implementation PageVisibilityStateDelegate + +- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + didGetPageSignalToContinue = true; +} + +@end + +// WebKit2 WKPageUIClient + +static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) +{ + didGetPageSignalToContinue = true; +} + +// WebKitAgnosticTest + +namespace TestWebKitAPI { + +class PageVisibilityStateWithWindowChanges : public WebKitAgnosticTest { +public: + template <typename View> void runTest(View); + + // WebKitAgnosticTest + virtual NSURL *url() const OVERRIDE { return [[NSBundle mainBundle] URLForResource:@"PageVisibilityStateWithWindowChanges" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; } + virtual void didLoadURL(WebView *webView) OVERRIDE { runTest(webView); } + virtual void didLoadURL(WKView *wkView) OVERRIDE { runTest(wkView); } + + // Setup and teardown the UIDelegate which gets alert() signals from the page. + virtual void initializeView(WebView *) OVERRIDE; + virtual void initializeView(WKView *) OVERRIDE; + virtual void teardownView(WebView *) OVERRIDE; + virtual void teardownView(WKView *) OVERRIDE; +}; + +void PageVisibilityStateWithWindowChanges::initializeView(WebView *webView) +{ + // Released in teardownView. + webView.UIDelegate = [[PageVisibilityStateDelegate alloc] init]; +} + +void PageVisibilityStateWithWindowChanges::teardownView(WebView *webView) +{ + id uiDelegate = webView.UIDelegate; + webView.UIDelegate = nil; + [uiDelegate release]; +} + +void PageVisibilityStateWithWindowChanges::initializeView(WKView *wkView) +{ + WKPageUIClient uiClient; + memset(&uiClient, 0, sizeof(uiClient)); + uiClient.version = 0; + uiClient.clientInfo = 0; + uiClient.runJavaScriptAlert = runJavaScriptAlert; + WKPageSetPageUIClient(wkView.pageRef, &uiClient); +} + +void PageVisibilityStateWithWindowChanges::teardownView(WKView *wkView) +{ + // We do not need to teardown the WKPageUIClient. +} + +template <typename View> +void PageVisibilityStateWithWindowChanges::runTest(View view) +{ + // This WebView does not have a window and superview. PageVisibility should be "hidden". + EXPECT_NULL([view window]); + EXPECT_NULL([view superview]); + EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden"); + + // Add it to a non-visible window. PageVisibility should still be "hidden". + RetainPtr<NSWindow> window(AdoptNS, [[NSWindow alloc] initWithContentRect:view.frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]); + [window.get().contentView addSubview:view]; + EXPECT_NOT_NULL([view window]); + EXPECT_NOT_NULL([view superview]); + EXPECT_FALSE([window.get() isVisible]); + EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden"); + + // Make the window visible. PageVisibility should become "visible". + didGetPageSignalToContinue = false; + [window.get() makeKeyAndOrderFront:nil]; + EXPECT_TRUE([window.get() isVisible]); + Util::run(&didGetPageSignalToContinue); + EXPECT_JS_EQ(view, "document.webkitVisibilityState", "visible"); + + // Minimize the window. PageVisibility should become "hidden". + didGetPageSignalToContinue = false; + [window.get() miniaturize:nil]; + Util::run(&didGetPageSignalToContinue); + EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden"); + + // Deminimize the window. PageVisibility should become "visible". + didGetPageSignalToContinue = false; + [window.get() deminiaturize:nil]; + Util::run(&didGetPageSignalToContinue); + EXPECT_JS_EQ(view, "document.webkitVisibilityState", "visible"); + + // Remove the WebView from its superview. PageVisibility should become "hidden". + didGetPageSignalToContinue = false; + [view removeFromSuperview]; + EXPECT_NULL([view window]); + EXPECT_NULL([view superview]); + EXPECT_TRUE([window.get() isVisible]); + Util::run(&didGetPageSignalToContinue); + EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden"); +} + +TEST_F(PageVisibilityStateWithWindowChanges, WebKit) +{ + runWebKit1Test(); +} + +TEST_F(PageVisibilityStateWithWindowChanges, WebKit2) +{ + runWebKit1Test(); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h b/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h index 9e5bf7ca7..c25c4b4cf 100644 --- a/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h +++ b/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h @@ -58,6 +58,9 @@ private: virtual void initializeView(WebView *) { } virtual void initializeView(WKView *) { } + virtual void teardownView(WebView *) { } + virtual void teardownView(WKView *) { } + bool didFinishLoad; }; diff --git a/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm b/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm index 60caca5ad..ce25a84da 100644 --- a/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm +++ b/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm @@ -91,6 +91,7 @@ void WebKitAgnosticTest::runWebKit1Test() loadURL(webView.get(), url()); waitForLoadToFinish(); didLoadURL(webView.get()); + teardownView(webView.get()); } void WebKitAgnosticTest::runWebKit2Test() @@ -104,6 +105,7 @@ void WebKitAgnosticTest::runWebKit2Test() loadURL(view.get(), url()); waitForLoadToFinish(); didLoadURL(view.get()); + teardownView(view.get()); } void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url) |