Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / media / mq-append-delete.html
blob224330a1ddfb9407e89913854ef47b43d4026b47
1 <!doctype html>
2 <style type="text/css">@media screen { }</style>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <div id=log></div>
6 <script>
7 var rules = document.styleSheets[0].cssRules;
8 var mediaList = rules.item(0).media;
10 // - appendMedium()
12 test(function () {
13 mediaList.mediaText = "screen";
14 mediaList.appendMedium("tv, screen");
15 assert_equals(mediaList.mediaText, "screen");
16 // CSSOM 4.1: Parsing media query returns none as
17 // there are more than one; terminate steps.
18 }, "Add 'tv, screen' to 'screen'");
20 test(function () {
21 mediaList.mediaText = "screen";
22 mediaList.appendMedium("tv");
23 assert_equals(mediaList.mediaText, "screen, tv");
24 // The valid media query is appended.
25 }, "Add 'tv' to 'screen'");
27 test(function () {
28 mediaList.mediaText = "screen, tv";
29 mediaList.appendMedium("tv");
30 assert_equals(mediaList.mediaText, "screen, tv");
31 // CSSOM says to ignore if it exists, terminate steps.
32 }, "Add 'tv' to 'screen, tv'");
34 test(function () {
35 mediaList.mediaText = "screen, tv";
36 mediaList.appendMedium("screen");
37 assert_equals(mediaList.mediaText, "screen, tv");
38 // CSSOM says to ignore if it exists, where as
39 // CSS 2.1 says to remove existing and then add
40 // it to the end.
41 // http://dev.w3.org/csswg/cssom/#dom-medialist-appendmedium
42 // http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets.html
43 }, "Add 'screen' to 'screen, tv'");
45 test(function () {
46 mediaList.mediaText = "screen, tv";
47 mediaList.appendMedium(" ");
48 // Ignored; terminate steps.
49 assert_equals(mediaList.mediaText, "screen, tv");
50 }, "Add ' ' to 'screen, tv'");
52 test(function () {
53 mediaList.mediaText = "screen, tv";
54 mediaList.appendMedium("");
55 // Ignored; terminate steps.
56 assert_equals(mediaList.mediaText, "screen, tv");
57 }, "Add '' to 'screen, tv'");
59 test(function () {
60 mediaList.mediaText = "screen, tv";
61 mediaList.appendMedium(",");
62 assert_equals(mediaList.mediaText, "screen, tv");
63 // CSSOM 4.1: Parsing media query returns none as
64 // there are more than one; terminate steps.
65 }, "Add ',' to 'screen, tv'");
67 test(function () {
68 mediaList.mediaText = "screen, tv";
69 mediaList.appendMedium("&invalid");
70 assert_equals(mediaList.mediaText, "screen, tv, not all");
71 // Ignored; terminate steps.
72 }, "Add '&invalid' to 'screen, tv'");
74 test(function () {
75 mediaList.mediaText = "screen, tv";
76 mediaList.appendMedium("not all");
77 assert_equals(mediaList.mediaText, "screen, tv, not all");
78 }, "Add 'not all' to 'screen, tv'");
80 test(function () {
81 mediaList.mediaText = "screen, tv";
82 mediaList.appendMedium("#?:/");
83 assert_equals(mediaList.mediaText, "screen, tv, not all");
84 // Ignored; terminate steps.
85 }, "Add '#?:/' to 'screen, tv'");
87 test(function () {
88 mediaList.mediaText = "screen, tv";
89 assert_throws({ name: "TypeError" },
90 function () { document.appendMedium(); },
91 "Not enough arguments");
92 }, "Add without argument");
94 // - deleteMedium()
96 test(function () {
97 mediaList.mediaText = "screen, tv, not all";
98 mediaList.deleteMedium("&invalid");
99 // Ignored; terminate steps.
100 assert_equals(mediaList.mediaText, "screen, tv");
101 }, "Remove '&invalid' from 'screen, tv, not all'");
103 test(function () {
104 mediaList.mediaText = "screen, tv";
105 assert_throws("NOT_FOUND_ERR",
106 function () { mediaList.deleteMedium("not all"); }
108 // Not found; throw NotFoundError.
109 }, "Remove 'not all' from 'screen, tv'");
111 test(function () {
112 mediaList.mediaText = "screen, tv";
113 assert_throws("NOT_FOUND_ERR",
114 function () { mediaList.deleteMedium("cow"); }
116 // Not found; throw NotFoundError.
117 }, "Remove 'cow' from 'screen, tv'");
119 test(function () {
120 mediaList.mediaText = "screen, tv, not all";
121 mediaList.deleteMedium("not all");
122 assert_equals(mediaList.mediaText, "screen, tv");
123 // Remove any media query from the collection of media queries
124 // for which comparing the media query returns true.
125 }, "Remove 'not all' from 'screen, tv, not all'");
127 test(function () {
128 mediaList.mediaText = "screen, tv";
129 mediaList.deleteMedium("tv");
130 assert_equals(mediaList.mediaText, "screen");
131 // Remove any media query from the collection of media queries
132 // for which comparing the media query returns true.
133 }, "Remove 'tv' from 'screen, tv'");
135 test(function () {
136 mediaList.mediaText = "not all, not all, tv, not all";
137 mediaList.deleteMedium("not all");
138 assert_equals(mediaList.mediaText, "tv");
139 // Remove any media query from the collection of media queries
140 // for which comparing the media query returns true.
141 }, "Remove 'not all' from 'not all, not all, tv, not all'");
143 test(function () {
144 mediaList.mediaText = "not all, not all, tv, not all";
145 mediaList.deleteMedium("tv");
146 assert_equals(mediaList.mediaText, "not all, not all, not all");
147 // Remove any media query from the collection of media queries
148 // for which comparing the media query returns true.
149 }, "Remove 'tv' from 'not all, not all, tv, not all'");
151 test(function () {
152 mediaList.mediaText = "tv, print, screen";
153 mediaList.deleteMedium("tv, print");
154 assert_equals(mediaList.mediaText, "tv, print, screen");
155 // CSSOM 4.1: Parsing media query returns none as
156 // there are more than one; terminate steps.
157 }, "Remove 'tv, print' from 'screen, tv, screen'");
159 test(function () {
160 mediaList.mediaText = "screen, tv, not all";
161 mediaList.deleteMedium("#?:/");
162 // Ignored; terminate steps.
163 assert_equals(mediaList.mediaText, "screen, tv");
164 }, "Remove '#?:/' from 'screen, tv, not all'");
166 test(function () {
167 mediaList.mediaText = "tv, print, screen";
168 assert_throws({ name: "TypeError" },
169 function () { document.deleteMedium(); },
170 "Not enough arguments");
171 }, "Remove without argument");
172 </script>