OLD | NEW |
---|---|
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-in line'"> | 3 <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-in line'"> |
4 <script src="/inspector/inspector-test.js"></script> | 4 <script src="/inspector/inspector-test.js"></script> |
5 <script> | 5 <script> |
6 | 6 |
7 function sendCSPRequest() | 7 function sendCSPRequest() |
8 { | 8 { |
9 var script = document.createElement("script"); | 9 var script = document.createElement("script"); |
10 script.src = "https://www.example.com/csp.js"; | 10 script.src = "https://www.example.com/csp.js"; |
11 document.head.appendChild(script); | 11 document.head.appendChild(script); |
12 } | 12 } |
13 | 13 |
14 function addBlockedScript() | 14 function addBlockedScript(url) |
15 { | 15 { |
16 var script = document.createElement("script"); | 16 var script = document.createElement("script"); |
17 script.src = "resources/silent_script.js"; | 17 script.src = url; |
18 document.head.appendChild(script); | 18 document.head.appendChild(script); |
19 } | 19 } |
20 | 20 |
21 function test() | 21 function test() |
22 { | 22 { |
23 var requestName; | 23 var requestName; |
24 var nextStep; | 24 var nextStep; |
25 var blockedSetting = WebInspector.settingForTest("blockedURLs"); | 25 var blockedSetting = WebInspector.settingForTest("blockedURLs"); |
26 | 26 |
27 function onRequest(event) | 27 function onRequest(event) |
28 { | 28 { |
29 var request = event.data; | 29 var request = event.data; |
30 if (request.name() !== requestName) | 30 if (request.name() !== requestName) |
31 return; | 31 return; |
32 requestName = undefined; | 32 requestName = undefined; |
33 InspectorTest.addResult(""); | |
34 InspectorTest.addResult("Request: " + request.name()); | |
35 InspectorTest.addResult("BlockedReason: " + request.blockedReason()); | 33 InspectorTest.addResult("BlockedReason: " + request.blockedReason()); |
caseq
2015/09/09 00:54:42
nit: I'd put it in a more readable form, i.e. Bloc
dgozman
2015/09/09 00:56:53
There are more reasons than just inspector.
| |
36 nextStep(); | 34 nextStep(); |
37 } | 35 } |
38 | 36 |
39 InspectorTest.networkManager.addEventListener(WebInspector.NetworkManager.Ev entTypes.RequestFinished, onRequest); | 37 InspectorTest.networkManager.addEventListener(WebInspector.NetworkManager.Ev entTypes.RequestFinished, onRequest); |
40 | 38 |
39 function testBlockedURL(patterns, url, next) | |
40 { | |
41 InspectorTest.addResult("Blocked patterns: " + patterns.join(";")); | |
42 InspectorTest.addResult("Request: " + url); | |
43 blockedSetting.set(patterns); | |
44 nextStep = next; | |
45 InspectorTest.runAfterPendingDispatches(addScript); | |
46 | |
47 function addScript() | |
48 { | |
49 requestName = url.substring(url.lastIndexOf("/") + 1); | |
50 InspectorTest.evaluateInPage("addBlockedScript(\"" + url + "\")"); | |
51 } | |
52 } | |
53 | |
41 InspectorTest.runTestSuite([ | 54 InspectorTest.runTestSuite([ |
42 function testCSP(next) | 55 function testCSP(next) |
43 { | 56 { |
44 requestName = "csp.js"; | 57 requestName = "csp.js"; |
45 nextStep = next; | 58 nextStep = next; |
46 InspectorTest.evaluateInPage("sendCSPRequest()"); | 59 InspectorTest.evaluateInPage("sendCSPRequest()"); |
47 }, | 60 }, |
48 | 61 |
49 function testDevTools(next) | 62 function testBlockedByDevTools1(next) |
50 { | 63 { |
51 blockedSetting.set(["http://some.strange.origin/script.js", "resourc es/silent_script.js"]); | 64 testBlockedURL(["resources**/silent*.js"], "resources/silent_script. js", next); |
52 nextStep = removeBlock; | 65 }, |
53 InspectorTest.runAfterPendingDispatches(addScript); | |
54 | 66 |
55 function removeBlock() | 67 function testBlockedByDevTools2(next) |
56 { | 68 { |
57 blockedSetting.set(["http://some.strange.origin/script.js"]); | 69 testBlockedURL(["a*b"], "ba", next); |
58 nextStep = next; | 70 }, |
59 InspectorTest.runAfterPendingDispatches(addScript); | |
60 } | |
61 | 71 |
62 function addScript() | 72 function testBlockedByDevTools3(next) |
63 { | 73 { |
64 requestName = "silent_script.js"; | 74 testBlockedURL(["***pattern***"], "there/is/a/pattern/inside.js", ne xt); |
65 InspectorTest.evaluateInPage("addBlockedScript()"); | 75 }, |
66 } | 76 |
77 function testBlockedByDevTools4(next) | |
78 { | |
79 testBlockedURL(["pattern"], "patt1ern", next); | |
80 }, | |
81 | |
82 function testBlockedByDevTools5(next) | |
83 { | |
84 testBlockedURL(["*this***is*a*pattern"], "file/this/is/the/pattern", next); | |
85 }, | |
86 | |
87 function testBlockedByDevTools6(next) | |
88 { | |
89 testBlockedURL(["*this***is*a*pattern"], "this/is/a/pattern", next); | |
90 }, | |
91 | |
92 function testBlockedByDevTools6(next) | |
93 { | |
94 testBlockedURL(["*this***is*a*pattern"], "this/is", next); | |
95 }, | |
96 | |
97 function testBlockedByDevTools7(next) | |
98 { | |
99 testBlockedURL(["pattern"], "long/pattern/inside", next); | |
100 }, | |
101 | |
102 function testBlockedByDevTools8(next) | |
103 { | |
104 testBlockedURL(["pattern"], "pattern", next); | |
105 }, | |
106 | |
107 function testBlockedByDevTools9(next) | |
108 { | |
109 testBlockedURL(["pattern", "pattern"], "pattern", next); | |
110 }, | |
111 | |
112 function testBlockedByDevTools10(next) | |
113 { | |
114 testBlockedURL(["a*b*c*d*e"], "edcbaedcbaedcbaedcba", next); | |
115 }, | |
116 | |
117 function testBlockedByDevTools11(next) | |
118 { | |
119 testBlockedURL(["a*b*c*d*e"], "edcbaedcbaedcbaedcbae", next); | |
120 }, | |
121 | |
122 function testBlockedByDevTools12(next) | |
123 { | |
124 testBlockedURL(["one1", "two2"], "one1two2", next); | |
125 }, | |
126 | |
127 function testBlockedByDevTools13(next) | |
128 { | |
129 testBlockedURL(["one1", "two2", "three3"], "four4", next); | |
130 }, | |
131 | |
132 function testBlockedByDevTools14(next) | |
133 { | |
134 testBlockedURL(["one1", "two2", "three3"], "only-two2-here", next); | |
135 }, | |
136 | |
137 function cleanupBlockedURLs(next) | |
138 { | |
139 testBlockedURL([], "resources/silent_script.js", next); | |
67 } | 140 } |
68 ]); | 141 ]); |
69 } | 142 } |
70 </script> | 143 </script> |
71 </head> | 144 </head> |
72 <body onload="runTest()"> | 145 <body onload="runTest()"> |
73 <p>Tests that blocked reason is recognized correctly.</p> | 146 <p>Tests that blocked reason is recognized correctly.</p> |
74 </body> | 147 </body> |
75 </html> | 148 </html> |
OLD | NEW |