Commit 0ecac343 authored by Momoko Sumida's avatar Momoko Sumida Committed by Commit Bot

Revert "Revert "Delete constructor for creating empty CSSStyleSheets""

This reverts commit 2472878c.

The following CL was reverted as a suspect for https://crbug.com/873015:
crrev.com/c/1164876

This CL reverts the revert as the failing test is not related to CSSStyleSheet.
The flaky test has been disabled in crrev.com/c/1171681

Bug: 873015
Change-Id: I54cefa72e4f82b1075550d6efb4a0ca8efe98383
Reviewed-on: https://chromium-review.googlesource.com/1174150
Commit-Queue: Momoko Sumida <momon@google.com>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Reviewed-by: default avatarRakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583191}
parent 04ee04c4
This is a testharness.js-based test. This is a testharness.js-based test.
Found 377 tests; 322 PASS, 55 FAIL, 0 TIMEOUT, 0 NOTRUN. Found 377 tests; 323 PASS, 54 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup PASS idl_test setup
PASS Partial interface Document: original interface defined PASS Partial interface Document: original interface defined
PASS Partial interface Window: original interface defined PASS Partial interface Window: original interface defined
...@@ -38,7 +38,7 @@ PASS StyleSheet interface: attribute parentStyleSheet ...@@ -38,7 +38,7 @@ PASS StyleSheet interface: attribute parentStyleSheet
PASS StyleSheet interface: attribute title PASS StyleSheet interface: attribute title
PASS StyleSheet interface: attribute media PASS StyleSheet interface: attribute media
PASS StyleSheet interface: attribute disabled PASS StyleSheet interface: attribute disabled
FAIL CSSStyleSheet interface: existence and properties of interface object assert_throws: interface object didn't throw TypeError when called as a constructor function "function () { [native code] }" did not throw PASS CSSStyleSheet interface: existence and properties of interface object
PASS CSSStyleSheet interface object length PASS CSSStyleSheet interface object length
PASS CSSStyleSheet interface object name PASS CSSStyleSheet interface object name
PASS CSSStyleSheet interface: existence and properties of interface prototype object PASS CSSStyleSheet interface: existence and properties of interface prototype object
......
...@@ -8,26 +8,6 @@ ...@@ -8,26 +8,6 @@
const redStyleTexts = [".red { color: red; }", ".red + span + span { color: red; }"]; const redStyleTexts = [".red { color: red; }", ".red + span + span { color: red; }"];
test(() => {
const sheet = new CSSStyleSheet({title: "Red", disabled: true, media: "screen, print"});
assert_equals(sheet.title, "Red");
assert_equals(sheet.ownerNode, null);
assert_equals(sheet.ownerRule, null);
assert_equals(sheet.media.length, 2);
assert_equals(sheet.media.item(0), "screen");
assert_equals(sheet.media.item(1), "print");
assert_true(sheet.disabled);
assert_equals(sheet.cssRules.length, 0);
sheet.insertRule(redStyleTexts[0]);
assert_equals(sheet.cssRules.length, 1);
assert_equals(sheet.cssRules[0].cssText, redStyleTexts[0]);
sheet.insertRule(redStyleTexts[1]);
assert_equals(sheet.cssRules.length, 2);
assert_equals(sheet.cssRules[0].cssText, redStyleTexts[1]);
}, 'Empty CSSStyleSheet can be constructed using script');
test(() => { test(() => {
const sheet = document.createEmptyCSSStyleSheet({title: "Red", disabled: true, media: "screen, print"}); const sheet = document.createEmptyCSSStyleSheet({title: "Red", disabled: true, media: "screen, print"});
assert_equals(sheet.title, "Red"); assert_equals(sheet.title, "Red");
......
...@@ -74,7 +74,7 @@ PASS TryAllocate('CSSRule') is 'exception' ...@@ -74,7 +74,7 @@ PASS TryAllocate('CSSRule') is 'exception'
PASS TryAllocate('CSSRuleList') is 'exception' PASS TryAllocate('CSSRuleList') is 'exception'
PASS TryAllocate('CSSStyleDeclaration') is 'exception' PASS TryAllocate('CSSStyleDeclaration') is 'exception'
PASS TryAllocate('CSSStyleRule') is 'exception' PASS TryAllocate('CSSStyleRule') is 'exception'
FAIL TryAllocate('CSSStyleSheet') should be exception. Was [object CSSStyleSheet]. PASS TryAllocate('CSSStyleSheet') is 'exception'
PASS TryAllocate('DOMImplementation') is 'exception' PASS TryAllocate('DOMImplementation') is 'exception'
PASS TryAllocate('HTMLCollection') is 'exception' PASS TryAllocate('HTMLCollection') is 'exception'
PASS TryAllocate('MediaList') is 'exception' PASS TryAllocate('MediaList') is 'exception'
......
...@@ -91,11 +91,6 @@ const Document* CSSStyleSheet::SingleOwnerDocument( ...@@ -91,11 +91,6 @@ const Document* CSSStyleSheet::SingleOwnerDocument(
return nullptr; return nullptr;
} }
CSSStyleSheet* CSSStyleSheet::Create(Document& document,
ExceptionState& exception_state) {
return CSSStyleSheet::Create(document, CSSStyleSheetInit(), exception_state);
}
CSSStyleSheet* CSSStyleSheet::Create(Document& document, CSSStyleSheet* CSSStyleSheet::Create(Document& document,
const CSSStyleSheetInit& options, const CSSStyleSheetInit& options,
ExceptionState& exception_state) { ExceptionState& exception_state) {
......
...@@ -53,7 +53,6 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet { ...@@ -53,7 +53,6 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
public: public:
static const Document* SingleOwnerDocument(const CSSStyleSheet*); static const Document* SingleOwnerDocument(const CSSStyleSheet*);
static CSSStyleSheet* Create(Document&, ExceptionState&);
static CSSStyleSheet* Create(Document&, static CSSStyleSheet* Create(Document&,
const CSSStyleSheetInit&, const CSSStyleSheetInit&,
ExceptionState&); ExceptionState&);
...@@ -196,6 +195,11 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet { ...@@ -196,6 +195,11 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
FRIEND_TEST_ALL_PREFIXES( FRIEND_TEST_ALL_PREFIXES(
CSSStyleSheetTest, CSSStyleSheetTest,
CSSStyleSheetConstructionWithNonEmptyCSSStyleSheetInit); CSSStyleSheetConstructionWithNonEmptyCSSStyleSheetInit);
FRIEND_TEST_ALL_PREFIXES(CSSStyleSheetTest,
CreateEmptyCSSStyleSheetWithEmptyCSSStyleSheetInit);
FRIEND_TEST_ALL_PREFIXES(
CSSStyleSheetTest,
CreateEmptyCSSStyleSheetWithNonEmptyCSSStyleSheetInit);
FRIEND_TEST_ALL_PREFIXES( FRIEND_TEST_ALL_PREFIXES(
CSSStyleSheetTest, CSSStyleSheetTest,
CreateCSSStyleSheetWithEmptyCSSStyleSheetInitAndText); CreateCSSStyleSheetWithEmptyCSSStyleSheetInitAndText);
......
...@@ -21,9 +21,6 @@ ...@@ -21,9 +21,6 @@
// https://drafts.csswg.org/cssom/#the-cssstylesheet-interface // https://drafts.csswg.org/cssom/#the-cssstylesheet-interface
[ [
ConstructorCallWith=Document,
RaisesException=Constructor,
Constructor(optional CSSStyleSheetInit options),
Exposed=Window Exposed=Window
] interface CSSStyleSheet : StyleSheet { ] interface CSSStyleSheet : StyleSheet {
readonly attribute CSSRule? ownerRule; readonly attribute CSSRule? ownerRule;
......
...@@ -49,13 +49,41 @@ class CSSStyleSheetTest : public PageTestBase { ...@@ -49,13 +49,41 @@ class CSSStyleSheetTest : public PageTestBase {
TEST_F(CSSStyleSheetTest, ConstructorWithoutRuntimeFlagThrowsException) { TEST_F(CSSStyleSheetTest, ConstructorWithoutRuntimeFlagThrowsException) {
DummyExceptionStateForTesting exception_state; DummyExceptionStateForTesting exception_state;
RuntimeEnabledFeatures::SetConstructableStylesheetsEnabled(false); RuntimeEnabledFeatures::SetConstructableStylesheetsEnabled(false);
EXPECT_EQ(CSSStyleSheet::Create(GetDocument(), exception_state), nullptr); EXPECT_EQ(CSSStyleSheet::Create(GetDocument(), CSSStyleSheetInit(),
exception_state),
nullptr);
ASSERT_TRUE(exception_state.HadException()); ASSERT_TRUE(exception_state.HadException());
} }
TEST_F(CSSStyleSheetTest, CSSStyleSheetConstructionWithEmptyCSSStyleSheetInit) { TEST_F(CSSStyleSheetTest,
CSSStyleSheetConstructionWithNonEmptyCSSStyleSheetInit) {
DummyExceptionStateForTesting exception_state;
CSSStyleSheetInit init;
init.setMedia(MediaListOrString::FromString("screen, print"));
init.setTitle("test");
init.setAlternate(true);
init.setDisabled(true);
CSSStyleSheet* sheet =
CSSStyleSheet::Create(GetDocument(), init, exception_state);
ASSERT_FALSE(exception_state.HadException());
EXPECT_TRUE(sheet->href().IsNull());
EXPECT_EQ(sheet->parentStyleSheet(), nullptr);
EXPECT_EQ(sheet->ownerNode(), nullptr);
EXPECT_EQ(sheet->ownerRule(), nullptr);
EXPECT_EQ(sheet->media()->length(), 2U);
EXPECT_EQ(sheet->media()->mediaText(), init.media().GetAsString());
EXPECT_EQ(sheet->title(), init.title());
EXPECT_TRUE(sheet->AlternateFromConstructor());
EXPECT_TRUE(sheet->disabled());
EXPECT_EQ(sheet->cssRules(exception_state)->length(), 0U);
ASSERT_FALSE(exception_state.HadException());
}
TEST_F(CSSStyleSheetTest, CreateEmptyCSSStyleSheetWithEmptyCSSStyleSheetInit) {
V8TestingScope scope;
DummyExceptionStateForTesting exception_state; DummyExceptionStateForTesting exception_state;
CSSStyleSheet* sheet = CSSStyleSheet::Create(GetDocument(), exception_state); CSSStyleSheet* sheet = GetDocument().createEmptyCSSStyleSheet(
scope.GetScriptState(), CSSStyleSheetInit(), exception_state);
ASSERT_FALSE(exception_state.HadException()); ASSERT_FALSE(exception_state.HadException());
EXPECT_TRUE(sheet->href().IsNull()); EXPECT_TRUE(sheet->href().IsNull());
EXPECT_EQ(sheet->parentStyleSheet(), nullptr); EXPECT_EQ(sheet->parentStyleSheet(), nullptr);
...@@ -70,15 +98,16 @@ TEST_F(CSSStyleSheetTest, CSSStyleSheetConstructionWithEmptyCSSStyleSheetInit) { ...@@ -70,15 +98,16 @@ TEST_F(CSSStyleSheetTest, CSSStyleSheetConstructionWithEmptyCSSStyleSheetInit) {
} }
TEST_F(CSSStyleSheetTest, TEST_F(CSSStyleSheetTest,
CSSStyleSheetConstructionWithNonEmptyCSSStyleSheetInit) { CreateEmptyCSSStyleSheetWithNonEmptyCSSStyleSheetInit) {
DummyExceptionStateForTesting exception_state;
CSSStyleSheetInit init; CSSStyleSheetInit init;
init.setMedia(MediaListOrString::FromString("screen, print")); init.setMedia(MediaListOrString::FromString("screen, print"));
init.setTitle("test"); init.setTitle("test");
init.setAlternate(true); init.setAlternate(true);
init.setDisabled(true); init.setDisabled(true);
CSSStyleSheet* sheet = V8TestingScope scope;
CSSStyleSheet::Create(GetDocument(), init, exception_state); DummyExceptionStateForTesting exception_state;
CSSStyleSheet* sheet = GetDocument().createEmptyCSSStyleSheet(
scope.GetScriptState(), init, exception_state);
ASSERT_FALSE(exception_state.HadException()); ASSERT_FALSE(exception_state.HadException());
EXPECT_TRUE(sheet->href().IsNull()); EXPECT_TRUE(sheet->href().IsNull());
EXPECT_EQ(sheet->parentStyleSheet(), nullptr); EXPECT_EQ(sheet->parentStyleSheet(), nullptr);
...@@ -89,7 +118,6 @@ TEST_F(CSSStyleSheetTest, ...@@ -89,7 +118,6 @@ TEST_F(CSSStyleSheetTest,
EXPECT_EQ(sheet->title(), init.title()); EXPECT_EQ(sheet->title(), init.title());
EXPECT_TRUE(sheet->AlternateFromConstructor()); EXPECT_TRUE(sheet->AlternateFromConstructor());
EXPECT_TRUE(sheet->disabled()); EXPECT_TRUE(sheet->disabled());
EXPECT_EQ(sheet->cssRules(exception_state)->length(), 0U);
ASSERT_FALSE(exception_state.HadException()); ASSERT_FALSE(exception_state.HadException());
} }
......
...@@ -435,9 +435,11 @@ TEST_F(CustomElementRegistryTest, lookupCustomElementDefinition) { ...@@ -435,9 +435,11 @@ TEST_F(CustomElementRegistryTest, lookupCustomElementDefinition) {
TEST_F(CustomElementRegistryTest, defineCustomElementWithStyle) { TEST_F(CustomElementRegistryTest, defineCustomElementWithStyle) {
RuntimeEnabledFeatures::SetConstructableStylesheetsEnabled(true); RuntimeEnabledFeatures::SetConstructableStylesheetsEnabled(true);
V8TestingScope scope;
NonThrowableExceptionState should_not_throw; NonThrowableExceptionState should_not_throw;
ElementDefinitionOptions options; ElementDefinitionOptions options;
CSSStyleSheet* sheet = CSSStyleSheet::Create(GetDocument(), should_not_throw); CSSStyleSheet* sheet = GetDocument().createEmptyCSSStyleSheet(
scope.GetScriptState(), CSSStyleSheetInit(), should_not_throw);
options.setStyle(sheet); options.setStyle(sheet);
TestCustomElementDefinitionBuilder builder(sheet); TestCustomElementDefinitionBuilder builder(sheet);
CustomElementDefinition* definition_a = CustomElementDefinition* definition_a =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment