From 5fa2f0edb8c1165cd1fe687e4c003c484e34d8f1 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Sat, 1 Dec 2012 15:10:45 +1100 Subject: [PATCH] Bug 816720 - Allow CSSRule.insertRule to insert non-style rules. r=bz --- layout/style/nsCSSStyleSheet.cpp | 21 +- layout/style/test/Makefile.in | 1 + layout/style/test/test_rule_insertion.html | 213 +++++++++++++++++++++ 3 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 layout/style/test/test_rule_insertion.html diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index ad7fce01a02..762325faaee 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -2142,10 +2142,25 @@ nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule, int32_t counter; css::Rule* rule; for (counter = 0; counter < rulecount; counter++) { - // Only rulesets are allowed in a group as of CSS2 rule = rules.ObjectAt(counter); - if (rule->GetType() != css::Rule::STYLE_RULE) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; + switch (rule->GetType()) { + case css::Rule::STYLE_RULE: + case css::Rule::MEDIA_RULE: + case css::Rule::FONT_FACE_RULE: + case css::Rule::PAGE_RULE: + case css::Rule::KEYFRAMES_RULE: + case css::Rule::DOCUMENT_RULE: + case css::Rule::SUPPORTS_RULE: + // these types are OK to insert into a group + break; + case css::Rule::CHARSET_RULE: + case css::Rule::IMPORT_RULE: + case css::Rule::NAMESPACE_RULE: + // these aren't + return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; + default: + NS_NOTREACHED("unexpected rule type"); + return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; } } diff --git a/layout/style/test/Makefile.in b/layout/style/test/Makefile.in index dc67fc3fd34..d86d19c9b54 100644 --- a/layout/style/test/Makefile.in +++ b/layout/style/test/Makefile.in @@ -127,6 +127,7 @@ MOCHITEST_FILES = test_acid3_test46.html \ test_priority_preservation.html \ test_property_syntax_errors.html \ test_rem_unit.html \ + test_rule_insertion.html \ test_rule_serialization.html \ test_rules_out_of_sheets.html \ test_selectors.html \ diff --git a/layout/style/test/test_rule_insertion.html b/layout/style/test/test_rule_insertion.html new file mode 100644 index 00000000000..5adc28dc73d --- /dev/null +++ b/layout/style/test/test_rule_insertion.html @@ -0,0 +1,213 @@ + + + + + Test for Bug 816720 + + + + + + +

+
+

.

+

.

+

.

+ + + + + +