|
Line 0
a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2013 INdT - Instituto Nokia de Tecnologia |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are |
| 6 |
* met: |
| 7 |
* |
| 8 |
* * Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* * Redistributions in binary form must reproduce the above |
| 11 |
* copyright notice, this list of conditions and the following disclaimer |
| 12 |
* in the documentation and/or other materials provided with the |
| 13 |
* distribution. |
| 14 |
* * Neither the name of Google Inc. nor the names of its |
| 15 |
* contributors may be used to endorse or promote products derived from |
| 16 |
* this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "config.h" |
| 32 |
|
| 33 |
#include "PlatformUtilities.h" |
| 34 |
#include "PlatformWebView.h" |
| 35 |
#include <WebKit2/WKContext.h> |
| 36 |
#include <WebKit2/WKPage.h> |
| 37 |
#include <WebKit2/WKPreferencesPrivate.h> |
| 38 |
#include <WebKit2/WKView.h> |
| 39 |
|
| 40 |
namespace TestWebKitAPI { |
| 41 |
|
| 42 |
static bool initialized = false; |
| 43 |
static bool terminated = false; |
| 44 |
static bool changedTitle = false; |
| 45 |
static bool initializedShared = false; |
| 46 |
static bool terminatedShared = false; |
| 47 |
static bool changedTitleShared = false; |
| 48 |
|
| 49 |
static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef, const void*) |
| 50 |
{ |
| 51 |
if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerInitMessage")) |
| 52 |
initialized = true; |
| 53 |
else if(WKStringIsEqualToUTF8CString(messageName, "WebWorkerTerminateMessage")) |
| 54 |
terminated = true; |
| 55 |
else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerSharedInitMessage")) |
| 56 |
initializedShared = true; |
| 57 |
else if(WKStringIsEqualToUTF8CString(messageName, "WebWorkerSharedTerminateMessage")) |
| 58 |
terminatedShared = true; |
| 59 |
} |
| 60 |
|
| 61 |
static void didReceiveTitleForFrame(WKPageRef, WKStringRef title, WKFrameRef, WKTypeRef, const void *) |
| 62 |
{ |
| 63 |
if (WKStringIsEqualToUTF8CString(title, "WebWorkerTitle")) |
| 64 |
changedTitle = true; |
| 65 |
else if (WKStringIsEqualToUTF8CString(title, "WebWorkerSharedTitle")) |
| 66 |
changedTitleShared = true; |
| 67 |
} |
| 68 |
|
| 69 |
TEST(WebKit2, WebWorker) |
| 70 |
{ |
| 71 |
// This test cover the binding between functions of JavaScript Workers and |
| 72 |
// functions defined at a previously loaded bundle. It verifies the two |
| 73 |
// types of Workers, dedicated and shared. |
| 74 |
|
| 75 |
WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("WebWorkerTest")); |
| 76 |
WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0)); |
| 77 |
|
| 78 |
WKViewInitialize(view.get()); |
| 79 |
|
| 80 |
|
| 81 |
WKPageLoaderClient pageLoaderClient; |
| 82 |
memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient)); |
| 83 |
pageLoaderClient.version = kWKPageLoaderClientCurrentVersion; |
| 84 |
pageLoaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame; |
| 85 |
WKPageSetPageLoaderClient(WKViewGetPage(view.get()), &pageLoaderClient); |
| 86 |
|
| 87 |
WKContextInjectedBundleClient injectedBundleClient; |
| 88 |
memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); |
| 89 |
injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; |
| 90 |
WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient); |
| 91 |
|
| 92 |
WKPageGroupRef pageGroup = WKPageGetPageGroup(WKViewGetPage(view.get())); |
| 93 |
WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup); |
| 94 |
WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); |
| 95 |
|
| 96 |
WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerTest", "html")); |
| 97 |
WKPageLoadURL(WKViewGetPage(view.get()), url.get()); |
| 98 |
Util::run(&initialized); |
| 99 |
Util::run(&terminated); |
| 100 |
Util::run(&changedTitle); |
| 101 |
|
| 102 |
url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerSharedTest", "html")); |
| 103 |
WKPageLoadURL(WKViewGetPage(view.get()), url.get()); |
| 104 |
Util::run(&initializedShared); |
| 105 |
Util::run(&terminatedShared); |
| 106 |
Util::run(&changedTitleShared); |
| 107 |
} |
| 108 |
|
| 109 |
} // TestWebKitAPI |