aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
commit-queue@webkit.org | f56d8d2 | 2011-09-15 14:08:42 +0000 | [diff] [blame] | 26 | #include "config.h" |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 27 | #include "PlatformUtilities.h" |
| 28 | #include "PlatformWebView.h" |
| 29 | #include <WebKit2/WKContextPrivate.h> |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 30 | |
| 31 | namespace TestWebKitAPI { |
| 32 | |
| 33 | static bool didReceiveMessage; |
| 34 | static bool canHandleRequest; |
| 35 | |
| 36 | static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) |
| 37 | { |
| 38 | didReceiveMessage = true; |
| 39 | |
weinig@apple.com | 4eef315 | 2011-05-16 20:28:20 +0000 | [diff] [blame] | 40 | EXPECT_WK_STREQ("DidCheckCanHandleRequest", messageName); |
| 41 | EXPECT_EQ(WKBooleanGetTypeID(), WKGetTypeID(body)); |
| 42 | |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 43 | canHandleRequest = WKBooleanGetValue(static_cast<WKBooleanRef>(body)); |
| 44 | } |
| 45 | |
| 46 | static void setInjectedBundleClient(WKContextRef context) |
| 47 | { |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 48 | WKContextInjectedBundleClientV0 injectedBundleClient; |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 49 | memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 50 | |
| 51 | injectedBundleClient.base.version = 0; |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 52 | injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; |
| 53 | |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 54 | WKContextSetInjectedBundleClient(context, &injectedBundleClient.base); |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | TEST(WebKit2, CanHandleRequest) |
| 58 | { |
weinig@apple.com | 7938217 | 2011-04-01 22:35:39 +0000 | [diff] [blame] | 59 | WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("CanHandleRequestTest")); |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 60 | setInjectedBundleClient(context.get()); |
| 61 | |
darin@apple.com | b01ae17 | 2011-10-06 01:14:15 +0000 | [diff] [blame] | 62 | WKContextRegisterURLSchemeAsEmptyDocument(context.get(), Util::toWK("emptyscheme").get()); |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 63 | |
| 64 | PlatformWebView webView(context.get()); |
| 65 | |
weinig@apple.com | 7938217 | 2011-04-01 22:35:39 +0000 | [diff] [blame] | 66 | WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 67 | |
| 68 | WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("CheckCanHandleRequest").get(), 0); |
| 69 | Util::run(&didReceiveMessage); |
weinig@apple.com | 4eef315 | 2011-05-16 20:28:20 +0000 | [diff] [blame] | 70 | EXPECT_TRUE(canHandleRequest); |
aroben@apple.com | 01b1448 | 2011-03-15 04:30:44 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace TestWebKitAPI |