| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Intel Corporation. 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 THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "ewk_view_private.h" | |
| 28 #include "PlatformUtilities.h" | |
| 29 #include "PlatformWebView.h" | |
| 30 #include "Test.h" | |
| 31 #include "WKView.h" | |
| 32 #include <WebKit2/WKRetainPtr.h> | |
| 33 | |
| 34 namespace TestWebKitAPI { | |
| 35 | |
| 36 struct TestStatesData { | |
| 37 TestStatesData(WKViewRef view, WKURLRef url) | |
| 38 : view(view) | |
| 39 , url(url) | |
| 40 , didFinishLoad(false) | |
| 41 , didCrash(false) | |
| 42 , didRelaunch(false) | |
| 43 { | |
| 44 } | |
| 45 | |
| 46 WKViewRef view; | |
| 47 WKURLRef url; | |
| 48 bool didFinishLoad; | |
| 49 bool didCrash; | |
| 50 bool didRelaunch; | |
| 51 }; | |
| 52 | |
| 53 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*
clientInfo) | |
| 54 { | |
| 55 TestStatesData* states = const_cast<TestStatesData*>(static_cast<const TestS
tatesData*>(clientInfo)); | |
| 56 states->didFinishLoad = true; | |
| 57 } | |
| 58 | |
| 59 static void setPageLoaderClient(WKPageRef page, const void* clientInfo) | |
| 60 { | |
| 61 WKPageLoaderClient loaderClient; | |
| 62 memset(&loaderClient, 0, sizeof(loaderClient)); | |
| 63 | |
| 64 loaderClient.didFinishLoadForFrame = didFinishLoadForFrame; | |
| 65 loaderClient.clientInfo = clientInfo; | |
| 66 | |
| 67 WKPageSetPageLoaderClient(page, &loaderClient); | |
| 68 } | |
| 69 | |
| 70 void webProcessCrashed(WKViewRef view, WKURLRef url, const void* clientInfo) | |
| 71 { | |
| 72 TestStatesData* states = const_cast<TestStatesData*>(static_cast<const TestS
tatesData*>(clientInfo)); | |
| 73 | |
| 74 EXPECT_EQ(states->view, view); | |
| 75 EXPECT_TRUE(WKURLIsEqual(url, states->url)); | |
| 76 | |
| 77 states->didCrash = true; | |
| 78 } | |
| 79 | |
| 80 void webProcessDidRelaunch(WKViewRef view, const void* clientInfo) | |
| 81 { | |
| 82 TestStatesData* states = const_cast<TestStatesData*>(static_cast<const TestS
tatesData*>(clientInfo)); | |
| 83 | |
| 84 EXPECT_EQ(states->view, view); | |
| 85 | |
| 86 states->didRelaunch = true; | |
| 87 } | |
| 88 | |
| 89 static void setViewClient(WKViewRef view, const void* clientInfo) | |
| 90 { | |
| 91 WKViewClient viewClient; | |
| 92 memset(&viewClient, 0, sizeof(WKViewClient)); | |
| 93 | |
| 94 viewClient.version = kWKViewClientCurrentVersion; | |
| 95 viewClient.clientInfo = clientInfo; | |
| 96 viewClient.webProcessCrashed = webProcessCrashed; | |
| 97 viewClient.webProcessDidRelaunch = webProcessDidRelaunch; | |
| 98 | |
| 99 WKViewSetViewClient(view, &viewClient); | |
| 100 } | |
| 101 | |
| 102 TEST(WebKit2, WKViewClientWebProcessCallbacks) | |
| 103 { | |
| 104 WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); | |
| 105 WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "htm
l")); | |
| 106 | |
| 107 PlatformWebView view(context.get()); | |
| 108 WKViewRef wkView = EWKViewGetWKView(view.platformView()); | |
| 109 | |
| 110 TestStatesData states = TestStatesData(wkView, url.get()); | |
| 111 | |
| 112 setPageLoaderClient(view.page(), &states); | |
| 113 setViewClient(wkView, &states); | |
| 114 | |
| 115 WKPageLoadURL(view.page(), url.get()); | |
| 116 Util::run(&states.didFinishLoad); | |
| 117 | |
| 118 WKPageTerminate(view.page()); | |
| 119 Util::run(&states.didCrash); | |
| 120 | |
| 121 WKPageReload(view.page()); | |
| 122 Util::run(&states.didRelaunch); | |
| 123 } | |
| 124 | |
| 125 } // namespace TestWebKitAPI | |
| OLD | NEW |