diff options
Diffstat (limited to 'Source/WebCore/testing/js')
-rw-r--r-- | Source/WebCore/testing/js/WebCoreTestSupport.cpp | 130 | ||||
-rw-r--r-- | Source/WebCore/testing/js/WebCoreTestSupport.h | 34 | ||||
-rw-r--r-- | Source/WebCore/testing/js/WebCoreTestSupportPrefix.cpp | 26 | ||||
-rw-r--r-- | Source/WebCore/testing/js/WebCoreTestSupportPrefix.h | 158 |
4 files changed, 337 insertions, 11 deletions
diff --git a/Source/WebCore/testing/js/WebCoreTestSupport.cpp b/Source/WebCore/testing/js/WebCoreTestSupport.cpp index 92623793c..faffd0c4a 100644 --- a/Source/WebCore/testing/js/WebCoreTestSupport.cpp +++ b/Source/WebCore/testing/js/WebCoreTestSupport.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 Google Inc. All rights reserved. + * Copyright (C) 2011, 2015 Google Inc. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,8 +32,15 @@ #include "Internals.h" #include "JSDocument.h" #include "JSInternals.h" +#include "LogInitialization.h" +#include "MockGamepadProvider.h" +#include "Page.h" +#include "URLParser.h" +#include "WheelEventTestTrigger.h" #include <JavaScriptCore/APICast.h> +#include <JavaScriptCore/JSValueRef.h> #include <interpreter/CallFrame.h> +#include <runtime/IdentifierInlines.h> using namespace JSC; using namespace WebCore; @@ -45,8 +53,8 @@ void injectInternalsObject(JSContextRef context) JSLockHolder lock(exec); JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()); ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext(); - if (scriptContext->isDocument()) - globalObject->putDirect(exec->vm(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(toDocument(scriptContext)))); + if (is<Document>(*scriptContext)) + globalObject->putDirect(exec->vm(), Identifier::fromString(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(downcast<Document>(*scriptContext)))); } void resetInternalsObject(JSContextRef context) @@ -55,9 +63,121 @@ void resetInternalsObject(JSContextRef context) JSLockHolder lock(exec); JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()); ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext(); - Page* page = toDocument(scriptContext)->frame()->page(); - Internals::resetToConsistentState(page); + Page* page = downcast<Document>(scriptContext)->frame()->page(); + Internals::resetToConsistentState(*page); InternalSettings::from(page)->resetToConsistentState(); } +void monitorWheelEvents(WebCore::Frame& frame) +{ + Page* page = frame.page(); + if (!page) + return; + + page->ensureTestTrigger(); +} + +void setTestCallbackAndStartNotificationTimer(WebCore::Frame& frame, JSContextRef context, JSObjectRef jsCallbackFunction) +{ + Page* page = frame.page(); + if (!page || !page->expectsWheelEventTriggers()) + return; + + JSValueProtect(context, jsCallbackFunction); + + page->ensureTestTrigger().setTestCallbackAndStartNotificationTimer([=](void) { + JSObjectCallAsFunction(context, jsCallbackFunction, nullptr, 0, nullptr, nullptr); + JSValueUnprotect(context, jsCallbackFunction); + }); +} + +void clearWheelEventTestTrigger(WebCore::Frame& frame) +{ + Page* page = frame.page(); + if (!page) + return; + + page->clearTrigger(); +} + +void setLogChannelToAccumulate(const String& name) +{ +#if !LOG_DISABLED + WebCore::setLogChannelToAccumulate(name); +#else + UNUSED_PARAM(name); +#endif +} + +void initializeLogChannelsIfNecessary() +{ +#if !LOG_DISABLED || !RELEASE_LOG_DISABLED + WebCore::initializeLogChannelsIfNecessary(); +#endif +} + +void setAllowsAnySSLCertificate(bool allowAnySSLCertificate) +{ + InternalSettings::setAllowsAnySSLCertificate(allowAnySSLCertificate); +} + +void installMockGamepadProvider() +{ +#if ENABLE(GAMEPAD) + GamepadProvider::setSharedProvider(MockGamepadProvider::singleton()); +#endif +} + +void connectMockGamepad(unsigned gamepadIndex) +{ +#if ENABLE(GAMEPAD) + MockGamepadProvider::singleton().connectMockGamepad(gamepadIndex); +#else + UNUSED_PARAM(gamepadIndex); +#endif +} + +void disconnectMockGamepad(unsigned gamepadIndex) +{ +#if ENABLE(GAMEPAD) + MockGamepadProvider::singleton().disconnectMockGamepad(gamepadIndex); +#else + UNUSED_PARAM(gamepadIndex); +#endif +} + +void setMockGamepadDetails(unsigned gamepadIndex, const WTF::String& gamepadID, unsigned axisCount, unsigned buttonCount) +{ +#if ENABLE(GAMEPAD) + MockGamepadProvider::singleton().setMockGamepadDetails(gamepadIndex, gamepadID, axisCount, buttonCount); +#else + UNUSED_PARAM(gamepadIndex); + UNUSED_PARAM(gamepadID); + UNUSED_PARAM(axisCount); + UNUSED_PARAM(buttonCount); +#endif +} + +void setMockGamepadAxisValue(unsigned gamepadIndex, unsigned axisIndex, double axisValue) +{ +#if ENABLE(GAMEPAD) + MockGamepadProvider::singleton().setMockGamepadAxisValue(gamepadIndex, axisIndex, axisValue); +#else + UNUSED_PARAM(gamepadIndex); + UNUSED_PARAM(axisIndex); + UNUSED_PARAM(axisValue); +#endif +} + +void setMockGamepadButtonValue(unsigned gamepadIndex, unsigned buttonIndex, double buttonValue) +{ +#if ENABLE(GAMEPAD) + MockGamepadProvider::singleton().setMockGamepadButtonValue(gamepadIndex, buttonIndex, buttonValue); +#else + UNUSED_PARAM(gamepadIndex); + UNUSED_PARAM(buttonIndex); + UNUSED_PARAM(buttonValue); +#endif +} + } diff --git a/Source/WebCore/testing/js/WebCoreTestSupport.h b/Source/WebCore/testing/js/WebCoreTestSupport.h index de7fc747f..564094a52 100644 --- a/Source/WebCore/testing/js/WebCoreTestSupport.h +++ b/Source/WebCore/testing/js/WebCoreTestSupport.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 Google Inc. All rights reserved. + * Copyright (C) 2011, 2015 Google Inc. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,22 +24,43 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebCoreTestSupport_h -#define WebCoreTestSupport_h +#pragma once typedef const struct OpaqueJSContext* JSContextRef; +typedef struct OpaqueJSString* JSStringRef; +typedef struct OpaqueJSValue* JSObjectRef; -#if PLATFORM(MAC) +#if PLATFORM(COCOA) #define TEST_SUPPORT_EXPORT WTF_EXPORT_PRIVATE #else #define TEST_SUPPORT_EXPORT #endif +namespace WTF { +class String; +} + +namespace WebCore { +class Frame; +} + namespace WebCoreTestSupport { void injectInternalsObject(JSContextRef) TEST_SUPPORT_EXPORT; void resetInternalsObject(JSContextRef) TEST_SUPPORT_EXPORT; +void monitorWheelEvents(WebCore::Frame&) TEST_SUPPORT_EXPORT; +void setTestCallbackAndStartNotificationTimer(WebCore::Frame&, JSContextRef, JSObjectRef) TEST_SUPPORT_EXPORT; +void clearWheelEventTestTrigger(WebCore::Frame&) TEST_SUPPORT_EXPORT; -} // namespace WebCore +void setLogChannelToAccumulate(const WTF::String& name) TEST_SUPPORT_EXPORT; +void initializeLogChannelsIfNecessary() TEST_SUPPORT_EXPORT; +void setAllowsAnySSLCertificate(bool) TEST_SUPPORT_EXPORT; -#endif +void installMockGamepadProvider() TEST_SUPPORT_EXPORT; +void connectMockGamepad(unsigned index) TEST_SUPPORT_EXPORT; +void disconnectMockGamepad(unsigned index) TEST_SUPPORT_EXPORT; +void setMockGamepadDetails(unsigned index, const WTF::String& gamepadID, unsigned axisCount, unsigned buttonCount) TEST_SUPPORT_EXPORT; +void setMockGamepadAxisValue(unsigned index, unsigned axisIndex, double value) TEST_SUPPORT_EXPORT; +void setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value) TEST_SUPPORT_EXPORT; + +} // namespace WebCoreTestSupport diff --git a/Source/WebCore/testing/js/WebCoreTestSupportPrefix.cpp b/Source/WebCore/testing/js/WebCoreTestSupportPrefix.cpp new file mode 100644 index 000000000..30eaa33c4 --- /dev/null +++ b/Source/WebCore/testing/js/WebCoreTestSupportPrefix.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "WebCoreTestSupportPrefix.h" diff --git a/Source/WebCore/testing/js/WebCoreTestSupportPrefix.h b/Source/WebCore/testing/js/WebCoreTestSupportPrefix.h new file mode 100644 index 000000000..da9b0fce9 --- /dev/null +++ b/Source/WebCore/testing/js/WebCoreTestSupportPrefix.h @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2015 Apple Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +/* This prefix file should contain only: + * 1) files to precompile for faster builds + * 2) in one case at least: OS-X-specific performance bug workarounds + * 3) the special trick to catch us using new or delete without including "config.h" + * The project should be able to build without this header, although we rarely test that. + */ + +/* Things that need to be defined globally should go into "config.h". */ + +#if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H && defined(BUILDING_WITH_CMAKE) +#include "cmakeconfig.h" +#endif + +#include <wtf/Platform.h> + +#if defined(__APPLE__) +#ifdef __cplusplus +#define NULL __null +#else +#define NULL ((void *)0) +#endif +#endif + +#if OS(WINDOWS) + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x601 +#endif + +#ifndef WINVER +#define WINVER 0x0601 +#endif + +#if !USE(CURL) +#ifndef _WINSOCKAPI_ +#define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h +#endif +#endif + +#undef WEBCORE_EXPORT +#define WEBCORE_EXPORT WTF_IMPORT_DECLARATION +#define WEBCORE_TESTSUPPORT_EXPORT WTF_EXPORT_DECLARATION + +#else + +#include <pthread.h> + +#define WEBCORE_TESTSUPPORT_EXPORT WEBCORE_EXPORT + +#endif // OS(WINDOWS) + +#include <fcntl.h> +#include <sys/types.h> +#if defined(__APPLE__) +#include <regex.h> +#endif + +#include <setjmp.h> + +#include <signal.h> +#include <stdarg.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#if defined(__APPLE__) +#include <unistd.h> +#endif + +#ifdef __cplusplus +#include <algorithm> +#include <cstddef> +#include <new> +#endif + +#if defined(__APPLE__) +#include <sys/param.h> +#endif +#include <sys/stat.h> +#if defined(__APPLE__) +#include <sys/resource.h> +#include <sys/time.h> +#endif + +#include <CoreFoundation/CoreFoundation.h> +#if PLATFORM(WIN_CAIRO) +#include <ConditionalMacros.h> +#include <windows.h> +#else + +#if OS(WINDOWS) +#if USE(CG) + +// FIXME <rdar://problem/8208868> Remove support for obsolete ColorSync API, CoreServices header in CoreGraphics +// We can remove this once the new ColorSync APIs are available in an internal Safari SDK. +#include <ColorSync/ColorSync.h> +#ifdef __COLORSYNCDEPRECATED__ +#define COREGRAPHICS_INCLUDES_CORESERVICES_HEADER +#define OBSOLETE_COLORSYNC_API +#endif +#endif +#if USE(CFURLCONNECTION) +#include <CFNetwork/CFNetwork.h> +// On Windows, dispatch.h needs to be included before certain CFNetwork headers. +#include <dispatch/dispatch.h> +#endif +#include <windows.h> +#else +#if !PLATFORM(IOS) +#include <CoreServices/CoreServices.h> +#endif // !PLATFORM(IOS) +#endif // OS(WINDOWS) + +#endif + +#ifdef __OBJC__ +#if PLATFORM(IOS) +#import <Foundation/Foundation.h> +#else +#import <Cocoa/Cocoa.h> +#endif // PLATFORM(IOS) +#endif + +#ifdef __cplusplus +#define new ("if you use new/delete make sure to include config.h at the top of the file"()) +#define delete ("if you use new/delete make sure to include config.h at the top of the file"()) +#endif + +/* When C++ exceptions are disabled, the C++ library defines |try| and |catch| + * to allow C++ code that expects exceptions to build. These definitions + * interfere with Objective-C++ uses of Objective-C exception handlers, which + * use |@try| and |@catch|. As a workaround, undefine these macros. */ +#ifdef __OBJC__ +#undef try +#undef catch +#endif + |