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

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

Issue 2723003002: Editing: Fix caret blinking after a typing. (Closed)
Patch Set: Apply review comments Created 3 years, 9 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/FrameCaret.h"
6
7 #include "core/editing/EditingTestBase.h"
8 #include "core/editing/FrameSelection.h"
9 #include "core/editing/commands/TypingCommand.h"
10 #include "core/frame/FrameView.h"
11 #include "core/layout/LayoutTheme.h"
12 #include "core/page/FocusController.h"
13 #include "platform/LayoutTestSupport.h"
14 #include "platform/scheduler/test/fake_web_task_runner.h"
15
16 namespace blink {
17
18 class FrameCaretTest : public EditingTestBase {
19 public:
20 FrameCaretTest()
21 : m_wasRunningLayoutTest(LayoutTestSupport::isRunningLayoutTest()) {
22 // The caret blink timer doesn't work if isRunningLayoutTest() because
23 // LayoutTheme::caretBlinkInterval() returns 0.
24 LayoutTestSupport::setIsRunningLayoutTest(false);
25 }
26 ~FrameCaretTest() override {
27 LayoutTestSupport::setIsRunningLayoutTest(m_wasRunningLayoutTest);
28 }
29
30 private:
31 const bool m_wasRunningLayoutTest;
32 };
33
34 TEST_F(FrameCaretTest, BlinkAfterTyping) {
35 FrameCaret& caret = selection().frameCaretForTesting();
36 RefPtr<scheduler::FakeWebTaskRunner> taskRunner =
37 adoptRef(new scheduler::FakeWebTaskRunner);
38 taskRunner->setTime(0);
39 caret.recreateCaretBlinkTimerForTesting(taskRunner.get());
40 const double kInterval = 10;
41 LayoutTheme::theme().setCaretBlinkInterval(kInterval);
42 document().page()->focusController().setActive(true);
43 document().page()->focusController().setFocused(true);
44 document().body()->setInnerHTML("<textarea>");
45 Element* editor = toElement(document().body()->firstChild());
46 editor->focus();
47 document().view()->updateAllLifecyclePhases();
48
49 EXPECT_TRUE(caret.isActive());
50 EXPECT_FALSE(caret.shouldShowBlockCursor());
51 EXPECT_TRUE(caret.shouldPaintCaretForTesting())
52 << "Initially a caret should be in visible cycle.";
53
54 taskRunner->advanceTimeAndRun(kInterval);
55 EXPECT_FALSE(caret.shouldPaintCaretForTesting())
56 << "The caret blinks normally.";
57
58 TypingCommand::insertLineBreak(document());
59 document().view()->updateAllLifecyclePhases();
60 EXPECT_TRUE(caret.shouldPaintCaretForTesting())
61 << "The caret should be in visible cycle just after a typing command.";
62
63 taskRunner->advanceTimeAndRun(kInterval - 1);
64 document().view()->updateAllLifecyclePhases();
65 EXPECT_TRUE(caret.shouldPaintCaretForTesting())
66 << "The typing command reset the timer. The caret is still visible.";
67
68 taskRunner->advanceTimeAndRun(1);
69 document().view()->updateAllLifecyclePhases();
70 EXPECT_FALSE(caret.shouldPaintCaretForTesting())
71 << "The caret should blink after the typing command.";
72 }
73
74 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameCaret.cpp ('k') | third_party/WebKit/Source/core/editing/FrameSelection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698