[chromium] Need a way to test lost compositor context recovery
[WebKit-https.git] / Tools / DumpRenderTree / chromium / LayoutTestController.cpp
index 97c0dc0..ad23aab 100644 (file)
@@ -44,6 +44,7 @@
 #include "WebElement.h"
 #include "WebFrame.h"
 #include "WebGeolocationClientMock.h"
+#include "WebIDBFactory.h"
 #include "WebInputElement.h"
 #include "WebKit.h"
 #include "WebNotificationPresenter.h"
@@ -76,6 +77,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     , m_deferMainResourceDataLoad(false)
     , m_showDebugLayerTree(false)
     , m_workQueue(this)
+    , m_shouldStayOnPageAfterHandlingBeforeUnload(false)
 {
 
     // Initialize the map that associates methods of this class with the names
@@ -83,6 +85,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     // names to their methods will be done by calling bindToJavaScript() (defined
     // by CppBoundClass, the parent to LayoutTestController).
     bindMethod("addFileToPasteboardOnDrag", &LayoutTestController::addFileToPasteboardOnDrag);
+    bindMethod("addMockSpeechInputResult", &LayoutTestController::addMockSpeechInputResult);
     bindMethod("addOriginAccessWhitelistEntry", &LayoutTestController::addOriginAccessWhitelistEntry);
     bindMethod("addUserScript", &LayoutTestController::addUserScript);
     bindMethod("addUserStyleSheet", &LayoutTestController::addUserStyleSheet);
@@ -106,15 +109,16 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("dumpStatusCallbacks", &LayoutTestController::dumpWindowStatusChanges);
     bindMethod("dumpTitleChanges", &LayoutTestController::dumpTitleChanges);
     bindMethod("elementDoesAutoCompleteForElementWithId", &LayoutTestController::elementDoesAutoCompleteForElementWithId);
-    bindMethod("ensureShadowRoot", &LayoutTestController::ensureShadowRoot);
     bindMethod("evaluateInWebInspector", &LayoutTestController::evaluateInWebInspector);
     bindMethod("evaluateScriptInIsolatedWorld", &LayoutTestController::evaluateScriptInIsolatedWorld);
     bindMethod("setIsolatedWorldSecurityOrigin", &LayoutTestController::setIsolatedWorldSecurityOrigin);
     bindMethod("execCommand", &LayoutTestController::execCommand);
+    bindMethod("forceRedSelectionColors", &LayoutTestController::forceRedSelectionColors);
     bindMethod("grantDesktopNotificationPermission", &LayoutTestController::grantDesktopNotificationPermission);
     bindMethod("hasSpellingMarker", &LayoutTestController::hasSpellingMarker);
     bindMethod("isCommandEnabled", &LayoutTestController::isCommandEnabled);
     bindMethod("layerTreeAsText", &LayoutTestController::layerTreeAsText);
+    bindMethod("loseCompositorContext", &LayoutTestController::loseCompositorContext);
     bindMethod("markerTextForListItem", &LayoutTestController::markerTextForListItem);
     bindMethod("notifyDone", &LayoutTestController::notifyDone);
     bindMethod("numberOfActiveAnimations", &LayoutTestController::numberOfActiveAnimations);
@@ -134,7 +138,6 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("queueNonLoadingScript", &LayoutTestController::queueNonLoadingScript);
     bindMethod("queueReload", &LayoutTestController::queueReload);
     bindMethod("removeOriginAccessWhitelistEntry", &LayoutTestController::removeOriginAccessWhitelistEntry);
-    bindMethod("removeShadowRoot", &LayoutTestController::removeShadowRoot);
     bindMethod("repaintSweepHorizontally", &LayoutTestController::repaintSweepHorizontally);
     bindMethod("resetPageVisibility", &LayoutTestController::resetPageVisibility);
     bindMethod("resumeAnimations", &LayoutTestController::resumeAnimations);
@@ -154,6 +157,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("setDeferMainResourceDataLoad", &LayoutTestController::setDeferMainResourceDataLoad);
     bindMethod("setDomainRelaxationForbiddenForURLScheme", &LayoutTestController::setDomainRelaxationForbiddenForURLScheme);
     bindMethod("setEditingBehavior", &LayoutTestController::setEditingBehavior);
+    bindMethod("setAudioData", &LayoutTestController::setAudioData);
     bindMethod("setGeolocationPermission", &LayoutTestController::setGeolocationPermission);
     bindMethod("setIconDatabaseEnabled", &LayoutTestController::setIconDatabaseEnabled);
     bindMethod("setJavaScriptCanAccessClipboard", &LayoutTestController::setJavaScriptCanAccessClipboard);
@@ -162,7 +166,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("setMockDeviceOrientation", &LayoutTestController::setMockDeviceOrientation);
     bindMethod("setMockGeolocationError", &LayoutTestController::setMockGeolocationError);
     bindMethod("setMockGeolocationPosition", &LayoutTestController::setMockGeolocationPosition);
-    bindMethod("addMockSpeechInputResult", &LayoutTestController::addMockSpeechInputResult);
+    bindMethod("setOverrideIndexedDBBackingStore", &LayoutTestController::setOverrideIndexedDBBackingStore);
     bindMethod("setPageVisibility", &LayoutTestController::setPageVisibility);
     bindMethod("setPluginsEnabled", &LayoutTestController::setPluginsEnabled);
     bindMethod("setPopupBlockingEnabled", &LayoutTestController::setPopupBlockingEnabled);
@@ -172,7 +176,6 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("setSmartInsertDeleteEnabled", &LayoutTestController::setSmartInsertDeleteEnabled);
     bindMethod("setStopProvisionalFrameLoads", &LayoutTestController::setStopProvisionalFrameLoads);
     bindMethod("setTabKeyCyclesThroughElements", &LayoutTestController::setTabKeyCyclesThroughElements);
-    bindMethod("setTimelineProfilingEnabled", &LayoutTestController::setTimelineProfilingEnabled);
     bindMethod("setUserStyleSheetEnabled", &LayoutTestController::setUserStyleSheetEnabled);
     bindMethod("setUserStyleSheetLocation", &LayoutTestController::setUserStyleSheetLocation);
     bindMethod("setValueForUser", &LayoutTestController::setValueForUser);
@@ -182,8 +185,6 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("setWindowIsKey", &LayoutTestController::setWindowIsKey);
     bindMethod("setXSSAuditorEnabled", &LayoutTestController::setXSSAuditorEnabled);
     bindMethod("setAsynchronousSpellCheckingEnabled", &LayoutTestController::setAsynchronousSpellCheckingEnabled);
-    bindMethod("shadowRoot", &LayoutTestController::shadowRoot);
-    bindMethod("shadowPseudoId", &LayoutTestController::shadowPseudoId);
     bindMethod("showWebInspector", &LayoutTestController::showWebInspector);
     bindMethod("simulateDesktopNotificationClick", &LayoutTestController::simulateDesktopNotificationClick);
     bindMethod("suspendAnimations", &LayoutTestController::suspendAnimations);
@@ -194,6 +195,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("setTextDirection", &LayoutTestController::setTextDirection);
     bindMethod("setImagesAllowed", &LayoutTestController::setImagesAllowed);
     bindMethod("setStorageAllowed", &LayoutTestController::setStorageAllowed);
+    bindMethod("setPluginsAllowed", &LayoutTestController::setPluginsAllowed);
 
     // The following are stubs.
     bindMethod("abortModal", &LayoutTestController::abortModal);
@@ -219,6 +221,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("deleteLocalStorageForOrigin", &LayoutTestController::deleteLocalStorageForOrigin);
     bindMethod("observeStorageTrackerNotifications", &LayoutTestController::observeStorageTrackerNotifications);
     bindMethod("syncLocalStorage", &LayoutTestController::syncLocalStorage);
+    bindMethod("setShouldStayOnPageAfterHandlingBeforeUnload", &LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload);
     
     // The fallback method is called when an unknown method is invoked.
     bindFallbackMethod(&LayoutTestController::fallbackMethod);
@@ -499,7 +502,7 @@ void LayoutTestController::queueLoad(const CppArgumentList& arguments, CppVarian
 {
     if (arguments.size() > 0 && arguments[0].isString()) {
         // FIXME: Implement WebURL::resolve() and avoid GURL.
-        GURL currentURL = m_shell->webView()->mainFrame()->url();
+        GURL currentURL = m_shell->webView()->mainFrame()->document().url();
         GURL fullURL = currentURL.Resolve(arguments[0].toString());
 
         string target = "";
@@ -571,6 +574,7 @@ void LayoutTestController::reset()
         m_shell->webView()->removeAllUserContent();
     }
     m_dumpAsText = false;
+    m_dumpAsAudio = false;
     m_dumpEditingCallbacks = false;
     m_dumpFrameLoadCallbacks = false;
     m_dumpUserGestureInFrameLoadCallbacks = false;
@@ -610,6 +614,7 @@ void LayoutTestController::reset()
         m_closeRemainingWindows = true;
     m_workQueue.reset();
     m_taskList.revokeAll();
+    m_shouldStayOnPageAfterHandlingBeforeUnload = false;
 }
 
 void LayoutTestController::locationChangeDone()
@@ -669,73 +674,6 @@ void LayoutTestController::setAsynchronousSpellCheckingEnabled(const CppArgument
     result->setNull();
 }
 
-void LayoutTestController::shadowRoot(const CppArgumentList& arguments, CppVariant* result)
-{
-    if (arguments.size() != 1 || !arguments[0].isObject()) {
-        result->setNull();
-        return;
-    }
-
-    WebElement element;
-    if (!WebBindings::getElement(arguments[0].value.objectValue, &element)) {
-        result->setNull();
-        return;
-    }
-
-    NPObject* shadowRoot = WebBindings::makeNode(element.shadowRoot());
-    if (!shadowRoot) {
-        result->setNull();
-        return;
-    }
-
-    result->set(shadowRoot);
-    WebBindings::releaseObject(shadowRoot);
-}
-
-void LayoutTestController::ensureShadowRoot(const CppArgumentList& arguments, CppVariant* result)
-{
-    if (arguments.size() != 1 || !arguments[0].isObject()) {
-        result->setNull();
-        return;
-    }
-
-    WebElement element;
-    if (!WebBindings::getElement(arguments[0].value.objectValue, &element)) {
-        result->setNull();
-        return;
-    }
-
-    NPObject* shadowRoot = WebBindings::makeNode(element.ensureShadowRoot());
-    if (!shadowRoot) {
-        result->setNull();
-        return;
-    }
-
-    result->set(shadowRoot);
-    WebBindings::releaseObject(shadowRoot);
-}
-
-void LayoutTestController::removeShadowRoot(const CppArgumentList& arguments, CppVariant* result)
-{
-    if (arguments.size() != 1 || !arguments[0].isObject())
-        return;
-
-    WebElement element;
-    if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
-        return;
-
-    element.removeShadowRoot();
-}
-
-void LayoutTestController::shadowPseudoId(const CppArgumentList& arguments, CppVariant* result)
-{
-    WebElement element;
-    if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
-        result->setNull();
-    else
-        result->set(element.shadowPseudoId().utf8());
-}
-
 void LayoutTestController::showWebInspector(const CppArgumentList&, CppVariant* result)
 {
     m_shell->showDevTools();
@@ -837,6 +775,13 @@ void LayoutTestController::setStorageAllowed(const CppArgumentList& arguments, C
     result->setNull();
 }
 
+void LayoutTestController::setPluginsAllowed(const CppArgumentList& arguments, CppVariant* result)
+{
+    if (arguments.size() > 0 && arguments[0].isBool())
+        m_shell->webPermissions()->setPluginsAllowed(arguments[0].toBoolean());
+    result->setNull();
+}
+
 void LayoutTestController::setUseDashboardCompatibilityMode(const CppArgumentList&, CppVariant* result)
 {
     // We have no need to support Dashboard Compatibility Mode (mac-only)
@@ -1147,6 +1092,22 @@ void LayoutTestController::setIconDatabaseEnabled(const CppArgumentList&, CppVar
     result->setNull();
 }
 
+void LayoutTestController::setOverrideIndexedDBBackingStore(const CppArgumentList& arguments, CppVariant* result)
+{
+    result->setNull();
+#if ENABLE(INDEXED_DATABASE)
+    if (arguments.size() < 1 || !arguments[0].isString())
+        return;
+    string name = arguments[0].toString();
+    if (name == "default")
+        WebIDBFactory::setOverrideBackingStoreType(WebIDBFactory::DefaultBackingStore);
+    else if (name == "sqlite")
+        WebIDBFactory::setOverrideBackingStoreType(WebIDBFactory::SQLiteBackingStore);
+    else if (name == "leveldb")
+        WebIDBFactory::setOverrideBackingStoreType(WebIDBFactory::LevelDBBackingStore);
+#endif
+}
+
 void LayoutTestController::callShouldCloseOnWebView(const CppArgumentList&, CppVariant* result)
 {
     result->set(m_shell->webView()->dispatchBeforeUnloadEvent());
@@ -1330,10 +1291,9 @@ void LayoutTestController::setAllowUniversalAccessFromFileURLs(const CppArgument
 
 void LayoutTestController::setAllowDisplayOfInsecureContent(const CppArgumentList& arguments, CppVariant* result)
 {
-    if (arguments.size() > 0 && arguments[0].isBool()) {
-        m_shell->preferences()->allowDisplayOfInsecureContent = arguments[0].value.boolValue;
-        m_shell->applyPreferences();
-    }
+    if (arguments.size() > 0 && arguments[0].isBool())
+        m_shell->webPermissions()->setDisplayingInsecureContentAllowed(arguments[0].toBoolean());
+
     result->setNull();
 }
 
@@ -1348,10 +1308,9 @@ void LayoutTestController::setAllowFileAccessFromFileURLs(const CppArgumentList&
 
 void LayoutTestController::setAllowRunningOfInsecureContent(const CppArgumentList& arguments, CppVariant* result)
 {
-    if (arguments.size() > 0 && arguments[0].isBool()) {
-        m_shell->preferences()->allowRunningOfInsecureContent = arguments[0].value.boolValue;
-        m_shell->applyPreferences();
-    }
+    if (arguments.size() > 0 && arguments[0].isBool())
+        m_shell->webPermissions()->setRunningInsecureContentAllowed(arguments[0].value.boolValue);
+
     result->setNull();
 }
 
@@ -1468,6 +1427,12 @@ void LayoutTestController::overridePreference(const CppArgumentList& arguments,
         prefs->hyperlinkAuditingEnabled = cppVariantToBool(value);
     else if (key == "WebKitEnableCaretBrowsing")
         prefs->caretBrowsingEnabled = cppVariantToBool(value);
+    else if (key == "WebKitAllowDisplayingInsecureContent")
+        prefs->allowDisplayOfInsecureContent = cppVariantToBool(value);
+    else if (key == "WebKitAllowRunningInsecureContent")
+        prefs->allowRunningOfInsecureContent = cppVariantToBool(value);
+    else if (key == "WebKitHixie76WebSocketProtocolEnabled")
+        prefs->hixie76WebSocketProtocolEnabled = cppVariantToBool(value);
     else {
         string message("Invalid name for preference: ");
         message.append(key);
@@ -1639,20 +1604,18 @@ void LayoutTestController::setJavaScriptProfilingEnabled(const CppArgumentList&
     m_shell->drtDevToolsAgent()->setJavaScriptProfilingEnabled(arguments[0].toBoolean());
 }
 
-void LayoutTestController::setTimelineProfilingEnabled(const CppArgumentList& arguments, CppVariant* result)
+void LayoutTestController::evaluateInWebInspector(const CppArgumentList& arguments, CppVariant* result)
 {
     result->setNull();
-    if (arguments.size() < 1 || !arguments[0].isBool())
+    if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isString())
         return;
-    m_shell->drtDevToolsAgent()->setTimelineProfilingEnabled(arguments[0].toBoolean());
+    m_shell->drtDevToolsAgent()->evaluateInWebInspector(arguments[0].toInt32(), arguments[1].toString());
 }
 
-void LayoutTestController::evaluateInWebInspector(const CppArgumentList& arguments, CppVariant* result)
+void LayoutTestController::forceRedSelectionColors(const CppArgumentList& arguments, CppVariant* result)
 {
     result->setNull();
-    if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isString())
-        return;
-    m_shell->drtDevToolsAgent()->evaluateInWebInspector(arguments[0].toInt32(), arguments[1].toString());
+    m_shell->webView()->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
 }
 
 void LayoutTestController::addUserScript(const CppArgumentList& arguments, CppVariant* result)
@@ -1759,6 +1722,11 @@ void LayoutTestController::layerTreeAsText(const CppArgumentList& args, CppVaria
     result->set(m_shell->webView()->mainFrame()->layerTreeAsText(m_showDebugLayerTree).utf8());
 }
 
+void LayoutTestController::loseCompositorContext(const CppArgumentList&, CppVariant*)
+{
+    m_shell->webView()->loseCompositorContext();
+}
+
 void LayoutTestController::markerTextForListItem(const CppArgumentList& args, CppVariant* result)
 {
     WebElement element;
@@ -1847,6 +1815,14 @@ void LayoutTestController::syncLocalStorage(const CppArgumentList&, CppVariant*)
     // Not Implemented
 }
 
+void LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload(const CppArgumentList& arguments, CppVariant* result)
+{
+    if (arguments.size() == 1 && arguments[0].isBool())
+        m_shouldStayOnPageAfterHandlingBeforeUnload = arguments[0].toBoolean();
+
+    result->setNull();
+}
+
 void LayoutTestController::setPluginsEnabled(const CppArgumentList& arguments, CppVariant* result)
 {
     if (arguments.size() > 0 && arguments[0].isBool()) {
@@ -1894,3 +1870,20 @@ void LayoutTestController::setTextDirection(const CppArgumentList& arguments, Cp
 
     m_shell->webView()->setTextDirection(direction);
 }
+
+void LayoutTestController::setAudioData(const CppArgumentList& arguments, CppVariant* result)
+{
+    result->setNull();
+
+    if (arguments.size() < 1 || !arguments[0].isObject())
+        return;
+
+    // Check that passed-in object is, in fact, an ArrayBufferView.
+    NPObject* npobject = NPVARIANT_TO_OBJECT(arguments[0]);
+    if (!npobject)
+        return;
+    if (!WebBindings::getArrayBufferView(npobject, &m_audioData))
+        return;
+
+    setShouldDumpAsAudio(true);
+}