Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/FrameCaret.h" | 5 #include "core/editing/FrameCaret.h" |
| 6 | 6 |
| 7 #include "core/editing/EditingTestBase.h" | 7 #include "core/editing/EditingTestBase.h" |
| 8 #include "core/editing/FrameSelection.h" | 8 #include "core/editing/FrameSelection.h" |
| 9 #include "core/editing/commands/TypingCommand.h" | 9 #include "core/editing/commands/TypingCommand.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/layout/LayoutTheme.h" | 11 #include "core/layout/LayoutTheme.h" |
| 12 #include "core/page/FocusController.h" | 12 #include "core/page/FocusController.h" |
| 13 #include "platform/LayoutTestSupport.h" | 13 #include "platform/LayoutTestSupport.h" |
| 14 #include "platform/scheduler/test/fake_web_task_runner.h" | 14 #include "platform/scheduler/test/fake_web_task_runner.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class FrameCaretTest : public EditingTestBase { | 18 class FrameCaretTest : public EditingTestBase { |
| 19 public: | 19 public: |
| 20 FrameCaretTest() | 20 FrameCaretTest() |
| 21 : was_running_layout_test_(LayoutTestSupport::IsRunningLayoutTest()) { | 21 : was_running_layout_test_(LayoutTestSupport::IsRunningLayoutTest()) { |
| 22 // The caret blink timer doesn't work if isRunningLayoutTest() because | 22 // The caret blink timer doesn't work if isRunningLayoutTest() because |
| 23 // LayoutTheme::caretBlinkInterval() returns 0. | 23 // LayoutTheme::caretBlinkInterval() returns 0. |
| 24 LayoutTestSupport::SetIsRunningLayoutTest(false); | 24 LayoutTestSupport::SetIsRunningLayoutTest(false); |
| 25 } | 25 } |
| 26 ~FrameCaretTest() override { | 26 ~FrameCaretTest() override { |
| 27 LayoutTestSupport::SetIsRunningLayoutTest(was_running_layout_test_); | 27 LayoutTestSupport::SetIsRunningLayoutTest(was_running_layout_test_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool ShouldBlinkCaret(const FrameCaret& caret) { | |
| 31 return caret.ShouldBlinkCaret(); | |
| 32 } | |
| 33 | |
| 30 private: | 34 private: |
| 31 const bool was_running_layout_test_; | 35 const bool was_running_layout_test_; |
| 32 }; | 36 }; |
| 33 | 37 |
| 34 TEST_F(FrameCaretTest, BlinkAfterTyping) { | 38 TEST_F(FrameCaretTest, BlinkAfterTyping) { |
| 35 FrameCaret& caret = Selection().FrameCaretForTesting(); | 39 FrameCaret& caret = Selection().FrameCaretForTesting(); |
| 36 RefPtr<scheduler::FakeWebTaskRunner> task_runner = | 40 RefPtr<scheduler::FakeWebTaskRunner> task_runner = |
| 37 AdoptRef(new scheduler::FakeWebTaskRunner); | 41 AdoptRef(new scheduler::FakeWebTaskRunner); |
| 38 task_runner->SetTime(0); | 42 task_runner->SetTime(0); |
| 39 caret.RecreateCaretBlinkTimerForTesting(task_runner.Get()); | 43 caret.RecreateCaretBlinkTimerForTesting(task_runner.Get()); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 64 GetDocument().View()->UpdateAllLifecyclePhases(); | 68 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 65 EXPECT_TRUE(caret.ShouldPaintCaretForTesting()) | 69 EXPECT_TRUE(caret.ShouldPaintCaretForTesting()) |
| 66 << "The typing command reset the timer. The caret is still visible."; | 70 << "The typing command reset the timer. The caret is still visible."; |
| 67 | 71 |
| 68 task_runner->AdvanceTimeAndRun(1); | 72 task_runner->AdvanceTimeAndRun(1); |
| 69 GetDocument().View()->UpdateAllLifecyclePhases(); | 73 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 70 EXPECT_FALSE(caret.ShouldPaintCaretForTesting()) | 74 EXPECT_FALSE(caret.ShouldPaintCaretForTesting()) |
| 71 << "The caret should blink after the typing command."; | 75 << "The caret should blink after the typing command."; |
| 72 } | 76 } |
| 73 | 77 |
| 78 TEST_F(FrameCaretTest, ShouldNotBlinkWhenSelectionLooseFocus) { | |
| 79 FrameCaret& caret = Selection().FrameCaretForTesting(); | |
| 80 GetDocument().GetPage()->GetFocusController().SetActive(true); | |
| 81 GetDocument().GetPage()->GetFocusController().SetFocused(true); | |
| 82 GetDocument().body()->setInnerHTML( | |
| 83 "<div id='outer' tabindex='-1'>" | |
| 84 "<div id='input' contenteditable>foo</div>" | |
| 85 "</div>"); | |
| 86 Element* input = GetDocument().QuerySelector("#input"); | |
| 87 input->focus(); | |
| 88 Element* outer = GetDocument().QuerySelector("#outer"); | |
| 89 outer->focus(); | |
| 90 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 91 const SelectionInDOMTree& dom = Selection().GetSelectionInDOMTree(); | |
|
yosin_UTC9
2017/05/19 06:12:21
nit: s/dom/selection/
It is "DOM Selection" inste
yoichio
2017/05/19 08:00:18
Done.
| |
| 92 EXPECT_EQ(dom.Base(), Position(input, PositionAnchorType::kBeforeChildren)); | |
| 93 EXPECT_FALSE(ShouldBlinkCaret(caret)); | |
| 94 } | |
| 95 | |
| 74 } // namespace blink | 96 } // namespace blink |
| OLD | NEW |