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
3 // found in the LICENSE file.
4 
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/blink/renderer/core/dom/document.h"
7 #include "third_party/blink/renderer/core/editing/dom_selection.h"
8 #include "third_party/blink/renderer/core/frame/local_dom_window.h"
9 #include "third_party/blink/renderer/core/html/html_element.h"
10 #include "third_party/blink/renderer/core/testing/sim/sim_compositor.h"
11 #include "third_party/blink/renderer/core/testing/sim/sim_request.h"
12 #include "third_party/blink/renderer/core/testing/sim/sim_test.h"
13 
14 namespace blink {
15 
16 class TextSelectionRepaintTest : public SimTest {};
17 
TEST_F(TextSelectionRepaintTest,RepaintSelectionOnFocus)18 TEST_F(TextSelectionRepaintTest, RepaintSelectionOnFocus) {
19   SimRequest main_resource("https://example.com/test.html", "text/html");
20 
21   LoadURL("https://example.com/test.html");
22 
23   main_resource.Complete(
24       "<!DOCTYPE html>"
25       "Text to select.");
26 
27   // Focus the window.
28   EXPECT_FALSE(GetPage().IsFocused());
29   GetPage().SetFocused(true);
30 
31   // First frame with nothing selected.
32   Compositor().BeginFrame();
33 
34   // Select some text.
35   auto* body = GetDocument().body();
36   Window().getSelection()->setBaseAndExtent(body, 0, body, 1);
37 
38   // Unfocus the page and check for a pending frame.
39   GetPage().SetFocused(false);
40   EXPECT_TRUE(Compositor().NeedsBeginFrame());
41 
42   // Frame with the unfocused selection appearance.
43   Compositor().BeginFrame();
44 
45   // Focus the page and check for a pending frame.
46   GetPage().SetFocused(true);
47   EXPECT_TRUE(Compositor().NeedsBeginFrame());
48 }
49 
50 }  // namespace blink
51