TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_Mutated) {
  ActiveStyleSheetVector oldSheets;
  ActiveStyleSheetVector newSheets;
  HeapVector<Member<RuleSet>> changedRuleSets;

  CSSStyleSheet* sheet1 = createSheet();
  CSSStyleSheet* sheet2 = createSheet();
  CSSStyleSheet* sheet3 = createSheet();

  oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
  oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
  oldSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));

  sheet2->contents()->clearRuleSet();
  sheet2->contents()->ensureRuleSet(MediaQueryEvaluator(),
                                    RuleHasDocumentSecurityOrigin);

  EXPECT_NE(oldSheets[1].second, &sheet2->contents()->ruleSet());

  newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
  newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
  newSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));

  EXPECT_EQ(ActiveSheetsChanged,
            compareActiveStyleSheets(oldSheets, newSheets, changedRuleSets));
  ASSERT_EQ(2u, changedRuleSets.size());
  EXPECT_EQ(&sheet2->contents()->ruleSet(), changedRuleSets[0]);
  EXPECT_EQ(oldSheets[1].second, changedRuleSets[1]);
}
Example #2
0
void StyleElement::process(Element* e)
{
    if (!e || !e->inDocument())
        return;

    unsigned resultLength = 0;
    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        if (isValidStyleChild(c)) {
            unsigned length = c->nodeValue().length();
            if (length > std::numeric_limits<unsigned>::max() - resultLength) {
                createSheet(e, m_startLineNumber, "");
                return;
            }
            resultLength += length;
        }
    }
    UChar* text;
    String sheetText = String::createUninitialized(resultLength, text);

    UChar* p = text;
    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        if (isValidStyleChild(c)) {
            String nodeValue = c->nodeValue();
            unsigned nodeLength = nodeValue.length();
            memcpy(p, nodeValue.characters(), nodeLength * sizeof(UChar));
            p += nodeLength;
        }
    }
    ASSERT(p == text + resultLength);

    createSheet(e, m_startLineNumber, sheetText);
}
Example #3
0
void StyleElement::process(Element* e)
{
    if (!e || !e->inDocument())
        return;

    unsigned resultLength = 0;
    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        if (isValidStyleChild(c)) {
            unsigned length = c->nodeValue().length();
            if (length > std::numeric_limits<unsigned>::max() - resultLength) {
                createSheet(e, m_startLineNumber, "");
                return;
            }
            resultLength += length;
        }
    }
    StringBuilder sheetText;
    sheetText.reserveCapacity(resultLength);

    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        if (isValidStyleChild(c)) {
            sheetText.append(c->nodeValue());
        }
    }
    ASSERT(sheetText.length() == resultLength);

    createSheet(e, m_startLineNumber, sheetText.toString());
}
TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_AppendedToEmpty) {
  ActiveStyleSheetVector oldSheets;
  ActiveStyleSheetVector newSheets;
  HeapVector<Member<RuleSet>> changedRuleSets;

  CSSStyleSheet* sheet1 = createSheet();
  CSSStyleSheet* sheet2 = createSheet();

  newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
  newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));

  EXPECT_EQ(ActiveSheetsAppended,
            compareActiveStyleSheets(oldSheets, newSheets, changedRuleSets));
  EXPECT_EQ(2u, changedRuleSets.size());
}
Example #5
0
void StyleElement::process(Element* e)
{
    if (!e || !e->inDocument())
        return;

    unsigned resultLength = 0;
    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        Node::NodeType nodeType = c->nodeType();
        if (nodeType == Node::TEXT_NODE || nodeType == Node::CDATA_SECTION_NODE || nodeType == Node::COMMENT_NODE)
            resultLength += c->nodeValue().length();
    }
    UChar* text;
    String sheetText = String::createUninitialized(resultLength, text);

    UChar* p = text;
    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        Node::NodeType nodeType = c->nodeType();
        if (nodeType == Node::TEXT_NODE || nodeType == Node::CDATA_SECTION_NODE || nodeType == Node::COMMENT_NODE) {
            String nodeValue = c->nodeValue();
            unsigned nodeLength = nodeValue.length();
            memcpy(p, nodeValue.characters(), nodeLength * sizeof(UChar));
            p += nodeLength;
        }
    }
    ASSERT(p == text + resultLength);

    createSheet(e, sheetText);
}
TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_RemoveNullRuleSet) {
  ActiveStyleSheetVector oldSheets;
  ActiveStyleSheetVector newSheets;
  HeapVector<Member<RuleSet>> changedRuleSets;

  CSSStyleSheet* sheet1 = createSheet();
  CSSStyleSheet* sheet2 = createSheet();

  oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
  oldSheets.append(std::make_pair(sheet2, nullptr));

  newSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));

  EXPECT_EQ(NoActiveSheetsChanged,
            compareActiveStyleSheets(oldSheets, newSheets, changedRuleSets));
  EXPECT_EQ(0u, changedRuleSets.size());
}
TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsPrepend)
{
    CSSStyleSheet* sheet1 = createSheet();
    CSSStyleSheet* sheet2 = createSheet();

    ContentsVector added;
    SheetVector previous;
    SheetVector current;

    previous.append(sheet2);

    current.append(sheet1);
    current.append(sheet2);

    added.append(sheet1->contents());

    compareStyleSheets(previous, current, added, Reconstruct);
}
TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsAppend)
{
    RawPtr<CSSStyleSheet> sheet1 = createSheet();
    RawPtr<CSSStyleSheet> sheet2 = createSheet();

    ContentsVector added;
    SheetVector previous;
    SheetVector current;

    previous.append(sheet1);

    current.append(sheet1);
    current.append(sheet2);

    added.append(sheet2->contents());

    compareStyleSheets(previous, current, added, Additive);
}
TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_InsertedAndRemoved) {
  ActiveStyleSheetVector oldSheets;
  ActiveStyleSheetVector newSheets;
  HeapVector<Member<RuleSet>> changedRuleSets;

  CSSStyleSheet* sheet1 = createSheet();
  CSSStyleSheet* sheet2 = createSheet();
  CSSStyleSheet* sheet3 = createSheet();

  oldSheets.append(std::make_pair(sheet1, &sheet1->contents()->ruleSet()));
  oldSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));

  newSheets.append(std::make_pair(sheet2, &sheet2->contents()->ruleSet()));
  newSheets.append(std::make_pair(sheet3, &sheet3->contents()->ruleSet()));

  EXPECT_EQ(ActiveSheetsChanged,
            compareActiveStyleSheets(oldSheets, newSheets, changedRuleSets));
  ASSERT_EQ(2u, changedRuleSets.size());
  EXPECT_EQ(&sheet1->contents()->ruleSet(), changedRuleSets[0]);
  EXPECT_EQ(&sheet3->contents()->ruleSet(), changedRuleSets[1]);
}
TEST_F(ApplyRulesetsTest, AddShadowV0BoundaryCrossingRuleToDocument) {
  document().view()->updateAllLifecyclePhases();

  CSSStyleSheet* sheet = createSheet(".a /deep/ .b { color:red }");

  ActiveStyleSheetVector newStyleSheets;
  newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet()));

  applyRuleSetChanges(styleEngine(), document(), ActiveStyleSheetVector(),
                      newStyleSheets);

  EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType());
}
TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsInsertRemove)
{
    CSSStyleSheet* sheet1 = createSheet();
    CSSStyleSheet* sheet2 = createSheet();
    CSSStyleSheet* sheet3 = createSheet();

    ContentsVector added;
    SheetVector previous;
    SheetVector current;

    previous.append(sheet1);
    previous.append(sheet2);

    current.append(sheet2);
    current.append(sheet3);

    // TODO([email protected]): This is clearly wrong. We add sheet3 and remove sheet1 and
    // compareStyleSheets returns sheet2 and sheet3 as added (crbug/475858).
    added.append(sheet2->contents());
    added.append(sheet3->contents());

    compareStyleSheets(previous, current, added, Reconstruct);
}
TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsRemove)
{
    CSSStyleSheet* sheet1 = createSheet();
    CSSStyleSheet* sheet2 = createSheet();
    CSSStyleSheet* sheet3 = createSheet();

    ContentsVector added;
    SheetVector previous;
    SheetVector current;

    previous.append(sheet1);
    previous.append(sheet2);
    previous.append(sheet3);

    current.append(sheet1);
    current.append(sheet3);

    added.append(sheet2->contents());

    // This is really the same as Insert. TreeScopeStyleSheetCollection::compareStyleSheets
    // will assert if you pass an array that is longer as the first parameter.
    compareStyleSheets(current, previous, added, Reconstruct);
}
TEST_F(ApplyRulesetsTest, AddFontFaceRuleToDocument) {
  document().view()->updateAllLifecyclePhases();

  CSSStyleSheet* sheet =
      createSheet("@font-face { font-family: ahum; src: url(ahum.ttf) }");

  ActiveStyleSheetVector newStyleSheets;
  newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet()));

  applyRuleSetChanges(styleEngine(), document(), ActiveStyleSheetVector(),
                      newStyleSheets);

  EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType());
}
TEST_F(ApplyRulesetsTest, AddShadowV0BoundaryCrossingRuleToShadowTree) {
  document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION);
  Element* host = document().getElementById("host");
  ASSERT_TRUE(host);

  ShadowRoot& shadowRoot = attachShadow(*host);
  document().view()->updateAllLifecyclePhases();

  CSSStyleSheet* sheet = createSheet(".a /deep/ .b { color:red }");

  ActiveStyleSheetVector newStyleSheets;
  newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet()));

  applyRuleSetChanges(styleEngine(), shadowRoot, ActiveStyleSheetVector(),
                      newStyleSheets);

  EXPECT_FALSE(document().needsStyleRecalc());
  EXPECT_EQ(SubtreeStyleChange, host->getStyleChangeType());
}
TEST_F(ApplyRulesetsTest, AddFontFaceRuleToShadowTree) {
  document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION);
  Element* host = document().getElementById("host");
  ASSERT_TRUE(host);

  ShadowRoot& shadowRoot = attachShadow(*host);
  document().view()->updateAllLifecyclePhases();

  CSSStyleSheet* sheet =
      createSheet("@font-face { font-family: ahum; src: url(ahum.ttf) }");

  ActiveStyleSheetVector newStyleSheets;
  newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet()));

  applyRuleSetChanges(styleEngine(), shadowRoot, ActiveStyleSheetVector(),
                      newStyleSheets);

  EXPECT_FALSE(document().needsLayoutTreeUpdate());
}
Example #16
0
/************************************************
 *
 * ***********************************************/
void TestBoomaga::test_PageRotation()
{
    QFETCH(int,      exp);
    Rotation expected = NoRotate + exp;

    QString dataTag = QTest::currentDataTag();
    QString layoutName = dataTag.section(";", 0, 0);
    QString sheetRotationName = dataTag.section(";", 1, 1);
    QString sheetDef =  dataTag.section(";", 2);

    Rotation sheetRotation = StrToRotation(sheetRotationName);


    Layout *layout = createLayout(layoutName);
    Sheet *sheet = createSheet(sheetDef);

    Rotation result = layout->calcPageRotation(sheet->page(0), sheetRotation);
    QCOMPARE((int)result, (int)expected);

    delete layout;
    delete sheet;
}
Example #17
0
void StyleElement::process(Element* element)
{
    if (!element || !element->inDocument())
        return;
    createSheet(element, element->textFromChildren());
}
Example #18
0
void InlineStyleSheetOwner::createSheetFromTextContents(Element* element)
{
    createSheet(element, TextNodeTraversal::contentsAsString(element));
}
StyleElement::ProcessingResult StyleElement::process(Element* element)
{
    if (!element || !element->inShadowIncludingDocument())
        return ProcessingSuccessful;
    return createSheet(element, element->textFromChildren());
}
Example #20
0
StyleSheet* StyleElement::sheet(Element* e)
{
    if (!m_sheet)
        createSheet(e);
    return m_sheet.get();
}
Example #21
0
StyleElement::ProcessingResult StyleElement::process(Element& element) {
  if (!element.isConnected())
    return ProcessingSuccessful;
  return createSheet(element, element.textFromChildren());
}