bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
simon.fraser@apple.com | aead0ac | 2014-12-18 19:22:48 +0000 | [diff] [blame] | 27 | |
| 28 | #if WK_HAVE_C_SPI |
| 29 | |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 30 | #include "JavaScriptTest.h" |
| 31 | #include "PlatformUtilities.h" |
| 32 | #include "PlatformWebView.h" |
ossy@webkit.org | 87ea0ef | 2014-05-16 08:53:19 +0000 | [diff] [blame] | 33 | #include <WebKit/WKRetainPtr.h> |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 34 | |
| 35 | namespace TestWebKitAPI { |
| 36 | |
| 37 | static bool didFinishTest; |
| 38 | static bool didNotHandleKeyDownEvent; |
| 39 | |
| 40 | static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, const void*) |
| 45 | { |
| 46 | if (Util::isKeyDown(event)) |
| 47 | didNotHandleKeyDownEvent = true; |
| 48 | didFinishTest = true; |
| 49 | } |
| 50 | |
| 51 | TEST(WebKit2, DidNotHandleKeyDown) |
| 52 | { |
| 53 | WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextWithInjectedBundle()); |
| 54 | PlatformWebView webView(context.get()); |
| 55 | |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 56 | WKPageLoaderClientV0 loaderClient; |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 57 | memset(&loaderClient, 0, sizeof(loaderClient)); |
| 58 | |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 59 | loaderClient.base.version = 0; |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 60 | loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 61 | |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 62 | WKPageSetPageLoaderClient(webView.page(), &loaderClient.base); |
| 63 | |
| 64 | WKPageUIClientV0 uiClient; |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 65 | memset(&uiClient, 0, sizeof(uiClient)); |
| 66 | |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 67 | uiClient.base.version = 0; |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 68 | uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback; |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 69 | |
| 70 | WKPageSetPageUIClient(webView.page(), &uiClient.base); |
bdakin@apple.com | 29f0102 | 2013-08-09 19:58:51 +0000 | [diff] [blame] | 71 | |
| 72 | WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html")); |
| 73 | WKPageLoadURL(webView.page(), url.get()); |
| 74 | |
| 75 | webView.simulateSpacebarKeyPress(); |
| 76 | |
| 77 | Util::run(&didFinishTest); |
| 78 | EXPECT_TRUE(didNotHandleKeyDownEvent); |
| 79 | } |
| 80 | |
| 81 | } // namespace TestWebKitAPI |
simon.fraser@apple.com | aead0ac | 2014-12-18 19:22:48 +0000 | [diff] [blame] | 82 | |
| 83 | #endif |