Backed out 2 changesets (bug 1546394) for devtools failures with getBlockedUrls. CLOSED TREE

Backed out changeset 0365ee129bc0 (bug 1546394)
Backed out changeset 1b05fad0314a (bug 1546394)
This commit is contained in:
Csoregi Natalia 2020-05-18 13:33:42 +03:00
Родитель f6ee95862e
Коммит 08fa2d05ed
17 изменённых файлов: 15 добавлений и 337 удалений

Просмотреть файл

@ -430,20 +430,6 @@ webconsole.cssWarningElements.label=Elements matching selector: %S
# Parameters: %S is the URL to file a bug about the error.
webconsole.message.componentDidCatch.label=[DEVTOOLS ERROR] Were sorry, we couldnt render the message. This shouldnt have happened - please file a bug at %S with the message metadata in the description.
# LOCALIZATION NOTE (webconsole.message.commands.blockedURL)
# Label displayed when the :block <url> command is successful
# Parameters: %S is the URL filter
webconsole.message.commands.blockedURL=Requests to URL containing "%S" are now blocked
# LOCALIZATION NOTE (webconsole.message.commands.unblockedURL)
# Label displayed when the :unblock <url> command is successful
# Parameters: %S is the URL filter
webconsole.message.commands.unblockedURL=Removed blocking filter "%S"
# LOCALIZATION NOTE (webconsole.messages.commands.blockArgMissing)
# Message displayed when no filter is passed to block/unblock command
webconsole.messages.commands.blockArgMissing=No filter was specified
# LOCALIZATION NOTE (webconsole.message.componentDidCatch.copyButton.label)
# Label displayed on the button next to the message we display when the webconsole
# couldn't handle a given packet (See webconsole.message.componentDidCatch.label).

Просмотреть файл

@ -14,8 +14,6 @@ const {
connect,
} = require("devtools/client/shared/redux/visibility-handler-connect");
const blockingActions = require("devtools/client/netmonitor/src/actions/request-blocking");
// Components
loader.lazyGetter(this, "MonitorPanel", function() {
return createFactory(
@ -56,16 +54,9 @@ class App extends Component {
statisticsOpen: PropTypes.bool.isRequired,
// Document which settings menu will be injected to
toolboxDoc: PropTypes.object.isRequired,
// Syncing blocked requests
addBlockedUrl: PropTypes.func,
};
}
async componentDidMount() {
const responses = await this.props.connector.getBlockedUrls();
const urls = responses.flat();
urls.forEach(url => this.props.addBlockedUrl(url));
}
// Rendering
render() {
@ -105,11 +96,6 @@ class App extends Component {
// Exports
module.exports = connect(
state => ({
statisticsOpen: state.ui.statisticsOpen,
}),
(dispatch, props) => ({
addBlockedUrl: url => dispatch(blockingActions.addBlockedUrl(url)),
})
)(App);
module.exports = connect(state => ({
statisticsOpen: state.ui.statisticsOpen,
}))(App);

Просмотреть файл

@ -342,13 +342,6 @@ class FirefoxConnector {
return this.webConsoleFront.unblockRequest(filter);
}
/*
* Get the list of blocked URLs
*/
getBlockedUrls() {
return this.webConsoleFront.getBlockedUrls();
}
/**
* Updates the list of blocked URLs
*

Просмотреть файл

@ -96,10 +96,6 @@ class Connector {
return this.connector.sendHTTPRequest(...arguments);
}
getBlockedUrls() {
return this.connector.getBlockedUrls();
}
setBlockedUrls() {
return this.connector.setBlockedUrls(...arguments);
}

Просмотреть файл

@ -11,7 +11,6 @@ const {
SET_TERMINAL_EAGER_RESULT,
} = require("devtools/client/webconsole/constants");
const { getAllPrefs } = require("devtools/client/webconsole/selectors/prefs");
const l10n = require("devtools/client/webconsole/utils/l10n");
loader.lazyServiceGetter(
this,
@ -40,12 +39,6 @@ loader.lazyRequireGetter(
"devtools/client/webconsole/types",
true
);
loader.lazyRequireGetter(
this,
"netmonitorBlockingActions",
"devtools/client/netmonitor/src/actions/request-blocking"
);
const HELP_URL = "https://developer.mozilla.org/docs/Tools/Web_Console/Helpers";
async function getMappedExpression(hud, expression) {
@ -169,7 +162,7 @@ function onExpressionEvaluated(response) {
}
function handleHelperResult(response) {
return async ({ dispatch, hud, toolbox, webConsoleUI }) => {
return async ({ dispatch, hud, webConsoleUI }) => {
const { result, helperResult } = response;
const helperHasRawOutput = !!helperResult?.rawOutput;
@ -211,47 +204,6 @@ function handleHelperResult(response) {
}))
)
);
break;
case "blockURL":
const blockURL = helperResult.args.url;
toolbox
.getPanel("netmonitor")
?.panelWin.store.dispatch(
netmonitorBlockingActions.addBlockedUrl(blockURL)
);
dispatch(
messagesActions.messagesAdd([
{
type: "logMessage",
message: l10n.getFormatStr(
"webconsole.message.commands.blockedURL",
[blockURL]
),
},
])
);
break;
case "unblockURL":
const unblockURL = helperResult.args.url;
toolbox
.getPanel("netmonitor")
?.panelWin.store.dispatch(
netmonitorBlockingActions.removeBlockedUrl(unblockURL)
);
dispatch(
messagesActions.messagesAdd([
{
type: "logMessage",
message: l10n.getFormatStr(
"webconsole.message.commands.unblockedURL",
[unblockURL]
),
},
])
);
// early return as we already dispatched necessary messages.
return;
}

Просмотреть файл

@ -4,8 +4,6 @@ subsuite = devtools
support-files =
head.js
test-autocomplete-in-stackframe.html
test-block-action.html
test-block-action-style.css
test-console-evaluation-context-selector-child.html
test-console-evaluation-context-selector.html
test-console.html
@ -73,7 +71,6 @@ skip-if = debug && (os == "win" && bits == 32) # Bug 1620856
[browser_jsterm_await_paused.js]
skip-if = debug # crashes on "Unexpected UpdateTransformLayer hint" bug 1570685
[browser_jsterm_await.js]
[browser_jsterm_block_command.js]
[browser_jsterm_completion_bracket_cached_results.js]
[browser_jsterm_completion_bracket.js]
skip-if = debug && (os == "win" && os_version == "6.1") # Bug 1620724

Просмотреть файл

@ -18,7 +18,7 @@ add_task(async function() {
EventUtils.sendString(":");
await onAutocompleUpdated;
const expectedCommands = [":block", ":help", ":screenshot", ":unblock"];
const expectedCommands = [":help", ":screenshot"];
ok(
hasExactPopupLabels(autocompletePopup, expectedCommands),
"popup contains expected commands"

Просмотреть файл

@ -1,90 +0,0 @@
"use strict";
const TEST_URI =
"http://example.com/browser/devtools/client/webconsole/" +
"test/browser/test-block-action.html";
const TIMEOUT = "TIMEOUT";
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
ok(hud, "web console opened");
const filter = "test-block-action-style.css";
const blockCommand = `:block ${filter}`;
const unblockCommand = `:unblock ${filter}`;
info("Before blocking");
await tryFetching();
const resp1 = await waitFor(() => findMessage(hud, "successful"));
ok(resp1, "the request was not blocked");
info(`Execute the :block command and try to do execute a network request`);
await executeAndWaitForMessage(hud, blockCommand, "are now blocked");
await tryFetching();
const resp2 = await waitFor(() => findMessage(hud, "blocked"));
ok(resp2, "the request was blocked as expected");
info("Open netmonitor check the blocked filter is registered in its state");
const { panelWin } = await openNetMonitor();
// wait until the blockedUrls property is populated
await waitFor(
() => panelWin.store.getState().requestBlocking.blockedUrls.length > 0
);
const netMonitorState1 = panelWin.store.getState();
is(
netMonitorState1.requestBlocking.blockedUrls[0].url,
filter,
"blocked request shows up in netmonitor state"
);
info("Switch back to the console");
await hud.toolbox.selectTool("webconsole");
// :unblock
await executeAndWaitForMessage(hud, unblockCommand, "Removed blocking");
info("After unblocking");
const netMonitorState2 = panelWin.store.getState();
is(
netMonitorState2.requestBlocking.blockedUrls.length,
0,
"unblocked request should not be in netmonitor state"
);
await tryFetching();
const resp3 = await waitFor(() => findMessage(hud, "successful"));
ok(resp3, "the request was not blocked");
});
async function tryFetching() {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [TIMEOUT], async function(
timeoutStr
) {
const win = content.wrappedJSObject;
const FETCH_URI =
"http://example.com/browser/devtools/client/webconsole/" +
"test/browser/test-block-action-style.css";
const timeout = new Promise(res =>
win.setTimeout(() => res(timeoutStr), 1000)
);
const fetchPromise = win.fetch(FETCH_URI);
try {
const resp = await Promise.race([fetchPromise, timeout]);
if (typeof resp === "object") {
// Request Promise
win.console.log("the request was successful");
} else if (resp === timeoutStr) {
// Timeout
win.console.log("the request was blocked");
} else {
win.console.error("Unkown response");
}
} catch {
// NetworkError
win.console.log("the request was blocked");
}
});
}

Просмотреть файл

@ -849,25 +849,6 @@ async function openInspector(options = {}) {
return toolbox.getCurrentPanel();
}
/**
* Open the netmonitor for the given tab, or the current one if none given.
*
* @param Element tab
* Optional tab element for which you want open the netmonitor.
* Defaults to current selected tab.
* @return Promise
* A promise that is resolved with the netmonitor panel once the netmonitor is open.
*/
async function openNetMonitor(tab) {
const target = await TargetFactory.forTab(tab || gBrowser.selectedTab);
let toolbox = await gDevTools.getToolbox(target);
if (!toolbox) {
toolbox = await gDevTools.showToolbox(target);
}
await toolbox.selectTool("netmonitor");
return toolbox.getCurrentPanel();
}
/**
* Open the Web Console for the given tab, or the current one if none given.
*

Просмотреть файл

@ -1,3 +0,0 @@
h1 {
color: red;
}

Просмотреть файл

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test for bug 1546394 - :block command</title>
<link rel="stylesheet" href="test-block-action-style.css">
</head>
<body>
<h1 id="heading">I won't be red for once.</h1>
</body>
</html>

Просмотреть файл

@ -66,7 +66,6 @@ const NetworkMonitorActor = ActorClassWithSpec(networkMonitorSpec, {
this.onBlockRequest = this.onBlockRequest.bind(this);
this.onUnblockRequest = this.onUnblockRequest.bind(this);
this.onSetBlockedUrls = this.onSetBlockedUrls.bind(this);
this.onGetBlockedUrls = this.onGetBlockedUrls.bind(this);
this.onGetNetworkEventActor = this.onGetNetworkEventActor.bind(this);
this.onDestroyMessage = this.onDestroyMessage.bind(this);
@ -104,10 +103,6 @@ const NetworkMonitorActor = ActorClassWithSpec(networkMonitorSpec, {
"debug:set-blocked-urls",
this.onSetBlockedUrls
);
this.messageManager.addMessageListener(
"debug:get-blocked-urls",
this.onGetBlockedUrls
);
this.messageManager.addMessageListener(
"debug:get-network-event-actor:request",
this.onGetNetworkEventActor
@ -143,10 +138,6 @@ const NetworkMonitorActor = ActorClassWithSpec(networkMonitorSpec, {
"debug:set-blocked-urls",
this.onSetBlockedUrls
);
this.messageManager.removeMessageListener(
"debug:get-blocked-urls",
this.onGetBlockedUrls
);
this.messageManager.removeMessageListener(
"debug:get-network-event-actor:request",
this.onGetNetworkEventActor
@ -269,14 +260,6 @@ const NetworkMonitorActor = ActorClassWithSpec(networkMonitorSpec, {
this.messageManager.sendAsyncMessage("debug:set-blocked-urls:response");
},
onGetBlockedUrls() {
const urls = this.observer.getBlockedUrls();
this.messageManager.sendAsyncMessage(
"debug:get-blocked-urls:response",
urls
);
},
onGetNetworkEventActor({ data }) {
const actor = this.getNetworkEventActor(data.channelId);
this.messageManager.sendAsyncMessage(

Просмотреть файл

@ -945,14 +945,6 @@ NetworkObserver.prototype = {
this.blockedURLs = urls || [];
},
/**
* Returns a list of blocked requests
* Useful as blockedURLs is mutated by both console & netmonitor
*/
getBlockedUrls() {
return this.blockedURLs;
},
/**
* Setup the network response listener for the given HTTP activity. The
* NetworkResponseListener is responsible for storing the response body.

Просмотреть файл

@ -1892,24 +1892,23 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
*/
async _sendMessageToNetmonitors(messageName, responseName, args) {
if (!this.netmonitors) {
return null;
return;
}
const results = await Promise.all(
await Promise.all(
this.netmonitors.map(({ messageManager }) => {
const onResponseReceived = new Promise(resolve => {
messageManager.addMessageListener(responseName, function onResponse(
response
) {
messageManager.removeMessageListener(responseName, onResponse);
resolve(response);
});
messageManager.addMessageListener(
responseName,
function onResponse() {
messageManager.removeMessageListener(responseName, onResponse);
resolve();
}
);
});
messageManager.sendAsyncMessage(messageName, args);
return onResponseReceived;
})
);
return results;
},
/**
@ -1952,28 +1951,6 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
return {};
},
/*
* Gets the list of blocked request urls as per the backend
*/
async getBlockedUrls() {
const responses =
(await this._sendMessageToNetmonitors(
"debug:get-blocked-urls",
"debug:get-blocked-urls:response"
)) || [];
if (!responses || responses.length == 0) {
return [];
}
return Array.from(
new Set(
responses
.filter(response => response.data)
.map(response => response.data)
)
);
},
/**
* Sets the list of blocked request URLs as provided by the netmonitor frontend
*

Просмотреть файл

@ -4,7 +4,7 @@
"use strict";
const validCommands = ["block", "help", "screenshot", "unblock"];
const validCommands = ["help", "screenshot"];
const COMMAND = "command";
const KEY = "key";
@ -16,9 +16,7 @@ const KEY_PREFIX = /^--/;
// default value for flags
const DEFAULT_VALUE = true;
const COMMAND_DEFAULT_FLAG = {
block: "url",
screenshot: "filename",
unblock: "url",
};
/**

Просмотреть файл

@ -648,60 +648,6 @@ WebConsoleCommands._registerOriginal("screenshot", function(owner, args = {}) {
})();
});
/**
* Block specific resource from loading
*
* @param object args
* an object with key "url", i.e. a filter
*
* @return void
*/
WebConsoleCommands._registerOriginal("block", function(owner, args = {}) {
if (!args.url) {
owner.helperResult = {
type: "error",
message: "webconsole.messages.commands.blockArgMissing",
};
return;
}
owner.helperResult = (async () => {
await owner.consoleActor.blockRequest(args);
return {
type: "blockURL",
args,
};
})();
});
/*
* Unblock a blocked a resource
*
* @param object filter
* an object with key "url", i.e. a filter
*
* @return void
*/
WebConsoleCommands._registerOriginal("unblock", function(owner, args = {}) {
if (!args.url) {
owner.helperResult = {
type: "error",
message: "webconsole.messages.commands.blockArgMissing",
};
return;
}
owner.helperResult = (async () => {
await owner.consoleActor.unblockRequest(args);
return {
type: "unblockURL",
args,
};
})();
});
/**
* (Internal only) Add the bindings to |owner.sandbox|.
* This is intended to be used by the WebConsole actor only.

Просмотреть файл

@ -245,10 +245,6 @@ const webconsoleSpecPrototype = {
url: Arg(0, "json"),
},
},
getBlockedUrls: {
request: {},
response: RetVal("array:string"),
},
},
};