+2012-07-02 Leandro Gracia Gil <leandrogracia@chromium.org>
+
+ [Chromium] Implement a Layout Test for editing/SurroundingText
+ https://bugs.webkit.org/show_bug.cgi?id=82461
+
+ Reviewed by Ryosuke Niwa.
+
+ Add a new layout test for the surrounding text feature.
+
+ * platform/chromium/editing/surrounding-text/surrounding-text-expected.txt: Added.
+ * platform/chromium/editing/surrounding-text/surrounding-text.html: Added.
+
2012-07-02 Emil A Eklund <eae@chromium.org>
Unreviewed chromium rebaseline.
--- /dev/null
+Test the extraction of the text surrounding an element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 0, 100) is "12345 6789 12345 6789"
+PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 5, 6) is "89 123"
+PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 5, 0) is ""
+PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 5, 1) is "1"
+PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 6, 2) is "12"
+PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 100, 5) is ""
+PASS surroundingText('<select>.</select><div>57th Street and Lake Shore Drive</div> <span>Chicago</span> <span id="here">IL</span> <span>60637</span><select>.</select>', 0, 100) is "57th Street and Lake Shore Drive Chicago IL 60637"
+PASS surroundingText('<fieldset>.</fieldset>12345<button>abc</button><p>6789<br id="here"/>12345</p>6789<textarea>abc</textarea>0123<fieldset>.</fieldset>', 0, 100) is "6789 12345 6789"
+PASS surroundingText('<button>.</button><div id="here">This is <!-- comment --!>a test <' + 'script language="javascript"><' + '/script>example<button>.</button>', 0, 100) is "This is a test example"
+PASS surroundingText('<button>.</button><div id="here">012345678901234567890123456789</div><button>.</button>', 15, 12) is "901234567890"
+PASS surroundingText('<option>.</option>12345<button id="here">test</button><option>.</option>', 0, 100) is ""
+PASS surroundingText('<option>.</option>12345<button>te<span id="here">st</span></button><option>.</option>', 0, 100) is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../../../fast/js/resources/js-test-pre.js"></script>
+<div id="test">
+</div>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description('Test the extraction of the text surrounding an element.');
+
+function surroundingText(html, offset, maxLength) {
+ document.getElementById('test').innerHTML = html;
+
+ var here = document.getElementById('here');
+ if (here == null)
+ throw 'Test case needs an element with id "here"';
+
+ var node = here.hasChildNodes() ? here.firstChild : here.nextSibling;
+ if (node == null)
+ throw 'No node after "here" element';
+
+ var text = window.testRunner.textSurroundingElement(node, offset, maxLength);
+ return text.replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
+}
+
+function run() {
+ if (!window.testRunner)
+ return;
+
+ shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 0, 100)', '12345 6789 12345 6789');
+ shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 5, 6)', '89 123');
+ shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 5, 0)', '');
+ shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 5, 1)', '1');
+ shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 6, 2)', '12');
+ shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 100, 5)', '');
+ shouldBeEqualToString('surroundingText(\'<select>.</select><div>57th Street and Lake Shore Drive</div> <span>Chicago</span> <span id="here">IL</span> <span>60637</span><select>.</select>\', 0, 100)', '57th Street and Lake Shore Drive Chicago IL 60637');
+ shouldBeEqualToString('surroundingText(\'<fieldset>.</fieldset>12345<button>abc</button><p>6789<br id="here"/>12345</p>6789<textarea>abc</textarea>0123<fieldset>.</fieldset>\', 0, 100)', '6789 12345 6789');
+ shouldBeEqualToString('surroundingText(\'<button>.</button><div id="here">This is <!-- comment --!>a test <\' + \'script language="javascript"><\' + \'/script>example<button>.</button>\', 0, 100)', 'This is a test example');
+ shouldBeEqualToString('surroundingText(\'<button>.</button><div id="here">012345678901234567890123456789</div><button>.</button>\', 15, 12)', '901234567890');
+ shouldBeEqualToString('surroundingText(\'<option>.</option>12345<button id="here">test</button><option>.</option>\', 0, 100)', '');
+ shouldBeEqualToString('surroundingText(\'<option>.</option>12345<button>te<span id="here">st</span></button><option>.</option>\', 0, 100)', '');
+
+ document.body.removeChild(document.getElementById('test'));
+ finishJSTest();
+}
+
+window.onload = run;
+window.jsTestIsAsync = true;
+window.successfullyParsed = true;
+</script>
+<script src="../../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+2012-07-02 Leandro Gracia Gil <leandrogracia@chromium.org>
+
+ [Chromium] Implement a Layout Test for editing/SurroundingText
+ https://bugs.webkit.org/show_bug.cgi?id=82461
+
+ Reviewed by Ryosuke Niwa.
+
+ Allow passing nodes as arguments for layout test methods.
+
+ * public/WebBindings.h:
+ (WebBindings):
+ * src/WebBindings.cpp:
+ (WebKit::getNodeImpl):
+ (WebKit):
+ (WebKit::WebBindings::getNode):
+
2012-07-02 Benjamin Poulain <bpoulain@apple.com>
Do not do any logging initialization when logging is disabled
// If so, return it as a WebArrayBufferView object.
WEBKIT_EXPORT static bool getArrayBufferView(NPObject* arrayBufferView, WebArrayBufferView*);
+ // Return true (success) if the given npobj is a node.
+ // If so, return that node as a WebNode object.
+ WEBKIT_EXPORT static bool getNode(NPObject* element, WebNode*);
+
// Return true (success) if the given npobj is an element.
// If so, return that element as a WebElement object.
WEBKIT_EXPORT static bool getElement(NPObject* element, WebElement*);
return true;
}
+static bool getNodeImpl(NPObject* object, WebNode* webNode)
+{
+ if (!object || (object->_class != npScriptObjectClass))
+ return false;
+
+ V8NPObject* v8NPObject = reinterpret_cast<V8NPObject*>(object);
+ v8::Handle<v8::Object> v8Object(v8NPObject->v8Object);
+ Node* native = V8Node::HasInstance(v8Object) ? V8Node::toNative(v8Object) : 0;
+ if (!native)
+ return false;
+
+ *webNode = WebNode(native);
+ return true;
+}
+
static bool getElementImpl(NPObject* object, WebElement* webElement)
{
if (!object || (object->_class != npScriptObjectClass))
#endif
}
+bool WebBindings::getNode(NPObject* node, WebNode* webNode)
+{
+#if USE(V8)
+ return getNodeImpl(node, webNode);
+#else
+ // Not supported on other ports (JSC, etc.).
+ return false;
+#endif
+}
+
bool WebBindings::getElement(NPObject* element, WebElement* webElement)
{
#if USE(V8)
+2012-07-02 Leandro Gracia Gil <leandrogracia@chromium.org>
+
+ [Chromium] Implement a Layout Test for editing/SurroundingText
+ https://bugs.webkit.org/show_bug.cgi?id=82461
+
+ Reviewed by Ryosuke Niwa.
+
+ Add a new method to the layout test controller in order to retrieve the
+ text surrounding a provided element.
+
+ * DumpRenderTree/chromium/LayoutTestController.cpp:
+ (LayoutTestController::LayoutTestController):
+ (LayoutTestController::textSurroundingElement):
+ * DumpRenderTree/chromium/LayoutTestController.h:
+ (LayoutTestController):
+
2012-07-02 Ojan Vafai <ojan@chromium.org>
Delete unused rebaseline method in gardeningserver.py
#include "TestShell.h"
#include "WebAnimationController.h"
#include "WebBindings.h"
-#include "WebWorkerInfo.h"
#include "WebConsoleMessage.h"
-#include "platform/WebData.h"
#include "WebDeviceOrientation.h"
#include "WebDeviceOrientationClientMock.h"
#include "WebDocument.h"
#include "WebPrintParams.h"
#include "WebScriptSource.h"
#include "WebSecurityPolicy.h"
-#include "platform/WebSerializedScriptValue.h"
#include "WebSettings.h"
-#include "platform/WebSize.h"
-#include "platform/WebURL.h"
+#include "WebSurroundingText.h"
#include "WebView.h"
#include "WebViewHost.h"
+#include "WebWorkerInfo.h"
+#include "platform/WebData.h"
+#include "platform/WebSerializedScriptValue.h"
+#include "platform/WebSize.h"
+#include "platform/WebURL.h"
#include "v8/include/v8.h"
#include "webkit/support/webkit_support.h"
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <sstream>
-#include <wtf/text/WTFString.h>
#include <wtf/OwnArrayPtr.h>
+#include <wtf/text/WTFString.h>
#if OS(LINUX) || OS(ANDROID)
#include "linux/WebFontRendering.h"
bindMethod("setFixedLayoutSize", &LayoutTestController::setFixedLayoutSize);
bindMethod("selectionAsMarkup", &LayoutTestController::selectionAsMarkup);
bindMethod("setHasCustomFullScreenBehavior", &LayoutTestController::setHasCustomFullScreenBehavior);
-
+ bindMethod("textSurroundingElement", &LayoutTestController::textSurroundingElement);
+
// The fallback method is called when an unknown method is invoked.
bindFallbackMethod(&LayoutTestController::fallbackMethod);
result->setNull();
}
#endif
+
+void LayoutTestController::textSurroundingElement(const CppArgumentList& arguments, CppVariant* result)
+{
+ result->setNull();
+ if (arguments.size() < 3 || !arguments[0].isObject() || !arguments[1].isNumber() || !arguments[2].isNumber())
+ return;
+
+ WebNode node;
+ if (!WebBindings::getNode(arguments[0].value.objectValue, &node))
+ return;
+
+ if (node.isNull() || !node.isTextNode())
+ return;
+
+ unsigned offset = arguments[1].toInt32();
+ if (offset >= node.nodeValue().length()) {
+ result->set(WebString().utf8());
+ return;
+ }
+
+ WebSurroundingText surroundingText;
+ unsigned maxLength = arguments[2].toInt32();
+ surroundingText.initialize(node, offset, maxLength);
+ result->set(surroundingText.textContent().utf8());
+}
// Used to set the device scale factor.
void setBackingScaleFactor(const CppArgumentList&, CppVariant*);
+ // Retrieves the text surrounding a position in a text node.
+ // The first child of the element given y its id will be used as reference,
+ // or its next sibling if not present. It must be a text node.
+ void textSurroundingElement(const CppArgumentList&, CppVariant*);
+
public:
// The following methods are not exposed to JavaScript.
void setWorkQueueFrozen(bool frozen) { m_workQueue.setFrozen(frozen); }