aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +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 | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 27 | #include "JavaScriptTest.h" |
| 28 | #include "PlatformUtilities.h" |
| 29 | #include "PlatformWebView.h" |
aroben@apple.com | f970230 | 2011-08-19 14:50:05 +0000 | [diff] [blame] | 30 | #include "Test.h" |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 31 | |
| 32 | namespace TestWebKitAPI { |
| 33 | |
| 34 | static bool didFinishLoad; |
| 35 | |
| 36 | static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*) |
| 37 | { |
| 38 | didFinishLoad = true; |
| 39 | } |
| 40 | |
| 41 | static void setPageLoaderClient(WKPageRef page) |
| 42 | { |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 43 | WKPageLoaderClientV0 loaderClient; |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 44 | memset(&loaderClient, 0, sizeof(loaderClient)); |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 45 | |
| 46 | loaderClient.base.version = 0; |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 47 | loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; |
| 48 | |
andersca@apple.com | a899664 | 2013-12-04 18:49:49 +0000 | [diff] [blame] | 49 | WKPageSetPageLoaderClient(page, &loaderClient.base); |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static WKRetainPtr<WKDataRef> createSessionStateContainingFormData(WKContextRef context) |
| 53 | { |
| 54 | PlatformWebView webView(context); |
| 55 | setPageLoaderClient(webView.page()); |
| 56 | |
weinig@apple.com | 7938217 | 2011-04-01 22:35:39 +0000 | [diff] [blame] | 57 | WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-form", "html")).get()); |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 58 | Util::run(&didFinishLoad); |
| 59 | didFinishLoad = false; |
| 60 | |
aroben@apple.com | 9669225 | 2011-08-15 19:30:42 +0000 | [diff] [blame] | 61 | EXPECT_JS_EQ(webView.page(), "submitForm()", "undefined"); |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 62 | Util::run(&didFinishLoad); |
| 63 | didFinishLoad = false; |
| 64 | |
weinig@apple.com | 7938217 | 2011-04-01 22:35:39 +0000 | [diff] [blame] | 65 | return adoptWK(WKPageCopySessionState(webView.page(), 0, 0)); |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | TEST(WebKit2, RestoreSessionStateContainingFormData) |
| 69 | { |
| 70 | WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); |
| 71 | |
| 72 | // FIXME: Once <rdar://problem/8708435> is fixed, we can move the creation of this |
| 73 | // PlatformWebView after the call to createSessionStaetContainingFormData. Until then, it must |
| 74 | // remain here to avoid a race condition between the UI and web processes. |
| 75 | PlatformWebView webView(context.get()); |
| 76 | setPageLoaderClient(webView.page()); |
| 77 | |
| 78 | WKRetainPtr<WKDataRef> data = createSessionStateContainingFormData(context.get()); |
weinig@apple.com | 4eef315 | 2011-05-16 20:28:20 +0000 | [diff] [blame] | 79 | EXPECT_NOT_NULL(data); |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 80 | |
| 81 | WKPageRestoreFromSessionState(webView.page(), data.get()); |
| 82 | Util::run(&didFinishLoad); |
| 83 | |
weinig@apple.com | 4eef315 | 2011-05-16 20:28:20 +0000 | [diff] [blame] | 84 | EXPECT_TRUE(WKPageCanGoBack(webView.page())); |
aroben@apple.com | 95ea66c | 2011-02-04 21:50:48 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } // namespace TestWebKitAPI |