Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/private_script_unittest.html

Issue 2571063002: Remove Blink-in-JS (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description('Unittests for private scripts.');
9 if (!internals || !internals.privateScriptTest())
10 debug('This test needs window.internals.privateScriptTest().');
11
12 var privateScriptTest = internals.privateScriptTest();
13 privateScriptTest.doNothing();
14 shouldBe('privateScriptTest.return123()', '123');
15 shouldBe('privateScriptTest.echoInteger(111)', '111');
16 shouldBeEqualToString('privateScriptTest.echoString("foo")', 'foo')
17 shouldBe('privateScriptTest.addInteger(111, 222)', '333');
18 shouldBeEqualToString('privateScriptTest.addString("foo", "bar")', 'foobar')
19
20 shouldBe('privateScriptTest.getIntegerFromPrototype()', '0');
21 privateScriptTest.setIntegerToPrototype(123);
22 shouldBe('privateScriptTest.getIntegerFromPrototype()', '123');
23
24 shouldBe('privateScriptTest.getIntegerFromDocument(document)', '0');
25 privateScriptTest.setIntegerToDocument(document, 123);
26 shouldBe('privateScriptTest.getIntegerFromDocument(document)', '123');
27
28 var node1 = privateScriptTest.createElement(document);
29 var node2 = privateScriptTest.createElement(document);
30 var node3 = privateScriptTest.createElement(document);
31 var node4 = privateScriptTest.createElement(document);
32 privateScriptTest.appendChild(node1, node2);
33 privateScriptTest.appendChild(node1, node3);
34 privateScriptTest.appendChild(node1, node4);
35 shouldBe('privateScriptTest.firstChild(node1)', 'node2');
36 shouldBe('privateScriptTest.nextSibling(node2)', 'node3');
37 shouldBe('privateScriptTest.nextSibling(node3)', 'node4');
38 shouldBe('privateScriptTest.nextSibling(node4)', 'null');
39
40 var node5 = privateScriptTest.createElement(document);
41 shouldBeEqualToString('privateScriptTest.innerHTML(node5)', '')
42 privateScriptTest.setInnerHTML(node5, '<div>foo</div>');
43 shouldBeEqualToString('privateScriptTest.innerHTML(node5)', '<div>foo</div>')
44 var node6 = privateScriptTest.firstChild(node5);
45 shouldBeEqualToString('privateScriptTest.innerHTML(node6)', 'foo');
46
47 var node7 = privateScriptTest.createElement(document);
48 shouldBeEqualToString('privateScriptTest.innerHTML(node7)', '')
49 privateScriptTest.addClickListener(node7);
50 privateScriptTest.clickNode(document, node7);
51 shouldBeEqualToString('privateScriptTest.innerHTML(node7)', 'clicked')
52
53 shouldBe('privateScriptTest.readonlyShortAttribute', '123');
54 shouldBe('privateScriptTest.shortAttribute', '-1');
55 privateScriptTest.shortAttribute = 111;
56 shouldBe('privateScriptTest.shortAttribute', '111');
57 shouldBeEqualToString('privateScriptTest.stringAttribute', 'xxx');
58 privateScriptTest.stringAttribute = "foo";
59 shouldBeEqualToString('privateScriptTest.stringAttribute', 'foo');
60 shouldBe('privateScriptTest.nodeAttribute', 'null');
61 var node8 = privateScriptTest.createElement(document);
62 privateScriptTest.nodeAttribute = node8;
63 shouldBe('privateScriptTest.nodeAttribute', 'node8');
64
65 shouldThrow('privateScriptTest.nodeAttributeThrowsIndexSizeError');
66 shouldThrow('privateScriptTest.nodeAttributeThrowsIndexSizeError = null');
67 shouldThrow('privateScriptTest.voidMethodThrowsDOMSyntaxError()');
68 shouldThrow('privateScriptTest.voidMethodThrowsError()');
69 shouldThrow('privateScriptTest.voidMethodThrowsTypeError()');
70 shouldThrow('privateScriptTest.voidMethodThrowsRangeError()');
71 shouldThrow('privateScriptTest.voidMethodThrowsSyntaxError()');
72 shouldThrow('privateScriptTest.voidMethodThrowsReferenceError()');
73 shouldThrow('privateScriptTest.voidMethodThrowsStackOverflowError()');
74
75 shouldBe('privateScriptTest.addIntegerImplementedInCPP(111, 222)', '333');
76 shouldBeEqualToString('privateScriptTest.stringAttributeImplementedInCPP', 'unde fined');
77 privateScriptTest.stringAttributeImplementedInCPP = "foo";
78 shouldBeEqualToString('privateScriptTest.stringAttributeImplementedInCPP', 'foo' );
79
80 // These tests are important. [OnlyExposedToPrivateScript] APIs should not be vi sible to user's script.
81 shouldBeUndefined('privateScriptTest.addIntegerImplementedInCPPForPrivateScriptO nly');
82 shouldBeUndefined('privateScriptTest.stringAttributeImplementedInCPPForPrivateSc riptOnly');
83
84 shouldBe('privateScriptTest.addIntegerInPartial(111, 222)', '333');
85 shouldBe('privateScriptTest.addInteger2InPartial(111, 222)', '333');
86 privateScriptTest.stringAttributeInPartial = "foo";
87 shouldBeEqualToString('privateScriptTest.stringAttributeInPartial', 'foo');
88
89 document.onload = function (event) {
90 shouldBeTrue('event.bubbles');
91 shouldBeTrue('event.cancelable');
92 // Object properties set in private scripts should not be visible in user's script.
93 shouldBeUndefined('event.valueInPrivateScript');
94 }
95 privateScriptTest.dispatchDocumentOnload(document);
96
97 var exception;
98 function testThrows(expression, type, code)
99 {
100 exception = undefined;
101 // Test that `expression` throws a userscript visible exception of `type`, o ptionally with
102 // exception code `code`
103 try {
104 eval(expression);
105 } catch (e) {
106 exception = e;
107 }
108
109 if (type === DOMException && typeof code === "string" && code in DOMExceptio n)
110 code = DOMException[code];
111
112 if (exception === undefined) {
113 testFailed("`" + expression + "` should throw");
114 } else {
115 shouldBeType("exception", type);
116 if (code !== undefined)
117 shouldBeEqualToNumber("exception.code", code);
118 }
119 }
120
121 testThrows("privateScriptTest.nodeAttributeThrowsIndexSizeError", DOMException, "INDEX_SIZE_ERR");
122 testThrows("privateScriptTest.nodeAttributeThrowsIndexSizeError = null", DOMExce ption, "INDEX_SIZE_ERR");
123 testThrows("privateScriptTest.voidMethodThrowsDOMSyntaxError()", DOMException, " SYNTAX_ERR");
124 testThrows("privateScriptTest.voidMethodThrowsError()", Error);
125 testThrows("privateScriptTest.voidMethodThrowsTypeError()", TypeError);
126 testThrows("privateScriptTest.voidMethodThrowsRangeError()", RangeError);
127 testThrows("privateScriptTest.voidMethodThrowsSyntaxError()", SyntaxError);
128 testThrows("privateScriptTest.voidMethodThrowsReferenceError()", ReferenceError) ;
129
130 </script>
131 </body>
132 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698