WebCore:
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Mar 2008 19:45:21 +0000 (19:45 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Mar 2008 19:45:21 +0000 (19:45 +0000)
        Dynamically inserting CSS rule with @media query fails with DOM Exception 12
        <http://bugs.webkit.org/show_bug.cgi?id=15986>

        Reviewed by Darin.

        Allow any valid rule (@font-face, @import, @media, @page or style) to be
        parsed when using CSSStyleSheet.insertRule().  Previously only import and
        style rules were allowed.  Note that @page rules always throw an exception
        because they're not implemented yet, so no test case was added for them.

        Tests: fast/css/insertRule-font-face.html
               fast/css/insertRule-media.html

        * css/CSSGrammar.y: Extracted 'valid_rule' out of 'rule'.  Renamed
        'ruleset_or_import' to 'valid_rule_or_import' and changed its definition.

LayoutTests:

        Dynamically inserting CSS rule with @media query fails with DOM Exception 12
        <http://bugs.webkit.org/show_bug.cgi?id=15986>

        Reviewed by Darin.

        * fast/css/insertRule-font-face.html: Added.
        * fast/css/insertRule-media.html: Added.
        * fast/css/resources/insertRule-font-face.js: Added.
        * fast/css/resources/insertRule-media.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30715 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css/insertRule-font-face-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/insertRule-font-face.html [new file with mode: 0644]
LayoutTests/fast/css/insertRule-media-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/insertRule-media.html [new file with mode: 0644]
LayoutTests/fast/css/resources/insertRule-font-face.js [new file with mode: 0644]
LayoutTests/fast/css/resources/insertRule-media.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSGrammar.y

index b06da899a8a07e681ae06d7dc1ac571488d16629..0bccd06f4947d3771bb965ae2cf02faa7a2e6e28 100644 (file)
@@ -1,3 +1,15 @@
+2008-03-03  David D. Kilzer  <ddkilzer@webkit.org>
+
+        Dynamically inserting CSS rule with @media query fails with DOM Exception 12
+        <http://bugs.webkit.org/show_bug.cgi?id=15986>
+
+        Reviewed by Darin.
+
+        * fast/css/insertRule-font-face.html: Added.
+        * fast/css/insertRule-media.html: Added.
+        * fast/css/resources/insertRule-font-face.js: Added.
+        * fast/css/resources/insertRule-media.js: Added.
+
 2008-03-03  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Mark Rowe.
diff --git a/LayoutTests/fast/css/insertRule-font-face-expected.txt b/LayoutTests/fast/css/insertRule-font-face-expected.txt
new file mode 100644 (file)
index 0000000..64d43c1
--- /dev/null
@@ -0,0 +1,11 @@
+Test parsing of @font-face rule using insertRule(). http://bugs.webkit.org/show_bug.cgi?id=15986
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.styleSheets[0].insertRule(rule, 0) is 0
+PASS document.styleSheets[0].rules[0].cssText is rule
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/css/insertRule-font-face.html b/LayoutTests/fast/css/insertRule-font-face.html
new file mode 100644 (file)
index 0000000..887d71a
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<style type="text/css"></style>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/insertRule-font-face.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/css/insertRule-media-expected.txt b/LayoutTests/fast/css/insertRule-media-expected.txt
new file mode 100644 (file)
index 0000000..51eaccd
--- /dev/null
@@ -0,0 +1,11 @@
+Test parsing of @media rule using insertRule(). http://bugs.webkit.org/show_bug.cgi?id=15986
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.styleSheets[0].insertRule(rule, 0) is 0
+PASS document.styleSheets[0].rules[0].cssText is rule
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/css/insertRule-media.html b/LayoutTests/fast/css/insertRule-media.html
new file mode 100644 (file)
index 0000000..de8f1d6
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<style type="text/css"></style>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/insertRule-media.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/css/resources/insertRule-font-face.js b/LayoutTests/fast/css/resources/insertRule-font-face.js
new file mode 100644 (file)
index 0000000..e5d16f5
--- /dev/null
@@ -0,0 +1,9 @@
+description(
+'Test parsing of @font-face rule using insertRule().  <a href="http://bugs.webkit.org/show_bug.cgi?id=15986">http://bugs.webkit.org/show_bug.cgi?id=15986</a>'
+);
+
+var rule = "@font-face { }";
+shouldBe("document.styleSheets[0].insertRule(rule, 0)", "0");
+shouldBe("document.styleSheets[0].rules[0].cssText", "rule");
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/css/resources/insertRule-media.js b/LayoutTests/fast/css/resources/insertRule-media.js
new file mode 100644 (file)
index 0000000..9b6d40a
--- /dev/null
@@ -0,0 +1,9 @@
+description(
+'Test parsing of @media rule using insertRule().  <a href="http://bugs.webkit.org/show_bug.cgi?id=15986">http://bugs.webkit.org/show_bug.cgi?id=15986</a>'
+);
+
+var rule = "@media all and (min-width: 0px) { \n  #greenid { color: green; }\n}";
+shouldBe("document.styleSheets[0].insertRule(rule, 0)", "0");
+shouldBe("document.styleSheets[0].rules[0].cssText", "rule");
+
+var successfullyParsed = true;
index 7e789f122692c7d3a14c170fdf93182bc5f3fd94..98c8274ba80ca2198890450f219685997dfc98b8 100644 (file)
@@ -1,3 +1,21 @@
+2008-03-03  David D. Kilzer  <ddkilzer@webkit.org>
+
+        Dynamically inserting CSS rule with @media query fails with DOM Exception 12
+        <http://bugs.webkit.org/show_bug.cgi?id=15986>
+
+        Reviewed by Darin.
+
+        Allow any valid rule (@font-face, @import, @media, @page or style) to be
+        parsed when using CSSStyleSheet.insertRule().  Previously only import and
+        style rules were allowed.  Note that @page rules always throw an exception
+        because they're not implemented yet, so no test case was added for them.
+
+        Tests: fast/css/insertRule-font-face.html
+               fast/css/insertRule-media.html
+
+        * css/CSSGrammar.y: Extracted 'valid_rule' out of 'rule'.  Renamed
+        'ruleset_or_import' to 'valid_rule_or_import' and changed its definition.
+
 2008-03-03  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Sam.
index c91ca328074f511e96485d215734208a71b2cacd..a431ad91c0ccab7b6303e841b98f13beb4db5f18 100644 (file)
@@ -148,7 +148,7 @@ static int cssyylex(YYSTYPE* yylval) { return CSSParser::current()->lex(yylval);
 
 %type <rule> charset
 %type <rule> ruleset
-%type <rule> ruleset_or_import
+%type <rule> valid_rule_or_import
 %type <rule> media
 %type <rule> import
 %type <rule> page
@@ -157,6 +157,7 @@ static int cssyylex(YYSTYPE* yylval) { return CSSParser::current()->lex(yylval);
 %type <rule> invalid_at
 %type <rule> invalid_import
 %type <rule> rule
+%type <rule> valid_rule
 
 %type <string> maybe_ns_prefix
 
@@ -219,13 +220,13 @@ stylesheet:
   | webkit_mediaquery maybe_space
   ;
 
-ruleset_or_import:
-   ruleset |
-   import
-;
+valid_rule_or_import:
+    valid_rule
+  | import
+  ;
 
 webkit_rule:
-    WEBKIT_RULE_SYM '{' maybe_space ruleset_or_import maybe_space '}' {
+    WEBKIT_RULE_SYM '{' maybe_space valid_rule_or_import maybe_space '}' {
         static_cast<CSSParser*>(parser)->rule = $4;
     }
 ;
@@ -310,15 +311,19 @@ rule_list:
  }
  ;
 
-rule:
+valid_rule:
     ruleset
   | media
   | page
   | font_face
+  ;
+
+rule:
+    valid_rule
   | invalid_rule
   | invalid_at
   | invalid_import
-    ;
+  ;
 
 import:
     IMPORT_SYM maybe_space string_or_uri maybe_space maybe_media_list ';' {