Commit 974cda70 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Use better variable names in RunTestMessageLoop

The message loop processes chrome.test messages: PASS, FAIL, and named
command _messages_ sent from the test extension.

Rename |entry| to |message|. Use auto where useful and add commentary.
No change in behavior, no new tests.

Tbr: slangley, yamaguchi
No-Presubmit: true
Bug: 833834
Change-Id: Ieacf994cd1cc9fb7004ef24dd869b3ce9d288c18
Reviewed-on: https://chromium-review.googlesource.com/1034617
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554944}
parent 598ee78d
......@@ -607,39 +607,39 @@ void FileManagerBrowserTestBase::InstallExtension(const base::FilePath& path,
}
void FileManagerBrowserTestBase::RunTestMessageLoop() {
// Handle the messages from JavaScript.
// The while loop is break when the test is passed or failed.
FileManagerTestMessageListener listener;
while (true) {
FileManagerTestMessageListener::Message entry = listener.GetNextMessage();
if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_PASSED) {
// Test succeed.
break;
} else if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_FAILED) {
// Test failed.
ADD_FAILURE() << entry.message;
break;
}
auto message = listener.GetNextMessage();
// Parse the message value as JSON.
const std::unique_ptr<const base::Value> value =
base::JSONReader::Read(entry.message);
if (message.type == extensions::NOTIFICATION_EXTENSION_TEST_PASSED)
return; // Test PASSED.
if (message.type == extensions::NOTIFICATION_EXTENSION_TEST_FAILED) {
ADD_FAILURE() << message.message;
return; // Test FAILED.
}
// If the message is not the expected format, just ignore it.
const base::DictionaryValue* message_dictionary = NULL;
std::string name;
if (!value || !value->GetAsDictionary(&message_dictionary) ||
!message_dictionary->GetString("name", &name)) {
entry.function->Reply(std::string());
// If the message in JSON format has no command, just ignore it.
const auto json = base::JSONReader::Read(message.message);
const base::DictionaryValue* dictionary = nullptr;
std::string command;
if (!json || !json->GetAsDictionary(&dictionary) ||
!dictionary->GetString("name", &command)) {
message.function->Reply(std::string());
continue;
}
std::string output;
OnCommand(name, *message_dictionary, &output);
if (HasFatalFailure())
break;
// Process the command, reply with the result.
std::string result;
OnCommand(command, *dictionary, &result);
if (!HasFatalFailure()) {
message.function->Reply(result);
continue;
}
entry.function->Reply(output);
// Test FAILED: while processing the command.
LOG(INFO) << "[FAILED] " << GetTestCaseNameParam();
return;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment