1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright 2015 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 "third_party/blink/renderer/core/page/chrome_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
namespace blink {
namespace {
class ChromeClientToolTipLogger : public EmptyChromeClient {
public:
void SetToolTip(LocalFrame&, const String& text, TextDirection) override {
tool_tip_for_last_set_tool_tip_ = text;
}
String ToolTipForLastSetToolTip() const {
return tool_tip_for_last_set_tool_tip_;
}
void ClearToolTipForLastSetToolTip() {
tool_tip_for_last_set_tool_tip_ = String();
}
private:
String tool_tip_for_last_set_tool_tip_;
};
} // anonymous namespace
class ChromeClientTest : public testing::Test {};
TEST_F(ChromeClientTest, SetToolTipFlood) {
ChromeClientToolTipLogger logger;
ChromeClient* client = &logger;
HitTestLocation location(PhysicalOffset(10, 20));
HitTestResult result(HitTestRequest(HitTestRequest::kMove), location);
auto* doc = MakeGarbageCollected<Document>();
auto* element = MakeGarbageCollected<HTMLElement>(html_names::kDivTag, *doc);
element->setAttribute(html_names::kTitleAttr, "tooltip");
result.SetInnerNode(element);
client->SetToolTip(*doc->GetFrame(), location, result);
EXPECT_EQ("tooltip", logger.ToolTipForLastSetToolTip());
// seToolTip(HitTestResult) again in the same condition.
logger.ClearToolTipForLastSetToolTip();
client->SetToolTip(*doc->GetFrame(), location, result);
// setToolTip(String,TextDirection) should not be called.
EXPECT_EQ(String(), logger.ToolTipForLastSetToolTip());
// Cancel the tooltip, and setToolTip(HitTestResult) again.
client->ClearToolTip(*doc->GetFrame());
logger.ClearToolTipForLastSetToolTip();
client->SetToolTip(*doc->GetFrame(), location, result);
// setToolTip(String,TextDirection) should not be called.
EXPECT_EQ(String(), logger.ToolTipForLastSetToolTip());
logger.ClearToolTipForLastSetToolTip();
element->setAttribute(html_names::kTitleAttr, "updated");
client->SetToolTip(*doc->GetFrame(), location, result);
// setToolTip(String,TextDirection) should be called because tooltip string
// is different from the last one.
EXPECT_EQ("updated", logger.ToolTipForLastSetToolTip());
}
TEST_F(ChromeClientTest, SetToolTipEmptyString) {
ChromeClient* client = MakeGarbageCollected<EmptyChromeClient>();
HitTestLocation location(PhysicalOffset(10, 20));
HitTestResult result(HitTestRequest(HitTestRequest::kMove), location);
auto& doc = *MakeGarbageCollected<Document>();
auto& input_element =
*MakeGarbageCollected<HTMLInputElement>(doc, CreateElementFlags());
input_element.setAttribute(html_names::kTypeAttr, "file");
result.SetInnerNode(&input_element);
client->SetToolTip(*doc.GetFrame(), location, result);
EXPECT_EQ("<<NoFileChosenLabel>>", client->last_tool_tip_text_);
client->last_tool_tip_text_ = String();
input_element.removeAttribute(html_names::kTitleAttr);
client->SetToolTip(*doc.GetFrame(), location, result);
EXPECT_EQ("<<NoFileChosenLabel>>", client->last_tool_tip_text_);
client->last_tool_tip_text_ = String();
input_element.setAttribute(html_names::kTitleAttr, g_empty_atom);
client->SetToolTip(*doc.GetFrame(), location, result);
EXPECT_EQ(g_empty_atom, client->last_tool_tip_text_);
client->last_tool_tip_text_ = String();
input_element.setAttribute(html_names::kTitleAttr, "test");
client->SetToolTip(*doc.GetFrame(), location, result);
EXPECT_EQ("test", client->last_tool_tip_text_);
}
} // namespace blink
|