OLD | NEW |
| (Empty) |
1 <script src="framework.js"> | |
2 </script> | |
3 <script> | |
4 // Constants as functions, not to be called until after runTests. | |
5 function getURLEchoUserAgent() { | |
6 return getServerURL('echoheader?User-Agent'); | |
7 } | |
8 | |
9 runTests([ | |
10 // Navigates to a page with subresources, with a blocking handler that | |
11 // cancels the page request. The page will not load, and we should not | |
12 // see the subresources. | |
13 function complexLoadCancelled() { | |
14 expect( | |
15 [ // events | |
16 { label: "onBeforeRequest", | |
17 event: "onBeforeRequest", | |
18 details: { | |
19 method: "GET", | |
20 tabId: tabId, | |
21 type: "main_frame", | |
22 url: getURL("complexLoad/a.html"), | |
23 frameUrl: getURL("complexLoad/a.html") | |
24 }, | |
25 retval: {cancel: true} | |
26 }, | |
27 // Cancelling is considered an error. | |
28 { label: "onErrorOccurred", | |
29 event: "onErrorOccurred", | |
30 details: { | |
31 url: getURL("complexLoad/a.html"), | |
32 fromCache: false, | |
33 error: "net::ERR_EMPTY_RESPONSE" | |
34 // Request to chrome-extension:// url has no IP. | |
35 } | |
36 }, | |
37 ], | |
38 [ // event order | |
39 ["onBeforeRequest"] | |
40 ], | |
41 {}, // filter | |
42 ["blocking"]); | |
43 navigateAndWait(getURL("complexLoad/a.html")); | |
44 }, | |
45 | |
46 // Navigates to a page with a blocking handler that redirects to a different | |
47 // page. | |
48 // TODO(mpcomplete): We should see an onBeforeRedirect as well, but our | |
49 // process switching logic cancels the original redirect request and | |
50 // starts a new one instead. See http://crbug.com/79520. | |
51 function complexLoadRedirected() { | |
52 expect( | |
53 [ // events | |
54 { label: "onBeforeRequest-1", | |
55 event: "onBeforeRequest", | |
56 details: { | |
57 method: "GET", | |
58 tabId: tabId, | |
59 type: "main_frame", | |
60 url: getURL("complexLoad/a.html"), | |
61 frameUrl: getURL("complexLoad/a.html") | |
62 }, | |
63 retval: {redirectUrl: getURL("simpleLoad/a.html")} | |
64 }, | |
65 { label: "onErrorOccurred-1", | |
66 event: "onErrorOccurred", | |
67 details: { | |
68 url: getURL("complexLoad/a.html"), | |
69 fromCache: false, | |
70 error: "net::ERR_ABORTED" | |
71 // Request to chrome-extension:// url has no IP. | |
72 } | |
73 }, | |
74 { label: "onBeforeRequest-2", | |
75 event: "onBeforeRequest", | |
76 details: { | |
77 method: "GET", | |
78 tabId: tabId, | |
79 type: "main_frame", | |
80 url: getURL("simpleLoad/a.html"), | |
81 frameUrl: getURL("simpleLoad/a.html"), | |
82 }, | |
83 }, | |
84 { label: "onResponseStarted", | |
85 event: "onResponseStarted", | |
86 details: { | |
87 url: getURL("simpleLoad/a.html"), | |
88 fromCache: false, | |
89 statusCode: 200 | |
90 // Request to chrome-extension:// url has no IP. | |
91 } | |
92 }, | |
93 { label: "onCompleted", | |
94 event: "onCompleted", | |
95 details: { | |
96 url: getURL("simpleLoad/a.html"), | |
97 fromCache: false, | |
98 statusCode: 200 | |
99 // Request to chrome-extension:// url has no IP. | |
100 } | |
101 }, | |
102 ], | |
103 [ // event order | |
104 ["onBeforeRequest-1", "onErrorOccurred-1", "onBeforeRequest-2", | |
105 "onResponseStarted", "onCompleted"], | |
106 ], | |
107 {}, // filter | |
108 ["blocking"]); | |
109 navigateAndWait(getURL("complexLoad/a.html")); | |
110 }, | |
111 | |
112 // Loads a testserver page that echoes the User-Agent header that was | |
113 // sent to fetch it. We modify the outgoing User-Agent in | |
114 // onBeforeSendHeaders, so we should see that modified version. | |
115 function modifyRequestHeaders() { | |
116 expect( | |
117 [ // events | |
118 { label: "onBeforeRequest", | |
119 event: "onBeforeRequest", | |
120 details: { | |
121 method: "GET", | |
122 tabId: tabId, | |
123 type: "main_frame", | |
124 url: getURLEchoUserAgent(), | |
125 frameUrl: getURLEchoUserAgent() | |
126 } | |
127 }, | |
128 { label: "onBeforeSendHeaders", | |
129 event: "onBeforeSendHeaders", | |
130 details: { | |
131 url: getURLEchoUserAgent(), | |
132 // Note: no requestHeaders because we don't ask for them. | |
133 }, | |
134 retval: {requestHeaders: [{name: "User-Agent", value: "FoobarUA"}]} | |
135 }, | |
136 { label: "onSendHeaders", | |
137 event: "onSendHeaders", | |
138 details: { | |
139 url: getURLEchoUserAgent() | |
140 } | |
141 }, | |
142 { label: "onResponseStarted", | |
143 event: "onResponseStarted", | |
144 details: { | |
145 url: getURLEchoUserAgent(), | |
146 fromCache: false, | |
147 statusCode: 200, | |
148 ip: "127.0.0.1" | |
149 } | |
150 }, | |
151 { label: "onCompleted", | |
152 event: "onCompleted", | |
153 details: { | |
154 url: getURLEchoUserAgent(), | |
155 fromCache: false, | |
156 statusCode: 200, | |
157 ip: "127.0.0.1" | |
158 } | |
159 }, | |
160 ], | |
161 [ // event order | |
162 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | |
163 "onResponseStarted", "onCompleted"] | |
164 ], | |
165 {}, ["blocking"]); | |
166 // Check the page content for our modified User-Agent string. | |
167 navigateAndWait(getURLEchoUserAgent(), function() { | |
168 chrome.test.listenOnce(chrome.extension.onRequest, function(request) { | |
169 chrome.test.assertTrue(request.pass, "Request header was not set."); | |
170 }); | |
171 chrome.tabs.executeScript(tabId, | |
172 { | |
173 code: "chrome.extension.sendRequest(" + | |
174 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});" | |
175 }); | |
176 }); | |
177 }, | |
178 ]); | |
179 </script> | |
OLD | NEW |