1e14391e94c850b8bd03680c23b38978db68687a8John Reck/* 2e14391e94c850b8bd03680c23b38978db68687a8John Reck * Copyright (C) 2010 Apple Inc. All rights reserved. 3e14391e94c850b8bd03680c23b38978db68687a8John Reck * 4e14391e94c850b8bd03680c23b38978db68687a8John Reck * Redistribution and use in source and binary forms, with or without 5e14391e94c850b8bd03680c23b38978db68687a8John Reck * modification, are permitted provided that the following conditions 6e14391e94c850b8bd03680c23b38978db68687a8John Reck * are met: 7e14391e94c850b8bd03680c23b38978db68687a8John Reck * 1. Redistributions of source code must retain the above copyright 8e14391e94c850b8bd03680c23b38978db68687a8John Reck * notice, this list of conditions and the following disclaimer. 9e14391e94c850b8bd03680c23b38978db68687a8John Reck * 2. Redistributions in binary form must reproduce the above copyright 10e14391e94c850b8bd03680c23b38978db68687a8John Reck * notice, this list of conditions and the following disclaimer in the 11e14391e94c850b8bd03680c23b38978db68687a8John Reck * documentation and/or other materials provided with the distribution. 12e14391e94c850b8bd03680c23b38978db68687a8John Reck * 13e14391e94c850b8bd03680c23b38978db68687a8John Reck * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14e14391e94c850b8bd03680c23b38978db68687a8John Reck * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15e14391e94c850b8bd03680c23b38978db68687a8John Reck * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16e14391e94c850b8bd03680c23b38978db68687a8John Reck * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17e14391e94c850b8bd03680c23b38978db68687a8John Reck * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18e14391e94c850b8bd03680c23b38978db68687a8John Reck * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19e14391e94c850b8bd03680c23b38978db68687a8John Reck * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20e14391e94c850b8bd03680c23b38978db68687a8John Reck * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21e14391e94c850b8bd03680c23b38978db68687a8John Reck * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22e14391e94c850b8bd03680c23b38978db68687a8John Reck * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23e14391e94c850b8bd03680c23b38978db68687a8John Reck * THE POSSIBILITY OF SUCH DAMAGE. 24e14391e94c850b8bd03680c23b38978db68687a8John Reck */ 25e14391e94c850b8bd03680c23b38978db68687a8John Reck 26e14391e94c850b8bd03680c23b38978db68687a8John Reck#include "Test.h" 27e14391e94c850b8bd03680c23b38978db68687a8John Reck 28e14391e94c850b8bd03680c23b38978db68687a8John Reck#include "PlatformUtilities.h" 29e14391e94c850b8bd03680c23b38978db68687a8John Reck#include "PlatformWebView.h" 30e14391e94c850b8bd03680c23b38978db68687a8John Reck#include <WebKit2/WebKit2.h> 31e14391e94c850b8bd03680c23b38978db68687a8John Reck#include <WebKit2/WKRetainPtr.h> 32e14391e94c850b8bd03680c23b38978db68687a8John Reck 33e14391e94c850b8bd03680c23b38978db68687a8John Recknamespace TestWebKitAPI { 34e14391e94c850b8bd03680c23b38978db68687a8John Reck 35e14391e94c850b8bd03680c23b38978db68687a8John Reckstatic bool done; 36e14391e94c850b8bd03680c23b38978db68687a8John Reck 37e14391e94c850b8bd03680c23b38978db68687a8John Reckstatic void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) 38e14391e94c850b8bd03680c23b38978db68687a8John Reck{ 39e14391e94c850b8bd03680c23b38978db68687a8John Reck TEST_ASSERT(frame); 40e14391e94c850b8bd03680c23b38978db68687a8John Reck TEST_ASSERT(WKFrameGetPage(frame) == page); 41e14391e94c850b8bd03680c23b38978db68687a8John Reck TEST_ASSERT(WKStringIsEqualToUTF8CString(alertText, "an alert")); 42e14391e94c850b8bd03680c23b38978db68687a8John Reck 43e14391e94c850b8bd03680c23b38978db68687a8John Reck done = true; 44e14391e94c850b8bd03680c23b38978db68687a8John Reck} 45e14391e94c850b8bd03680c23b38978db68687a8John Reck 46e14391e94c850b8bd03680c23b38978db68687a8John ReckTEST(WebKit2, DocumentStartUserScriptAlertCrashTest) 47e14391e94c850b8bd03680c23b38978db68687a8John Reck{ 48f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DocumentStartUserScriptAlertCrashTestPageGroup"))); 49f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch 50f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DocumentStartUserScriptAlertCrashTest", pageGroup.get())); 51f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch PlatformWebView webView(context.get(), pageGroup.get()); 52e14391e94c850b8bd03680c23b38978db68687a8John Reck 53e14391e94c850b8bd03680c23b38978db68687a8John Reck WKPageUIClient uiClient; 54e14391e94c850b8bd03680c23b38978db68687a8John Reck memset(&uiClient, 0, sizeof(uiClient)); 55e14391e94c850b8bd03680c23b38978db68687a8John Reck uiClient.version = 0; 56e14391e94c850b8bd03680c23b38978db68687a8John Reck uiClient.clientInfo = 0; 57e14391e94c850b8bd03680c23b38978db68687a8John Reck uiClient.runJavaScriptAlert = runJavaScriptAlert; 58e14391e94c850b8bd03680c23b38978db68687a8John Reck WKPageSetPageUIClient(webView.page(), &uiClient); 59e14391e94c850b8bd03680c23b38978db68687a8John Reck 60e14391e94c850b8bd03680c23b38978db68687a8John Reck WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html")); 61e14391e94c850b8bd03680c23b38978db68687a8John Reck WKPageLoadURL(webView.page(), url.get()); 62e14391e94c850b8bd03680c23b38978db68687a8John Reck 63e14391e94c850b8bd03680c23b38978db68687a8John Reck Util::run(&done); 64e14391e94c850b8bd03680c23b38978db68687a8John Reck} 65e14391e94c850b8bd03680c23b38978db68687a8John Reck 66e14391e94c850b8bd03680c23b38978db68687a8John Reck} // namespace TestWebKitAPI 67