Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommandTest.cpp

Issue 2574793002: [Editing] Store |CommandSource| in |CompositeEditCommand| (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/commands/ReplaceSelectionCommand.h" 5 #include "core/editing/commands/ReplaceSelectionCommand.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/HTMLNames.h" 8 #include "core/HTMLNames.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/DocumentFragment.h" 10 #include "core/dom/DocumentFragment.h"
(...skipping 26 matching lines...) Expand all
37 DocumentFragment* fragment = document().createDocumentFragment(); 37 DocumentFragment* fragment = document().createDocumentFragment();
38 fragment->appendChild(document().createElement("span")); 38 fragment->appendChild(document().createElement("span"));
39 39
40 // |options| are taken from |Editor::replaceSelectionWithFragment()| with 40 // |options| are taken from |Editor::replaceSelectionWithFragment()| with
41 // |selectReplacement| and |smartReplace|. 41 // |selectReplacement| and |smartReplace|.
42 ReplaceSelectionCommand::CommandOptions options = 42 ReplaceSelectionCommand::CommandOptions options =
43 ReplaceSelectionCommand::PreventNesting | 43 ReplaceSelectionCommand::PreventNesting |
44 ReplaceSelectionCommand::SanitizeFragment | 44 ReplaceSelectionCommand::SanitizeFragment |
45 ReplaceSelectionCommand::SelectReplacement | 45 ReplaceSelectionCommand::SelectReplacement |
46 ReplaceSelectionCommand::SmartReplace; 46 ReplaceSelectionCommand::SmartReplace;
47 ReplaceSelectionCommand* command = 47 ReplaceSelectionCommand* command = ReplaceSelectionCommand::create(
48 ReplaceSelectionCommand::create(document(), fragment, options); 48 document(), CommandSource::MenuOrKeyBinding, fragment, options);
49 49
50 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; 50 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded";
51 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation"; 51 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation";
52 } 52 }
53 53
54 // This is a regression test for https://crbug.com/668808 54 // This is a regression test for https://crbug.com/668808
55 TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) { 55 TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) {
56 document().setDesignMode("on"); 56 document().setDesignMode("on");
57 setBodyContent("<b>text</b>"); 57 setBodyContent("<b>text</b>");
58 58
59 Element* bElement = document().querySelector("b"); 59 Element* bElement = document().querySelector("b");
60 LocalFrame* frame = document().frame(); 60 LocalFrame* frame = document().frame();
61 frame->selection().setSelection( 61 frame->selection().setSelection(
62 SelectionInDOMTree::Builder() 62 SelectionInDOMTree::Builder()
63 .collapse(Position(bElement->firstChild(), 1)) 63 .collapse(Position(bElement->firstChild(), 1))
64 .build()); 64 .build());
65 65
66 DocumentFragment* fragment = document().createDocumentFragment(); 66 DocumentFragment* fragment = document().createDocumentFragment();
67 fragment->parseHTML("<span><div>bar</div></span>", bElement); 67 fragment->parseHTML("<span><div>bar</div></span>", bElement);
68 68
69 ReplaceSelectionCommand::CommandOptions options = 0; 69 ReplaceSelectionCommand::CommandOptions options = 0;
70 ReplaceSelectionCommand* command = 70 ReplaceSelectionCommand* command = ReplaceSelectionCommand::create(
71 ReplaceSelectionCommand::create(document(), fragment, options); 71 document(), CommandSource::MenuOrKeyBinding, fragment, options);
72 72
73 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; 73 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded";
74 EXPECT_EQ("<b>t</b>bar<b>ext</b>", document().body()->innerHTML()) 74 EXPECT_EQ("<b>t</b>bar<b>ext</b>", document().body()->innerHTML())
75 << "'bar' should have been inserted"; 75 << "'bar' should have been inserted";
76 } 76 }
77 77
78 // This is a regression test for https://crbug.com/121163 78 // This is a regression test for https://crbug.com/121163
79 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) { 79 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) {
80 document().setDesignMode("on"); 80 document().setDesignMode("on");
81 updateAllLifecyclePhases(); 81 updateAllLifecyclePhases();
82 dummyPageHolder().frame().selection().setSelection( 82 dummyPageHolder().frame().selection().setSelection(
83 SelectionInDOMTree::Builder() 83 SelectionInDOMTree::Builder()
84 .collapse(Position(document().body(), 0)) 84 .collapse(Position(document().body(), 0))
85 .build()); 85 .build());
86 86
87 DocumentFragment* fragment = document().createDocumentFragment(); 87 DocumentFragment* fragment = document().createDocumentFragment();
88 fragment->parseHTML( 88 fragment->parseHTML(
89 "<head><style>foo { bar: baz; }</style></head>" 89 "<head><style>foo { bar: baz; }</style></head>"
90 "<body><p>Text</p></body>", 90 "<body><p>Text</p></body>",
91 document().documentElement(), DisallowScriptingAndPluginContent); 91 document().documentElement(), DisallowScriptingAndPluginContent);
92 92
93 ReplaceSelectionCommand::CommandOptions options = 0; 93 ReplaceSelectionCommand::CommandOptions options = 0;
94 ReplaceSelectionCommand* command = 94 ReplaceSelectionCommand* command = ReplaceSelectionCommand::create(
95 ReplaceSelectionCommand::create(document(), fragment, options); 95 document(), CommandSource::MenuOrKeyBinding, fragment, options);
96 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; 96 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded";
97 97
98 EXPECT_EQ( 98 EXPECT_EQ(
99 "<head><style>foo { bar: baz; }</style></head>" 99 "<head><style>foo { bar: baz; }</style></head>"
100 "<body><p>Text</p></body>", 100 "<body><p>Text</p></body>",
101 document().body()->innerHTML()) 101 document().body()->innerHTML())
102 << "the STYLE and P elements should have been pasted into the body " 102 << "the STYLE and P elements should have been pasted into the body "
103 << "of the document"; 103 << "of the document";
104 } 104 }
105 105
106 } // namespace blink 106 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698