Title: [127042] trunk/Tools
Revision
127042
Author
jon...@apple.com
Date
2012-08-29 13:32:19 -0700 (Wed, 29 Aug 2012)

Log Message

[Mac] Basic DRT support for web notifications
https://bugs.webkit.org/show_bug.cgi?id=79492
<rdar://problem/10357639>

Reviewed by Alexey Proskuryakov.

This patch implements the stubs for web notification support on DRT. Assume that when
Notification.requestPermission() is called, the user always chooses to allow it. This can be easily
overridden in layout tests with testRunner.denyWebNotificationPermission() when needed.

* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj: Add MockWebNotificationProvider.
* DumpRenderTree/mac/DumpRenderTree.mm:
(createWebViewAndOffscreenWindow): Set MockWebNotificationProvider singleton as the provider for the
web view.
(resetWebViewToConsistentStateBeforeTesting): Make sure to reset the provider's state between each test.

* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::grantWebNotificationPermission): Set permission to granted for specified origin.
(TestRunner::denyWebNotificationPermission): Set permission to denied for specified origin.
(TestRunner::removeAllWebNotificationPermissions):
(TestRunner::simulateWebNotificationClick): Retrieve the notification ID from the JS notification object, and
simulate the click. This is similar to how WTR performs the click.
* DumpRenderTree/mac/UIDelegate.mm:
(-[UIDelegate webView:decidePolicyForNotificationRequestFromOrigin:listener:]): Assume when asked, the
user allows web notifications.

* DumpRenderTree/mac/MockWebNotificationProvider.h: Added. Maintains a list of registered web views, known permissions,
a map of notification IDs to WebNotification instances, and a map of the WebViews from which the notifications were dispatched.
* DumpRenderTree/mac/MockWebNotificationProvider.mm: Added.
(+[MockWebNotificationProvider shared]): The provider is a singleton.
(-[MockWebNotificationProvider init]): Instantiate the permissions map.
(-[MockWebNotificationProvider registerWebView:]):
(-[MockWebNotificationProvider unregisterWebView:]):
(-[MockWebNotificationProvider showNotification:fromWebView:]): Add the notification to the maps. Tell the web view that the
notification did show.
(-[MockWebNotificationProvider cancelNotification:]): Tell the web view the notification did close.
(-[MockWebNotificationProvider notificationDestroyed:]): Remove the notification from the maps. Here we don't make a callback.
(-[MockWebNotificationProvider clearNotifications:]): Remove the specified notifications from the maps. Here we don't make a callback.
(-[MockWebNotificationProvider webView:didShowNotification:]): Delegate callback. Dispatch the show event.
(-[MockWebNotificationProvider webView:didClickNotification:]): Delegate callback. Dispatch the click event.
(-[MockWebNotificationProvider webView:didCloseNotifications:]): Delegate callback. Dispatch the close event.
(-[MockWebNotificationProvider simulateWebNotificationClick:]): Tell the web view we clicked the notification.
(-[MockWebNotificationProvider policyForOrigin:]): Look in the permission dictionary.
(-[MockWebNotificationProvider setWebNotificationOrigin:permission:]): Set the permission for the origin in the dictionary.
(-[MockWebNotificationProvider removeAllWebNotificationPermissions]): Clear the permission map.
(-[MockWebNotificationProvider reset]): Remove all mappings and permissions.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (127041 => 127042)


--- trunk/Tools/ChangeLog	2012-08-29 20:28:30 UTC (rev 127041)
+++ trunk/Tools/ChangeLog	2012-08-29 20:32:19 UTC (rev 127042)
@@ -1,3 +1,52 @@
+2012-08-29  Jon Lee  <jon...@apple.com>
+
+        [Mac] Basic DRT support for web notifications
+        https://bugs.webkit.org/show_bug.cgi?id=79492
+        <rdar://problem/10357639>
+
+        Reviewed by Alexey Proskuryakov.
+
+        This patch implements the stubs for web notification support on DRT. Assume that when
+        Notification.requestPermission() is called, the user always chooses to allow it. This can be easily
+        overridden in layout tests with testRunner.denyWebNotificationPermission() when needed.
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj: Add MockWebNotificationProvider.
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (createWebViewAndOffscreenWindow): Set MockWebNotificationProvider singleton as the provider for the
+        web view.
+        (resetWebViewToConsistentStateBeforeTesting): Make sure to reset the provider's state between each test.
+
+        * DumpRenderTree/mac/TestRunnerMac.mm:
+        (TestRunner::grantWebNotificationPermission): Set permission to granted for specified origin.
+        (TestRunner::denyWebNotificationPermission): Set permission to denied for specified origin.
+        (TestRunner::removeAllWebNotificationPermissions):
+        (TestRunner::simulateWebNotificationClick): Retrieve the notification ID from the JS notification object, and
+        simulate the click. This is similar to how WTR performs the click.
+        * DumpRenderTree/mac/UIDelegate.mm:
+        (-[UIDelegate webView:decidePolicyForNotificationRequestFromOrigin:listener:]): Assume when asked, the
+        user allows web notifications.
+
+        * DumpRenderTree/mac/MockWebNotificationProvider.h: Added. Maintains a list of registered web views, known permissions,
+        a map of notification IDs to WebNotification instances, and a map of the WebViews from which the notifications were dispatched.
+        * DumpRenderTree/mac/MockWebNotificationProvider.mm: Added.
+        (+[MockWebNotificationProvider shared]): The provider is a singleton.
+        (-[MockWebNotificationProvider init]): Instantiate the permissions map.
+        (-[MockWebNotificationProvider registerWebView:]):
+        (-[MockWebNotificationProvider unregisterWebView:]):
+        (-[MockWebNotificationProvider showNotification:fromWebView:]): Add the notification to the maps. Tell the web view that the
+        notification did show.
+        (-[MockWebNotificationProvider cancelNotification:]): Tell the web view the notification did close.
+        (-[MockWebNotificationProvider notificationDestroyed:]): Remove the notification from the maps. Here we don't make a callback.
+        (-[MockWebNotificationProvider clearNotifications:]): Remove the specified notifications from the maps. Here we don't make a callback.
+        (-[MockWebNotificationProvider webView:didShowNotification:]): Delegate callback. Dispatch the show event.
+        (-[MockWebNotificationProvider webView:didClickNotification:]): Delegate callback. Dispatch the click event.
+        (-[MockWebNotificationProvider webView:didCloseNotifications:]): Delegate callback. Dispatch the close event.
+        (-[MockWebNotificationProvider simulateWebNotificationClick:]): Tell the web view we clicked the notification.
+        (-[MockWebNotificationProvider policyForOrigin:]): Look in the permission dictionary.
+        (-[MockWebNotificationProvider setWebNotificationOrigin:permission:]): Set the permission for the origin in the dictionary.
+        (-[MockWebNotificationProvider removeAllWebNotificationPermissions]): Clear the permission map.
+        (-[MockWebNotificationProvider reset]): Remove all mappings and permissions.
+
 2012-08-29  Rob Buis  <rb...@rim.com>
 
         [BlackBerry] Adjust wtf include header style

Modified: trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj (127041 => 127042)


--- trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj	2012-08-29 20:28:30 UTC (rev 127041)
+++ trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj	2012-08-29 20:32:19 UTC (rev 127042)
@@ -60,6 +60,8 @@
 		2D403F06150871F9005358D2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A84F608908B136DA00E9745F /* Cocoa.framework */; };
 		2D403F08150871F9005358D2 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23BCB88F0EA57623003C6289 /* OpenGL.framework */; };
 		2D403F1B15087209005358D2 /* LayoutTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D403EA215087142005358D2 /* LayoutTestHelper.m */; };
+		31117B3C15D9A56A00163BC8 /* MockWebNotificationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 31117B3A15D9A56A00163BC8 /* MockWebNotificationProvider.h */; };
+		31117B3D15D9A56A00163BC8 /* MockWebNotificationProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 31117B3B15D9A56A00163BC8 /* MockWebNotificationProvider.mm */; };
 		3A5626CB131CA02A002BE6D9 /* StorageTrackerDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3A5626C1131C8B17002BE6D9 /* StorageTrackerDelegate.mm */; };
 		3A5626CC131CA036002BE6D9 /* StorageTrackerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A5626C0131C8B17002BE6D9 /* StorageTrackerDelegate.h */; };
 		417DAA1D137B3E24007C57FB /* WebCoreTestSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 417DAA1C137B3E24007C57FB /* WebCoreTestSupport.h */; };
@@ -263,6 +265,8 @@
 		29CFBA2D12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityTextMarkerMac.mm; path = mac/AccessibilityTextMarkerMac.mm; sourceTree = "<group>"; };
 		2D403EA215087142005358D2 /* LayoutTestHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LayoutTestHelper.m; path = mac/LayoutTestHelper.m; sourceTree = "<group>"; };
 		2D403F19150871F9005358D2 /* LayoutTestHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = LayoutTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
+		31117B3A15D9A56A00163BC8 /* MockWebNotificationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MockWebNotificationProvider.h; path = mac/MockWebNotificationProvider.h; sourceTree = "<group>"; };
+		31117B3B15D9A56A00163BC8 /* MockWebNotificationProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MockWebNotificationProvider.mm; path = mac/MockWebNotificationProvider.mm; sourceTree = "<group>"; };
 		32A70AAB03705E1F00C91783 /* DumpRenderTreePrefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DumpRenderTreePrefix.h; sourceTree = "<group>"; };
 		375F09710DAC3CB600C8B4E5 /* WebKitWeightWatcher100.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = WebKitWeightWatcher100.ttf; path = fonts/WebKitWeightWatcher100.ttf; sourceTree = "<group>"; };
 		375F09720DAC3CB600C8B4E5 /* WebKitWeightWatcher200.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = WebKitWeightWatcher200.ttf; path = fonts/WebKitWeightWatcher200.ttf; sourceTree = "<group>"; };
@@ -482,11 +486,11 @@
 		1422A2690AF6F45200E1A883 /* Controllers */ = {
 			isa = PBXGroup;
 			children = (
-				80045AEB147718E7008290A8 /* AccessibilityNotificationHandler.h */,
-				80045AEC147718E7008290A8 /* AccessibilityNotificationHandler.mm */,
 				BCD08B390E1057EF00A7D0C1 /* AccessibilityController.cpp */,
 				BCD08A580E10496B00A7D0C1 /* AccessibilityController.h */,
 				BCD08B700E1059D200A7D0C1 /* AccessibilityControllerMac.mm */,
+				80045AEB147718E7008290A8 /* AccessibilityNotificationHandler.h */,
+				80045AEC147718E7008290A8 /* AccessibilityNotificationHandler.mm */,
 				29CFBA0F122736E600BC30C0 /* AccessibilityTextMarker.cpp */,
 				29CFBA0E122736E600BC30C0 /* AccessibilityTextMarker.h */,
 				29CFBA2D12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm */,
@@ -505,6 +509,8 @@
 				BCA18B220C9B014B00114369 /* TestRunnerMac.mm */,
 				E1B7808511AF1643007E1BC2 /* MockGeolocationProvider.h */,
 				E1B7808711AF1669007E1BC2 /* MockGeolocationProvider.mm */,
+				31117B3A15D9A56A00163BC8 /* MockWebNotificationProvider.h */,
+				31117B3B15D9A56A00163BC8 /* MockWebNotificationProvider.mm */,
 				BCA18B6D0C9B08DB00114369 /* NavigationController.h */,
 				BCA18B6E0C9B08DB00114369 /* NavigationController.m */,
 				BCA18B2F0C9B01B400114369 /* ObjCController.h */,
@@ -736,6 +742,7 @@
 				3A5626CC131CA036002BE6D9 /* StorageTrackerDelegate.h in Headers */,
 				417DAA1D137B3E24007C57FB /* WebCoreTestSupport.h in Headers */,
 				80045AED147718E7008290A8 /* AccessibilityNotificationHandler.h in Headers */,
+				31117B3C15D9A56A00163BC8 /* MockWebNotificationProvider.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -967,6 +974,7 @@
 				3A5626CB131CA02A002BE6D9 /* StorageTrackerDelegate.mm in Sources */,
 				80045AEE147718E7008290A8 /* AccessibilityNotificationHandler.mm in Sources */,
 				9830F31F15C81181005AB206 /* DumpRenderTreeCommon.cpp in Sources */,
+				31117B3D15D9A56A00163BC8 /* MockWebNotificationProvider.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (127041 => 127042)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2012-08-29 20:28:30 UTC (rev 127041)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2012-08-29 20:32:19 UTC (rev 127042)
@@ -42,6 +42,7 @@
 #import "_javascript_Threading.h"
 #import "TestRunner.h"
 #import "MockGeolocationProvider.h"
+#import "MockWebNotificationProvider.h"
 #import "NavigationController.h"
 #import "ObjCPlugin.h"
 #import "ObjCPluginFunction.h"
@@ -519,6 +520,7 @@
     [webView setResourceLoadDelegate:resourceLoadDelegate];
     [webView _setGeolocationProvider:[MockGeolocationProvider shared]];
     [webView _setDeviceOrientationProvider:[WebDeviceOrientationProviderMock shared]];
+    [webView _setNotificationProvider:[MockWebNotificationProvider shared]];
 
     // Register the same schemes that Safari does
     [WebView registerURLSchemeAsLocal:@"feed"];
@@ -1269,6 +1271,7 @@
     [WebView _setAllowsRoundingHacks:NO];
 
     [[MockGeolocationProvider shared] stopTimer];
+    [[MockWebNotificationProvider shared] reset];
     
     // Clear the contents of the general pasteboard
     [[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];

Added: trunk/Tools/DumpRenderTree/mac/MockWebNotificationProvider.h (0 => 127042)


--- trunk/Tools/DumpRenderTree/mac/MockWebNotificationProvider.h	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/mac/MockWebNotificationProvider.h	2012-08-29 20:32:19 UTC (rev 127042)
@@ -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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 MockWebNotificationProvider_h
+#define MockWebNotificationProvider_h
+
+#import <WebKit/WebNotification.h>
+#import <WebKit/WebViewPrivate.h>
+#import <wtf/HashMap.h>
+#import <wtf/HashSet.h>
+#import <wtf/RetainPtr.h>
+
+typedef HashMap<uint64_t, RetainPtr<WebNotification> > NotificationIDMap;
+typedef HashMap<uint64_t, WebView *> NotificationViewMap;
+
+@interface MockWebNotificationProvider : NSObject <WebNotificationProvider> {
+    HashSet<WebView *> _registeredWebViews;
+    NotificationIDMap _notifications;
+    NotificationViewMap _notificationViewMap;
+    RetainPtr<NSMutableDictionary> _permissions;
+}
+
++ (MockWebNotificationProvider *)shared;
+
+- (void)simulateWebNotificationClick:(uint64_t)notificationID;
+- (void)setWebNotificationOrigin:(NSString*)origin permission:(BOOL)allowed;
+- (void)removeAllWebNotificationPermissions;
+
+- (void)reset;
+@end
+
+#endif // MockWebNotificationProvider_h

Added: trunk/Tools/DumpRenderTree/mac/MockWebNotificationProvider.mm (0 => 127042)


--- trunk/Tools/DumpRenderTree/mac/MockWebNotificationProvider.mm	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/mac/MockWebNotificationProvider.mm	2012-08-29 20:32:19 UTC (rev 127042)
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "MockWebNotificationProvider.h"
+#import <WebKit/WebSecurityOriginPrivate.h>
+
+@implementation MockWebNotificationProvider
+
++ (MockWebNotificationProvider *)shared
+{
+    static MockWebNotificationProvider *provider = [[MockWebNotificationProvider alloc] init];
+    return provider;
+}
+
+- (id)init
+{
+    if (!(self = [super init]))
+        return nil;
+    _permissions.adoptNS([[NSMutableDictionary alloc] init]);
+    return self;
+}
+
+- (void)registerWebView:(WebView *)webView
+{
+    ASSERT(!_registeredWebViews.contains(webView));
+    _registeredWebViews.add(webView);
+}
+
+- (void)unregisterWebView:(WebView *)webView
+{
+    ASSERT(_registeredWebViews.contains(webView));
+    _registeredWebViews.remove(webView);
+}
+
+- (void)showNotification:(WebNotification *)notification fromWebView:(WebView *)webView
+{
+    ASSERT(_registeredWebViews.contains(webView));
+
+    uint64_t notificationID = [notification notificationID];
+    _notifications.add(notificationID, notification);
+    _notificationViewMap.add(notificationID, webView);
+
+    [webView _notificationDidShow:notificationID];
+}
+
+- (void)cancelNotification:(WebNotification *)notification
+{
+    uint64_t notificationID = [notification notificationID];
+    ASSERT(_notifications.contains(notificationID));
+
+    [_notificationViewMap.get(notificationID) _notificationsDidClose:[NSArray arrayWithObject:[NSNumber numberWithUnsignedLongLong:notificationID]]];
+}
+
+- (void)notificationDestroyed:(WebNotification *)notification
+{
+    _notifications.remove([notification notificationID]);
+    _notificationViewMap.remove([notification notificationID]);
+}
+
+- (void)clearNotifications:(NSArray *)notificationIDs
+{
+    for (NSNumber *notificationID in notificationIDs) {
+        uint64_t id = [notificationID unsignedLongLongValue];
+        RetainPtr<WebNotification> notification = _notifications.take(id);
+        _notificationViewMap.remove(id);
+    }
+}
+
+- (void)webView:(WebView *)webView didShowNotification:(uint64_t)notificationID
+{
+    [_notifications.get(notificationID).get() dispatchShowEvent];
+}
+
+- (void)webView:(WebView *)webView didClickNotification:(uint64_t)notificationID
+{
+    [_notifications.get(notificationID).get() dispatchClickEvent];
+}
+
+- (void)webView:(WebView *)webView didCloseNotifications:(NSArray *)notificationIDs
+{
+    for (NSNumber *notificationID in notificationIDs) {
+        uint64_t id = [notificationID unsignedLongLongValue];
+        NotificationIDMap::iterator it = _notifications.find(id);
+        ASSERT(it != _notifications.end());
+        [it->second.get() dispatchCloseEvent];
+        _notifications.remove(it);
+        _notificationViewMap.remove(id);
+    }
+}
+
+- (void)simulateWebNotificationClick:(uint64_t)notificationID
+{
+    ASSERT(_notifications.contains(notificationID));
+    [_notificationViewMap.get(notificationID) _notificationDidClick:notificationID];
+}
+
+- (WebNotificationPermission)policyForOrigin:(WebSecurityOrigin *)origin
+{
+    NSNumber *permission = [_permissions.get() objectForKey:[origin stringValue]];
+    if (!permission)
+        return WebNotificationPermissionNotAllowed;
+    if ([permission boolValue])
+        return WebNotificationPermissionAllowed;
+    return WebNotificationPermissionDenied;
+}
+
+- (void)setWebNotificationOrigin:(NSString*)origin permission:(BOOL)allowed
+{
+    [_permissions.get() setObject:[NSNumber numberWithBool:allowed] forKey:origin];
+}
+
+- (void)removeAllWebNotificationPermissions
+{
+    [_permissions.get() removeAllObjects];
+}
+
+- (void)reset
+{
+    _notifications.clear();
+    _notificationViewMap.clear();
+    [self removeAllWebNotificationPermissions];
+}
+
+@end

Modified: trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm (127041 => 127042)


--- trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm	2012-08-29 20:28:30 UTC (rev 127041)
+++ trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm	2012-08-29 20:32:19 UTC (rev 127042)
@@ -32,6 +32,7 @@
 
 #import "EditingDelegate.h"
 #import "MockGeolocationProvider.h"
+#import "MockWebNotificationProvider.h"
 #import "PolicyDelegate.h"
 #import "StorageTrackerDelegate.h"
 #import "UIDelegate.h"
@@ -1163,10 +1164,6 @@
     [[mainFrame webView] _setCustomBackingScaleFactor:backingScaleFactor];
 }
 
-void TestRunner::simulateLegacyWebNotificationClick(JSStringRef jsTitle)
-{
-}
-
 void TestRunner::resetPageVisibility()
 {
     // FIXME: Implement.
@@ -1187,20 +1184,32 @@
     // FIXME: Implement.
 }
 
-
 void TestRunner::grantWebNotificationPermission(JSStringRef jsOrigin)
 {
+    RetainPtr<CFStringRef> cfOrigin(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, jsOrigin));
+    ASSERT([[mainFrame webView] _notificationProvider] == [MockWebNotificationProvider shared]);
+    [[MockWebNotificationProvider shared] setWebNotificationOrigin:(NSString *)cfOrigin.get() permission:TRUE];
 }
 
 void TestRunner::denyWebNotificationPermission(JSStringRef jsOrigin)
 {
+    RetainPtr<CFStringRef> cfOrigin(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, jsOrigin));
+    ASSERT([[mainFrame webView] _notificationProvider] == [MockWebNotificationProvider shared]);
+    [[MockWebNotificationProvider shared] setWebNotificationOrigin:(NSString *)cfOrigin.get() permission:FALSE];
 }
 
 void TestRunner::removeAllWebNotificationPermissions()
 {
+    [[MockWebNotificationProvider shared] removeAllWebNotificationPermissions];
 }
 
 void TestRunner::simulateWebNotificationClick(JSValueRef jsNotification)
 {
+    uint64_t notificationID = [[mainFrame webView] _notificationIDForTesting:jsNotification];
+    [[MockWebNotificationProvider shared] simulateWebNotificationClick:notificationID];
 }
 
+void TestRunner::simulateLegacyWebNotificationClick(JSStringRef jsTitle)
+{
+}
+

Modified: trunk/Tools/DumpRenderTree/mac/UIDelegate.mm (127041 => 127042)


--- trunk/Tools/DumpRenderTree/mac/UIDelegate.mm	2012-08-29 20:28:30 UTC (rev 127041)
+++ trunk/Tools/DumpRenderTree/mac/UIDelegate.mm	2012-08-29 20:32:19 UTC (rev 127042)
@@ -32,6 +32,7 @@
 #import "DumpRenderTree.h"
 #import "DumpRenderTreeDraggingInfo.h"
 #import "EventSendingController.h"
+#import "MockWebNotificationProvider.h"
 #import "TestRunner.h"
 #import <WebKit/WebApplicationCache.h>
 #import <WebKit/WebFramePrivate.h>
@@ -288,6 +289,12 @@
     return TRUE;
 }
 
+- (void)webView:(WebView *)webView decidePolicyForNotificationRequestFromOrigin:(WebSecurityOrigin *)origin listener:(id<WebAllowDenyPolicyListener>)listener
+{
+    [(MockWebNotificationProvider *)[webView _notificationProvider] setWebNotificationOrigin:[origin stringValue] permission:YES];
+    [listener allow];
+}
+
 - (void)dealloc
 {
     [draggingInfo release];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to