Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / testing / Internals.cpp
index 1735dd0..3a66ea2 100644 (file)
@@ -42,6 +42,7 @@
 #include "core/css/resolver/ViewportStyleResolver.h"
 #include "core/dom/ClientRect.h"
 #include "core/dom/ClientRectList.h"
+#include "core/dom/DOMArrayBuffer.h"
 #include "core/dom/DOMPoint.h"
 #include "core/dom/DOMStringList.h"
 #include "core/dom/Document.h"
@@ -67,6 +68,7 @@
 #include "core/editing/SpellChecker.h"
 #include "core/editing/SurroundingText.h"
 #include "core/editing/TextIterator.h"
+#include "core/editing/markup.h"
 #include "core/fetch/MemoryCache.h"
 #include "core/fetch/ResourceFetcher.h"
 #include "core/frame/EventHandlerRegistry.h"
 #include "core/page/Page.h"
 #include "core/page/PagePopupController.h"
 #include "core/page/PrintContext.h"
+#include "core/plugins/testing/DictionaryPluginPlaceholder.h"
+#include "core/plugins/testing/DocumentFragmentPluginPlaceholder.h"
 #include "core/rendering/RenderLayer.h"
 #include "core/rendering/RenderMenuList.h"
 #include "core/rendering/RenderObject.h"
 #include "core/testing/MockPagePopupDriver.h"
 #include "core/testing/PrivateScriptTest.h"
 #include "core/testing/TypeConversions.h"
+#include "core/testing/UnionTypesTest.h"
 #include "core/workers/WorkerThread.h"
 #include "platform/Cursor.h"
 #include "platform/Language.h"
@@ -148,11 +153,11 @@ namespace blink {
 
 namespace {
 
-class InternalsIterator FINAL : public Iterator {
+class InternalsIterator final : public Iterator {
 public:
     InternalsIterator() : m_current(0) { }
 
-    virtual ScriptValue next(ScriptState* scriptState, ExceptionState& exceptionState) OVERRIDE
+    virtual ScriptValue next(ScriptState* scriptState, ExceptionState& exceptionState) override
     {
         v8::Isolate* isolate = scriptState->isolate();
         int value = m_current * m_current;
@@ -162,7 +167,7 @@ public:
         return ScriptValue(scriptState, v8IteratorResult(scriptState, value));
     }
 
-    virtual ScriptValue next(ScriptState* scriptState, ScriptValue value, ExceptionState& exceptionState) OVERRIDE
+    virtual ScriptValue next(ScriptState* scriptState, ScriptValue value, ExceptionState& exceptionState) override
     {
         exceptionState.throwTypeError("Not implemented");
         return ScriptValue();
@@ -294,7 +299,7 @@ GCObservation* Internals::observeGC(ScriptValue scriptValue)
     v8::Handle<v8::Value> observedValue = scriptValue.v8Value();
     ASSERT(!observedValue.IsEmpty());
     if (observedValue->IsNull() || observedValue->IsUndefined()) {
-        V8ThrowException::throwTypeError("value to observe is null or undefined", v8::Isolate::GetCurrent());
+        V8ThrowException::throwTypeError(v8::Isolate::GetCurrent(), "value to observe is null or undefined");
         return nullptr;
     }
 
@@ -350,7 +355,8 @@ bool Internals::isLoadingFromMemoryCache(const String& url)
 {
     if (!contextDocument())
         return false;
-    Resource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url));
+    const String cacheIdentifier = contextDocument()->fetcher()->getCacheIdentifier();
+    Resource* resource = memoryCache()->resourceForURL(contextDocument()->completeURL(url), cacheIdentifier);
     return resource && resource->status() == Resource::Cached;
 }
 
@@ -541,6 +547,12 @@ PassRefPtrWillBeRawPtr<CSSStyleDeclaration> Internals::computedStyleIncludingVis
     return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
 }
 
+PassRefPtrWillBeRawPtr<ShadowRoot> Internals::createUserAgentShadowRoot(Element* host)
+{
+    ASSERT(host);
+    return PassRefPtrWillBeRawPtr<ShadowRoot>(host->ensureUserAgentShadowRoot());
+}
+
 ShadowRoot* Internals::shadowRoot(Element* host)
 {
     // FIXME: Internals::shadowRoot() in tests should be converted to youngestShadowRoot() or oldestShadowRoot().
@@ -682,6 +694,20 @@ PassRefPtrWillBeRawPtr<PagePopupController> Internals::pagePopupController()
     return s_pagePopupDriver ? s_pagePopupDriver->pagePopupController() : 0;
 }
 
+LocalDOMWindow* Internals::pagePopupWindow() const
+{
+    Document* document = contextDocument();
+    if (!document)
+        return nullptr;
+    Page* page = document->page();
+    if (!page)
+        return nullptr;
+    PagePopupDriver* pagePopupDriver = page->chrome().client().pagePopupDriver();
+    if (!pagePopupDriver)
+        return nullptr;
+    return pagePopupDriver->pagePopupWindow();
+}
+
 PassRefPtrWillBeRawPtr<ClientRect> Internals::absoluteCaretBounds(ExceptionState& exceptionState)
 {
     Document* document = contextDocument();
@@ -786,7 +812,7 @@ void Internals::setMarkedTextMatchesAreHighlighted(Document* document, bool high
     document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
 }
 
-void Internals::setScrollViewPosition(Document* document, long x, long y, ExceptionState& exceptionState)
+void Internals::setFrameViewPosition(Document* document, long x, long y, ExceptionState& exceptionState)
 {
     ASSERT(document);
     if (!document->view()) {
@@ -994,7 +1020,7 @@ DOMPoint* Internals::touchPositionAdjustedToBestClickableNode(long x, long y, lo
     IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
     HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
 
-    Node* targetNode;
+    Node* targetNode = 0;
     IntPoint adjustedPoint;
 
     bool foundNode = eventHandler.bestClickableNodeForHitTestResult(result, adjustedPoint, targetNode);
@@ -1021,7 +1047,7 @@ Node* Internals::touchNodeAdjustedToBestClickableNode(long x, long y, long width
     IntPoint hitTestPoint = document->frame()->view()->windowToContents(point);
     HitTestResult result = eventHandler.hitTestResultAtPoint(hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active, radius);
 
-    Node* targetNode;
+    Node* targetNode = 0;
     IntPoint adjustedPoint;
     document->frame()->eventHandler().bestClickableNodeForHitTestResult(result, adjustedPoint, targetNode);
     return targetNode;
@@ -1090,7 +1116,7 @@ PassRefPtrWillBeRawPtr<ClientRect> Internals::bestZoomableAreaForTouchPoint(long
     IntSize radius(width / 2, height / 2);
     IntPoint point(x + radius.width(), y + radius.height());
 
-    Node* targetNode;
+    Node* targetNode = 0;
     IntRect zoomableArea;
     bool foundNode = document->frame()->eventHandler().bestZoomableAreaForTouchPoint(point, radius, zoomableArea, targetNode);
     if (foundNode)
@@ -1432,11 +1458,11 @@ String Internals::dumpRefCountedInstanceCounts() const
 
 Vector<String> Internals::consoleMessageArgumentCounts(Document* document) const
 {
-    LocalFrame* frame = document->frame();
-    if (!frame)
+    FrameHost* host = document->frameHost();
+    if (!host)
         return Vector<String>();
 
-    Vector<unsigned> counts = frame->console().messageStorage()->argumentCounts();
+    Vector<unsigned> counts = host->consoleMessageStorage().argumentCounts();
     Vector<String> result(counts.size());
     for (size_t i = 0; i < counts.size(); i++)
         result[i] = String::number(counts[i]);
@@ -1463,6 +1489,17 @@ void Internals::setInspectorResourcesDataSizeLimits(int maximumResourcesContentS
     page->inspectorController().setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
 }
 
+String Internals::inspectorHighlightJSON(Node* node, ExceptionState& exceptionState)
+{
+    Page* page = contextDocument()->frame()->page();
+    if (!page) {
+        exceptionState.throwDOMException(InvalidAccessError, "No page can be obtained from the current context document.");
+        return String();
+    }
+    RefPtr<JSONObject> json(page->inspectorController().highlightJSONForNode(node));
+    return json->toPrettyJSONString();
+}
+
 bool Internals::hasGrammarMarker(Document* document, int from, int length)
 {
     ASSERT(document);
@@ -1537,26 +1574,6 @@ bool Internals::scrollsWithRespectTo(Element* element1, Element* element2, Excep
     return layer1->scrollsWithRespectTo(layer2);
 }
 
-bool Internals::isUnclippedDescendant(Element* element, ExceptionState& exceptionState)
-{
-    ASSERT(element);
-    element->document().view()->updateLayoutAndStyleForPainting();
-
-    RenderObject* renderer = element->renderer();
-    if (!renderer || !renderer->isBox()) {
-        exceptionState.throwDOMException(InvalidAccessError, renderer ? "The provided element's renderer is not a box." : "The provided element has no renderer.");
-        return 0;
-    }
-
-    RenderLayer* layer = toRenderBox(renderer)->layer();
-    if (!layer) {
-        exceptionState.throwDOMException(InvalidAccessError, "No render layer can be obtained from the provided element.");
-        return 0;
-    }
-
-    return layer->isUnclippedDescendant();
-}
-
 String Internals::layerTreeAsText(Document* document, unsigned flags, ExceptionState& exceptionState) const
 {
     ASSERT(document);
@@ -1770,7 +1787,7 @@ TypeConversions* Internals::typeConversions() const
 
 PrivateScriptTest* Internals::privateScriptTest() const
 {
-    return PrivateScriptTest::create(frame());
+    return PrivateScriptTest::create(frame()->document());
 }
 
 DictionaryTest* Internals::dictionaryTest() const
@@ -1778,6 +1795,11 @@ DictionaryTest* Internals::dictionaryTest() const
     return DictionaryTest::create();
 }
 
+UnionTypesTest* Internals::unionTypesTest() const
+{
+    return UnionTypesTest::create();
+}
+
 Vector<String> Internals::getReferencedFilePaths() const
 {
     return frame()->loader().currentItem()->getReferencedFilePaths();
@@ -1958,15 +1980,15 @@ String Internals::getCurrentCursorInfo(Document* document, ExceptionState& excep
     return result.toString();
 }
 
-PassRefPtr<ArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
+PassRefPtr<DOMArrayBuffer> Internals::serializeObject(PassRefPtr<SerializedScriptValue> value) const
 {
     String stringValue = value->toWireString();
     RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(stringValue.length(), sizeof(UChar));
     stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0, stringValue.length());
-    return buffer.release();
+    return DOMArrayBuffer::create(buffer.release());
 }
 
-PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<ArrayBuffer> buffer) const
+PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(PassRefPtr<DOMArrayBuffer> buffer) const
 {
     String value(static_cast<const UChar*>(buffer->data()), buffer->byteLength() / sizeof(UChar));
     return SerializedScriptValue::createFromWire(value);
@@ -2105,7 +2127,7 @@ private:
     {
     }
 
-    virtual ScriptValue call(ScriptValue value) OVERRIDE
+    virtual ScriptValue call(ScriptValue value) override
     {
         v8::Local<v8::Value> v8Value = value.v8Value();
         ASSERT(v8Value->IsNumber());
@@ -2155,6 +2177,21 @@ ScriptPromise Internals::promiseCheckRange(ScriptState* scriptState, long arg1)
     return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
 }
 
+ScriptPromise Internals::promiseCheckOverload(ScriptState* scriptState, Location*)
+{
+    return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
+}
+
+ScriptPromise Internals::promiseCheckOverload(ScriptState* scriptState, Document*)
+{
+    return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
+}
+
+ScriptPromise Internals::promiseCheckOverload(ScriptState* scriptState, Location*, long, long)
+{
+    return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(), "done"));
+}
+
 void Internals::trace(Visitor* visitor)
 {
     visitor->trace(m_runtimeFlags);
@@ -2243,18 +2280,13 @@ void Internals::hideAllTransitionElements()
         frame()->document()->hideTransitionElements(AtomicString(iter->selector));
 }
 
-void Internals::forcePluginPlaceholder(HTMLElement* element, const String& htmlSource, ExceptionState& exceptionState)
+void Internals::forcePluginPlaceholder(HTMLElement* element, PassRefPtrWillBeRawPtr<DocumentFragment> fragment, ExceptionState& exceptionState)
 {
     if (!element->isPluginElement()) {
         exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a plugin.");
         return;
     }
-
-    element->ensureUserAgentShadowRoot().setInnerHTML(htmlSource, exceptionState);
-    if (exceptionState.hadException())
-        return;
-
-    toHTMLPlugInElement(element)->setUsePlaceholderContent(true);
+    toHTMLPlugInElement(element)->setPlaceholder(DocumentFragmentPluginPlaceholder::create(fragment));
 }
 
 void Internals::forcePluginPlaceholder(HTMLElement* element, const Dictionary& options, ExceptionState& exceptionState)
@@ -2263,19 +2295,7 @@ void Internals::forcePluginPlaceholder(HTMLElement* element, const Dictionary& o
         exceptionState.throwDOMException(InvalidNodeTypeError, "The element provided is not a plugin.");
         return;
     }
-
-    RefPtrWillBeRawPtr<PluginPlaceholderElement> placeholder = PluginPlaceholderElement::create(element->document());
-    String stringValue;
-    if (DictionaryHelper::get(options, "message", stringValue))
-        placeholder->setMessage(stringValue);
-
-    ShadowRoot& shadowRoot = element->ensureUserAgentShadowRoot();
-    shadowRoot.removeChildren();
-    shadowRoot.appendChild(placeholder.release(), exceptionState);
-    if (exceptionState.hadException())
-        return;
-
-    toHTMLPlugInElement(element)->setUsePlaceholderContent(true);
+    toHTMLPlugInElement(element)->setPlaceholder(DictionaryPluginPlaceholder::create(element->document(), options));
 }
 
 Iterator* Internals::iterator(ScriptState* scriptState, ExceptionState& exceptionState)