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 "InjectedBundleTest.h"
27f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch#include <WebKit2/WKBundlePageGroup.h>
28e14391e94c850b8bd03680c23b38978db68687a8John Reck#include <WebKit2/WKBundlePrivate.h>
29e14391e94c850b8bd03680c23b38978db68687a8John Reck#include <WebKit2/WKBundleScriptWorld.h>
30e14391e94c850b8bd03680c23b38978db68687a8John Reck#include <WebKit2/WKRetainPtr.h>
31f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch#include <WebKit2/WebKit2.h>
32f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch#include <assert.h>
33e14391e94c850b8bd03680c23b38978db68687a8John Reck
34e14391e94c850b8bd03680c23b38978db68687a8John Recknamespace TestWebKitAPI {
35e14391e94c850b8bd03680c23b38978db68687a8John Reck
36e14391e94c850b8bd03680c23b38978db68687a8John Reckclass DocumentStartUserScriptAlertCrashTest : public InjectedBundleTest {
37e14391e94c850b8bd03680c23b38978db68687a8John Reckpublic:
38e14391e94c850b8bd03680c23b38978db68687a8John Reck    DocumentStartUserScriptAlertCrashTest(const std::string& identifier)
39e14391e94c850b8bd03680c23b38978db68687a8John Reck        : InjectedBundleTest(identifier)
40e14391e94c850b8bd03680c23b38978db68687a8John Reck    {
41e14391e94c850b8bd03680c23b38978db68687a8John Reck    }
42e14391e94c850b8bd03680c23b38978db68687a8John Reck
43f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    virtual void initialize(WKBundleRef bundle, WKTypeRef userData)
44e14391e94c850b8bd03680c23b38978db68687a8John Reck    {
45f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID());
46f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        WKBundlePageGroupRef pageGroup = static_cast<WKBundlePageGroupRef>(userData);
47f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch
48e14391e94c850b8bd03680c23b38978db68687a8John Reck        WKRetainPtr<WKStringRef> source(AdoptWK, WKStringCreateWithUTF8CString("alert('an alert');"));
49f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        WKBundleAddUserScript(bundle, pageGroup, WKBundleScriptWorldNormalWorld(), source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames);
50e14391e94c850b8bd03680c23b38978db68687a8John Reck    }
51f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch
52f05b935882198ccf7d81675736e3aeb089c5113aBen Murdochprivate:
53f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    WKBundlePageGroupRef m_pageGroup;
54e14391e94c850b8bd03680c23b38978db68687a8John Reck};
55e14391e94c850b8bd03680c23b38978db68687a8John Reck
56e14391e94c850b8bd03680c23b38978db68687a8John Reckstatic InjectedBundleTest::Register<DocumentStartUserScriptAlertCrashTest> registrar("DocumentStartUserScriptAlertCrashTest");
57e14391e94c850b8bd03680c23b38978db68687a8John Reck
58e14391e94c850b8bd03680c23b38978db68687a8John Reck} // namespace TestWebKitAPI
59