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, ...@@ -607,39 +607,39 @@ void FileManagerBrowserTestBase::InstallExtension(const base::FilePath& path,
} }
void FileManagerBrowserTestBase::RunTestMessageLoop() { void FileManagerBrowserTestBase::RunTestMessageLoop() {
// Handle the messages from JavaScript.
// The while loop is break when the test is passed or failed.
FileManagerTestMessageListener listener; FileManagerTestMessageListener listener;
while (true) { while (true) {
FileManagerTestMessageListener::Message entry = listener.GetNextMessage(); auto message = listener.GetNextMessage();
if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_PASSED) {
// Test succeed. if (message.type == extensions::NOTIFICATION_EXTENSION_TEST_PASSED)
break; return; // Test PASSED.
} else if (entry.type == extensions::NOTIFICATION_EXTENSION_TEST_FAILED) { if (message.type == extensions::NOTIFICATION_EXTENSION_TEST_FAILED) {
// Test failed. ADD_FAILURE() << message.message;
ADD_FAILURE() << entry.message; return; // Test FAILED.
break; }
// 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;
} }
// Parse the message value as JSON. // Process the command, reply with the result.
const std::unique_ptr<const base::Value> value = std::string result;
base::JSONReader::Read(entry.message); OnCommand(command, *dictionary, &result);
if (!HasFatalFailure()) {
// If the message is not the expected format, just ignore it. message.function->Reply(result);
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());
continue; continue;
} }
std::string output; // Test FAILED: while processing the command.
OnCommand(name, *message_dictionary, &output); LOG(INFO) << "[FAILED] " << GetTestCaseNameParam();
if (HasFatalFailure()) return;
break;
entry.function->Reply(output);
} }
} }
......
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