Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: third_party/WebKit/Source/core/page/ChromeClientTest.cpp

Issue 1504743002: Do not show a tooltip same as the previous one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/page/ChromeClient.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/page/ChromeClientTest.cpp
diff --git a/third_party/WebKit/Source/core/page/ChromeClientTest.cpp b/third_party/WebKit/Source/core/page/ChromeClientTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..42099adfdcb4a48dff35a8851ce92eef150c76d7
--- /dev/null
+++ b/third_party/WebKit/Source/core/page/ChromeClientTest.cpp
@@ -0,0 +1,70 @@
+// 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 "config.h"
+#include "core/page/ChromeClient.h"
+
+#include "core/dom/Document.h"
+#include "core/layout/HitTestResult.h"
+#include "core/loader/EmptyClients.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+class ChromeClientToolTipLogger : public EmptyChromeClient {
+public:
+ void setToolTip(const String& text, TextDirection) override
+ {
+ m_toolTipForLastSetToolTip = text;
+ }
+
+ String toolTipForLastSetToolTip() const { return m_toolTipForLastSetToolTip; }
+ void clearToolTipForLastSetToolTip() { m_toolTipForLastSetToolTip = String(); }
+
+private:
+ String m_toolTipForLastSetToolTip;
+};
+
+} // anonymous namespace
+
+class ChromeClientTest : public testing::Test {
+};
+
+TEST_F(ChromeClientTest, SetToolTipFlood)
+{
+ ChromeClientToolTipLogger logger;
+ ChromeClient* client = &logger;
+ HitTestResult result(HitTestRequest(HitTestRequest::Move), LayoutPoint(10, 20));
+ RefPtrWillBeRawPtr<Document> doc = Document::create();
+ RefPtrWillBeRawPtr<Element> element = HTMLElement::create(HTMLNames::divTag, *doc);
+ element->setAttribute(HTMLNames::titleAttr, "tooltip");
+ result.setInnerNode(element.get());
+
+ client->setToolTip(result);
+ EXPECT_EQ("tooltip", logger.toolTipForLastSetToolTip());
+
+ // seToolTip(HitTestResult) again in the same condition.
+ logger.clearToolTipForLastSetToolTip();
+ client->setToolTip(result);
+ // setToolTip(String,TextDirection) should not be called.
+ EXPECT_EQ(String(), logger.toolTipForLastSetToolTip());
+
+ // Cancel the tooltip, and setToolTip(HitTestResult) again.
+ client->clearToolTip();
+ logger.clearToolTipForLastSetToolTip();
+ client->setToolTip(result);
+ // setToolTip(String,TextDirection) should not be called.
+ EXPECT_EQ(String(), logger.toolTipForLastSetToolTip());
+
+ logger.clearToolTipForLastSetToolTip();
+ element->setAttribute(HTMLNames::titleAttr, "updated");
+ client->setToolTip(result);
+ // setToolTip(String,TextDirection) should be called because tooltip string
+ // is different from the last one.
+ EXPECT_EQ("updated", logger.toolTipForLastSetToolTip());
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/page/ChromeClient.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698