Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
Devlin
2016/11/15 15:12:02
no (c)
Ivan Šandrk
2016/11/15 16:07:40
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var LOCAL_FOLDER = 'extensions/api_test/webrequest_public_session/'; | |
| 6 | |
| 7 function getResURL(url) { | |
| 8 return getServerURL(LOCAL_FOLDER + url); | |
| 9 } | |
| 10 | |
| 11 function getStrippedURL(url) { | |
| 12 // In Public Session URL is stripped down to origin, that's why '' is used | |
| 13 // here, otherwise the same as in getResURL would have to be used. | |
| 14 return getServerURL(''); | |
| 15 } | |
| 16 | |
| 17 runTests([ | |
| 18 // Navigates to a page with a blocking handler that cancels the page request. | |
| 19 // The page will not load. This tests the following: | |
| 20 // - listeners can be registered on the webRequest API with empty URL | |
| 21 // permissions in manifest | |
| 22 // - url is stripped down to origin | |
| 23 // - cancel can be used (it's not blocked) | |
| 24 // - extension can access arbitrary URL (all URLs are whitelisted for purposes | |
| 25 // of webRequest in Public Session); in case the extension cannot access the | |
| 26 // URL, this test will timeout. | |
| 27 function cancelIsNotBlocked() { | |
| 28 var targetUrl = getResURL('res/a.html'); | |
| 29 var expectUrl = getStrippedURL('res/a.html'); | |
| 30 expect( | |
| 31 [ // events | |
| 32 { label: 'onBeforeRequest', | |
| 33 event: 'onBeforeRequest', | |
| 34 details: { | |
| 35 type: 'main_frame', | |
| 36 url: expectUrl, | |
| 37 frameUrl: expectUrl | |
| 38 }, | |
| 39 retval: {cancel: true} | |
| 40 }, | |
| 41 // Cancelling is considered an error. | |
| 42 { label: 'onErrorOccurred', | |
| 43 event: 'onErrorOccurred', | |
| 44 details: { | |
| 45 url: expectUrl, | |
| 46 fromCache: false, | |
| 47 error: 'net::ERR_BLOCKED_BY_CLIENT' | |
| 48 } | |
| 49 }, | |
| 50 ], | |
| 51 [['onBeforeRequest', 'onErrorOccurred']], // event order | |
| 52 {urls: ['<all_urls>']}, // filter | |
| 53 ['blocking']); | |
| 54 navigateAndWait(targetUrl); | |
| 55 }, | |
| 56 | |
| 57 // Tests that a redirect is successfully blocked (without the code that blocks | |
| 58 // the redirect the following would error out with an unexpected event | |
| 59 // 'onBeforeRedirect'). The test is good even with the URL stripped down to | |
| 60 // origin because it doesn't rely on the URL for the check. | |
| 61 function redirectIsBlocked() { | |
|
Devlin
2016/11/15 15:12:02
From your comment, it sounded like you got checkin
Ivan Šandrk
2016/11/15 16:07:40
Yes, the test is working now, with *no* changes to
| |
| 62 var targetUrl = getURL('res/a.html'); | |
| 63 var redirectUrl = getURL('res/b.html'); | |
| 64 var expectUrl = getURL(''); | |
| 65 expect( | |
| 66 [ | |
| 67 { label: 'onBeforeRequest', | |
| 68 event: 'onBeforeRequest', | |
| 69 details: { | |
| 70 type: 'main_frame', | |
| 71 url: expectUrl, | |
| 72 frameUrl: expectUrl | |
| 73 }, | |
| 74 retval: {redirectUrl: redirectUrl} | |
| 75 }, | |
| 76 { label: 'onResponseStarted', | |
| 77 event: 'onResponseStarted', | |
| 78 details: { | |
| 79 frameId: 0, | |
| 80 fromCache: false, | |
| 81 method: 'GET', | |
| 82 parentFrameId: -1, | |
| 83 statusCode: 200, | |
| 84 statusLine: 'HTTP/1.1 200 OK', | |
| 85 tabId: 0, | |
| 86 type: 'main_frame', | |
| 87 url: expectUrl | |
| 88 } | |
| 89 }, | |
| 90 { label: 'onCompleted', | |
| 91 event: 'onCompleted', | |
| 92 details: { | |
| 93 frameId: 0, | |
| 94 fromCache: false, | |
| 95 method: 'GET', | |
| 96 parentFrameId: -1, | |
| 97 statusCode: 200, | |
| 98 statusLine: 'HTTP/1.1 200 OK', | |
| 99 tabId: 0, | |
| 100 type: 'main_frame', | |
| 101 url: expectUrl | |
| 102 } | |
| 103 }, | |
| 104 ], | |
| 105 [['onBeforeRequest', 'onResponseStarted', 'onCompleted']], | |
| 106 {urls: ['<all_urls>']}, | |
| 107 ['blocking']); | |
| 108 navigateAndWait(targetUrl); | |
| 109 }, | |
| 110 ]); | |
| OLD | NEW |