blob: 4c0c77963d3892131e66081fc7057d024f43a30c [file] [log] [blame]
aroben@apple.com01b14482011-03-15 04:30:44 +00001/*
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.orgf56d8d22011-09-15 14:08:42 +000026#include "config.h"
aroben@apple.com01b14482011-03-15 04:30:44 +000027#include "PlatformUtilities.h"
28#include "PlatformWebView.h"
29#include <WebKit2/WKContextPrivate.h>
aroben@apple.com01b14482011-03-15 04:30:44 +000030
31namespace TestWebKitAPI {
32
33static bool didReceiveMessage;
34static bool canHandleRequest;
35
36static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*)
37{
38 didReceiveMessage = true;
39
weinig@apple.com4eef3152011-05-16 20:28:20 +000040 EXPECT_WK_STREQ("DidCheckCanHandleRequest", messageName);
41 EXPECT_EQ(WKBooleanGetTypeID(), WKGetTypeID(body));
42
aroben@apple.com01b14482011-03-15 04:30:44 +000043 canHandleRequest = WKBooleanGetValue(static_cast<WKBooleanRef>(body));
44}
45
46static void setInjectedBundleClient(WKContextRef context)
47{
andersca@apple.coma8996642013-12-04 18:49:49 +000048 WKContextInjectedBundleClientV0 injectedBundleClient;
aroben@apple.com01b14482011-03-15 04:30:44 +000049 memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
andersca@apple.coma8996642013-12-04 18:49:49 +000050
51 injectedBundleClient.base.version = 0;
aroben@apple.com01b14482011-03-15 04:30:44 +000052 injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
53
andersca@apple.coma8996642013-12-04 18:49:49 +000054 WKContextSetInjectedBundleClient(context, &injectedBundleClient.base);
aroben@apple.com01b14482011-03-15 04:30:44 +000055}
56
57TEST(WebKit2, CanHandleRequest)
58{
weinig@apple.com79382172011-04-01 22:35:39 +000059 WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("CanHandleRequestTest"));
aroben@apple.com01b14482011-03-15 04:30:44 +000060 setInjectedBundleClient(context.get());
61
darin@apple.comb01ae172011-10-06 01:14:15 +000062 WKContextRegisterURLSchemeAsEmptyDocument(context.get(), Util::toWK("emptyscheme").get());
aroben@apple.com01b14482011-03-15 04:30:44 +000063
64 PlatformWebView webView(context.get());
65
weinig@apple.com79382172011-04-01 22:35:39 +000066 WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get());
aroben@apple.com01b14482011-03-15 04:30:44 +000067
68 WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("CheckCanHandleRequest").get(), 0);
69 Util::run(&didReceiveMessage);
weinig@apple.com4eef3152011-05-16 20:28:20 +000070 EXPECT_TRUE(canHandleRequest);
aroben@apple.com01b14482011-03-15 04:30:44 +000071}
72
73} // namespace TestWebKitAPI