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

Unified Diff: third_party/WebKit/Source/core/dom/DocumentStatisticsCollectorTest.cpp

Issue 1650303002: Move DOM-inspecting language detection logic to Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 10 months 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
Index: third_party/WebKit/Source/core/dom/DocumentStatisticsCollectorTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/DocumentStatisticsCollectorTest.cpp b/third_party/WebKit/Source/core/dom/DocumentStatisticsCollectorTest.cpp
index 0612c8e89048f442eaeafb0b307089c311a5a560..73fb197b537f48aa263f99fd1ca36e17b1d93484 100644
--- a/third_party/WebKit/Source/core/dom/DocumentStatisticsCollectorTest.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentStatisticsCollectorTest.cpp
@@ -11,6 +11,7 @@
#include "core/html/HTMLLinkElement.h"
#include "core/testing/DummyPageHolder.h"
#include "public/platform/WebDistillability.h"
+#include "public/platform/WebLanguageDetectionDetails.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/text/StringBuilder.h"
@@ -61,7 +62,7 @@ TEST_F(DocumentStatisticsCollectorTest, HasOpenGraphArticle)
" <meta property='og:type' content='arTiclE' />"
"</head>"
);
- WebDistillabilityFeatures features = DocumentStatisticsCollector::collectStatistics(document());
+ WebDistillabilityFeatures features = DocumentStatisticsCollector::collectDistillabilityFeatures(document());
EXPECT_TRUE(features.openGraph);
}
@@ -74,7 +75,7 @@ TEST_F(DocumentStatisticsCollectorTest, NoOpenGraphArticle)
" <meta property='og:type' content='movie' />"
"</head>"
);
- WebDistillabilityFeatures features = DocumentStatisticsCollector::collectStatistics(document());
+ WebDistillabilityFeatures features = DocumentStatisticsCollector::collectDistillabilityFeatures(document());
EXPECT_FALSE(features.openGraph);
}
@@ -91,7 +92,7 @@ TEST_F(DocumentStatisticsCollectorTest, CountElements)
"<p><a> </a></p>"
"<ul><li><p><a> </a></p></li></ul>"
);
- WebDistillabilityFeatures features = DocumentStatisticsCollector::collectStatistics(document());
+ WebDistillabilityFeatures features = DocumentStatisticsCollector::collectDistillabilityFeatures(document());
EXPECT_FALSE(features.openGraph);
@@ -122,7 +123,7 @@ TEST_F(DocumentStatisticsCollectorTest, CountScore)
"<p style='opacity:0'>12345678</p>" // textContentLength = 8, skipped because invisible
"<p><a href='#'>1234 </a>6 <b> 9</b></p>" // textContentLength = 9
);
- WebDistillabilityFeatures features = DocumentStatisticsCollector::collectStatistics(document());
+ WebDistillabilityFeatures features = DocumentStatisticsCollector::collectDistillabilityFeatures(document());
EXPECT_DOUBLE_EQ(features.mozScore, sqrt(144 - kParagraphLengthThreshold));
EXPECT_DOUBLE_EQ(features.mozScoreAllSqrt, 1 + sqrt(144) + sqrt(9));
@@ -143,7 +144,7 @@ TEST_F(DocumentStatisticsCollectorTest, CountScoreSaturation)
setHtmlInnerHTML(
html.toString()
);
- WebDistillabilityFeatures features = DocumentStatisticsCollector::collectStatistics(document());
+ WebDistillabilityFeatures features = DocumentStatisticsCollector::collectDistillabilityFeatures(document());
double error = 1e-5;
EXPECT_NEAR(features.mozScore, 6 * sqrt(kTextContentLengthSaturation - kParagraphLengthThreshold), error);
@@ -151,4 +152,40 @@ TEST_F(DocumentStatisticsCollectorTest, CountScoreSaturation)
EXPECT_NEAR(features.mozScoreAllLinear, 6 * kTextContentLengthSaturation, error);
}
+TEST_F(DocumentStatisticsCollectorTest, HasNoTranslateMeta)
+{
+ setHtmlInnerHTML("<head></head>");
+ EXPECT_FALSE(DocumentStatisticsCollector::collectLanguageDetectionDetails(document()).hasNoTranslateMeta);
+
+ setHtmlInnerHTML("<head><meta name=something>");
+ EXPECT_FALSE(DocumentStatisticsCollector::collectLanguageDetectionDetails(document()).hasNoTranslateMeta);
+
+ setHtmlInnerHTML("<head><meta name=google>");
+ EXPECT_FALSE(DocumentStatisticsCollector::collectLanguageDetectionDetails(document()).hasNoTranslateMeta);
+
+ setHtmlInnerHTML("<head><meta content=notranslate>");
+ EXPECT_FALSE(DocumentStatisticsCollector::collectLanguageDetectionDetails(document()).hasNoTranslateMeta);
+
+ setHtmlInnerHTML("<head><meta name=google content=notranslate>");
+ EXPECT_TRUE(DocumentStatisticsCollector::collectLanguageDetectionDetails(document()).hasNoTranslateMeta);
+
+ setHtmlInnerHTML("<head><meta name=google value=notranslate>");
+ EXPECT_TRUE(DocumentStatisticsCollector::collectLanguageDetectionDetails(document()).hasNoTranslateMeta);
+}
+
+TEST_F(DocumentStatisticsCollectorTest, LanguageDetails)
+{
+ document().documentElement()->setAttribute(HTMLNames::langAttr, "potato");
+ setHtmlInnerHTML("<meta http-equiv=content-language content=onion>TEST");
+ KURL url = KURL(ParsedURLString, "https://example.com");
+ document().setURL(url);
+
+ WebLanguageDetectionDetails details = DocumentStatisticsCollector::collectLanguageDetectionDetails(document());
+ EXPECT_EQ(details.contentLanguage, "onion");
+ EXPECT_EQ(details.htmlLanguage, "potato");
+ EXPECT_EQ(details.url, WebURL(url));
+ EXPECT_FALSE(details.hasNoTranslateMeta);
+ EXPECT_EQ(details.content, "TEST");
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/DocumentStatisticsCollector.cpp ('k') | third_party/WebKit/Source/web/WebDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698