1a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/* 2a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Copyright (C) 2010 Apple Inc. All rights reserved. 3a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 4a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Redistribution and use in source and binary forms, with or without 5a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * modification, are permitted provided that the following conditions 6a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * are met: 7a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 1. Redistributions of source code must retain the above copyright 8a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * notice, this list of conditions and the following disclaimer. 9a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 2. Redistributions in binary form must reproduce the above copyright 10a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * notice, this list of conditions and the following disclaimer in the 11a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * documentation and/or other materials provided with the distribution. 12a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 13a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * THE POSSIBILITY OF SUCH DAMAGE. 24a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch */ 25a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 26a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "Test.h" 27a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 28a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "PlatformUtilities.h" 29a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "PlatformWebView.h" 30a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include <WebKit2/WebKit2.h> 31a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include <WebKit2/WKRetainPtr.h> 32a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 33a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochnamespace TestWebKitAPI { 34a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 35a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch// FIXME: This should also test the that the load state after didFailLoadWithErrorForFrame is kWKFrameLoadStateFinished 36a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 37a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochstatic bool testDone; 38a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 39a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochstatic void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo) 40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch TEST_ASSERT(WKFrameGetFrameLoadState(frame) == kWKFrameLoadStateFinished); 42a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch WKURLRef url = WKFrameCopyProvisionalURL(frame); 4428040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu TEST_ASSERT(!url); 45a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 46a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch testDone = true; 47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 48a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 49a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochTEST(WebKit2, FailedLoad) 50a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{ 51a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); 52f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch PlatformWebView webView(context.get()); 53a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 54a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch WKPageLoaderClient loaderClient; 55a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch memset(&loaderClient, 0, sizeof(loaderClient)); 56a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 57a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch loaderClient.version = 0; 58a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch loaderClient.clientInfo = 0; 59a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch loaderClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame; 60a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch WKPageSetPageLoaderClient(webView.page(), &loaderClient); 61a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 62a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch WKRetainPtr<WKURLRef> url(AdoptWK, Util::URLForNonExistentResource()); 63a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch WKPageLoadURL(webView.page(), url.get()); 64a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 65a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch Util::run(&testDone); 66a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} 67a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 68a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} // namespace TestWebKitAPI 69