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

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

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 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
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 15 matching lines...) Expand all
26 }; 26 };
27 27
28 // This is a regression test for https://crbug.com/619131 28 // This is a regression test for https://crbug.com/619131
29 TEST_F(ReplaceSelectionCommandTest, pastingEmptySpan) 29 TEST_F(ReplaceSelectionCommandTest, pastingEmptySpan)
30 { 30 {
31 document().setDesignMode("on"); 31 document().setDesignMode("on");
32 setBodyContent("foo"); 32 setBodyContent("foo");
33 33
34 LocalFrame* frame = document().frame(); 34 LocalFrame* frame = document().frame();
35 frame->selection().setSelection( 35 frame->selection().setSelection(
36 VisibleSelection(Position(document().body(), 0))); 36 createVisibleSelectionDeprecated(Position(document().body(), 0)));
37 37
38 DocumentFragment* fragment = document().createDocumentFragment(); 38 DocumentFragment* fragment = document().createDocumentFragment();
39 fragment->appendChild(document().createElement("span", ASSERT_NO_EXCEPTION)) ; 39 fragment->appendChild(document().createElement("span", ASSERT_NO_EXCEPTION)) ;
40 40
41 // |options| are taken from |Editor::replaceSelectionWithFragment()| with 41 // |options| are taken from |Editor::replaceSelectionWithFragment()| with
42 // |selectReplacement| and |smartReplace|. 42 // |selectReplacement| and |smartReplace|.
43 ReplaceSelectionCommand::CommandOptions options = 43 ReplaceSelectionCommand::CommandOptions options =
44 ReplaceSelectionCommand::PreventNesting | 44 ReplaceSelectionCommand::PreventNesting |
45 ReplaceSelectionCommand::SanitizeFragment | 45 ReplaceSelectionCommand::SanitizeFragment |
46 ReplaceSelectionCommand::SelectReplacement | 46 ReplaceSelectionCommand::SelectReplacement |
47 ReplaceSelectionCommand::SmartReplace; 47 ReplaceSelectionCommand::SmartReplace;
48 ReplaceSelectionCommand* command = 48 ReplaceSelectionCommand* command =
49 ReplaceSelectionCommand::create(document(), fragment, options); 49 ReplaceSelectionCommand::create(document(), fragment, options);
50 50
51 EXPECT_TRUE(command->apply()) 51 EXPECT_TRUE(command->apply())
52 << "the replace command should have succeeded"; 52 << "the replace command should have succeeded";
53 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation"; 53 EXPECT_EQ("foo", document().body()->innerHTML()) << "no DOM tree mutation";
54 } 54 }
55 55
56 // This is a regression test for https://crbug.com/121163 56 // This is a regression test for https://crbug.com/121163
57 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) 57 TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent)
58 { 58 {
59 document().setDesignMode("on"); 59 document().setDesignMode("on");
60 dummyPageHolder().frame().selection().setSelection( 60 dummyPageHolder().frame().selection().setSelection(
61 VisibleSelection(Position(document().body(), 0))); 61 createVisibleSelectionDeprecated(Position(document().body(), 0)));
62 62
63 DocumentFragment* fragment = document().createDocumentFragment(); 63 DocumentFragment* fragment = document().createDocumentFragment();
64 fragment->parseHTML( 64 fragment->parseHTML(
65 "<head><style>foo { bar: baz; }</style></head>" 65 "<head><style>foo { bar: baz; }</style></head>"
66 "<body><p>Text</p></body>", 66 "<body><p>Text</p></body>",
67 document().documentElement(), 67 document().documentElement(),
68 DisallowScriptingAndPluginContent); 68 DisallowScriptingAndPluginContent);
69 69
70 ReplaceSelectionCommand::CommandOptions options = 0; 70 ReplaceSelectionCommand::CommandOptions options = 0;
71 ReplaceSelectionCommand* command = 71 ReplaceSelectionCommand* command =
72 ReplaceSelectionCommand::create(document(), fragment, options); 72 ReplaceSelectionCommand::create(document(), fragment, options);
73 EXPECT_TRUE(command->apply()) 73 EXPECT_TRUE(command->apply())
74 << "the replace command should have succeeded"; 74 << "the replace command should have succeeded";
75 75
76 EXPECT_EQ( 76 EXPECT_EQ(
77 "<head><style>foo { bar: baz; }</style></head>" 77 "<head><style>foo { bar: baz; }</style></head>"
78 "<body><p>Text</p></body>", 78 "<body><p>Text</p></body>",
79 document().body()->innerHTML()) 79 document().body()->innerHTML())
80 << "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 "
81 << "of the document"; 81 << "of the document";
82 } 82 }
83 83
84 } // namespace blink 84 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698