Esempio n. 1
0
TEST_F(StyleEngineTest, RuleSetInvalidationHostContext) {
  document().body()->setInnerHTML("<div id=host></div>");
  Element* host = document().getElementById("host");
  ASSERT_TRUE(host);

  ShadowRootInit init;
  init.setMode("open");
  ShadowRoot* shadowRoot = host->attachShadow(
      ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
  ASSERT_TRUE(shadowRoot);

  shadowRoot->setInnerHTML("<div></div><div class=a></div><div></div>");
  document().view()->updateAllLifecyclePhases();

  unsigned beforeCount = styleEngine().styleForElementCount();
  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, ":host-context(.nomatch) .a { background: green}"),
            RuleSetInvalidationsScheduled);
  document().view()->updateAllLifecyclePhases();
  unsigned afterCount = styleEngine().styleForElementCount();
  EXPECT_EQ(1u, afterCount - beforeCount);

  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, ":host-context(:hover) { background: green}"),
            RuleSetInvalidationFullRecalc);
  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, ":host-context(#host) { background: green}"),
            RuleSetInvalidationFullRecalc);
}
ShadowRoot& ApplyRulesetsTest::attachShadow(Element& host) {
  ShadowRootInit init;
  init.setMode("open");
  ShadowRoot* shadowRoot = host.attachShadow(
      ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
  EXPECT_TRUE(shadowRoot);
  return *shadowRoot;
}
Esempio n. 3
0
TEST_F(FocusControllerTest, DoNotCrash2) {
  document().body()->setInnerHTML(
      "<p id='target' tabindex='0'></p>This test is for crbug.com/609012<div "
      "id='host'></div>");
  // <p>
  Element* target = toElement(document().body()->firstChild());
  // "This test is for crbug.com/609012"
  Node* text = target->nextSibling();
  // <div> with shadow root
  Element* host = toElement(text->nextSibling());
  ShadowRootInit init;
  init.setMode("open");
  host->attachShadow(ScriptState::forMainWorld(document().frame()), init,
                     ASSERT_NO_EXCEPTION);

  // Set sequential focus navigation point at text node.
  document().setSequentialFocusNavigationStartingPoint(text);

  focusController().advanceFocus(WebFocusTypeBackward);
  EXPECT_EQ(target, document().focusedElement())
      << "This should not hit assertion and finish properly.";
}
Esempio n. 4
0
TEST_F(StyleEngineTest, RuleSetInvalidationSlotted) {
  document().body()->setInnerHTML(
      "<div id=host>"
      "  <span slot=other class=s1></span>"
      "  <span class=s2></span>"
      "  <span class=s1></span>"
      "  <span></span>"
      "</div>");

  Element* host = document().getElementById("host");
  ASSERT_TRUE(host);

  ShadowRootInit init;
  init.setMode("open");
  ShadowRoot* shadowRoot = host->attachShadow(
      ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
  ASSERT_TRUE(shadowRoot);

  shadowRoot->setInnerHTML("<slot name=other></slot><slot></slot>");
  document().view()->updateAllLifecyclePhases();

  unsigned beforeCount = styleEngine().styleForElementCount();
  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, "::slotted(.s1) { background: green}"),
            RuleSetInvalidationsScheduled);
  document().view()->updateAllLifecyclePhases();
  unsigned afterCount = styleEngine().styleForElementCount();
  EXPECT_EQ(4u, afterCount - beforeCount);

  beforeCount = afterCount;
  EXPECT_EQ(scheduleInvalidationsForRules(*shadowRoot,
                                          "::slotted(*) { background: green}"),
            RuleSetInvalidationsScheduled);
  document().view()->updateAllLifecyclePhases();
  afterCount = styleEngine().styleForElementCount();
  EXPECT_EQ(4u, afterCount - beforeCount);
}
Esempio n. 5
0
TEST_F(StyleEngineTest, RuleSetInvalidationV0BoundaryCrossing) {
  document().body()->setInnerHTML("<div id=host></div>");
  Element* host = document().getElementById("host");
  ASSERT_TRUE(host);

  ShadowRootInit init;
  init.setMode("open");
  ShadowRoot* shadowRoot = host->attachShadow(
      ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
  ASSERT_TRUE(shadowRoot);

  shadowRoot->setInnerHTML("<div></div><div class=a></div><div></div>");
  document().view()->updateAllLifecyclePhases();

  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, ".a ::content span { background: green}"),
            RuleSetInvalidationFullRecalc);
  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, ".a /deep/ span { background: green}"),
            RuleSetInvalidationFullRecalc);
  EXPECT_EQ(scheduleInvalidationsForRules(
                *shadowRoot, ".a::shadow span { background: green}"),
            RuleSetInvalidationFullRecalc);
}
Esempio n. 6
0
 ShadowRoot* attachShadowTo(Element* element) {
   NonThrowableExceptionState noExceptions;
   ShadowRootInit shadowRootInit;
   shadowRootInit.setMode("open");
   return element->attachShadow(scriptState(), shadowRootInit, noExceptions);
 }