OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 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" | |
27 #include "JavaScriptTest.h" | |
28 #include "PlatformUtilities.h" | |
29 #include "PlatformWebView.h" | |
30 #include <WebKit2/WKRetainPtr.h> | |
31 | |
32 namespace TestWebKitAPI { | |
33 | |
34 static bool didFinishLoad; | |
35 static bool didNotHandleKeyDownEvent; | |
36 | |
37 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) | |
38 { | |
39 didFinishLoad = true; | |
40 } | |
41 | |
42 static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, cons
t void*) | |
43 { | |
44 if (Util::isKeyDown(event)) | |
45 didNotHandleKeyDownEvent = true; | |
46 } | |
47 | |
48 TEST(WebKit2, SpacebarScrolling) | |
49 { | |
50 WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextWithInjectedBu
ndle()); | |
51 PlatformWebView webView(context.get()); | |
52 | |
53 WKPageLoaderClient loaderClient; | |
54 memset(&loaderClient, 0, sizeof(loaderClient)); | |
55 | |
56 loaderClient.version = 0; | |
57 loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; | |
58 WKPageSetPageLoaderClient(webView.page(), &loaderClient); | |
59 | |
60 WKPageUIClient uiClient; | |
61 memset(&uiClient, 0, sizeof(uiClient)); | |
62 | |
63 uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback; | |
64 WKPageSetPageUIClient(webView.page(), &uiClient); | |
65 | |
66 WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("spacebar-scro
lling", "html")); | |
67 WKPageLoadURL(webView.page(), url.get()); | |
68 Util::run(&didFinishLoad); | |
69 | |
70 EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()"); | |
71 EXPECT_JS_FALSE(webView.page(), "textFieldContainsSpace()"); | |
72 | |
73 webView.simulateSpacebarKeyPress(); | |
74 | |
75 EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()"); | |
76 EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()"); | |
77 | |
78 // On Mac, a key down event represents both a raw key down and a key press.
On Windows, a key | |
79 // down event only represents a raw key down. We expect the key press to be
handled (because it | |
80 // inserts text into the text field). But the raw key down should not be han
dled. | |
81 #if PLATFORM(MAC) | |
82 EXPECT_FALSE(didNotHandleKeyDownEvent); | |
83 #elif PLATFORM(WIN) | |
84 EXPECT_TRUE(didNotHandleKeyDownEvent); | |
85 #endif | |
86 | |
87 EXPECT_JS_EQ(webView.page(), "blurTextField()", "undefined"); | |
88 | |
89 didNotHandleKeyDownEvent = false; | |
90 webView.simulateSpacebarKeyPress(); | |
91 | |
92 // This EXPECT_JS_TRUE test fails on Windows port | |
93 // https://bugs.webkit.org/show_bug.cgi?id=84961 | |
94 #if !PLATFORM(WIN) | |
95 EXPECT_JS_TRUE(webView.page(), "isDocumentScrolled()"); | |
96 #endif | |
97 EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()"); | |
98 | |
99 #if PLATFORM(MAC) | |
100 EXPECT_FALSE(didNotHandleKeyDownEvent); | |
101 #elif PLATFORM(WIN) | |
102 EXPECT_TRUE(didNotHandleKeyDownEvent); | |
103 #endif | |
104 } | |
105 | |
106 } // namespace TestWebKitAPI | |
OLD | NEW |