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 "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
8 #include "core/css/CSSStyleSheet.h" | 8 #include "core/css/CSSStyleSheet.h" |
9 #include "core/css/MediaQueryEvaluator.h" | 9 #include "core/css/MediaQueryEvaluator.h" |
10 #include "core/css/StyleSheetContents.h" | 10 #include "core/css/StyleSheetContents.h" |
11 #include "core/css/StyleSheetList.h" | 11 #include "core/css/StyleSheetList.h" |
12 #include "core/css/parser/CSSParserContext.h" | 12 #include "core/css/parser/CSSParserContext.h" |
| 13 #include "core/css/parser/MediaQueryParser.h" |
13 #include "core/dom/StyleEngine.h" | 14 #include "core/dom/StyleEngine.h" |
14 #include "core/dom/shadow/ShadowRoot.h" | 15 #include "core/dom/shadow/ShadowRoot.h" |
15 #include "core/dom/shadow/ShadowRootInit.h" | 16 #include "core/dom/shadow/ShadowRootInit.h" |
16 #include "core/frame/FrameView.h" | 17 #include "core/frame/FrameView.h" |
17 #include "core/html/HTMLElement.h" | 18 #include "core/html/HTMLElement.h" |
18 #include "core/testing/DummyPageHolder.h" | 19 #include "core/testing/DummyPageHolder.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 new_sheets.push_back(std::make_pair(sheet1, nullptr)); | 403 new_sheets.push_back(std::make_pair(sheet1, nullptr)); |
403 new_sheets.push_back( | 404 new_sheets.push_back( |
404 std::make_pair(sheet2, &sheet2->Contents()->GetRuleSet())); | 405 std::make_pair(sheet2, &sheet2->Contents()->GetRuleSet())); |
405 | 406 |
406 EXPECT_EQ( | 407 EXPECT_EQ( |
407 kActiveSheetsChanged, | 408 kActiveSheetsChanged, |
408 CompareActiveStyleSheets(old_sheets, new_sheets, changed_rule_sets)); | 409 CompareActiveStyleSheets(old_sheets, new_sheets, changed_rule_sets)); |
409 EXPECT_EQ(2u, changed_rule_sets.size()); | 410 EXPECT_EQ(2u, changed_rule_sets.size()); |
410 } | 411 } |
411 | 412 |
| 413 TEST_F(ActiveStyleSheetsTest, CompareActiveStyleSheets_AddRemoveNonMatchingMQ) { |
| 414 ActiveStyleSheetVector old_sheets; |
| 415 ActiveStyleSheetVector new_sheets; |
| 416 HeapHashSet<Member<RuleSet>> changed_rule_sets; |
| 417 |
| 418 EXPECT_EQ( |
| 419 kNoActiveSheetsChanged, |
| 420 CompareActiveStyleSheets(old_sheets, new_sheets, changed_rule_sets)); |
| 421 EXPECT_EQ(0u, changed_rule_sets.size()); |
| 422 |
| 423 CSSStyleSheet* sheet1 = CreateSheet(); |
| 424 MediaQuerySet* mq = |
| 425 MediaQueryParser::ParseMediaQuerySet("(min-width: 9000px)"); |
| 426 sheet1->SetMediaQueries(mq); |
| 427 sheet1->MatchesMediaQueries(MediaQueryEvaluator()); |
| 428 |
| 429 new_sheets.push_back(std::make_pair(sheet1, nullptr)); |
| 430 |
| 431 EXPECT_EQ( |
| 432 kActiveSheetsAppended, |
| 433 CompareActiveStyleSheets(old_sheets, new_sheets, changed_rule_sets)); |
| 434 EXPECT_EQ(0u, changed_rule_sets.size()); |
| 435 |
| 436 EXPECT_EQ( |
| 437 kActiveSheetsChanged, |
| 438 CompareActiveStyleSheets(new_sheets, old_sheets, changed_rule_sets)); |
| 439 EXPECT_EQ(0u, changed_rule_sets.size()); |
| 440 } |
| 441 |
412 TEST_F(ApplyRulesetsTest, AddUniversalRuleToDocument) { | 442 TEST_F(ApplyRulesetsTest, AddUniversalRuleToDocument) { |
413 GetDocument().View()->UpdateAllLifecyclePhases(); | 443 GetDocument().View()->UpdateAllLifecyclePhases(); |
414 | 444 |
415 CSSStyleSheet* sheet = CreateSheet("body * { color:red }"); | 445 CSSStyleSheet* sheet = CreateSheet("body * { color:red }"); |
416 | 446 |
417 ActiveStyleSheetVector new_style_sheets; | 447 ActiveStyleSheetVector new_style_sheets; |
418 new_style_sheets.push_back( | 448 new_style_sheets.push_back( |
419 std::make_pair(sheet, &sheet->Contents()->GetRuleSet())); | 449 std::make_pair(sheet, &sheet->Contents()->GetRuleSet())); |
420 | 450 |
421 GetStyleEngine().ApplyRuleSetChanges(GetDocument(), ActiveStyleSheetVector(), | 451 GetStyleEngine().ApplyRuleSetChanges(GetDocument(), ActiveStyleSheetVector(), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 ActiveStyleSheetVector old_style_sheets; | 571 ActiveStyleSheetVector old_style_sheets; |
542 old_style_sheets.push_back( | 572 old_style_sheets.push_back( |
543 std::make_pair(css_sheet, &css_sheet->Contents()->GetRuleSet())); | 573 std::make_pair(css_sheet, &css_sheet->Contents()->GetRuleSet())); |
544 GetStyleEngine().ApplyRuleSetChanges(shadow_root, old_style_sheets, | 574 GetStyleEngine().ApplyRuleSetChanges(shadow_root, old_style_sheets, |
545 ActiveStyleSheetVector()); | 575 ActiveStyleSheetVector()); |
546 | 576 |
547 EXPECT_TRUE(GetStyleEngine().TreeBoundaryCrossingScopes().IsEmpty()); | 577 EXPECT_TRUE(GetStyleEngine().TreeBoundaryCrossingScopes().IsEmpty()); |
548 } | 578 } |
549 | 579 |
550 } // namespace blink | 580 } // namespace blink |
OLD | NEW |