blob: 0669de475696c13706d54e177e303c278627e1b9 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function openTab(url) {
return new Promise((resolve) => {
chrome.tabs.onUpdated.addListener(
function listener(tabId, changeInfo, tab) {
// Note: Use new URL(...).href to compare in order to normalize the URL,
// which is important if the path referenced a parent (as happens in the
// file urls).
if (changeInfo.status !== 'complete' ||
(new URL(tab.url)).href !== (new URL(url)).href) {
return;
}
chrome.tabs.onUpdated.removeListener(listener);
resolve(tab.id);
});
chrome.tabs.create({url: url});
});
}
chrome.test.getConfig((config) => {
const fileUrl = config.testDataDirectory + '/../body1.html';
const expectFileAccess = !!config.customArg;
console.log(fileUrl);
chrome.test.runTests([
function verifyInitialState() {
if (config.customArg)
chrome.test.assertEq('enabled', config.customArg);
chrome.extension.isAllowedFileSchemeAccess((allowed) => {
chrome.test.assertEq(expectFileAccess, allowed);
chrome.test.succeed();
});
},
function testAttach() {
openTab(fileUrl).then((tabId) => {
chrome.debugger.attach({tabId: tabId}, '1.1', function() {
if (expectFileAccess) {
chrome.test.assertNoLastError();
chrome.debugger.detach({tabId: tabId}, function() {
chrome.test.assertNoLastError();
chrome.test.succeed();
});
} else {
chrome.test.assertLastError('Cannot attach to this target.');
chrome.test.succeed();
}
});
});
},
function testAttachAndNavigate() {
openTab(chrome.runtime.getURL('dummy.html')).then((tabId) => {
chrome.debugger.attach({tabId: tabId}, '1.1', function() {
chrome.test.assertNoLastError();
let responded = false;
function onResponse() {
responded = true;
if (expectFileAccess) {
chrome.test.assertNoLastError();
chrome.tabs.remove(tabId);
} else {
chrome.test.assertLastError('Detached while handling command.');
}
}
function onDetach(from, reason) {
console.warn('Detached');
chrome.debugger.onDetach.removeListener(onDetach);
chrome.test.assertTrue(responded);
chrome.test.assertEq(tabId, from.tabId);
chrome.test.assertEq('target_closed', reason);
chrome.test.succeed();
}
chrome.debugger.onDetach.addListener(onDetach);
chrome.debugger.sendCommand({tabId: tabId}, 'Page.navigate',
{url: fileUrl}, onResponse);
});
});
},
]);
});