4 <link rel="help" href="https://dom.spec.whatwg.org/#dom-domtokenlist-toggle"/>
5 <script src="../../../resources/js-test-pre.js"></script>
9 description("Tests the behavior of DOMTokenList.toggle()");
11 var div = document.createElement('div');
13 debug("* Not enough parameters");
14 shouldThrow("div.classList.toggle()", "'TypeError: Not enough arguments'");
17 debug("* Token is an empty string");
18 shouldThrow("div.classList.toggle('')", "'Error: SyntaxError: DOM Exception 12'");
21 debug("Token contains an ASCII white space");
22 var stringWithSpace = "a b";
23 shouldThrow("div.classList.toggle(stringWithSpace)", "'Error: InvalidCharacterError: DOM Exception 5'");
24 stringWithSpace = "a\nb";
25 shouldThrow("div.classList.toggle(stringWithSpace)", "'Error: InvalidCharacterError: DOM Exception 5'");
26 stringWithSpace = "a\tb";
27 shouldThrow("div.classList.toggle(stringWithSpace)", "'Error: InvalidCharacterError: DOM Exception 5'");
28 stringWithSpace = "a\rb";
29 shouldThrow("div.classList.toggle(stringWithSpace)", "'Error: InvalidCharacterError: DOM Exception 5'");
30 stringWithSpace = "a\fb";
31 shouldThrow("div.classList.toggle(stringWithSpace)", "'Error: InvalidCharacterError: DOM Exception 5'");
34 debug("* 'force' parameter omitted, token does not exist");
35 evalAndLog("div.classList.toggle('a')");
36 shouldBeEqualToString("div.classList[0]", "a"); // Should add the class.
39 debug("* 'force' parameter omitted, token exists");
40 evalAndLog("div.classList.toggle('a')");
41 shouldBe("div.classList.length", "0"); // Should remove the class.
44 debug("* 'force' parameter is undefined, token does not exist");
45 evalAndLog("div.classList.toggle('a', undefined)");
46 shouldBeEqualToString("div.classList[0]", "a"); // Should add the class.
49 debug("* 'force' parameter is undefined, token exists");
50 evalAndLog("div.classList.toggle('a', undefined)");
51 shouldBe("div.classList.length", "0"); // Should remove the class.
54 debug("* 'force' parameter is false, token does not exist");
55 evalAndLog("div.classList.toggle('a', false)");
56 shouldBe("div.classList.length", "0"); // Should not add the class.
59 debug("* 'force' parameter is true, token does not exist");
60 evalAndLog("div.classList.toggle('a', true)");
61 shouldBeEqualToString("div.classList[0]", "a"); // Should add the class.
64 debug("* 'force' parameter is true, token exists");
65 evalAndLog("div.classList.toggle('a', true)");
66 shouldBeEqualToString("div.classList[0]", "a"); // Should not remove the class.
69 debug("* 'force' parameter is false, token exists");
70 evalAndLog("div.classList.toggle('a', false)");
71 shouldBe("div.classList.length", "0"); // Should remove the class.
73 <script src="../../../resources/js-test-post.js"></script>