- Revision
- 127026
- Author
- [email protected]
- Date
- 2012-08-29 11:54:28 -0700 (Wed, 29 Aug 2012)
Log Message
[WK2] Basic WTR support for web notifications
https://bugs.webkit.org/show_bug.cgi?id=95154
<rdar://problem/12184492>
Reviewed by Alexey Proskuryakov.
Implement WTR support, without platform event output (bug 95233).
Legacy APIs will not be supported, since many of the tests are skipped
on ports that do test notifications, and the issue with using file:// as the origin means a lot of the permissions
tests won't work. Bugs 81048 and 81697 will track migrating the existing tests to use the new testRunner API, and move
the tests to http/tests/notifications.
Permissions will be handled only in the injected bundle. This allows tests to set permission synchronously, and not
require a chain of setTimeout()'s when writing a notification test. Clicking a notification, however, should
be invoked from the UIProcess.
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::didReceiveMessage): When told to "Reset", clear out all of the permissions.
(WTR::InjectedBundle::postSimulateWebNotificationClick): Tell the bundle client to simulate a click based on the
notification's internal ID.
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::grantWebNotificationPermission): Manually set the permission using WKBundle SPI.
(WTR::TestRunner::denyWebNotificationPermission): Manually set the permission using WKBundle SPI.
(WTR::TestRunner::removeAllWebNotificationPermissions):
(WTR::TestRunner::simulateWebNotificationClick): Post a message through the injected bundle.
* WebKitTestRunner/InjectedBundle/TestRunner.h:
Because supporting web notifications goes beyond a couple functions, move all of the logic into a WebNotificationProvider
class.
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle): When the injected bundle sends a message to simulate a click,
TestInvocation forwards that request to the TestController.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::initialize): Set the provider.
(WTR::TestController::resetStateToConsistentValues): Tell the provider to reset.
(WTR::TestController::simulateWebNotificationClick): Tell the provider to simulate a user clicking on a platform notification.
* WebKitTestRunner/TestController.h: Holds an instance to the provider.
The provider maintains a pointer to one notification manager (presumably the web process associated with WTR), and a set
of notification IDs that have been "shown" by the platform. This allows us to simulate a click on a notification.
* WebKitTestRunner/WebNotificationProvider.h: Added.
* WebKitTestRunner/WebNotificationProvider.cpp: Added.
(WTR::WebNotificationProvider::showWebNotification): Adds the notification to set of shown notifications. Notifies provider that
the notification got shown.
(WTR::WebNotificationProvider::closeWebNotification): Removes the notification from the set. Notifies provider that the notification
got closed.
(WTR::WebNotificationProvider::addNotificationManager): Maintains one manager, which is fine for testing purposes.
(WTR::WebNotificationProvider::removeNotificationManager): Maintains one manager.
(WTR::WebNotificationProvider::notificationPermissions): When the web process starts, it maintains an initial set of known
permissions. For testing purposes, we always want this set to be empty.
(WTR::WebNotificationProvider::simulateWebNotificationClick): Notifies provider that the notification got "clicked".
(WTR::WebNotificationProvider::reset): To reset the state, we pretend that we closed all of the platform notifications.
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj: Add WebNotificationProvider.
Modified Paths
Added Paths
Diff
Modified: trunk/Tools/ChangeLog (127025 => 127026)
--- trunk/Tools/ChangeLog 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/ChangeLog 2012-08-29 18:54:28 UTC (rev 127026)
@@ -1,3 +1,63 @@
+2012-08-29 Jon Lee <[email protected]>
+
+ [WK2] Basic WTR support for web notifications
+ https://bugs.webkit.org/show_bug.cgi?id=95154
+ <rdar://problem/12184492>
+
+ Reviewed by Alexey Proskuryakov.
+
+ Implement WTR support, without platform event output (bug 95233).
+
+ Legacy APIs will not be supported, since many of the tests are skipped
+ on ports that do test notifications, and the issue with using file:// as the origin means a lot of the permissions
+ tests won't work. Bugs 81048 and 81697 will track migrating the existing tests to use the new testRunner API, and move
+ the tests to http/tests/notifications.
+
+ Permissions will be handled only in the injected bundle. This allows tests to set permission synchronously, and not
+ require a chain of setTimeout()'s when writing a notification test. Clicking a notification, however, should
+ be invoked from the UIProcess.
+
+ * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+ * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+ (WTR::InjectedBundle::didReceiveMessage): When told to "Reset", clear out all of the permissions.
+ (WTR::InjectedBundle::postSimulateWebNotificationClick): Tell the bundle client to simulate a click based on the
+ notification's internal ID.
+ * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+ * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+ (WTR::TestRunner::grantWebNotificationPermission): Manually set the permission using WKBundle SPI.
+ (WTR::TestRunner::denyWebNotificationPermission): Manually set the permission using WKBundle SPI.
+ (WTR::TestRunner::removeAllWebNotificationPermissions):
+ (WTR::TestRunner::simulateWebNotificationClick): Post a message through the injected bundle.
+ * WebKitTestRunner/InjectedBundle/TestRunner.h:
+
+ Because supporting web notifications goes beyond a couple functions, move all of the logic into a WebNotificationProvider
+ class.
+ * WebKitTestRunner/TestInvocation.cpp:
+ (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): When the injected bundle sends a message to simulate a click,
+ TestInvocation forwards that request to the TestController.
+ * WebKitTestRunner/TestController.cpp:
+ (WTR::TestController::initialize): Set the provider.
+ (WTR::TestController::resetStateToConsistentValues): Tell the provider to reset.
+ (WTR::TestController::simulateWebNotificationClick): Tell the provider to simulate a user clicking on a platform notification.
+ * WebKitTestRunner/TestController.h: Holds an instance to the provider.
+
+ The provider maintains a pointer to one notification manager (presumably the web process associated with WTR), and a set
+ of notification IDs that have been "shown" by the platform. This allows us to simulate a click on a notification.
+ * WebKitTestRunner/WebNotificationProvider.h: Added.
+ * WebKitTestRunner/WebNotificationProvider.cpp: Added.
+ (WTR::WebNotificationProvider::showWebNotification): Adds the notification to set of shown notifications. Notifies provider that
+ the notification got shown.
+ (WTR::WebNotificationProvider::closeWebNotification): Removes the notification from the set. Notifies provider that the notification
+ got closed.
+ (WTR::WebNotificationProvider::addNotificationManager): Maintains one manager, which is fine for testing purposes.
+ (WTR::WebNotificationProvider::removeNotificationManager): Maintains one manager.
+ (WTR::WebNotificationProvider::notificationPermissions): When the web process starts, it maintains an initial set of known
+ permissions. For testing purposes, we always want this set to be empty.
+ (WTR::WebNotificationProvider::simulateWebNotificationClick): Notifies provider that the notification got "clicked".
+ (WTR::WebNotificationProvider::reset): To reset the state, we pretend that we closed all of the platform notifications.
+
+ * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj: Add WebNotificationProvider.
+
2012-08-29 Kamil Blank <[email protected]>
[EFL] Add setting API for allow universal/file access from file URLs.
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl 2012-08-29 18:54:28 UTC (rev 127026)
@@ -160,6 +160,12 @@
// Control full screen behavior.
void setHasCustomFullScreenBehavior(in boolean value);
+
+ // Web notifications support
+ void grantWebNotificationPermission(in DOMString origin);
+ void denyWebNotificationPermission(in DOMString origin);
+ void removeAllWebNotificationPermissions();
+ void simulateWebNotificationClick(in object notification);
};
}
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp 2012-08-29 18:54:28 UTC (rev 127026)
@@ -171,6 +171,7 @@
m_dumpPixels = false;
resetLocalSettings();
+ m_testRunner->removeAllWebNotificationPermissions();
return;
}
@@ -338,4 +339,11 @@
WKBundlePostSynchronousMessage(m_bundle, messageName.get(), messageBody.get(), 0);
}
+void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID)
+{
+ WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SimulateWebNotificationClick"));
+ WKRetainPtr<WKUInt64Ref> messageBody(AdoptWK, WKUInt64Create(notificationID));
+ WKBundlePostMessage(m_bundle, messageName.get(), messageBody.get());
+}
+
} // namespace WTR
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h 2012-08-29 18:54:28 UTC (rev 127026)
@@ -88,6 +88,7 @@
void postFocusWebView();
void postSetBackingScaleFactor(double);
void postSetWindowIsKey(bool);
+ void postSimulateWebNotificationClick(uint64_t notificationID);
private:
InjectedBundle();
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp 2012-08-29 18:54:28 UTC (rev 127026)
@@ -684,4 +684,29 @@
setUserStyleSheetEnabled(true);
}
+void TestRunner::grantWebNotificationPermission(JSStringRef origin)
+{
+ WKRetainPtr<WKStringRef> originWK = toWK(origin);
+ WKBundleSetWebNotificationPermission(InjectedBundle::shared().bundle(), InjectedBundle::shared().page()->page(), originWK.get(), true);
+}
+
+void TestRunner::denyWebNotificationPermission(JSStringRef origin)
+{
+ WKRetainPtr<WKStringRef> originWK = toWK(origin);
+ WKBundleSetWebNotificationPermission(InjectedBundle::shared().bundle(), InjectedBundle::shared().page()->page(), originWK.get(), false);
+}
+
+void TestRunner::removeAllWebNotificationPermissions()
+{
+ WKBundleRemoveAllWebNotificationPermissions(InjectedBundle::shared().bundle(), InjectedBundle::shared().page()->page());
+}
+
+void TestRunner::simulateWebNotificationClick(JSValueRef notification)
+{
+ WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
+ JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
+ uint64_t notificationID = WKBundleGetWebNotificationID(InjectedBundle::shared().bundle(), context, notification);
+ InjectedBundle::shared().postSimulateWebNotificationClick(notificationID);
+}
+
} // namespace WTR
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h 2012-08-29 18:54:28 UTC (rev 127026)
@@ -224,6 +224,12 @@
void setHasCustomFullScreenBehavior(bool value) { m_customFullScreenBehavior = value; }
bool hasCustomFullScreenBehavior() const { return m_customFullScreenBehavior; }
+ // Web notifications.
+ void grantWebNotificationPermission(JSStringRef origin);
+ void denyWebNotificationPermission(JSStringRef origin);
+ void removeAllWebNotificationPermissions();
+ void simulateWebNotificationClick(JSValueRef notification);
+
JSRetainPtr<JSStringRef> platformName();
void setPageVisibility(JSStringRef state);
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2012-08-29 18:54:28 UTC (rev 127026)
@@ -30,6 +30,8 @@
#include "StringFunctions.h"
#include "TestInvocation.h"
#include <WebKit2/WKContextPrivate.h>
+#include <WebKit2/WKNotification.h>
+#include <WebKit2/WKNotificationManager.h>
#include <WebKit2/WKNumber.h>
#include <WebKit2/WKPageGroup.h>
#include <WebKit2/WKPagePrivate.h>
@@ -333,6 +335,10 @@
};
WKContextSetInjectedBundleClient(m_context.get(), &injectedBundleClient);
+ WKNotificationManagerRef notificationManager = WKContextGetNotificationManager(m_context.get());
+ WKNotificationProvider notificationKit = m_webNotificationProvider.provider();
+ WKNotificationManagerSetProvider(notificationManager, ¬ificationKit);
+
if (testPluginDirectory())
WKContextSetAdditionalPluginsDirectory(m_context.get(), testPluginDirectory());
@@ -501,6 +507,9 @@
// Re-set to the default backing scale factor by setting the custom scale factor to 0.
WKPageSetCustomBackingScaleFactor(m_mainWebView->page(), 0);
+ // Reset notification permissions
+ m_webNotificationProvider.reset();
+
// Reset main page back to about:blank
m_doneResetting = false;
@@ -921,4 +930,9 @@
exit(1);
}
+void TestController::simulateWebNotificationClick(uint64_t notificationID)
+{
+ m_webNotificationProvider.simulateWebNotificationClick(notificationID);
+}
+
} // namespace WTR
Modified: trunk/Tools/WebKitTestRunner/TestController.h (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/TestController.h 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/TestController.h 2012-08-29 18:54:28 UTC (rev 127026)
@@ -26,6 +26,7 @@
#ifndef TestController_h
#define TestController_h
+#include "WebNotificationProvider.h"
#include <WebKit2/WKRetainPtr.h>
#include <string>
#include <vector>
@@ -62,6 +63,8 @@
bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
+ void simulateWebNotificationClick(uint64_t notificationID);
+
bool resetStateToConsistentValues();
private:
@@ -112,6 +115,8 @@
WKRetainPtr<WKStringRef> m_injectedBundlePath;
WKRetainPtr<WKStringRef> m_testPluginDirectory;
+ WebNotificationProvider m_webNotificationProvider;
+
OwnPtr<PlatformWebView> m_mainWebView;
WKRetainPtr<WKContextRef> m_context;
WKRetainPtr<WKPageGroupRef> m_pageGroup;
Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp 2012-08-29 18:54:28 UTC (rev 127026)
@@ -339,6 +339,13 @@
return;
}
+ if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) {
+ ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
+ uint64_t notificationID = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
+ TestController::shared().simulateWebNotificationClick(notificationID);
+ return;
+ }
+
ASSERT_NOT_REACHED();
}
Modified: trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj (127025 => 127026)
--- trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj 2012-08-29 18:50:56 UTC (rev 127025)
+++ trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj 2012-08-29 18:54:28 UTC (rev 127026)
@@ -34,6 +34,7 @@
29A8FCDD145F0337009045A6 /* JSAccessibilityTextMarkerRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A8FCE1345E7021006AA5A6 /* JSAccessibilityTextMarkerRange.cpp */; };
29A8FCE2145F037B009045A6 /* AccessibilityTextMarkerRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A8FCE1145F037B009045A6 /* AccessibilityTextMarkerRange.cpp */; };
29A8FCE5145F0464009045A6 /* AccessibilityTextMarkerRangeMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29A8FCE4145F0464009045A6 /* AccessibilityTextMarkerRangeMac.mm */; };
+ 3164C8F015D1ADA100EF1FE0 /* WebNotificationProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3164C8EF15D1ADA100EF1FE0 /* WebNotificationProvider.cpp */; };
5322FB4313FDA0CD0041ABCC /* CyclicRedundancyCheck.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5322FB4113FDA0CD0041ABCC /* CyclicRedundancyCheck.cpp */; };
5322FB4613FDA0EA0041ABCC /* PixelDumpSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5322FB4413FDA0EA0041ABCC /* PixelDumpSupport.cpp */; };
5641E2D014335E95008307E5 /* JSTextInputController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5641E2CE14335E95008307E5 /* JSTextInputController.cpp */; };
@@ -120,6 +121,8 @@
29A8FCE1345E7021006AA5A6 /* JSAccessibilityTextMarkerRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSAccessibilityTextMarkerRange.cpp; path = DerivedSources/WebKitTestRunner/JSAccessibilityTextMarkerRange.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
29A8FCE1345E7021006AA5A7 /* JSAccessibilityTextMarkerRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSAccessibilityTextMarkerRange.h; path = DerivedSources/WebKitTestRunner/JSAccessibilityTextMarkerRange.h; sourceTree = BUILT_PRODUCTS_DIR; };
29A8FCE4145F0464009045A6 /* AccessibilityTextMarkerRangeMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityTextMarkerRangeMac.mm; path = mac/AccessibilityTextMarkerRangeMac.mm; sourceTree = "<group>"; };
+ 3110BE0F15BA011400D216AC /* WebNotificationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebNotificationProvider.h; sourceTree = "<group>"; };
+ 3164C8EF15D1ADA100EF1FE0 /* WebNotificationProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNotificationProvider.cpp; sourceTree = "<group>"; };
378D442213346D00006A777B /* config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
41230E16138C78BF00BCCFCA /* libWebCoreTestSupport.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libWebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
4181731B138AD39D0057AAA4 /* WebCoreTestSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebCoreTestSupport.h; path = WebCoreTestSupport/WebCoreTestSupport.h; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -260,6 +263,8 @@
BCD7D2F611921278006DB7EE /* TestInvocation.h */,
BCD7D2F711921278006DB7EE /* TestInvocation.cpp */,
BC251A1711D16774002EBC01 /* WebKitTestRunnerPrefix.h */,
+ 3110BE0F15BA011400D216AC /* WebNotificationProvider.h */,
+ 3164C8EF15D1ADA100EF1FE0 /* WebNotificationProvider.cpp */,
);
name = TestRunner;
sourceTree = "<group>";
@@ -567,6 +572,7 @@
BCD7D2F811921278006DB7EE /* TestInvocation.cpp in Sources */,
BC9192051333E4F8003011DC /* TestInvocationCG.cpp in Sources */,
5670B8281386FCA5002EB355 /* EventSenderProxy.mm in Sources */,
+ 3164C8F015D1ADA100EF1FE0 /* WebNotificationProvider.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp (0 => 127026)
--- trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp (rev 0)
+++ trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp 2012-08-29 18:54:28 UTC (rev 127026)
@@ -0,0 +1,155 @@
+/*
+ * 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 "WebNotificationProvider.h"
+
+#include <WebKit2/WKMutableArray.h>
+#include <WebKit2/WKNotification.h>
+#include <WebKit2/WKNumber.h>
+#include <WebKit2/WKSecurityOrigin.h>
+#include <wtf/Assertions.h>
+
+namespace WTR {
+
+static void showWebNotification(WKPageRef page, WKNotificationRef notification, const void* clientInfo)
+{
+ static_cast<WebNotificationProvider*>(const_cast<void*>(clientInfo))->showWebNotification(page, notification);
+}
+
+static void closeWebNotification(WKNotificationRef notification, const void* clientInfo)
+{
+ static_cast<WebNotificationProvider*>(const_cast<void*>(clientInfo))->closeWebNotification(notification);
+}
+
+static void addNotificationManager(WKNotificationManagerRef manager, const void* clientInfo)
+{
+ static_cast<WebNotificationProvider*>(const_cast<void*>(clientInfo))->addNotificationManager(manager);
+}
+
+static void removeNotificationManager(WKNotificationManagerRef manager, const void* clientInfo)
+{
+ static_cast<WebNotificationProvider*>(const_cast<void*>(clientInfo))->removeNotificationManager(manager);
+}
+
+static WKDictionaryRef notificationPermissions(const void* clientInfo)
+{
+ return static_cast<WebNotificationProvider*>(const_cast<void*>(clientInfo))->notificationPermissions();
+}
+
+WebNotificationProvider::WebNotificationProvider()
+{
+}
+
+WKNotificationProvider WebNotificationProvider::provider()
+{
+ WKNotificationProvider notificationProvider = {
+ kWKNotificationProviderCurrentVersion,
+ this,
+ WTR::showWebNotification,
+ WTR::closeWebNotification,
+ 0, // didDestroyNotification
+ WTR::addNotificationManager,
+ WTR::removeNotificationManager,
+ WTR::notificationPermissions,
+ 0, // clearNotifications
+ };
+ return notificationProvider;
+}
+
+void WebNotificationProvider::showWebNotification(WKPageRef, WKNotificationRef notification)
+{
+ if (!m_notificationManager)
+ return;
+
+ uint64_t id = WKNotificationGetID(notification);
+ HashSet<uint64_t>::AddResult result = m_shownNotifications.add(id);
+ ASSERT(result.isNewEntry);
+
+ WKNotificationManagerProviderDidShowNotification(m_notificationManager.get(), WKNotificationGetID(notification));
+}
+
+void WebNotificationProvider::closeWebNotification(WKNotificationRef notification)
+{
+ if (!m_notificationManager)
+ return;
+
+ uint64_t id = WKNotificationGetID(notification);
+ WKRetainPtr<WKUInt64Ref> wkID = WKUInt64Create(id);
+ WKRetainPtr<WKMutableArrayRef> array(AdoptWK, WKMutableArrayCreate());
+ WKArrayAppendItem(array.get(), wkID.get());
+ m_shownNotifications.remove(id);
+ WKNotificationManagerProviderDidCloseNotifications(m_notificationManager.get(), array.get());
+}
+
+void WebNotificationProvider::addNotificationManager(WKNotificationManagerRef manager)
+{
+ // We assume there is only one for testing.
+ ASSERT(!m_notificationManager);
+ m_notificationManager = manager;
+}
+
+void WebNotificationProvider::removeNotificationManager(WKNotificationManagerRef manager)
+{
+ // We assume there is only one for testing.
+ ASSERT(m_notificationManager);
+ ASSERT(m_notificationManager.get() == manager);
+ m_notificationManager = 0;
+}
+
+WKDictionaryRef WebNotificationProvider::notificationPermissions()
+{
+ // Initial permissions are always empty.
+ return WKMutableDictionaryCreate();
+}
+
+void WebNotificationProvider::simulateWebNotificationClick(uint64_t notificationID)
+{
+ if (!m_notificationManager)
+ return;
+
+ ASSERT(m_shownNotifications.contains(notificationID));
+ WKNotificationManagerProviderDidClickNotification(m_notificationManager.get(), notificationID);
+}
+
+void WebNotificationProvider::reset()
+{
+ if (!m_notificationManager) {
+ m_shownNotifications.clear();
+ return;
+ }
+
+ WKRetainPtr<WKMutableArrayRef> array(AdoptWK, WKMutableArrayCreate());
+ HashSet<uint64_t>::const_iterator itEnd = m_shownNotifications.end();
+ for (HashSet<uint64_t>::const_iterator it = m_shownNotifications.begin(); it != itEnd; ++it) {
+ WKRetainPtr<WKUInt64Ref> wkID = WKUInt64Create(*it);
+ WKArrayAppendItem(array.get(), wkID.get());
+ }
+
+ m_shownNotifications.clear();
+ WKNotificationManagerProviderDidCloseNotifications(m_notificationManager.get(), array.get());
+}
+
+} // namespace WTR
Added: trunk/Tools/WebKitTestRunner/WebNotificationProvider.h (0 => 127026)
--- trunk/Tools/WebKitTestRunner/WebNotificationProvider.h (rev 0)
+++ trunk/Tools/WebKitTestRunner/WebNotificationProvider.h 2012-08-29 18:54:28 UTC (rev 127026)
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#ifndef WebNotificationProvider_h
+#define WebNotificationProvider_h
+
+#include <WebKit2/WKNotificationManager.h>
+#include <WebKit2/WKNotificationProvider.h>
+#include <WebKit2/WKRetainPtr.h>
+#include <wtf/HashSet.h>
+
+namespace WTR {
+
+class WebNotificationProvider {
+public:
+ WebNotificationProvider();
+ WKNotificationProvider provider();
+
+ void showWebNotification(WKPageRef, WKNotificationRef);
+ void closeWebNotification(WKNotificationRef);
+ void addNotificationManager(WKNotificationManagerRef);
+ void removeNotificationManager(WKNotificationManagerRef);
+ WKDictionaryRef notificationPermissions();
+
+ void simulateWebNotificationClick(uint64_t notificationID);
+ void reset();
+
+private:
+ WKRetainPtr<WKNotificationManagerRef> m_notificationManager;
+ HashSet<uint64_t> m_shownNotifications;
+};
+
+}
+
+#endif