1/*
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2015 Igalia S.L.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28
29#if WK_HAVE_C_SPI
30
31#include "JavaScriptTest.h"
32#include "PlatformUtilities.h"
33#include "PlatformWebView.h"
34
35#include <WebKit/WKContext.h>
36#include <WebKit/WKPage.h>
37#include <WebKit/WKRetainPtr.h>
38
39namespace TestWebKitAPI {
40
41static bool didFinishLoad = false;
42
43static void didFinishNavigation(WKPageRef page, WKNavigationRef, WKTypeRef userData, const void* clientInfo)
44{
45 didFinishLoad = true;
46}
47
48static void loadAlternateHTMLString(WKURLRef baseURL, WKURLRef unreachableURL)
49{
50 WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreateWithConfiguration(nullptr));
51 PlatformWebView webView(context.get());
52
53 WKPageNavigationClientV0 loaderClient;
54 memset(&loaderClient, 0, sizeof(loaderClient));
55
56 loaderClient.base.version = 0;
57 loaderClient.didFinishNavigation = didFinishNavigation;
58 WKPageSetPageNavigationClient(webView.page(), &loaderClient.base);
59
60 WKRetainPtr<WKStringRef> alternateHTMLString = adoptWK(WKStringCreateWithUTF8CString("<html><body><img src='icon.png'></body></html>"));
61 WKPageLoadAlternateHTMLString(webView.page(), alternateHTMLString.get(), baseURL, unreachableURL);
62
63 // If we can finish loading the html without resulting in an invalid message being sent from the WebProcess, this test passes.
64 Util::run(&didFinishLoad);
65}
66
67TEST(WebKit, LoadAlternateHTMLStringWithNonDirectoryURL)
68{
69 // Call WKPageLoadAlternateHTMLString() with fileURL which does not point to a directory.
70 WKRetainPtr<WKURLRef> fileURL = adoptWK(Util::createURLForResource("simple", "html"));
71 loadAlternateHTMLString(fileURL.get(), fileURL.get());
72}
73
74TEST(WebKit, LoadAlternateHTMLStringWithEmptyBaseURL)
75{
76 // Call WKPageLoadAlternateHTMLString() with empty baseURL to make sure this test works
77 // when baseURL does not grant read access to the unreachableURL. We use a separate test
78 // to ensure the previous test does not pollute the result.
79 WKRetainPtr<WKURLRef> unreachableURL = adoptWK(Util::URLForNonExistentResource());
80 loadAlternateHTMLString(nullptr, unreachableURL.get());
81}
82
83} // namespace TestWebKitAPI
84
85#endif
86