protocol: provide default response code for custom request jobs
This commit is contained in:
parent
190c9c916e
commit
3c88447be6
3 changed files with 43 additions and 4 deletions
|
@ -82,6 +82,9 @@ class JsAsker : public RequestJob {
|
||||||
base::Bind(&JsAsker::OnResponse,
|
base::Bind(&JsAsker::OnResponse,
|
||||||
weak_factory_.GetWeakPtr())));
|
weak_factory_.GetWeakPtr())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetResponseCode() const override { return 200; }
|
||||||
|
|
||||||
void GetResponseInfo(net::HttpResponseInfo* info) override {
|
void GetResponseInfo(net::HttpResponseInfo* info) override {
|
||||||
info->headers = new net::HttpResponseHeaders("");
|
info->headers = new net::HttpResponseHeaders("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ void URLRequestBufferJob::StartAsync(std::unique_ptr<base::Value> options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void URLRequestBufferJob::GetResponseInfo(net::HttpResponseInfo* info) {
|
void URLRequestBufferJob::GetResponseInfo(net::HttpResponseInfo* info) {
|
||||||
std::string status("HTTP/1.1 ");
|
std::string status("HTTP/1.1 200 OK");
|
||||||
status.append(base::IntToString(status_code_));
|
status.append(base::IntToString(status_code_));
|
||||||
status.append(" ");
|
status.append(" ");
|
||||||
status.append(net::GetHttpReasonPhrase(status_code_));
|
status.append(net::GetHttpReasonPhrase(status_code_));
|
||||||
|
|
|
@ -149,8 +149,6 @@ describe('chromium feature', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('navigator.serviceWorker', function () {
|
describe('navigator.serviceWorker', function () {
|
||||||
var url = 'file://' + fixtures + '/pages/service-worker/index.html'
|
|
||||||
|
|
||||||
it('should register for file scheme', function (done) {
|
it('should register for file scheme', function (done) {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
|
@ -169,7 +167,45 @@ describe('chromium feature', function () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
w.loadURL(url)
|
w.loadURL(`file://${fixtures}/pages/service-worker/index.html`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should register for intercepted file scheme', function (done) {
|
||||||
|
const customSession = session.fromPartition('intercept-file')
|
||||||
|
customSession.protocol.interceptBufferProtocol('file', function (request, callback) {
|
||||||
|
const file = url.parse(request.url).pathname
|
||||||
|
const content = fs.readFileSync(path.normalize(file))
|
||||||
|
const ext = path.extname(file)
|
||||||
|
let type = 'text/html'
|
||||||
|
if (ext === '.js') {
|
||||||
|
type = 'application/javascript'
|
||||||
|
}
|
||||||
|
callback({data: content, mimeType: type})
|
||||||
|
}, function (error) {
|
||||||
|
if (error) done(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
session: customSession
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.webContents.on('ipc-message', function (event, args) {
|
||||||
|
if (args[0] === 'reload') {
|
||||||
|
w.webContents.reload()
|
||||||
|
} else if (args[0] === 'error') {
|
||||||
|
done('unexpected error : ' + args[1])
|
||||||
|
} else if (args[0] === 'response') {
|
||||||
|
assert.equal(args[1], 'Hello from serviceWorker!')
|
||||||
|
customSession.clearStorageData({
|
||||||
|
storages: ['serviceworkers']
|
||||||
|
}, function () {
|
||||||
|
customSession.protocol.uninterceptProtocol('file', (error) => done(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.loadURL(`file://${fixtures}/pages/service-worker/index.html`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue