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

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

Issue 2122003003: Make ReplaceSelectionCommand to handle empty SPAN replacement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-07T10:52:58 Created 4 years, 5 months 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/DocumentFragment.h" 9 #include "core/dom/DocumentFragment.h"
10 #include "core/dom/ParserContentPolicy.h" 10 #include "core/dom/ParserContentPolicy.h"
11 #include "core/editing/EditingTestBase.h" 11 #include "core/editing/EditingTestBase.h"
12 #include "core/editing/FrameSelection.h" 12 #include "core/editing/FrameSelection.h"
13 #include "core/editing/Position.h" 13 #include "core/editing/Position.h"
14 #include "core/editing/VisibleSelection.h" 14 #include "core/editing/VisibleSelection.h"
15 #include "core/frame/FrameView.h" 15 #include "core/frame/FrameView.h"
16 #include "core/frame/LocalFrame.h" 16 #include "core/frame/LocalFrame.h"
17 #include "core/html/HTMLDocument.h" 17 #include "core/html/HTMLDocument.h"
18 #include "core/testing/DummyPageHolder.h" 18 #include "core/testing/DummyPageHolder.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 #include <memory> 21 #include <memory>
22 22
23 namespace blink { 23 namespace blink {
24 24
25 class ReplaceSelectionCommandTest : public EditingTestBase { 25 class ReplaceSelectionCommandTest : public EditingTestBase {
26 }; 26 };
27 27
28 // This is a regression test for https://crbug.com/619131
29 TEST_F(ReplaceSelectionCommandTest, pastingEmptySpan)
30 {
31 document().setDesignMode("on");
32 setBodyContent("foo");
33
34 LocalFrame* frame = document().frame();
35 frame->selection().setSelection(
36 VisibleSelection(Position(document().body(), 0)));
37
38 DocumentFragment* fragment = document().createDocumentFragment();
39 fragment->appendChild(document().createElement("span", ASSERT_NO_EXCEPTION)) ;
40
41 // |options| are taken from |Editor::replaceSelectionWithFragment()| with
42 // |selectReplacement| and |smartReplace|.
43 ReplaceSelectionCommand::CommandOptions options =
44 ReplaceSelectionCommand::PreventNesting |
45 ReplaceSelectionCommand::SanitizeFragment |
46 ReplaceSelectionCommand::SelectReplacement |
47 ReplaceSelectionCommand::SmartReplace;
48 ReplaceSelectionCommand* command =
49 ReplaceSelectionCommand::create(document(), fragment, options);
50
51 EXPECT_TRUE(command->apply())
52 << "the replace command should have succeeded";
53 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation";
54 }
55
28 // This is a regression test for https://crbug.com/121163 56 // This is a regression test for https://crbug.com/121163
29 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) 57 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent)
30 { 58 {
31 document().setDesignMode("on"); 59 document().setDesignMode("on");
32 dummyPageHolder().frame().selection().setSelection( 60 dummyPageHolder().frame().selection().setSelection(
33 VisibleSelection(Position(document().body(), 0))); 61 VisibleSelection(Position(document().body(), 0)));
34 62
35 DocumentFragment* fragment = document().createDocumentFragment(); 63 DocumentFragment* fragment = document().createDocumentFragment();
36 fragment->parseHTML( 64 fragment->parseHTML(
37 "<head><style>foo { bar: baz; }</style></head>" 65 "<head><style>foo { bar: baz; }</style></head>"
38 "<body><p>Text</p></body>", 66 "<body><p>Text</p></body>",
39 document().documentElement(), 67 document().documentElement(),
40 DisallowScriptingAndPluginContent); 68 DisallowScriptingAndPluginContent);
41 69
42 ReplaceSelectionCommand::CommandOptions options = 0; 70 ReplaceSelectionCommand::CommandOptions options = 0;
43 ReplaceSelectionCommand* command = 71 ReplaceSelectionCommand* command =
44 ReplaceSelectionCommand::create(document(), fragment, options); 72 ReplaceSelectionCommand::create(document(), fragment, options);
45 EXPECT_TRUE(command->apply()) 73 EXPECT_TRUE(command->apply())
46 << "the replace command should have succeeded"; 74 << "the replace command should have succeeded";
47 75
48 EXPECT_EQ( 76 EXPECT_EQ(
49 "<head><style>foo { bar: baz; }</style></head>" 77 "<head><style>foo { bar: baz; }</style></head>"
50 "<body><p>Text</p></body>", 78 "<body><p>Text</p></body>",
51 document().body()->innerHTML()) 79 document().body()->innerHTML())
52 << "the STYLE and P elements should have been pasted into the body " 80 << "the STYLE and P elements should have been pasted into the body "
53 << "of the document"; 81 << "of the document";
54 } 82 }
55 83
56 } // namespace blink 84 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698