Skip to content

Commit

Permalink
Block box tests: disable telemetry_test, fix deep_links and web_debug…
Browse files Browse the repository at this point in the history
…ger (#2986)

b/330355045
  • Loading branch information
aee-google committed Apr 18, 2024
1 parent 549b2c5 commit 27c4a5c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cobalt/black_box_tests/black_box_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
'service_worker_test',
'service_worker_persist_test',
'soft_mic_platform_service_test',
'telemetry_test',
# 'telemetry_test',
'text_encoding_test',
'wasm_basic_test',
'web_debugger',
Expand Down
18 changes: 15 additions & 3 deletions cobalt/black_box_tests/tests/deep_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,26 @@
_SERVER_ROOT_PATH = os.path.join(os.path.dirname(__file__), os.pardir)


def is_deep_links_js(path):
"""Check request path is for deep_links.js."""
parsed_path = urlparse(path)
return parsed_path.path == '/testdata/' + _DEEP_LINKS_JS


class JavascriptRequestDetector(MakeRequestHandlerClass(_SERVER_ROOT_PATH)):
"""Proxies everything to SimpleHTTPRequestHandler, except some paths."""

def end_headers(self):
"""Send the blank line ending the MIME headers."""
if is_deep_links_js(self.path):
# Prevent caching so |do_GET()| can delay response.
self.send_header('Cache-Control', 'no-store')

SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)

def do_GET(self): # pylint: disable=invalid-name
"""Handles HTTP GET requests for resources."""

parsed_path = urlparse(self.path)
if parsed_path.path == '/testdata/' + _DEEP_LINKS_JS:
if is_deep_links_js(self.path):
# It is important not to send any response back, so we block.
logging.info('Waiting on links to be fired.')
_script_loading_signal.wait()
Expand Down
19 changes: 10 additions & 9 deletions cobalt/debug/remote/debug_web_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ void DebugWebServer::OnWebSocketMessage(int connection_id, std::string json) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK_EQ(connection_id, websocket_id_) << "Mismatched WebSocket ID";

// Parse the json string to get id, method and params.
JSONObject json_object = JSONParse(json);
if (json_object.empty()) {
return SendErrorResponseOverWebSocket(websocket_id_, "Error parsing JSON");
Expand All @@ -221,19 +220,17 @@ void DebugWebServer::OnWebSocketMessage(int connection_id, std::string json) {
return SendErrorResponseOverWebSocket(id.value(), "Missing method");
}
// Parameters are optional.
const base::Value* params_value = json_object.Find(kParamsField);
std::string json_params;
if (json_object.Remove(kParamsField) && params_value->is_dict()) {
JSONObject params;
DCHECK(!params.empty());
json_params = JSONStringify(params);
const base::Value::Dict* params = json_object.FindDict(kParamsField);
if (params && !params->empty()) {
json_params = JSONStringify(*params);
json_object.Remove(kParamsField);
}

if (!debug_client_ || !debug_client_->IsAttached()) {
return SendErrorResponseOverWebSocket(id.value(),
"Debugger is not connected.");
}

debug_client_->SendCommand(*method, json_params,
base::Bind(&DebugWebServer::OnDebuggerResponse,
base::Unretained(this), id.value()));
Expand All @@ -251,8 +248,12 @@ void DebugWebServer::SendErrorResponseOverWebSocket(

void DebugWebServer::OnDebuggerResponse(
int id, const base::Optional<std::string>& response) {
JSONObject response_object = JSONParse(response.value());
DCHECK(!response_object.empty());
std::string parse_error;
JSONObject response_object = JSONParse(response.value(), &parse_error);
DCHECK(parse_error.empty());
if (!parse_error.empty()) {
DLOG(ERROR) << "Parse response error: " << parse_error;
}
response_object.Set(kIdField, id);
server_->SendOverWebSocket(websocket_id_, JSONStringify(response_object),
kNetworkTrafficAnnotation);
Expand Down

0 comments on commit 27c4a5c

Please sign in to comment.