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

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

Issue 2579253002: [EditCommandSource] Pass source to |CompositEditCommand| and |TypingCommand| (3/3) (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 29 matching lines...) Expand all
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 =
48 ReplaceSelectionCommand::create(document(), fragment, options); 48 ReplaceSelectionCommand::create(document(), fragment, options);
49 49
50 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; 50 EXPECT_TRUE(command->apply(EditCommandSource::kMenuOrKeyBinding))
51 << "the replace command should have succeeded";
51 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation"; 52 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation";
52 } 53 }
53 54
54 // This is a regression test for https://crbug.com/668808 55 // This is a regression test for https://crbug.com/668808
55 TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) { 56 TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) {
56 document().setDesignMode("on"); 57 document().setDesignMode("on");
57 setBodyContent("<b>text</b>"); 58 setBodyContent("<b>text</b>");
58 59
59 Element* bElement = document().querySelector("b"); 60 Element* bElement = document().querySelector("b");
60 LocalFrame* frame = document().frame(); 61 LocalFrame* frame = document().frame();
61 frame->selection().setSelection( 62 frame->selection().setSelection(
62 SelectionInDOMTree::Builder() 63 SelectionInDOMTree::Builder()
63 .collapse(Position(bElement->firstChild(), 1)) 64 .collapse(Position(bElement->firstChild(), 1))
64 .build()); 65 .build());
65 66
66 DocumentFragment* fragment = document().createDocumentFragment(); 67 DocumentFragment* fragment = document().createDocumentFragment();
67 fragment->parseHTML("<span><div>bar</div></span>", bElement); 68 fragment->parseHTML("<span><div>bar</div></span>", bElement);
68 69
69 ReplaceSelectionCommand::CommandOptions options = 0; 70 ReplaceSelectionCommand::CommandOptions options = 0;
70 ReplaceSelectionCommand* command = 71 ReplaceSelectionCommand* command =
71 ReplaceSelectionCommand::create(document(), fragment, options); 72 ReplaceSelectionCommand::create(document(), fragment, options);
72 73
73 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; 74 EXPECT_TRUE(command->apply(EditCommandSource::kMenuOrKeyBinding))
75 << "the replace command should have succeeded";
74 EXPECT_EQ("<b>t</b>bar<b>ext</b>", document().body()->innerHTML()) 76 EXPECT_EQ("<b>t</b>bar<b>ext</b>", document().body()->innerHTML())
75 << "'bar' should have been inserted"; 77 << "'bar' should have been inserted";
76 } 78 }
77 79
78 // This is a regression test for https://crbug.com/121163 80 // This is a regression test for https://crbug.com/121163
79 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) { 81 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) {
80 document().setDesignMode("on"); 82 document().setDesignMode("on");
81 updateAllLifecyclePhases(); 83 updateAllLifecyclePhases();
82 dummyPageHolder().frame().selection().setSelection( 84 dummyPageHolder().frame().selection().setSelection(
83 SelectionInDOMTree::Builder() 85 SelectionInDOMTree::Builder()
84 .collapse(Position(document().body(), 0)) 86 .collapse(Position(document().body(), 0))
85 .build()); 87 .build());
86 88
87 DocumentFragment* fragment = document().createDocumentFragment(); 89 DocumentFragment* fragment = document().createDocumentFragment();
88 fragment->parseHTML( 90 fragment->parseHTML(
89 "<head><style>foo { bar: baz; }</style></head>" 91 "<head><style>foo { bar: baz; }</style></head>"
90 "<body><p>Text</p></body>", 92 "<body><p>Text</p></body>",
91 document().documentElement(), DisallowScriptingAndPluginContent); 93 document().documentElement(), DisallowScriptingAndPluginContent);
92 94
93 ReplaceSelectionCommand::CommandOptions options = 0; 95 ReplaceSelectionCommand::CommandOptions options = 0;
94 ReplaceSelectionCommand* command = 96 ReplaceSelectionCommand* command =
95 ReplaceSelectionCommand::create(document(), fragment, options); 97 ReplaceSelectionCommand::create(document(), fragment, options);
96 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; 98 EXPECT_TRUE(command->apply(EditCommandSource::kMenuOrKeyBinding))
99 << "the replace command should have succeeded";
97 100
98 EXPECT_EQ( 101 EXPECT_EQ(
99 "<head><style>foo { bar: baz; }</style></head>" 102 "<head><style>foo { bar: baz; }</style></head>"
100 "<body><p>Text</p></body>", 103 "<body><p>Text</p></body>",
101 document().body()->innerHTML()) 104 document().body()->innerHTML())
102 << "the STYLE and P elements should have been pasted into the body " 105 << "the STYLE and P elements should have been pasted into the body "
103 << "of the document"; 106 << "of the document";
104 } 107 }
105 108
106 } // namespace blink 109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698