Commit cfc9d280 authored by John Chen's avatar John Chen Committed by Commit Bot

[Offline Pages] Update Generate Page Bundle handler for testability

Update the handler for Generate Page Bundle button, so that output
text has information needed by UI automation test.

Bug: 794011
Change-Id: I67894eab2fac59cb0368e5dda53552bb889a0009
Reviewed-on: https://chromium-review.googlesource.com/823210Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Commit-Queue: John Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524589}
parent d49ccee4
......@@ -12,6 +12,7 @@
#include "base/bind.h"
#include "base/guid.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
......@@ -323,8 +324,18 @@ void OfflineInternalsUIMessageHandler::HandleGeneratePageBundle(
prefetch_service_->GetPrefetchDispatcher()->AddCandidatePrefetchURLs(
offline_pages::kSuggestedArticlesNamespace, prefetch_urls);
ResolveJavascriptCallback(base::Value(callback_id),
base::Value("Added candidate URLs."));
std::string message("Added candidate URLs.\n");
// Construct a JSON array containing all the URLs. To guard against malicious
// URLs that might contain special characters, we create a ListValue and then
// serialize it into JSON, instead of doing direct string manipulation.
base::ListValue urls;
for (const auto& prefetch_url : prefetch_urls) {
urls.GetList().emplace_back(prefetch_url.url.spec());
}
std::string json;
base::JSONWriter::Write(urls, &json);
message.append(json);
ResolveJavascriptCallback(base::Value(callback_id), base::Value(message));
}
void OfflineInternalsUIMessageHandler::HandleGetOperation(
......
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