OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/ActiveStyleSheets.h" | 5 #include "core/css/ActiveStyleSheets.h" |
6 | 6 |
7 #include "core/css/CSSStyleSheet.h" | 7 #include "core/css/CSSStyleSheet.h" |
8 #include "core/css/MediaQueryEvaluator.h" | 8 #include "core/css/MediaQueryEvaluator.h" |
9 #include "core/css/StyleSheetContents.h" | 9 #include "core/css/StyleSheetContents.h" |
10 #include "core/css/StyleSheetList.h" | 10 #include "core/css/StyleSheetList.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 303 } |
304 | 304 |
305 TEST_F(ApplyRulesetsTest, AddUniversalRuleToDocument) { | 305 TEST_F(ApplyRulesetsTest, AddUniversalRuleToDocument) { |
306 document().view()->updateAllLifecyclePhases(); | 306 document().view()->updateAllLifecyclePhases(); |
307 | 307 |
308 CSSStyleSheet* sheet = createSheet("body * { color:red }"); | 308 CSSStyleSheet* sheet = createSheet("body * { color:red }"); |
309 | 309 |
310 ActiveStyleSheetVector newStyleSheets; | 310 ActiveStyleSheetVector newStyleSheets; |
311 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); | 311 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); |
312 | 312 |
313 applyRuleSetChanges(styleEngine(), document(), ActiveStyleSheetVector(), | 313 styleEngine().applyRuleSetChanges(document(), ActiveStyleSheetVector(), |
314 newStyleSheets); | 314 newStyleSheets); |
315 | 315 |
316 EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType()); | 316 EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType()); |
317 } | 317 } |
318 | 318 |
319 TEST_F(ApplyRulesetsTest, AddUniversalRuleToShadowTree) { | 319 TEST_F(ApplyRulesetsTest, AddUniversalRuleToShadowTree) { |
320 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); | 320 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); |
321 Element* host = document().getElementById("host"); | 321 Element* host = document().getElementById("host"); |
322 ASSERT_TRUE(host); | 322 ASSERT_TRUE(host); |
323 | 323 |
324 ShadowRoot& shadowRoot = attachShadow(*host); | 324 ShadowRoot& shadowRoot = attachShadow(*host); |
325 document().view()->updateAllLifecyclePhases(); | 325 document().view()->updateAllLifecyclePhases(); |
326 | 326 |
327 CSSStyleSheet* sheet = createSheet("body * { color:red }"); | 327 CSSStyleSheet* sheet = createSheet("body * { color:red }"); |
328 | 328 |
329 ActiveStyleSheetVector newStyleSheets; | 329 ActiveStyleSheetVector newStyleSheets; |
330 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); | 330 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); |
331 | 331 |
332 applyRuleSetChanges(styleEngine(), shadowRoot, ActiveStyleSheetVector(), | 332 styleEngine().applyRuleSetChanges(shadowRoot, ActiveStyleSheetVector(), |
333 newStyleSheets); | 333 newStyleSheets); |
334 | 334 |
335 EXPECT_FALSE(document().needsStyleRecalc()); | 335 EXPECT_FALSE(document().needsStyleRecalc()); |
336 EXPECT_EQ(SubtreeStyleChange, host->getStyleChangeType()); | 336 EXPECT_EQ(SubtreeStyleChange, host->getStyleChangeType()); |
337 } | 337 } |
338 | 338 |
339 TEST_F(ApplyRulesetsTest, AddShadowV0BoundaryCrossingRuleToDocument) { | 339 TEST_F(ApplyRulesetsTest, AddShadowV0BoundaryCrossingRuleToDocument) { |
340 document().view()->updateAllLifecyclePhases(); | 340 document().view()->updateAllLifecyclePhases(); |
341 | 341 |
342 CSSStyleSheet* sheet = createSheet(".a /deep/ .b { color:red }"); | 342 CSSStyleSheet* sheet = createSheet(".a /deep/ .b { color:red }"); |
343 | 343 |
344 ActiveStyleSheetVector newStyleSheets; | 344 ActiveStyleSheetVector newStyleSheets; |
345 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); | 345 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); |
346 | 346 |
347 applyRuleSetChanges(styleEngine(), document(), ActiveStyleSheetVector(), | 347 styleEngine().applyRuleSetChanges(document(), ActiveStyleSheetVector(), |
348 newStyleSheets); | 348 newStyleSheets); |
349 | 349 |
350 EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType()); | 350 EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType()); |
351 } | 351 } |
352 | 352 |
353 TEST_F(ApplyRulesetsTest, AddShadowV0BoundaryCrossingRuleToShadowTree) { | 353 TEST_F(ApplyRulesetsTest, AddShadowV0BoundaryCrossingRuleToShadowTree) { |
354 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); | 354 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); |
355 Element* host = document().getElementById("host"); | 355 Element* host = document().getElementById("host"); |
356 ASSERT_TRUE(host); | 356 ASSERT_TRUE(host); |
357 | 357 |
358 ShadowRoot& shadowRoot = attachShadow(*host); | 358 ShadowRoot& shadowRoot = attachShadow(*host); |
359 document().view()->updateAllLifecyclePhases(); | 359 document().view()->updateAllLifecyclePhases(); |
360 | 360 |
361 CSSStyleSheet* sheet = createSheet(".a /deep/ .b { color:red }"); | 361 CSSStyleSheet* sheet = createSheet(".a /deep/ .b { color:red }"); |
362 | 362 |
363 ActiveStyleSheetVector newStyleSheets; | 363 ActiveStyleSheetVector newStyleSheets; |
364 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); | 364 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); |
365 | 365 |
366 applyRuleSetChanges(styleEngine(), shadowRoot, ActiveStyleSheetVector(), | 366 styleEngine().applyRuleSetChanges(shadowRoot, ActiveStyleSheetVector(), |
367 newStyleSheets); | 367 newStyleSheets); |
368 | 368 |
369 EXPECT_FALSE(document().needsStyleRecalc()); | 369 EXPECT_FALSE(document().needsStyleRecalc()); |
370 EXPECT_EQ(SubtreeStyleChange, host->getStyleChangeType()); | 370 EXPECT_EQ(SubtreeStyleChange, host->getStyleChangeType()); |
371 } | 371 } |
372 | 372 |
373 TEST_F(ApplyRulesetsTest, AddFontFaceRuleToDocument) { | 373 TEST_F(ApplyRulesetsTest, AddFontFaceRuleToDocument) { |
374 document().view()->updateAllLifecyclePhases(); | 374 document().view()->updateAllLifecyclePhases(); |
375 | 375 |
376 CSSStyleSheet* sheet = | 376 CSSStyleSheet* sheet = |
377 createSheet("@font-face { font-family: ahum; src: url(ahum.ttf) }"); | 377 createSheet("@font-face { font-family: ahum; src: url(ahum.ttf) }"); |
378 | 378 |
379 ActiveStyleSheetVector newStyleSheets; | 379 ActiveStyleSheetVector newStyleSheets; |
380 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); | 380 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); |
381 | 381 |
382 applyRuleSetChanges(styleEngine(), document(), ActiveStyleSheetVector(), | 382 styleEngine().applyRuleSetChanges(document(), ActiveStyleSheetVector(), |
383 newStyleSheets); | 383 newStyleSheets); |
384 | 384 |
385 EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType()); | 385 EXPECT_EQ(SubtreeStyleChange, document().getStyleChangeType()); |
386 } | 386 } |
387 | 387 |
388 TEST_F(ApplyRulesetsTest, AddFontFaceRuleToShadowTree) { | 388 TEST_F(ApplyRulesetsTest, AddFontFaceRuleToShadowTree) { |
389 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); | 389 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); |
390 Element* host = document().getElementById("host"); | 390 Element* host = document().getElementById("host"); |
391 ASSERT_TRUE(host); | 391 ASSERT_TRUE(host); |
392 | 392 |
393 ShadowRoot& shadowRoot = attachShadow(*host); | 393 ShadowRoot& shadowRoot = attachShadow(*host); |
394 document().view()->updateAllLifecyclePhases(); | 394 document().view()->updateAllLifecyclePhases(); |
395 | 395 |
396 CSSStyleSheet* sheet = | 396 CSSStyleSheet* sheet = |
397 createSheet("@font-face { font-family: ahum; src: url(ahum.ttf) }"); | 397 createSheet("@font-face { font-family: ahum; src: url(ahum.ttf) }"); |
398 | 398 |
399 ActiveStyleSheetVector newStyleSheets; | 399 ActiveStyleSheetVector newStyleSheets; |
400 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); | 400 newStyleSheets.append(std::make_pair(sheet, &sheet->contents()->ruleSet())); |
401 | 401 |
402 applyRuleSetChanges(styleEngine(), shadowRoot, ActiveStyleSheetVector(), | 402 styleEngine().applyRuleSetChanges(shadowRoot, ActiveStyleSheetVector(), |
403 newStyleSheets); | 403 newStyleSheets); |
404 | 404 |
405 EXPECT_FALSE(document().needsLayoutTreeUpdate()); | 405 EXPECT_FALSE(document().needsLayoutTreeUpdate()); |
406 } | 406 } |
407 | 407 |
408 TEST_F(ApplyRulesetsTest, RemoveSheetFromShadowTree) { | 408 TEST_F(ApplyRulesetsTest, RemoveSheetFromShadowTree) { |
409 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); | 409 document().body()->setInnerHTML("<div id=host></div>", ASSERT_NO_EXCEPTION); |
410 Element* host = document().getElementById("host"); | 410 Element* host = document().getElementById("host"); |
411 ASSERT_TRUE(host); | 411 ASSERT_TRUE(host); |
412 | 412 |
413 ShadowRoot& shadowRoot = attachShadow(*host); | 413 ShadowRoot& shadowRoot = attachShadow(*host); |
414 shadowRoot.setInnerHTML("<style>::slotted(#dummy){color:pink}</style>", | 414 shadowRoot.setInnerHTML("<style>::slotted(#dummy){color:pink}</style>", |
415 ASSERT_NO_EXCEPTION); | 415 ASSERT_NO_EXCEPTION); |
416 document().view()->updateAllLifecyclePhases(); | 416 document().view()->updateAllLifecyclePhases(); |
417 | 417 |
418 EXPECT_EQ(1u, styleEngine().treeBoundaryCrossingScopes().size()); | 418 EXPECT_EQ(1u, styleEngine().treeBoundaryCrossingScopes().size()); |
419 ASSERT_EQ(1u, shadowRoot.styleSheets().length()); | 419 ASSERT_EQ(1u, shadowRoot.styleSheets().length()); |
420 | 420 |
421 StyleSheet* sheet = shadowRoot.styleSheets().item(0); | 421 StyleSheet* sheet = shadowRoot.styleSheets().item(0); |
422 ASSERT_TRUE(sheet); | 422 ASSERT_TRUE(sheet); |
423 ASSERT_TRUE(sheet->isCSSStyleSheet()); | 423 ASSERT_TRUE(sheet->isCSSStyleSheet()); |
424 | 424 |
425 CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); | 425 CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); |
426 ActiveStyleSheetVector oldStyleSheets; | 426 ActiveStyleSheetVector oldStyleSheets; |
427 oldStyleSheets.append( | 427 oldStyleSheets.append( |
428 std::make_pair(cssSheet, &cssSheet->contents()->ruleSet())); | 428 std::make_pair(cssSheet, &cssSheet->contents()->ruleSet())); |
429 applyRuleSetChanges(styleEngine(), shadowRoot, oldStyleSheets, | 429 styleEngine().applyRuleSetChanges(shadowRoot, oldStyleSheets, |
430 ActiveStyleSheetVector()); | 430 ActiveStyleSheetVector()); |
431 | 431 |
432 EXPECT_TRUE(styleEngine().treeBoundaryCrossingScopes().isEmpty()); | 432 EXPECT_TRUE(styleEngine().treeBoundaryCrossingScopes().isEmpty()); |
433 } | 433 } |
434 | 434 |
435 } // namespace blink | 435 } // namespace blink |
OLD | NEW |