Commit d1996865 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Add AddEntriesMessage::ConvertJSONValue helper

Add a AddEntriesMessage helper to convert the JSON dictionary value of
the addEntries command to an AddEntriesMessage |message|.

In the addEntries command, use that converter to extract the |message|
and also FAIL if the message.volume is an invalid volume type.

Covered by existing FileManager browser tests.

Bug: 833834
Change-Id: Ib7ec56fee7c5b4857ccdfb0155a414430db73e97
Reviewed-on: https://chromium-review.googlesource.com/1042125Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555922}
parent 9a6936e7
...@@ -138,7 +138,14 @@ struct AddEntriesMessage { ...@@ -138,7 +138,14 @@ struct AddEntriesMessage {
// Target volume to add |entries| to. // Target volume to add |entries| to.
TargetVolume volume; TargetVolume volume;
// Registers the member information to the given converter. // Converts |value| to an AddEntriesMessage: true on success.
static bool ConvertJSONValue(const base::DictionaryValue& value,
AddEntriesMessage* message) {
base::JSONValueConverter<AddEntriesMessage> converter;
return converter.Convert(value, message);
}
// Registers AddEntriesMessage member info to the |converter|.
static void RegisterJSONConverter( static void RegisterJSONConverter(
base::JSONValueConverter<AddEntriesMessage>* converter) { base::JSONValueConverter<AddEntriesMessage>* converter) {
converter->RegisterCustomField("volume", &AddEntriesMessage::volume, converter->RegisterCustomField("volume", &AddEntriesMessage::volume,
...@@ -707,10 +714,9 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name, ...@@ -707,10 +714,9 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name,
} }
if (name == "addEntries") { if (name == "addEntries") {
// Add entries to the specified volume. // Add the message.entries to the message.volume.
base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter;
AddEntriesMessage message; AddEntriesMessage message;
ASSERT_TRUE(add_entries_message_converter.Convert(value, &message)); ASSERT_TRUE(AddEntriesMessage::ConvertJSONValue(value, &message));
for (size_t i = 0; i < message.entries.size(); ++i) { for (size_t i = 0; i < message.entries.size(); ++i) {
switch (message.volume) { switch (message.volume) {
...@@ -725,9 +731,6 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name, ...@@ -725,9 +731,6 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name,
if (usb_volume_) if (usb_volume_)
usb_volume_->CreateEntry(*message.entries[i]); usb_volume_->CreateEntry(*message.entries[i]);
break; break;
default:
NOTREACHED();
break;
} }
} }
......
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