diff options
Diffstat (limited to 'xfa/fde')
-rw-r--r-- | xfa/fde/css/cfde_cssselector.cpp | 10 | ||||
-rw-r--r-- | xfa/fde/css/cfde_cssselector.h | 1 | ||||
-rw-r--r-- | xfa/fde/css/cfde_cssstylesheet_unittest.cpp | 53 |
3 files changed, 53 insertions, 11 deletions
diff --git a/xfa/fde/css/cfde_cssselector.cpp b/xfa/fde/css/cfde_cssselector.cpp index 718cb46415..6d181ac325 100644 --- a/xfa/fde/css/cfde_cssselector.cpp +++ b/xfa/fde/css/cfde_cssselector.cpp @@ -53,10 +53,6 @@ CFDE_CSSSelector* CFDE_CSSSelector::GetNextSelector() const { return m_pNext.get(); } -std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::ReleaseNextSelector() { - return std::move(m_pNext); -} - std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( const FX_WCHAR* psz, int32_t iLen) { @@ -74,15 +70,10 @@ std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( } std::unique_ptr<CFDE_CSSSelector> pFirst = nullptr; - CFDE_CSSSelector* pLast = nullptr; - for (psz = pStart; psz < pEnd;) { FX_WCHAR wch = *psz; if (IsCSSChar(wch) || wch == '*') { int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd); - if (iNameLen == 0) - return nullptr; - auto p = pdfium::MakeUnique<CFDE_CSSSelector>( FDE_CSSSelectorType::Element, psz, iNameLen, true); if (pFirst) { @@ -90,7 +81,6 @@ std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( p->SetNext(std::move(pFirst)); } pFirst = std::move(p); - pLast = pFirst.get(); psz += iNameLen; } else if (wch == ' ') { psz++; diff --git a/xfa/fde/css/cfde_cssselector.h b/xfa/fde/css/cfde_cssselector.h index 18a7c340e5..a5d9cf9c7c 100644 --- a/xfa/fde/css/cfde_cssselector.h +++ b/xfa/fde/css/cfde_cssselector.h @@ -27,7 +27,6 @@ class CFDE_CSSSelector { FDE_CSSSelectorType GetType() const; uint32_t GetNameHash() const; CFDE_CSSSelector* GetNextSelector() const; - std::unique_ptr<CFDE_CSSSelector> ReleaseNextSelector(); void SetNext(std::unique_ptr<CFDE_CSSSelector> pNext) { m_pNext = std::move(pNext); 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); } |