Skip to content

Commit

Permalink
Converts drag-in-iframe.html to utilize w3c test harness
Browse files Browse the repository at this point in the history
Because of "drag-in-iframe.html" doesn't require pixel comparison, this patch
converts "drag-in-iframe.html" to utilize w3c test harness with introducing
|internals.getDragCaret()| to check position of drag caret in test scripts, for
ease of maintenance.

Note: This patch helps to utilize --enable-display-compositor-pixel-dump.

Bug: 891427
Change-Id: Ie1ae56ac971271bccd6109a5044d25b433620f92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1552397
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648082}
  • Loading branch information
yosinch authored and Commit Bot committed Apr 5, 2019
1 parent ae159fe commit 695e802
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 21 deletions.
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/editing/drag_caret.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DragCaret final : public GarbageCollectedFinalized<DragCaret>,
bool IsContentRichlyEditable() const;

bool HasCaret() const { return position_.IsNotNull(); }
const PositionWithAffinity& CaretPosition() { return position_; }
const PositionWithAffinity& CaretPosition() const { return position_; }
void SetCaretPosition(const PositionWithAffinity&);
void Clear() { SetCaretPosition(PositionWithAffinity()); }

Expand Down
12 changes: 12 additions & 0 deletions third_party/blink/renderer/core/testing/internals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "third_party/blink/renderer/core/dom/shadow_root_v0.h"
#include "third_party/blink/renderer/core/dom/static_node_list.h"
#include "third_party/blink/renderer/core/dom/tree_scope.h"
#include "third_party/blink/renderer/core/editing/drag_caret.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
Expand Down Expand Up @@ -2898,6 +2899,17 @@ void Internals::forceReload(bool bypass_cache) {
: WebFrameLoadType::kReload);
}

StaticSelection* Internals::getDragCaret() {
SelectionInDOMTree::Builder builder;
if (GetFrame()) {
const DragCaret& caret = GetFrame()->GetPage()->GetDragCaret();
const PositionWithAffinity& position = caret.CaretPosition();
if (position.GetDocument() == GetFrame()->GetDocument())
builder.Collapse(caret.CaretPosition());
}
return StaticSelection::FromSelectionInDOMTree(builder.Build());
}

StaticSelection* Internals::getSelectionInFlatTree(
DOMWindow* window,
ExceptionState& exception_state) {
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/testing/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ class Internals final : public ScriptWrappable {
int selectPopupItemStyleFontHeight(Node*, int);
void resetTypeAheadSession(HTMLSelectElement*);

StaticSelection* getDragCaret();
StaticSelection* getSelectionInFlatTree(DOMWindow*, ExceptionState&);
Node* visibleSelectionAnchorNode();
unsigned visibleSelectionAnchorOffset();
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/testing/internals.idl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
long selectPopupItemStyleFontHeight(Node select, long itemIndex);
void resetTypeAheadSession(HTMLSelectElement select);

StaticSelection getDragCaret();
[RaisesException] StaticSelection getSelectionInFlatTree(Window window);
// TODO(editing-dev): We should change |visibleSelection*| to
// |StaticSelection|.
Expand Down
16 changes: 16 additions & 0 deletions third_party/blink/renderer/core/testing/static_selection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@

namespace blink {

// static
StaticSelection* StaticSelection::FromSelectionInDOMTree(
const SelectionInDOMTree& selection) {
return MakeGarbageCollected<StaticSelection>(selection);
}

// static
StaticSelection* StaticSelection::FromSelectionInFlatTree(
const SelectionInFlatTree& seleciton) {
return MakeGarbageCollected<StaticSelection>(seleciton);
}

StaticSelection::StaticSelection(const SelectionInDOMTree& selection)
: anchor_node_(selection.Base().ComputeContainerNode()),
anchor_offset_(selection.Base().ComputeOffsetInContainerNode()),
focus_node_(selection.Extent().ComputeContainerNode()),
focus_offset_(selection.Extent().ComputeOffsetInContainerNode()) {}

StaticSelection::StaticSelection(const SelectionInFlatTree& seleciton)
: anchor_node_(seleciton.Base().ComputeContainerNode()),
anchor_offset_(seleciton.Base().ComputeOffsetInContainerNode()),
focus_node_(seleciton.Extent().ComputeContainerNode()),
focus_offset_(seleciton.Extent().ComputeOffsetInContainerNode()) {}

bool StaticSelection::isCollapsed() const {
return anchor_node_ == focus_node_ && anchor_offset_ == focus_offset_;
}

void StaticSelection::Trace(blink::Visitor* visitor) {
visitor->Trace(anchor_node_);
visitor->Trace(focus_node_);
Expand Down
3 changes: 3 additions & 0 deletions third_party/blink/renderer/core/testing/static_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class StaticSelection final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();

public:
static StaticSelection* FromSelectionInDOMTree(const SelectionInDOMTree&);
static StaticSelection* FromSelectionInFlatTree(const SelectionInFlatTree&);

explicit StaticSelection(const SelectionInFlatTree&);
explicit StaticSelection(const SelectionInDOMTree&);

Node* anchorNode() const { return anchor_node_; }
unsigned anchorOffset() const { return anchor_offset_; }
Node* focusNode() const { return focus_node_; }
unsigned focusOffset() const { return focus_offset_; }
bool isCollapsed() const;

void Trace(blink::Visitor*) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ interface StaticSelection {
readonly attribute unsigned long anchorOffset;
readonly attribute Node? focusNode;
readonly attribute unsigned long focusOffset;
readonly attribute boolean isCollapsed;
};
1 change: 0 additions & 1 deletion third_party/blink/web_tests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,6 @@ crbug.com/891427 virtual/android/url-bar/bottom-and-top-fixed-sticks-to-top.html
## Next 4 here: https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux_chromium_rel_ng/216317
crbug.com/891427 virtual/threaded/animations/timing/animation-duration-infinite.html [ Failure ]
crbug.com/891427 virtual/disable-blink-gen-property-trees/animations/timing/animation-duration-infinite.html [ Skip ]
crbug.com/891427 editing/selection/drag-in-iframe.html [ Failure ]
crbug.com/891427 fast/overflow/transformed-frame-scrollIntoView.html [ Crash ]

### Flaky on trybots:
Expand Down
42 changes: 23 additions & 19 deletions third_party/blink/web_tests/editing/selection/drag-in-iframe.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<html>
<body contenteditable="true" onload="test()">
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body contenteditable="true">
<p>
This is an automatic pixel test. To test interactively, drag selected text onto the iframe
To test interactively, drag selected text onto the iframe
below and verify that a drag caret appears inside the frame.
</p>
<iframe id="subframe" style="border: 1px solid black;"
srcdoc="<body contenteditable><span id='target'>There</span> should be a caret here --> <br>See it?</body>"></iframe>
<script>
function dragAndDrop()
{
const t = async_test('Drag-In-Iframge');
window.addEventListener('load', t.step_func_done(() => {
var iframe = document.getElementById("subframe");
var target = iframe.contentDocument.getElementById("target");

Expand All @@ -18,27 +20,29 @@

iframe.contentWindow.getSelection().setBaseAndExtent(target, 0, target, 1);

assert_own_property(window, 'eventSender');
assert_own_property(window, 'internals');

eventSender.mouseMoveTo(x1, y);
eventSender.dragMode = false;
eventSender.mouseDown();
eventSender.leapForward(1000);
eventSender.mouseMoveTo(x2, y);

// Dump pixel results before we drop so we can see where the drag caret is painted.
testRunner.notifyDone();

// Pixel dumping is asynchronous. We still have chance to send mouseUp.
setTimeout(function() { eventSender.mouseUp(); }, 0);
}

function test()
{
if (!window.testRunner)
return;
const caretInMainFrame = internals.getDragCaret();
assert_equals(caretInMainFrame.anchorNode, null,
'No drag caret in main frame');

const caretInIframe = iframe.contentWindow.internals.getDragCaret();
assert_true(caretInIframe.isCollapsed,
'Caret in iframe should be collapsed');
const textBeforeCaret= target.nextSibling;
assert_equals(caretInIframe.anchorNode, textBeforeCaret);
assert_equals(caretInIframe.anchorOffset, textBeforeCaret.length);

testRunner.waitUntilDone();
setTimeout(dragAndDrop, 0);
}
// To avoid crash, we should release mouse button.
eventSender.mouseUp();
}));
</script>
</body>
</html>
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 695e802

Please sign in to comment.