OSDN Git Service

Merge Webkit at r70949: Initial merge by git.
[android-x86/external-webkit.git] / WebKitTools / WebKitTestRunner / InjectedBundle / LayoutTestController.cpp
index f2393f1..e828c46 100644 (file)
 #include "InjectedBundlePage.h"
 #include "JSLayoutTestController.h"
 #include "StringFunctions.h"
+#include <WebKit2/WKBundleBackForwardList.h>
 #include <WebKit2/WKBundleFrame.h>
 #include <WebKit2/WKBundleFramePrivate.h>
 #include <WebKit2/WKBundlePagePrivate.h>
+#include <WebKit2/WKBundleScriptWorld.h>
 #include <WebKit2/WKBundlePrivate.h>
 #include <WebKit2/WKRetainPtr.h>
 #include <WebKit2/WebKit2.h>
@@ -40,7 +42,7 @@ namespace WTR {
 
 // This is lower than DumpRenderTree's timeout, to make it easier to work through the failures
 // Eventually it should be changed to match.
-static const CFTimeInterval waitToDumpWatchdogInterval = 6.0;
+const double LayoutTestController::waitToDumpWatchdogTimerInterval = 6;
 
 static JSValueRef propertyValue(JSContextRef context, JSObjectRef object, const char* propertyName)
 {
@@ -84,6 +86,7 @@ PassRefPtr<LayoutTestController> LayoutTestController::create()
 LayoutTestController::LayoutTestController()
     : m_whatToDump(RenderTree)
     , m_shouldDumpAllFrameScrollPositions(false)
+    , m_shouldDumpBackForwardListsForAllWindows(false)
     , m_shouldAllowEditing(true)
     , m_shouldCloseExtraWindows(false)
     , m_dumpEditingCallbacks(false)
@@ -93,6 +96,7 @@ LayoutTestController::LayoutTestController()
     , m_testRepaint(false)
     , m_testRepaintSweepHorizontally(false)
 {
+    platformInitialize();
 }
 
 LayoutTestController::~LayoutTestController()
@@ -109,32 +113,15 @@ void LayoutTestController::display()
     // FIXME: actually implement, once we want pixel tests
 }
 
-void LayoutTestController::invalidateWaitToDumpWatchdog()
-{
-    if (m_waitToDumpWatchdog) {
-        CFRunLoopTimerInvalidate(m_waitToDumpWatchdog.get());
-        m_waitToDumpWatchdog = 0;
-    }
-}
-
-static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info)
-{
-    InjectedBundle::shared().layoutTestController()->waitToDumpWatchdogTimerFired();
-}
-
 void LayoutTestController::waitUntilDone()
 {
     m_waitToDump = true;
-    if (!m_waitToDumpWatchdog) {
-        m_waitToDumpWatchdog.adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + waitToDumpWatchdogInterval, 
-                                                      0, 0, 0, waitUntilDoneWatchdogFired, NULL));
-        CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_waitToDumpWatchdog.get(), kCFRunLoopCommonModes);
-    }
+    initializeWaitToDumpWatchdogTimerIfNeeded();
 }
 
 void LayoutTestController::waitToDumpWatchdogTimerFired()
 {
-    invalidateWaitToDumpWatchdog();
+    invalidateWaitToDumpWatchdogTimer();
     const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
     InjectedBundle::shared().os() << message << "\n";
     InjectedBundle::shared().done();
@@ -163,6 +150,32 @@ bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef anima
     return WKBundleFramePauseAnimationOnElementWithId(mainFrame, toWK(animationName).get(), toWK(elementId).get(), time);
 }
 
+JSRetainPtr<JSStringRef> LayoutTestController::layerTreeAsText() const
+{
+    WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
+    WKRetainPtr<WKStringRef> text(AdoptWK, WKBundleFrameCopyLayerTreeAsText(mainFrame));
+    return toJS(text);
+}
+
+void LayoutTestController::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
+{
+    WKRetainPtr<WKStringRef> sourceWK = toWK(source);
+    WKRetainPtr<WKBundleScriptWorldRef> scriptWorld(AdoptWK, WKBundleScriptWorldCreateWorld());
+
+    WKBundleAddUserScript(InjectedBundle::shared().bundle(), scriptWorld.get(), sourceWK.get(), 0, 0, 0,
+        (runAtStart ? kWKInjectAtDocumentStart : kWKInjectAtDocumentEnd),
+        (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly));
+}
+
+void LayoutTestController::addUserStyleSheet(JSStringRef source, bool allFrames)
+{
+    WKRetainPtr<WKStringRef> sourceWK = toWK(source);
+    WKRetainPtr<WKBundleScriptWorldRef> scriptWorld(AdoptWK, WKBundleScriptWorldCreateWorld());
+
+    WKBundleAddUserStyleSheet(InjectedBundle::shared().bundle(), scriptWorld.get(), sourceWK.get(), 0, 0, 0,
+        (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly));
+}
+
 void LayoutTestController::keepWebHistory()
 {
     WKBundleSetShouldTrackVisitedLinks(InjectedBundle::shared().bundle(), true);
@@ -219,11 +232,21 @@ void LayoutTestController::setCanOpenWindows(bool)
     // For now, just ignore this setting, and if we find later it's needed we can add it.
 }
 
+void LayoutTestController::setXSSAuditorEnabled(bool enabled)
+{
+    WKBundleOverrideXSSAuditorEnabledForTestRunner(InjectedBundle::shared().bundle(), true);
+}
+
 unsigned LayoutTestController::windowCount()
 {
     return InjectedBundle::shared().pageCount();
 }
 
+void LayoutTestController::clearBackForwardList()
+{
+    WKBundleBackForwardListClear(WKBundlePageGetBackForwardList(InjectedBundle::shared().page()->page()));
+}
+
 // Object Creation
 
 void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)