Add some more CFX_CSSStyleSheet test cases.

Shows current behavior, although it can be argued that some of
these should fail outright.

Change-Id: Ib10a342adabfb259fd58da8f405128a9f832f611
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66511
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
index a69c68f..5468a1c 100644
--- a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
@@ -27,6 +27,11 @@
 
   void TearDown() override { decl_ = nullptr; }
 
+  void VerifyLoadFails(const wchar_t* buf) {
+    ASSERT(sheet_);
+    EXPECT_FALSE(sheet_->LoadBuffer(buf, wcslen(buf)));
+  }
+
   void LoadAndVerifyRuleCount(const wchar_t* buf, size_t rule_count) {
     ASSERT(sheet_);
     EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
@@ -96,6 +101,26 @@
   LoadAndVerifyRuleCount(L"  \n\r\t", 0);
 }
 
+TEST_F(CFX_CSSStyleSheetTest, ParseStrayClose1) {
+  VerifyLoadFails(L"}");
+}
+
+TEST_F(CFX_CSSStyleSheetTest, ParseStrayClose2) {
+  LoadAndVerifyRuleCount(L"foo }", 0);
+}
+
+TEST_F(CFX_CSSStyleSheetTest, ParseStrayClose3) {
+  VerifyLoadFails(L"foo {a: b}}");
+}
+
+TEST_F(CFX_CSSStyleSheetTest, ParseEmptySelector) {
+  VerifyLoadFails(L"{a: b}");
+}
+
+TEST_F(CFX_CSSStyleSheetTest, ParseEmptyBody) {
+  LoadAndVerifyRuleCount(L"foo {}", 0);
+}
+
 TEST_F(CFX_CSSStyleSheetTest, ParseMultipleSelectors) {
   const wchar_t* buf =
       L"a { border: 10px; }\nb { text-decoration: underline; }";