summaryrefslogtreecommitdiff
path: root/Tools/TestWebKitAPI/Tests
diff options
context:
space:
mode:
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>2013-01-28 22:38:23 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-08 17:34:02 +0200
commit0dd9e57645d192fca388abe8f04e93ca7bef6ad6 (patch)
tree580a6d97c337b8e5cd7ad71e58ee6081e01d84e8 /Tools/TestWebKitAPI/Tests
parentf0ce121cf5367b340160408821ab6b9d00d3d0cb (diff)
downloadqtwebkit-0dd9e57645d192fca388abe8f04e93ca7bef6ad6.tar.gz
Improve PageVisibility API with enums
https://bugs.webkit.org/show_bug.cgi?id=107364 Reviewed by Sam Weinig. Source/WebKit/mac: * WebView/WebView.mm: * WebView/WebViewPrivate.h: (corePageVisibilityState): (-[WebView _setVisibilityState:isInitialState:]): Switch the private API form int to a WebPageVisibilityState enum. Source/WebKit2: * Shared/API/c/WKPageVisibilityTypes.h: Added. * Shared/API/c/WKSharedAPICast.h: (WebKit::toPageVisibilityState): Create an enum for page visibility APIs and a conversion function for the WK2 values to WebCore values. * Target.pri: * GNUmakefile.list.am: * WebKit2.xcodeproj/project.pbxproj: Add WKPageVisibilityTypes.h to the build as a private export. * UIProcess/API/C/WKPage.h: * UIProcess/API/C/WKPage.cpp: (WKPageSetVisibilityState): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::setVisibilityState): UIProcess API to set visibility state. WebPageProxy already had m_visibilityState, so update that when setter is used. * WebProcess/InjectedBundle/API/c/WKBundle.cpp: * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h: * WebProcess/InjectedBundle/InjectedBundle.cpp: * WebProcess/InjectedBundle/InjectedBundle.h: Remove the old SPI for WebKitTestRunner. Tests now use the C API. * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setVisibilityState): * WebProcess/WebPage/WebPage.messages.in: Update the existing WebPage API to use uint32_t, which matches other enum message types. Tools: * DumpRenderTree/mac/TestRunnerMac.mm: (TestRunner::resetPageVisibility): (TestRunner::setPageVisibility): Update the WK1 test code to use the new WK1 enums. * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp: (WTR::InjectedBundle::setVisibilityState): * WebKitTestRunner/InjectedBundle/InjectedBundle.h: (InjectedBundle): * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setPageVisibility): (WTR::TestRunner::resetPageVisibility): * WebKitTestRunner/TestController.cpp: (WTR::TestController::setVisibilityState): * WebKitTestRunner/TestController.h: (TestController): * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Update the WK2 test code to use the new WK2 API and enums. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp: Added. (TestWebKitAPI): (TestWebKitAPI::setPageVisibilityStateWithEvalContinuation): (TestWebKitAPI::assertSerializedScriptValueIsStringValue): (TestWebKitAPI::didRunStep1StateChangeVisibleToHidden): (TestWebKitAPI::didRunStep2StateChangeHiddenToPrerender): (TestWebKitAPI::didRunStep3StateChangePrerenderToPreview): (TestWebKitAPI::didRunStep4InStatePreview): (TestWebKitAPI::TEST): Test the new WK2 API with all enum types. Change-Id: I0a057111d7ef26cb87ade328291d4f94322480b7 git-svn-id: http://svn.webkit.org/repository/webkit/trunk@141010 268f45cc-cd09-0410-ab3c-d52691b4dbfc Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Tools/TestWebKitAPI/Tests')
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp
new file mode 100644
index 000000000..00c79ce3a
--- /dev/null
+++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <JavaScriptCore/JSContextRef.h>
+#include <WebKit2/WKRetainPtr.h>
+#include <WebKit2/WKSerializedScriptValue.h>
+
+namespace TestWebKitAPI {
+
+static bool testDone;
+
+static void didRunStep1StateChangeVisibleToHidden(WKSerializedScriptValueRef, WKErrorRef, void*);
+static void didRunStep2StateChangeHiddenToPrerender(WKSerializedScriptValueRef, WKErrorRef, void*);
+static void didRunStep3StateChangePrerenderToPreview(WKSerializedScriptValueRef, WKErrorRef, void*);
+static void didRunStep4InStatePreview(WKSerializedScriptValueRef, WKErrorRef, void*);
+
+static void setPageVisibilityStateWithEvalContinuation(PlatformWebView* webView, WKPageVisibilityState visibilityState, WKPageRunJavaScriptFunction callback)
+{
+ WKPageSetVisibilityState(webView->page(), visibilityState, false);
+ WKRetainPtr<WKStringRef> javaScriptString(AdoptWK, WKStringCreateWithUTF8CString("document.webkitVisibilityState"));
+ WKPageRunJavaScriptInMainFrame(webView->page(), javaScriptString.get(), static_cast<void*>(webView), callback);
+}
+
+static void assertSerializedScriptValueIsStringValue(WKSerializedScriptValueRef serializedValue, WKErrorRef error, const char *expected)
+{
+ EXPECT_NULL(error);
+ EXPECT_NOT_NULL(serializedValue);
+ if (error || !serializedValue)
+ return;
+
+ JSGlobalContextRef scriptContext = JSGlobalContextCreate(0);
+ JSValueRef scriptValue = WKSerializedScriptValueDeserialize(serializedValue, scriptContext, 0);
+ EXPECT_TRUE(JSValueIsString(scriptContext, scriptValue));
+ if (!JSValueIsString(scriptContext, scriptValue)) {
+ JSGlobalContextRelease(scriptContext);
+ return;
+ }
+
+ JSStringRef expectedString = JSStringCreateWithUTF8CString(expected);
+ JSStringRef scriptString = JSValueToStringCopy(scriptContext, scriptValue, 0);
+ EXPECT_TRUE(JSStringIsEqual(scriptString, expectedString));
+
+ JSStringRelease(scriptString);
+ JSStringRelease(expectedString);
+ JSGlobalContextRelease(scriptContext);
+}
+
+static void didRunStep1StateChangeVisibleToHidden(WKSerializedScriptValueRef resultSerializedScriptValue, WKErrorRef error, void* context)
+{
+ assertSerializedScriptValueIsStringValue(resultSerializedScriptValue, error, "visible");
+ setPageVisibilityStateWithEvalContinuation(static_cast<PlatformWebView*>(context), kWKPageVisibilityStateHidden, didRunStep2StateChangeHiddenToPrerender);
+}
+
+static void didRunStep2StateChangeHiddenToPrerender(WKSerializedScriptValueRef resultSerializedScriptValue, WKErrorRef error, void* context)
+{
+ assertSerializedScriptValueIsStringValue(resultSerializedScriptValue, error, "hidden");
+ setPageVisibilityStateWithEvalContinuation(static_cast<PlatformWebView*>(context), kWKPageVisibilityStatePrerender, didRunStep3StateChangePrerenderToPreview);
+}
+
+static void didRunStep3StateChangePrerenderToPreview(WKSerializedScriptValueRef resultSerializedScriptValue, WKErrorRef error, void* context)
+{
+ assertSerializedScriptValueIsStringValue(resultSerializedScriptValue, error, "prerender");
+ setPageVisibilityStateWithEvalContinuation(static_cast<PlatformWebView*>(context), kWKPageVisibilityStatePreview, didRunStep4InStatePreview);
+}
+
+static void didRunStep4InStatePreview(WKSerializedScriptValueRef resultSerializedScriptValue, WKErrorRef error, void* context)
+{
+ assertSerializedScriptValueIsStringValue(resultSerializedScriptValue, error, "preview");
+ testDone = true;
+}
+
+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());
+ setPageVisibilityStateWithEvalContinuation(&webView, kWKPageVisibilityStateVisible, didRunStep1StateChangeVisibleToHidden);
+
+ Util::run(&testDone);
+}
+
+} // namespace TestWebKitAPI