1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 #include "config.h"
   5 
   6 #include "JavaEnv.h"
   7 #include "TestRunner.h"
   8 #include "EventSender.h"
   9 #include "WorkQueue.h"
  10 #include "WebCore/testing/js/WebCoreTestSupport.h"
  11 
  12 #include <wtf/RefPtr.h>
  13 #include <API/JavaScript.h>
  14 
  15 RefPtr<TestRunner> gTestRunner;
  16 
  17 #ifdef __cplusplus
  18 extern "C" {
  19 #endif
  20 
  21 JNIEXPORT void JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_init
  22     (JNIEnv* env, jclass cls, jstring testPath, jstring pixelsHash)
  23 {
  24     const char* testPathChars = env->GetStringUTFChars(testPath, NULL);
  25     const char* pixelsHashChars = env->GetStringUTFChars(pixelsHash, NULL);
  26 
  27     ASSERT(!gTestRunner);
  28     gTestRunner = TestRunner::create(testPathChars, pixelsHashChars);
  29 
  30     WorkQueue::shared()->clear();
  31 
  32     env->ReleaseStringUTFChars(testPath, testPathChars);
  33     env->ReleaseStringUTFChars(pixelsHash, pixelsHashChars);
  34 }
  35 
  36 JNIEXPORT void JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_didClearWindowObject
  37     (JNIEnv* env, jclass cls, jlong pContext, jlong pWindowObject,
  38     jobject eventSender)
  39 {
  40     ASSERT(gTestRunner);
  41     ASSERT(pContext);
  42     ASSERT(pWindowObject);
  43     ASSERT(eventSender);
  44 
  45     JSGlobalContextRef context =
  46             static_cast<JSGlobalContextRef>(jlong_to_ptr(pContext));
  47     JSObjectRef windowObject =
  48             static_cast<JSObjectRef>(jlong_to_ptr(pWindowObject));
  49 
  50     JSValueRef exception = 0;
  51 
  52     gTestRunner->makeWindowObject(context, windowObject, &exception);
  53     ASSERT(!exception);
  54 
  55     JLObject jlEventSender(eventSender, true);
  56     makeEventSender(context, windowObject, jlEventSender, &exception);
  57     ASSERT(!exception);
  58     WebCoreTestSupport::injectInternalsObject(context);
  59 }
  60 
  61 JNIEXPORT void JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_dispose
  62     (JNIEnv* env, jclass cls)
  63 {
  64     ASSERT(gTestRunner);
  65     gTestRunner.clear();
  66 }
  67 
  68 JNIEXPORT jboolean JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_dumpAsText
  69     (JNIEnv* env, jclass cls)
  70 {
  71     ASSERT(gTestRunner);
  72     return bool_to_jbool(gTestRunner->dumpAsText());
  73 }
  74 
  75 JNIEXPORT jboolean JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_dumpChildFramesAsText
  76     (JNIEnv* env, jclass cls)
  77 {
  78     ASSERT(gTestRunner);
  79     return bool_to_jbool(gTestRunner->dumpChildFramesAsText());
  80 }
  81 
  82 JNIEXPORT jboolean JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_didFinishLoad
  83     (JNIEnv* env, jclass cls)
  84 {
  85     ASSERT(gTestRunner);
  86     return bool_to_jbool(WorkQueue::shared()->processWork());
  87 }
  88 
  89 JNIEXPORT jboolean JNICALL Java_com_sun_javafx_webkit_drt_DumpRenderTree_dumpBackForwardList
  90     (JNIEnv* env, jclass cls)
  91 {
  92     ASSERT(gTestRunner);
  93     return bool_to_jbool(gTestRunner->dumpBackForwardList());
  94 }
  95 
  96 #ifdef __cplusplus
  97 }
  98 #endif