|
| 1 | +/* |
| 2 | + * Copyright (C) 2014 Igalia S.L. |
| 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 | + |
| 28 | +#if WK_HAVE_C_SPI |
| 29 | + |
| 30 | +#include "PlatformUtilities.h" |
| 31 | +#include "PlatformWebView.h" |
| 32 | +#include "Test.h" |
| 33 | +#include <WebKit/WKRetainPtr.h> |
| 34 | + |
| 35 | +namespace TestWebKitAPI { |
| 36 | + |
| 37 | +TEST(WebKit2, PendingAPIRequestURL) |
| 38 | +{ |
| 39 | + WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); |
| 40 | + PlatformWebView webView(context.get()); |
| 41 | + |
| 42 | + WKRetainPtr<WKURLRef> activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 43 | + EXPECT_NULL(activeURL.get()); |
| 44 | + |
| 45 | + WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("simple", "html")); |
| 46 | + WKPageLoadURL(webView.page(), url.get()); |
| 47 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 48 | + ASSERT_NOT_NULL(activeURL.get()); |
| 49 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); |
| 50 | + WKPageStopLoading(webView.page()); |
| 51 | + |
| 52 | + WKRetainPtr<WKStringRef> htmlString = Util::toWK("<body>Hello, World</body>"); |
| 53 | + WKRetainPtr<WKURLRef> blankURL = adoptWK(WKURLCreateWithUTF8CString("about:blank")); |
| 54 | + WKPageLoadHTMLString(webView.page(), htmlString.get(), nullptr); |
| 55 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 56 | + ASSERT_NOT_NULL(activeURL.get()); |
| 57 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); |
| 58 | + WKPageStopLoading(webView.page()); |
| 59 | + |
| 60 | + url = adoptWK(WKURLCreateWithUTF8CString("http://www.webkit.org")); |
| 61 | + WKPageLoadHTMLString(webView.page(), htmlString.get(), url.get()); |
| 62 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 63 | + ASSERT_NOT_NULL(activeURL.get()); |
| 64 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); |
| 65 | + WKPageStopLoading(webView.page()); |
| 66 | + |
| 67 | + WKRetainPtr<WKDataRef> data = adoptWK(WKDataCreate(nullptr, 0)); |
| 68 | + WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, nullptr); |
| 69 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 70 | + ASSERT_NOT_NULL(activeURL.get()); |
| 71 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); |
| 72 | + WKPageStopLoading(webView.page()); |
| 73 | + |
| 74 | + WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, url.get()); |
| 75 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 76 | + ASSERT_NOT_NULL(activeURL.get()); |
| 77 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); |
| 78 | + WKPageStopLoading(webView.page()); |
| 79 | + |
| 80 | + WKPageLoadAlternateHTMLString(webView.page(), htmlString.get(), nullptr, url.get()); |
| 81 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 82 | + ASSERT_NOT_NULL(activeURL.get()); |
| 83 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); |
| 84 | + WKPageStopLoading(webView.page()); |
| 85 | + |
| 86 | + WKRetainPtr<WKStringRef> plainTextString = Util::toWK("Hello, World"); |
| 87 | + WKPageLoadPlainTextString(webView.page(), plainTextString.get()); |
| 88 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 89 | + ASSERT_NOT_NULL(activeURL.get()); |
| 90 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get())); |
| 91 | + WKPageStopLoading(webView.page()); |
| 92 | + |
| 93 | + url = adoptWK(WKURLCreateWithUTF8CString("file:///tmp/index.html")); |
| 94 | + WKPageLoadFile(webView.page(), url.get(), nullptr); |
| 95 | + activeURL = adoptWK(WKPageCopyActiveURL(webView.page())); |
| 96 | + ASSERT_NOT_NULL(activeURL.get()); |
| 97 | + EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get())); |
| 98 | + WKPageStopLoading(webView.page()); |
| 99 | +} |
| 100 | + |
| 101 | +} // namespace TestWebKitAPI |
| 102 | + |
| 103 | +#endif |
0 commit comments