OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var assertEq = chrome.test.assertEq; | 5 var assertEq = chrome.test.assertEq; |
6 var assertTrue = chrome.test.assertTrue; | 6 var assertTrue = chrome.test.assertTrue; |
7 var fail = chrome.test.fail; | 7 var fail = chrome.test.fail; |
8 var succeed = chrome.test.succeed; | 8 var succeed = chrome.test.succeed; |
9 | 9 |
10 function assertThrowsError(method, opt_expectedError) { | 10 function assertThrowsError(method, opt_expectedError) { |
(...skipping 15 matching lines...) Expand all Loading... | |
26 } | 26 } |
27 | 27 |
28 chrome.test.runTests([ | 28 chrome.test.runTests([ |
29 function testDocument() { | 29 function testDocument() { |
30 assertThrowsError(document.open); | 30 assertThrowsError(document.open); |
31 assertThrowsError(document.clear); | 31 assertThrowsError(document.clear); |
32 assertThrowsError(document.close); | 32 assertThrowsError(document.close); |
33 assertThrowsError(document.write); | 33 assertThrowsError(document.write); |
34 assertThrowsError(document.writeln); | 34 assertThrowsError(document.writeln); |
35 | 35 |
36 assertThrowsError(function() {document.all;}); | 36 assertEq('undefined', typeof(document.all)); |
37 assertThrowsError(function() {document.bgColor;}); | 37 assertEq('undefined', typeof(document.bgColor)); |
38 assertThrowsError(function() {document.fgColor;}); | 38 assertEq('undefined', typeof(document.fgColor)); |
39 assertThrowsError(function() {document.alinkColor;}); | 39 assertEq('undefined', typeof(document.alinkColor)); |
40 assertThrowsError(function() {document.linkColor;}); | 40 assertEq('undefined', typeof(document.linkColor)); |
41 assertThrowsError(function() {document.vlinkColor;}); | 41 assertEq('undefined', typeof(document.vlinkColor)); |
42 | 42 |
43 succeed(); | 43 succeed(); |
44 }, | 44 }, |
45 | 45 |
46 function testHistory() { | 46 function testHistory() { |
47 // These are replaced by wrappers that throws exceptions. | 47 // Accessing these logs warnings to the console. |
48 assertThrowsError(history.back); | 48 assertEq('undefined', typeof(history.back)); |
49 assertThrowsError(history.forward); | 49 assertEq('undefined', typeof(history.forward)); |
50 assertThrowsError(function() {history.length;}); | 50 assertEq('undefined', typeof(history.length)); |
51 | 51 |
52 // These are part of the HTML5 History API that is feature detected, so we | 52 // These are part of the HTML5 History API that are feature detected, so we |
53 // remove them altogether, allowing apps to have fallback behavior. | 53 // remove them altogether, allowing apps to have fallback behavior. |
54 chrome.test.assertFalse('pushState' in history); | 54 chrome.test.assertFalse('pushState' in history); |
55 chrome.test.assertFalse('replaceState' in history); | 55 chrome.test.assertFalse('replaceState' in history); |
56 chrome.test.assertFalse('state' in history); | 56 chrome.test.assertFalse('state' in history); |
57 | 57 |
58 succeed(); | 58 succeed(); |
59 }, | 59 }, |
60 | 60 |
61 function testWindowFind() { | 61 function testWindowFind() { |
62 assertThrowsError(Window.prototype.find); | 62 assertEq('undefined', typeof(Window.prototype.find('needle'))); |
63 assertThrowsError(window.find); | 63 assertEq('undefined', typeof(window.find('needle'))); |
64 assertThrowsError(find); | 64 assertEq('undefined', typeof(find('needle'))); |
65 succeed(); | 65 succeed(); |
66 }, | 66 }, |
67 | 67 |
68 function testWindowAlert() { | 68 function testWindowAlert() { |
69 assertThrowsError(Window.prototype.alert); | 69 assertEq('undefined', typeof(Window.prototype.alert())); |
70 assertThrowsError(window.alert); | 70 assertEq('undefined', typeof(window.alert())); |
71 assertThrowsError(alert); | 71 assertEq('undefined', typeof(alert())); |
72 succeed(); | 72 succeed(); |
73 }, | 73 }, |
74 | 74 |
75 function testWindowConfirm() { | 75 function testWindowConfirm() { |
76 assertThrowsError(Window.prototype.confirm); | 76 assertEq('undefined', typeof(Window.prototype.confirm('Failed'))); |
77 assertThrowsError(window.confirm); | 77 assertEq('undefined', typeof(window.confirm('Failed'))); |
78 assertThrowsError(confirm); | 78 assertEq('undefined', typeof(confirm('Failed'))); |
79 succeed(); | 79 succeed(); |
80 }, | 80 }, |
81 | 81 |
82 function testWindowPrompt() { | 82 function testWindowPrompt() { |
83 assertThrowsError(Window.prototype.prompt); | 83 assertEq('undefined', typeof(Window.prototype.prompt('Failed'))); |
84 assertThrowsError(window.prompt); | 84 assertEq('undefined', typeof(window.prompt('Failed'))); |
85 assertThrowsError(prompt); | 85 assertEq('undefined', typeof(prompt('Failed'))); |
86 succeed(); | 86 succeed(); |
87 }, | 87 }, |
88 | 88 |
89 function testBars() { | 89 function testBars() { |
90 var bars = ['locationbar', 'menubar', 'personalbar', | 90 var bars = ['locationbar', 'menubar', 'personalbar', |
91 'scrollbars', 'statusbar', 'toolbar']; | 91 'scrollbars', 'statusbar', 'toolbar']; |
92 for (var x = 0; x < bars.length; x++) { | 92 for (var x = 0; x < bars.length; x++) { |
93 assertThrowsError(function() { | 93 assertEq('undefined', typeof(this[bars[x]])); |
94 var visible = this[bars[x]].visible; | 94 assertEq('undefined', typeof(window[bars[x]])); |
95 visible = window[bars[x]].visible; | |
96 }); | |
97 } | 95 } |
98 succeed(); | 96 succeed(); |
99 }, | 97 }, |
100 | 98 |
101 function testBlockedEvents() { | 99 function testBlockedEvents() { |
102 var eventHandler = function() { fail('event handled'); }; | 100 var eventHandler = function() { fail('blocked event handled'); }; |
103 var blockedEvents = ['unload', 'beforeunload']; | 101 var blockedEvents = ['unload', 'beforeunload']; |
104 | 102 |
105 for (var i = 0; i < blockedEvents.length; ++i) { | 103 for (var i = 0; i < blockedEvents.length; ++i) { |
106 assertThrowsError(function() { | 104 window['on' + blockedEvents[i]] = eventHandler; |
107 window['on' + blockedEvents[i]] = eventHandler; | 105 assertEq(undefined, window['on' + blockedEvents[i]]); |
108 }); | 106 |
109 assertThrowsError(function() { | 107 var event = new Event(blockedEvents[i]); |
110 window.addEventListener(blockedEvents[i], eventHandler); | 108 window.addEventListener(blockedEvents[i], eventHandler); |
111 }); | 109 window.dispatchEvent(event); |
112 assertThrowsError(function() { | 110 Window.prototype.addEventListener.apply(window, |
113 Window.prototype.addEventListener.apply(window, | 111 [blockedEvents[i], eventHandler]); |
114 [blockedEvents[i], eventHandler]); | 112 window.dispatchEvent(event); |
Jeffrey Yasskin
2014/01/08 22:49:17
Can you comment how this tests something?
pwnall-personal
2014/01/08 23:20:46
Done.
Does this sound reasonable?
| |
115 }); | |
116 } | 113 } |
117 | 114 |
118 succeed(); | 115 succeed(); |
119 }, | 116 }, |
120 | 117 |
121 function testSyncXhr() { | 118 function testSyncXhr() { |
122 var xhr = new XMLHttpRequest(); | 119 var xhr = new XMLHttpRequest(); |
123 assertThrowsError(function() { | 120 assertThrowsError(function() { |
124 xhr.open('GET', 'data:should not load', false); | 121 xhr.open('GET', 'data:should not load', false); |
125 }, 'InvalidAccessError'); | 122 }, 'InvalidAccessError'); |
126 succeed(); | 123 succeed(); |
127 }, | 124 }, |
128 | 125 |
129 /** | 126 /** |
130 * Tests that restrictions apply to iframes as well. | 127 * Tests that restrictions apply to iframes as well. |
131 */ | 128 */ |
132 function testIframe() { | 129 function testIframe() { |
133 var iframe = document.createElement('iframe'); | 130 var iframe = document.createElement('iframe'); |
134 iframe.onload = function() { | 131 iframe.onload = function() { |
135 assertThrowsError(iframe.contentWindow.alert); | 132 assertThrowsError(iframe.contentWindow.document.write); |
136 succeed(); | 133 succeed(); |
137 }; | 134 }; |
138 iframe.src = 'iframe.html'; | 135 iframe.src = 'iframe.html'; |
139 document.body.appendChild(iframe); | 136 document.body.appendChild(iframe); |
140 }, | 137 }, |
141 | 138 |
142 /** | 139 /** |
143 * Tests that restrictions apply to sandboxed iframes. | 140 * Tests that restrictions apply to sandboxed iframes. |
144 */ | 141 */ |
145 function testSandboxedIframe() { | 142 function testSandboxedIframe() { |
(...skipping 21 matching lines...) Expand all Loading... | |
167 assertEq('undefined', typeof(chrome.extension)); | 164 assertEq('undefined', typeof(chrome.extension)); |
168 succeed(); | 165 succeed(); |
169 }, | 166 }, |
170 | 167 |
171 function testExtensionApis() { | 168 function testExtensionApis() { |
172 assertEq('undefined', typeof(chrome.tabs)); | 169 assertEq('undefined', typeof(chrome.tabs)); |
173 assertEq('undefined', typeof(chrome.windows)); | 170 assertEq('undefined', typeof(chrome.windows)); |
174 succeed(); | 171 succeed(); |
175 } | 172 } |
176 ]); | 173 ]); |
OLD | NEW |