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 "third_party/blink/renderer/core/editing/markers/suggestion_marker.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/blink/renderer/core/editing/markers/suggestion_marker_properties.h"
9 
10 namespace blink {
11 
12 class SuggestionMarkerTest : public testing::Test {};
13 
TEST_F(SuggestionMarkerTest,MarkerType)14 TEST_F(SuggestionMarkerTest, MarkerType) {
15   DocumentMarker* marker = MakeGarbageCollected<SuggestionMarker>(
16       0, 1, SuggestionMarkerProperties());
17   EXPECT_EQ(DocumentMarker::kSuggestion, marker->GetType());
18 }
19 
TEST_F(SuggestionMarkerTest,IsStyleableMarker)20 TEST_F(SuggestionMarkerTest, IsStyleableMarker) {
21   DocumentMarker* marker = MakeGarbageCollected<SuggestionMarker>(
22       0, 1, SuggestionMarkerProperties());
23   EXPECT_TRUE(IsStyleableMarker(*marker));
24 }
25 
TEST_F(SuggestionMarkerTest,ConstructorAndGetters)26 TEST_F(SuggestionMarkerTest, ConstructorAndGetters) {
27   Vector<String> suggestions = {"this", "that"};
28   SuggestionMarker* marker = MakeGarbageCollected<SuggestionMarker>(
29       0, 1,
30       SuggestionMarkerProperties::Builder()
31           .SetType(SuggestionMarker::SuggestionType::kNotMisspelling)
32           .SetSuggestions(suggestions)
33           .SetHighlightColor(Color::kTransparent)
34           .SetUnderlineColor(Color::kDarkGray)
35           .SetThickness(ui::mojom::ImeTextSpanThickness::kThin)
36           .SetBackgroundColor(Color::kGray)
37           .Build());
38   EXPECT_EQ(suggestions, marker->Suggestions());
39   EXPECT_FALSE(marker->IsMisspelling());
40   EXPECT_EQ(Color::kTransparent, marker->SuggestionHighlightColor());
41   EXPECT_EQ(Color::kDarkGray, marker->UnderlineColor());
42   EXPECT_TRUE(marker->HasThicknessThin());
43   EXPECT_EQ(Color::kGray, marker->BackgroundColor());
44 
45   SuggestionMarker* marker2 = MakeGarbageCollected<SuggestionMarker>(
46       0, 1,
47       SuggestionMarkerProperties::Builder()
48           .SetType(SuggestionMarker::SuggestionType::kMisspelling)
49           .SetHighlightColor(Color::kBlack)
50           .SetThickness(ui::mojom::ImeTextSpanThickness::kThick)
51           .Build());
52   EXPECT_TRUE(marker2->HasThicknessThick());
53   EXPECT_TRUE(marker2->IsMisspelling());
54   EXPECT_EQ(marker2->SuggestionHighlightColor(), Color::kBlack);
55 }
56 
TEST_F(SuggestionMarkerTest,SetSuggestion)57 TEST_F(SuggestionMarkerTest, SetSuggestion) {
58   Vector<String> suggestions = {"this", "that"};
59   SuggestionMarker* marker = MakeGarbageCollected<SuggestionMarker>(
60       0, 1,
61       SuggestionMarkerProperties::Builder()
62           .SetSuggestions(suggestions)
63           .Build());
64 
65   marker->SetSuggestion(1, "these");
66 
67   EXPECT_EQ(2u, marker->Suggestions().size());
68 
69   EXPECT_EQ("this", marker->Suggestions()[0]);
70   EXPECT_EQ("these", marker->Suggestions()[1]);
71 }
72 
73 }  // namespace blink
74