blob: 079c51856d177e7df657b04aa8a867fa6eca4eea [file] [log] [blame]
aroben@apple.com95ea66c2011-02-04 21:50:48 +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.com95ea66c2011-02-04 21:50:48 +000027#include "JavaScriptTest.h"
28#include "PlatformUtilities.h"
29#include "PlatformWebView.h"
aroben@apple.comf9702302011-08-19 14:50:05 +000030#include "Test.h"
aroben@apple.com95ea66c2011-02-04 21:50:48 +000031
32namespace TestWebKitAPI {
33
34static bool didFinishLoad;
35
36static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
37{
38 didFinishLoad = true;
39}
40
41static void setPageLoaderClient(WKPageRef page)
42{
andersca@apple.coma8996642013-12-04 18:49:49 +000043 WKPageLoaderClientV0 loaderClient;
aroben@apple.com95ea66c2011-02-04 21:50:48 +000044 memset(&loaderClient, 0, sizeof(loaderClient));
andersca@apple.coma8996642013-12-04 18:49:49 +000045
46 loaderClient.base.version = 0;
aroben@apple.com95ea66c2011-02-04 21:50:48 +000047 loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
48
andersca@apple.coma8996642013-12-04 18:49:49 +000049 WKPageSetPageLoaderClient(page, &loaderClient.base);
aroben@apple.com95ea66c2011-02-04 21:50:48 +000050}
51
52static WKRetainPtr<WKDataRef> createSessionStateContainingFormData(WKContextRef context)
53{
54 PlatformWebView webView(context);
55 setPageLoaderClient(webView.page());
56
weinig@apple.com79382172011-04-01 22:35:39 +000057 WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-form", "html")).get());
aroben@apple.com95ea66c2011-02-04 21:50:48 +000058 Util::run(&didFinishLoad);
59 didFinishLoad = false;
60
aroben@apple.com96692252011-08-15 19:30:42 +000061 EXPECT_JS_EQ(webView.page(), "submitForm()", "undefined");
aroben@apple.com95ea66c2011-02-04 21:50:48 +000062 Util::run(&didFinishLoad);
63 didFinishLoad = false;
64
weinig@apple.com79382172011-04-01 22:35:39 +000065 return adoptWK(WKPageCopySessionState(webView.page(), 0, 0));
aroben@apple.com95ea66c2011-02-04 21:50:48 +000066}
67
68TEST(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.com4eef3152011-05-16 20:28:20 +000079 EXPECT_NOT_NULL(data);
aroben@apple.com95ea66c2011-02-04 21:50:48 +000080
81 WKPageRestoreFromSessionState(webView.page(), data.get());
82 Util::run(&didFinishLoad);
83
weinig@apple.com4eef3152011-05-16 20:28:20 +000084 EXPECT_TRUE(WKPageCanGoBack(webView.page()));
aroben@apple.com95ea66c2011-02-04 21:50:48 +000085}
86
87} // namespace TestWebKitAPI