| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()) << "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 |
| 55 TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) { |
| 56 document().setDesignMode("on"); |
| 57 setBodyContent("<b>text</b>"); |
| 58 |
| 59 Element* bElement = document().querySelector("b"); |
| 60 LocalFrame* frame = document().frame(); |
| 61 frame->selection().setSelection( |
| 62 SelectionInDOMTree::Builder() |
| 63 .collapse(Position(bElement->firstChild(), 1)) |
| 64 .build()); |
| 65 |
| 66 DocumentFragment* fragment = document().createDocumentFragment(); |
| 67 fragment->parseHTML("<span><div>bar</div></span>", bElement); |
| 68 |
| 69 ReplaceSelectionCommand::CommandOptions options = 0; |
| 70 ReplaceSelectionCommand* command = |
| 71 ReplaceSelectionCommand::create(document(), fragment, options); |
| 72 |
| 73 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; |
| 74 EXPECT_EQ("<b>t</b>bar<b>ext</b>", document().body()->innerHTML()) |
| 75 << "'bar' should have been inserted"; |
| 76 } |
| 77 |
| 54 // This is a regression test for https://crbug.com/121163 | 78 // This is a regression test for https://crbug.com/121163 |
| 55 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) { | 79 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) { |
| 56 document().setDesignMode("on"); | 80 document().setDesignMode("on"); |
| 57 updateAllLifecyclePhases(); | 81 updateAllLifecyclePhases(); |
| 58 dummyPageHolder().frame().selection().setSelection( | 82 dummyPageHolder().frame().selection().setSelection( |
| 59 SelectionInDOMTree::Builder() | 83 SelectionInDOMTree::Builder() |
| 60 .collapse(Position(document().body(), 0)) | 84 .collapse(Position(document().body(), 0)) |
| 61 .build()); | 85 .build()); |
| 62 | 86 |
| 63 DocumentFragment* fragment = document().createDocumentFragment(); | 87 DocumentFragment* fragment = document().createDocumentFragment(); |
| 64 fragment->parseHTML( | 88 fragment->parseHTML( |
| 65 "<head><style>foo { bar: baz; }</style></head>" | 89 "<head><style>foo { bar: baz; }</style></head>" |
| 66 "<body><p>Text</p></body>", | 90 "<body><p>Text</p></body>", |
| 67 document().documentElement(), DisallowScriptingAndPluginContent); | 91 document().documentElement(), DisallowScriptingAndPluginContent); |
| 68 | 92 |
| 69 ReplaceSelectionCommand::CommandOptions options = 0; | 93 ReplaceSelectionCommand::CommandOptions options = 0; |
| 70 ReplaceSelectionCommand* command = | 94 ReplaceSelectionCommand* command = |
| 71 ReplaceSelectionCommand::create(document(), fragment, options); | 95 ReplaceSelectionCommand::create(document(), fragment, options); |
| 72 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; | 96 EXPECT_TRUE(command->apply()) << "the replace command should have succeeded"; |
| 73 | 97 |
| 74 EXPECT_EQ( | 98 EXPECT_EQ( |
| 75 "<head><style>foo { bar: baz; }</style></head>" | 99 "<head><style>foo { bar: baz; }</style></head>" |
| 76 "<body><p>Text</p></body>", | 100 "<body><p>Text</p></body>", |
| 77 document().body()->innerHTML()) | 101 document().body()->innerHTML()) |
| 78 << "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 " |
| 79 << "of the document"; | 103 << "of the document"; |
| 80 } | 104 } |
| 81 | 105 |
| 82 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |