Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/FrameCaretTest.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/FrameCaretTest.cpp b/third_party/WebKit/Source/core/editing/FrameCaretTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64635fc55098c6adc7de18db0d3e2d57f4957540 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/FrameCaretTest.cpp |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/editing/FrameCaret.h" |
| + |
| +#include "core/editing/EditingTestBase.h" |
| +#include "core/editing/FrameSelection.h" |
| +#include "core/editing/commands/TypingCommand.h" |
| +#include "core/frame/FrameView.h" |
| +#include "core/layout/LayoutTheme.h" |
| +#include "core/page/FocusController.h" |
| +#include "platform/LayoutTestSupport.h" |
| +#include "platform/scheduler/test/fake_web_task_runner.h" |
| + |
| +namespace blink { |
| + |
| +class FrameCaretTest : public EditingTestBase { |
| + private: |
| + void SetUp() override { |
| + EditingTestBase::SetUp(); |
| + // The caret blink timer doesn't work if isRunningLayoutTest() because |
| + // LayoutTheme::caretBlinkInterval() returns 0. |
| + m_wasRunningLayoutTest = LayoutTestSupport::isRunningLayoutTest(); |
| + LayoutTestSupport::setIsRunningLayoutTest(false); |
| + } |
| + |
| + void TearDown() override { |
| + LayoutTestSupport::setIsRunningLayoutTest(m_wasRunningLayoutTest); |
| + EditingTestBase::TearDown(); |
| + } |
| + |
| + 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.
|
| +}; |
| + |
| +TEST_F(FrameCaretTest, BlinkAfterTyping) { |
| + FrameCaret& caret = selection().frameCaretForTesting(); |
| + RefPtr<scheduler::FakeWebTaskRunner> taskRunner = |
| + adoptRef(new scheduler::FakeWebTaskRunner); |
| + taskRunner->setTime(0); |
| + caret.recreateCaretBlinkTimerForTesting(taskRunner.get()); |
| + const double kInterval = 10; |
| + LayoutTheme::theme().setCaretBlinkInterval(kInterval); |
| + document().page()->focusController().setActive(true); |
| + document().page()->focusController().setFocused(true); |
| + document().body()->setInnerHTML("<textarea>"); |
| + Element* editor = toElement(document().body()->firstChild()); |
| + editor->focus(); |
| + document().view()->updateAllLifecyclePhases(); |
| + |
| + EXPECT_TRUE(caret.isActive()); |
| + EXPECT_FALSE(caret.shouldShowBlockCursor()); |
| + EXPECT_TRUE(caret.shouldPaintCaretForTesting()) |
| + << "Initially a caret should be in visible cycle."; |
| + |
| + taskRunner->advanceTimeAndRun(kInterval); |
| + EXPECT_FALSE(caret.shouldPaintCaretForTesting()) |
| + << "The caret blinks normally."; |
| + |
| + TypingCommand::insertLineBreak(document()); |
| + document().view()->updateAllLifecyclePhases(); |
| + EXPECT_TRUE(caret.shouldPaintCaretForTesting()) |
| + << "The caret should be in visible cycle just after a typing command."; |
| + |
| + taskRunner->advanceTimeAndRun(kInterval - 1); |
| + document().view()->updateAllLifecyclePhases(); |
| + EXPECT_TRUE(caret.shouldPaintCaretForTesting()) |
| + << "The typing command reset the timer. The caret is still visible."; |
| + |
| + taskRunner->advanceTimeAndRun(1); |
| + document().view()->updateAllLifecyclePhases(); |
| + EXPECT_FALSE(caret.shouldPaintCaretForTesting()) |
| + << "The caret should blink after the typing command."; |
| +} |
| + |
| +} // namespace blink |