OLD | NEW |
---|---|
(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 private: | |
20 void SetUp() override { | |
21 EditingTestBase::SetUp(); | |
22 // The caret blink timer doesn't work if isRunningLayoutTest() because | |
23 // LayoutTheme::caretBlinkInterval() returns 0. | |
24 m_wasRunningLayoutTest = LayoutTestSupport::isRunningLayoutTest(); | |
25 LayoutTestSupport::setIsRunningLayoutTest(false); | |
26 } | |
27 | |
28 void TearDown() override { | |
29 LayoutTestSupport::setIsRunningLayoutTest(m_wasRunningLayoutTest); | |
30 EditingTestBase::TearDown(); | |
31 } | |
32 | |
33 bool m_wasRunningLayoutTest; | |
yosin_UTC9
2017/03/01 03:21:07
nit: Use |const bool| and initialized in ctor to a
tkent
2017/03/01 05:50:40
Done.
| |
34 }; | |
35 | |
36 TEST_F(FrameCaretTest, BlinkAfterTyping) { | |
37 FrameCaret& caret = selection().frameCaretForTesting(); | |
38 RefPtr<scheduler::FakeWebTaskRunner> taskRunner = | |
39 adoptRef(new scheduler::FakeWebTaskRunner); | |
40 taskRunner->setTime(0); | |
41 caret.recreateCaretBlinkTimerForTesting(taskRunner.get()); | |
42 const double kInterval = 10; | |
43 LayoutTheme::theme().setCaretBlinkInterval(kInterval); | |
44 document().page()->focusController().setActive(true); | |
45 document().page()->focusController().setFocused(true); | |
46 document().body()->setInnerHTML("<textarea>"); | |
47 Element* editor = toElement(document().body()->firstChild()); | |
48 editor->focus(); | |
49 document().view()->updateAllLifecyclePhases(); | |
50 | |
51 EXPECT_TRUE(caret.isActive()); | |
52 EXPECT_FALSE(caret.shouldShowBlockCursor()); | |
53 EXPECT_TRUE(caret.shouldPaintCaretForTesting()) | |
54 << "Initially a caret should be in visible cycle."; | |
55 | |
56 taskRunner->advanceTimeAndRun(kInterval); | |
57 EXPECT_FALSE(caret.shouldPaintCaretForTesting()) | |
58 << "The caret blinks normally."; | |
59 | |
60 TypingCommand::insertLineBreak(document()); | |
61 document().view()->updateAllLifecyclePhases(); | |
62 EXPECT_TRUE(caret.shouldPaintCaretForTesting()) | |
63 << "The caret should be in visible cycle just after a typing command."; | |
64 | |
65 taskRunner->advanceTimeAndRun(kInterval - 1); | |
66 document().view()->updateAllLifecyclePhases(); | |
67 EXPECT_TRUE(caret.shouldPaintCaretForTesting()) | |
68 << "The typing command reset the timer. The caret is still visible."; | |
69 | |
70 taskRunner->advanceTimeAndRun(1); | |
71 document().view()->updateAllLifecyclePhases(); | |
72 EXPECT_FALSE(caret.shouldPaintCaretForTesting()) | |
73 << "The caret should blink after the typing command."; | |
74 } | |
75 | |
76 } // namespace blink | |
OLD | NEW |