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