Title: [141011] trunk
Revision
141011
Author
joep...@webkit.org
Date
2013-01-28 14:38:26 -0800 (Mon, 28 Jan 2013)

Log Message

[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.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (141010 => 141011)


--- trunk/Source/WebKit/mac/ChangeLog	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Source/WebKit/mac/ChangeLog	2013-01-28 22:38:26 UTC (rev 141011)
@@ -1,5 +1,26 @@
 2013-01-28  Joseph Pecoraro  <pecor...@apple.com>
 
+        [Mac] Update PageVisibilityState when WebView is hidden / visible
+        https://bugs.webkit.org/show_bug.cgi?id=107509
+
+        Reviewed by Sam Weinig.
+
+        * 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.
+
+2013-01-28  Joseph Pecoraro  <pecor...@apple.com>
+
         Improve PageVisibility API with enums
         https://bugs.webkit.org/show_bug.cgi?id=107364
 

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (141010 => 141011)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2013-01-28 22:38:26 UTC (rev 141011)
@@ -810,6 +810,8 @@
 
     [self _registerDraggedTypes];
 
+    [self _setVisibilityState:([self _isViewVisible] ? WebPageVisibilityStateVisible : WebPageVisibilityStateHidden) isInitialState:YES];
+
     WebPreferences *prefs = [self preferences];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:)
                                                  name:WebPreferencesChangedInternalNotification object:prefs];
@@ -2623,11 +2625,31 @@
     SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
 }
 
-+(void)_resetOriginAccessWhitelists
++ (void)_resetOriginAccessWhitelists
 {
     SecurityPolicy::resetOriginAccessWhitelists();
 }
 
+- (BOOL)_isViewVisible
+{
+    if (![self window])
+        return false;
+
+    if (![[self window] isVisible])
+        return false;
+
+    if ([self isHiddenOrHasHiddenAncestor])
+        return false;
+
+    return true;
+}
+
+- (void)_updateVisibilityState
+{
+    if (_private && _private->page)
+        [self _setVisibilityState:([self _isViewVisible] ? WebPageVisibilityStateVisible : WebPageVisibilityStateHidden) isInitialState:NO];
+}
+
 - (void)_updateActiveState
 {
     if (_private && _private->page)
@@ -3543,6 +3565,14 @@
             name:windowDidChangeBackingPropertiesNotification object:window];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidChangeScreen:)
             name:NSWindowDidChangeScreenNotification object:window];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:) 
+            name:NSWindowDidMiniaturizeNotification object:window];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
+            name:NSWindowDidDeminiaturizeNotification object:window];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:) 
+            name:@"NSWindowDidOrderOffScreenNotification" object:window];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:) 
+            name:@"_NSWindowDidBecomeVisible" object:window];
     }
 }
 
@@ -3558,6 +3588,14 @@
             name:windowDidChangeBackingPropertiesNotification object:window];
         [[NSNotificationCenter defaultCenter] removeObserver:self
             name:NSWindowDidChangeScreenNotification object:window];
+        [[NSNotificationCenter defaultCenter] removeObserver:self
+            name:NSWindowDidMiniaturizeNotification object:window];
+        [[NSNotificationCenter defaultCenter] removeObserver:self
+            name:NSWindowDidDeminiaturizeNotification object:window];
+        [[NSNotificationCenter defaultCenter] removeObserver:self
+            name:@"NSWindowDidOrderOffScreenNotification" object:window];
+        [[NSNotificationCenter defaultCenter] removeObserver:self
+            name:@"_NSWindowDidBecomeVisible" object:window];
     }
 }
 
@@ -3608,6 +3646,7 @@
     _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
 
     [self _updateActiveState];
+    [self _updateVisibilityState];
 }
 
 - (void)doWindowDidChangeScreen
@@ -3648,6 +3687,11 @@
     }
 }
 
+- (void)_windowVisibilityChanged:(NSNotification *)notification
+{
+    [self _updateVisibilityState];
+}
+
 - (void)_windowWillClose:(NSNotification *)notification
 {
     if ([self shouldCloseWithWindow] && ([self window] == [self hostWindow] || ([self window] && ![self hostWindow]) || (![self window] && [self hostWindow])))

Modified: trunk/Source/WebKit/mac/WebView/WebViewPrivate.h (141010 => 141011)


--- trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2013-01-28 22:38:26 UTC (rev 141011)
@@ -322,6 +322,10 @@
 // Indicates if the WebView is in the midst of a user gesture.
 - (BOOL)_isProcessingUserGesture;
 
+// Determining and updating page visibility state.
+- (BOOL)_isViewVisible;
+- (void)_updateVisibilityState;
+
 // SPI for DumpRenderTree
 - (void)_updateActiveState;
 
@@ -648,9 +652,6 @@
  */
 + (void)_setHTTPPipeliningEnabled:(BOOL)enabled;
 
-// SPI for DumpRenderTree
-- (void)_setVisibilityState:(int)visibilityState isInitialState:(BOOL)isInitialState;
-
 @end
 
 @interface WebView (WebViewPrintingPrivate)

Modified: trunk/Tools/ChangeLog (141010 => 141011)


--- trunk/Tools/ChangeLog	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Tools/ChangeLog	2013-01-28 22:38:26 UTC (rev 141011)
@@ -1,5 +1,36 @@
 2013-01-28  Joseph Pecoraro  <pecor...@apple.com>
 
+        [Mac] Update PageVisibilityState when WebView is hidden / visible
+        https://bugs.webkit.org/show_bug.cgi?id=107509
+
+        Reviewed by Sam Weinig.
+
+        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.
+
+        * 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::teardownView):
+        (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::teardownView):
+        (TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test):
+        (TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test):
+        Add a WK1 and WK2 teardownView to balance initializeView.
+
+2013-01-28  Joseph Pecoraro  <pecor...@apple.com>
+
         Improve PageVisibility API with enums
         https://bugs.webkit.org/show_bug.cgi?id=107364
 

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (141010 => 141011)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2013-01-28 22:38:26 UTC (rev 141011)
@@ -104,6 +104,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 */; };
@@ -246,6 +248,7 @@
 				E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */,
 				517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.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 */,
 				52B8CF9815868D9100281053 /* SetDocumentURI.html in Copy Resources */,
 				1ADBEFE3130C6AA100D61D19 /* simple-accelerated-compositing.html in Copy Resources */,
@@ -361,6 +364,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>"; };
@@ -786,6 +791,7 @@
 				4BB4160116815B2600824238 /* JSWrapperForNodeInWebFrame.mm */,
 				E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */,
 				517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */,
+				A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */,
 				3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */,
 				261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */,
 				52B8CF9515868CF000281053 /* SetDocumentURI.mm */,
@@ -815,6 +821,7 @@
 				9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */,
 				E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */,
 				517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */,
+				A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */,
 				52B8CF9415868CF000281053 /* SetDocumentURI.html */,
 				C540F783152E5A7800A40C8C /* verboseMarkup.html */,
 				A5E2027015B2180600C13E14 /* WindowlessWebViewWithMedia.html */,
@@ -1016,6 +1023,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 */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp (141010 => 141011)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp	2013-01-28 22:38:26 UTC (rev 141011)
@@ -100,7 +100,7 @@
     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);

Added: trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html (0 => 141011)


--- trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html	2013-01-28 22:38:26 UTC (rev 141011)
@@ -0,0 +1,6 @@
+<script>
+document.addEventListener("webkitvisibilitychange", function(event) {
+    // Send a signal to the test controller via alert.
+    alert('webkitvisibilitychange');
+});
+</script>

Added: trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm (0 => 141011)


--- trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm	2013-01-28 22:38:26 UTC (rev 141011)
@@ -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 "_javascript_Test.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

Modified: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h (141010 => 141011)


--- trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h	2013-01-28 22:38:26 UTC (rev 141011)
@@ -58,6 +58,9 @@
     virtual void initializeView(WebView *) { }
     virtual void initializeView(WKView *) { }
 
+    virtual void teardownView(WebView *) { }
+    virtual void teardownView(WKView *) { }
+
     bool didFinishLoad;
 };
 

Modified: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm (141010 => 141011)


--- trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm	2013-01-28 22:38:26 UTC (rev 141011)
@@ -91,6 +91,7 @@
     loadURL(webView.get(), url());
     waitForLoadToFinish();
     didLoadURL(webView.get());
+    teardownView(webView.get());
 }
 
 void WebKitAgnosticTest::runWebKit2Test()
@@ -104,6 +105,7 @@
     loadURL(view.get(), url());
     waitForLoadToFinish();
     didLoadURL(view.get());
+    teardownView(view.get());
 }
 
 void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url)

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (141010 => 141011)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2013-01-28 22:38:23 UTC (rev 141010)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2013-01-28 22:38:26 UTC (rev 141011)
@@ -554,7 +554,7 @@
 
         TestController::shared().setVisibilityState(visibilityState, isInitialState);
         return;
-    }    
+    }
 
     if (WKStringIsEqualToUTF8CString(messageName, "ProcessWorkQueue")) {
         if (TestController::shared().workQueueManager().processWorkQueue()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to