diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-01-26 10:02:06 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-01-26 15:21:52 +0000 |
commit | 98909bf9f458614abc1bb7f4df34a319a1d5ce3f (patch) | |
tree | 432f597117086be5dfaee02576109edd539e54c7 /xfa/fde/css/cfde_cssstylesheet_unittest.cpp | |
parent | 35ee5bb4a2e51fd42f07c23a4008bfb97e390b25 (diff) | |
download | pdfium-98909bf9f458614abc1bb7f4df34a319a1d5ce3f.tar.xz |
Add CSS parser tests
This CL adds more unit tests to the css parser and removes some unused code.
Change-Id: If233040e19c7a79a907a3215877e042ac388d61b
Reviewed-on: https://pdfium-review.googlesource.com/2412
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fde/css/cfde_cssstylesheet_unittest.cpp')
-rw-r--r-- | xfa/fde/css/cfde_cssstylesheet_unittest.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/xfa/fde/css/cfde_cssstylesheet_unittest.cpp b/xfa/fde/css/cfde_cssstylesheet_unittest.cpp index 048eeb7c84..c6886428ab 100644 --- a/xfa/fde/css/cfde_cssstylesheet_unittest.cpp +++ b/xfa/fde/css/cfde_cssstylesheet_unittest.cpp @@ -135,6 +135,59 @@ TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) { {FDE_CSSPropertyValue::Underline}); } +TEST_F(CFDE_CSSStyleSheetTest, ParseChildSelectors) { + const FX_WCHAR* buf = L"a b c { border: 10px; }"; + EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_EQ(1, sheet_->CountRules()); + + CFDE_CSSStyleRule* style = sheet_->GetRule(0); + EXPECT_EQ(1UL, style->CountSelectorLists()); + + auto sel = style->GetSelectorList(0); + EXPECT_TRUE(sel != nullptr); + EXPECT_EQ(FX_HashCode_GetW(L"c", true), sel->GetNameHash()); + + sel = sel->GetNextSelector(); + EXPECT_TRUE(sel != nullptr); + EXPECT_EQ(FX_HashCode_GetW(L"b", true), sel->GetNameHash()); + + sel = sel->GetNextSelector(); + EXPECT_TRUE(sel != nullptr); + EXPECT_EQ(FX_HashCode_GetW(L"a", true), sel->GetNameHash()); + + sel = sel->GetNextSelector(); + EXPECT_TRUE(sel == nullptr); + + decl_ = style->GetDeclaration(); + EXPECT_EQ(4UL, decl_->PropertyCountForTesting()); + + VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0, + FDE_CSSNumberType::Pixels); + VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0, + FDE_CSSNumberType::Pixels); + VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels); + VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0, + FDE_CSSNumberType::Pixels); +} + +TEST_F(CFDE_CSSStyleSheetTest, ParseUnhandledSelectors) { + const FX_WCHAR* buf = L"a > b { padding: 0; }"; + EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_EQ(0, sheet_->CountRules()); + + buf = L"a[first] { padding: 0; }"; + EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_EQ(0, sheet_->CountRules()); + + buf = L"a+b { padding: 0; }"; + EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_EQ(0, sheet_->CountRules()); + + buf = L"a ^ b { padding: 0; }"; + EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_EQ(0, sheet_->CountRules()); +} + TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectorsCombined) { LoadAndVerifyDecl(L"a, b, c { border: 5px; }", {L"a", L"b", L"c"}, 4); } |