|
48 | 48 |
|
49 | 49 | test(() => {
|
50 | 50 | const sheet = new CSSStyleSheet({disabled: true, media: "screen, print"});
|
51 |
| - assert_equals(sheet.title, null); |
| 51 | + assert_equals(sheet.title, ""); |
52 | 52 | assert_equals(sheet.ownerNode, null);
|
53 | 53 | assert_equals(sheet.ownerRule, null);
|
54 | 54 | assert_equals(sheet.media.length, 2);
|
|
66 | 66 | assert_equals(sheet.cssRules[0].cssText, redStyleTexts[1]);
|
67 | 67 |
|
68 | 68 | const sheet2 = new CSSStyleSheet({});
|
69 |
| - assert_equals(sheet2.title, null); |
| 69 | + assert_equals(sheet2.title, ""); |
70 | 70 | assert_equals(sheet2.ownerNode, null);
|
71 | 71 | assert_equals(sheet2.ownerRule, null);
|
72 | 72 | assert_equals(sheet2.media.length, 0);
|
|
81 | 81 | assert_equals(sheet2.cssRules.length, 0);
|
82 | 82 |
|
83 | 83 | const sheet3 = new CSSStyleSheet();
|
84 |
| - assert_equals(sheet3.title, null); |
| 84 | + assert_equals(sheet3.title, ""); |
85 | 85 | assert_equals(sheet3.ownerNode, null);
|
86 | 86 | assert_equals(sheet3.ownerRule, null);
|
87 | 87 | assert_equals(sheet3.media.length, 0);
|
|
98 | 98 |
|
99 | 99 | test(() => {
|
100 | 100 | const sheet = new CSSStyleSheet({title: "something"});
|
101 |
| - assert_equals(sheet.title, null); |
102 |
| -}, "title cannot be set in the CSSStyleSheet constructor"); |
| 101 | + assert_equals(sheet.title, "something"); |
| 102 | +}, "title can be set in the CSSStyleSheet constructor"); |
103 | 103 |
|
104 | 104 | promise_test(() => {
|
105 | 105 | const sheet = new CSSStyleSheet({disabled: true, media: "screen, print"});
|
106 | 106 | const promise_sheet = sheet.replace(redStyleTexts[0]);
|
107 | 107 | return promise_sheet.then(function(sheet) {
|
108 |
| - assert_equals(sheet.title, null); |
| 108 | + assert_equals(sheet.title, ""); |
109 | 109 | assert_equals(sheet.ownerNode, null);
|
110 | 110 | assert_equals(sheet.ownerRule, null);
|
111 | 111 | assert_equals(sheet.media.length, 2);
|
|
535 | 535 | const style = document.createElement("style");
|
536 | 536 | style.textContent = ".target { color: white; }";
|
537 | 537 | span.shadowRoot.appendChild(style)
|
538 |
| - // non-adopted styles should be ordered before adopted styles |
539 |
| - assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)"); |
| 538 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)", "non-adopted styles should be ordered before adopted styles"); |
540 | 539 |
|
541 | 540 | span.shadowRoot.adoptedStyleSheets = [];
|
542 |
| - // with no adopted styles in conflict, the non-adopted style should take effect |
543 |
| - assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 255, 255)"); |
| 541 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 255, 255)", "with no adopted styles in conflict, the non-adopted style should take effect"); |
544 | 542 |
|
545 | 543 | span.shadowRoot.adoptedStyleSheets = [sheet];
|
546 |
| - // the adopted style should be ordered after the non-adopted style |
547 |
| - assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)"); |
| 544 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)", "the adopted style should be ordered after the non-adopted style"); |
548 | 545 |
|
549 | 546 | sheet.disabled = true;
|
550 |
| - // with the adopted sheet disabled, the non-adopted style should take effect |
551 |
| - assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 255, 255)"); |
| 547 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 255, 255)", "with the adopted sheet disabled, the non-adopted style should take effect"); |
552 | 548 |
|
553 | 549 | sheet.disabled = false;
|
554 |
| - // the adopted sheet re-enabled, it should take effect again. |
555 |
| - assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)"); |
| 550 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)", "the adopted sheet re-enabled, it should take effect again"); |
556 | 551 | }, 'Adopted sheets are ordered after non-adopted sheets in the shadow root')
|
557 | 552 |
|
558 | 553 | test(() => {
|
|
574 | 569 | const style = document.createElement("style");
|
575 | 570 | style.textContent = ".target { color: white; }";
|
576 | 571 | span.appendChild(style)
|
577 |
| - // non-adopted styles should be ordered before adopted styles |
578 |
| - assert_equals(getComputedStyle(span).color, "rgb(255, 0, 0)"); |
| 572 | + assert_equals(getComputedStyle(span).color, "rgb(255, 0, 0)", "non-adopted styles should be ordered before adopted styles"); |
579 | 573 |
|
580 | 574 | document.adoptedStyleSheets = [];
|
581 |
| - // with no adopted styles in conflict, the non-adopted style should take effect |
582 |
| - assert_equals(getComputedStyle(span).color, "rgb(255, 255, 255)"); |
| 575 | + assert_equals(getComputedStyle(span).color, "rgb(255, 255, 255)", "with no adopted styles in conflict, the non-adopted style should take effect"); |
583 | 576 |
|
584 | 577 | document.adoptedStyleSheets = [sheet];
|
585 |
| - // the adopted style should be ordered after the non-adopted style |
586 |
| - assert_equals(getComputedStyle(span).color, "rgb(255, 0, 0)"); |
| 578 | + assert_equals(getComputedStyle(span).color, "rgb(255, 0, 0)", "the adopted style should be ordered after the non-adopted style"); |
587 | 579 |
|
588 | 580 | sheet.disabled = true;
|
589 |
| - // with the adopted sheet disabled, the non-adopted style should take effect |
590 |
| - assert_equals(getComputedStyle(span).color, "rgb(255, 255, 255)"); |
| 581 | + assert_equals(getComputedStyle(span).color, "rgb(255, 255, 255)", "with the adopted sheet disabled, the non-adopted style should take effect"); |
591 | 582 |
|
592 | 583 | sheet.disabled = false;
|
593 |
| - // the adopted sheet re-enabled, it should take effect again. |
594 |
| - assert_equals(getComputedStyle(span).color, "rgb(255, 0, 0)") |
| 584 | + assert_equals(getComputedStyle(span).color, "rgb(255, 0, 0)", "the adopted sheet re-enabled, it should take effect again") |
595 | 585 | }, 'Adopted sheets are ordered after non-adopted sheets in the document')
|
596 | 586 |
|
597 | 587 | const import_text = '@import url("support/constructable-import.css");';
|
598 | 588 |
|
599 |
| -test(() => { |
600 |
| - assert_throws_dom("NotAllowedError", () => { (new CSSStyleSheet).replaceSync(import_text) }); |
601 |
| -}, 'CSSStyleSheet.replaceSync throws exception when there is import rule inside'); |
602 |
| - |
603 | 589 | test(() => {
|
604 | 590 | assert_throws_dom("NotAllowedError", () => { (new CSSStyleSheet).insertRule(import_text) });
|
605 | 591 | }, 'Inserting an @import rule through insertRule on a constructed stylesheet throws an exception');
|
606 | 592 |
|
| 593 | +test(() => { |
| 594 | + assert_throws_dom("NotAllowedError", () => { document.styleSheets[0].insertRule(import_text) }); |
| 595 | +}, 'Inserting an @import rule through insertRule on a document stylesheet throws an exception'); |
| 596 | + |
607 | 597 | async_test(t => {
|
608 | 598 | const importUrl = "support/constructable-import.css";
|
609 | 599 | const sheet = new CSSStyleSheet();
|
610 | 600 |
|
611 |
| - assert_throws_dom("NotAllowedError", () => { sheet.replaceSync(`@import url("${importUrl}");`) }); |
| 601 | + sheet.replaceSync(`@import url("${importUrl}");`); |
612 | 602 |
|
613 | 603 | const timeAfterReplaceSync = performance.now();
|
614 | 604 | let link = document.createElement("link");
|
|
632 | 622 | const sheet = new CSSStyleSheet();
|
633 | 623 | span.shadowRoot.adoptedStyleSheets = [sheet];
|
634 | 624 | assert_equals(getComputedStyle(shadowDiv).color, "rgb(0, 0, 0)");
|
635 |
| - // Replace and assert that the imported rule is applied. |
| 625 | + // Replace and assert that the imported rule is NOT applied. |
636 | 626 | const sheet_promise = sheet.replace(import_text);
|
637 | 627 | return sheet_promise.then((sheet) => {
|
638 |
| - assert_equals(sheet.cssRules.length, 1); |
639 |
| - assert_equals(sheet.cssRules[0].cssText, import_text); |
640 |
| - assert_equals(getComputedStyle(shadowDiv).color, "rgb(255, 0, 0)"); |
| 628 | + // replace() ignores @import rules: |
| 629 | + assert_equals(sheet.cssRules.length, 0); |
| 630 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(0, 0, 0)"); |
641 | 631 | }).catch((reason) => {
|
642 | 632 | assert_unreached(`Promise was rejected (${reason}) when it should have been resolved`);
|
643 | 633 | });
|
644 |
| -}, 'CSSStyleSheet.replace allows import rule inside'); |
| 634 | +}, 'CSSStyleSheet.replace allows, but ignores, import rule inside'); |
| 635 | + |
| 636 | + |
| 637 | +test(() => { |
| 638 | + const span = document.createElement("span"); |
| 639 | + thirdSection.appendChild(span); |
| 640 | + const shadowDiv = attachShadowDiv(span); |
| 641 | + const sheet = new CSSStyleSheet(); |
| 642 | + span.shadowRoot.adoptedStyleSheets = [sheet]; |
| 643 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(0, 0, 0)"); |
| 644 | + // Replace and assert that the imported rule is NOT applied. |
| 645 | + try { |
| 646 | + sheet.replaceSync(import_text); |
| 647 | + // replaceSync() ignores @import rules: |
| 648 | + assert_equals(sheet.cssRules.length, 0); |
| 649 | + assert_equals(getComputedStyle(shadowDiv).color, "rgb(0, 0, 0)"); |
| 650 | + } catch(reason) { |
| 651 | + assert_unreached(`replaceSync threw an exception (${reason}) when it shouldn't have`); |
| 652 | + } |
| 653 | +}, 'CSSStyleSheet.replaceSync allows, but ignores, import rule inside'); |
645 | 654 |
|
646 | 655 | promise_test(() => {
|
647 | 656 | const sheet = new CSSStyleSheet();
|
648 | 657 | const sheet_promise = sheet.replace("@import url('not-there.css');");
|
649 | 658 |
|
650 | 659 | return sheet_promise.then((sheet) => {
|
651 |
| - assert_unreached("Promise was resolved when it should have been rejected"); |
| 660 | + // No exception here |
652 | 661 | }).catch((reason) => {
|
653 |
| - assert_equals(reason.name, "NetworkError"); |
| 662 | + assert_unreached("Promise was rejected"); |
654 | 663 | });
|
655 |
| -}, 'CSSStyleSheet.replace returns rejected promise on failed imports'); |
| 664 | +}, 'CSSStyleSheet.replace does not reject on failed imports'); |
656 | 665 |
|
657 | 666 | test(() => {
|
658 | 667 | const span = document.createElement("span");
|
|
0 commit comments