Commit 7b918d9c authored by Ben Wells's avatar Ben Wells Committed by Commit Bot

Remove deprecated base::Values calls from default web app install.

Bug: 906961
Change-Id: I6cdb8bbb17772d0b7c733ccccb46198eeec3e936
Reviewed-on: https://chromium-review.googlesource.com/c/1343474Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Ben Wells <benwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609896}
parent 174f5ac8
...@@ -112,6 +112,15 @@ TEST_F(ScanDirForExternalWebAppsTest, MissingAppUrl) { ...@@ -112,6 +112,15 @@ TEST_F(ScanDirForExternalWebAppsTest, MissingAppUrl) {
EXPECT_EQ(0u, app_infos.size()); EXPECT_EQ(0u, app_infos.size());
} }
TEST_F(ScanDirForExternalWebAppsTest, EmptyAppUrl) {
auto app_infos =
web_app::ScanDirForExternalWebAppsForTesting(test_dir("empty_app_url"));
// The empty_app_url directory contains one JSON file which is correct
// except for an empty "app_url" field.
EXPECT_EQ(0u, app_infos.size());
}
TEST_F(ScanDirForExternalWebAppsTest, InvalidAppUrl) { TEST_F(ScanDirForExternalWebAppsTest, InvalidAppUrl) {
auto app_infos = auto app_infos =
web_app::ScanDirForExternalWebAppsForTesting(test_dir("invalid_app_url")); web_app::ScanDirForExternalWebAppsForTesting(test_dir("invalid_app_url"));
......
...@@ -97,24 +97,23 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(base::FilePath dir) { ...@@ -97,24 +97,23 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(base::FilePath dir) {
continue; continue;
} }
// TODO(benwells): Remove deprecated use of base::DictionaryValue API.
JSONFileValueDeserializer deserializer(file); JSONFileValueDeserializer deserializer(file);
std::string error_msg; std::string error_msg;
std::unique_ptr<base::Value> value = std::unique_ptr<base::Value> dict =
deserializer.Deserialize(nullptr, &error_msg); deserializer.Deserialize(nullptr, &error_msg);
if (!value) { if (!dict) {
LOG(ERROR) << file.value() << " was not valid JSON: " << error_msg; LOG(ERROR) << file.value() << " was not valid JSON: " << error_msg;
continue; continue;
} }
if (value->type() != base::Value::Type::DICTIONARY) { if (dict->type() != base::Value::Type::DICTIONARY) {
LOG(ERROR) << file.value() << " was not a dictionary as the top level"; LOG(ERROR) << file.value() << " was not a dictionary as the top level";
continue; continue;
} }
std::unique_ptr<base::DictionaryValue> dict_value =
base::DictionaryValue::From(std::move(value));
std::string feature_name; base::Value* value =
if (dict_value->GetString(kFeatureName, &feature_name)) { dict->FindKeyOfType(kFeatureName, base::Value::Type::STRING);
if (value) {
std::string feature_name = value->GetString();
VLOG(1) << file.value() << " checking feature " << feature_name; VLOG(1) << file.value() << " checking feature " << feature_name;
if (!IsFeatureEnabled(feature_name)) { if (!IsFeatureEnabled(feature_name)) {
VLOG(1) << file.value() << " feature not enabled"; VLOG(1) << file.value() << " feature not enabled";
...@@ -122,30 +121,34 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(base::FilePath dir) { ...@@ -122,30 +121,34 @@ std::vector<web_app::PendingAppManager::AppInfo> ScanDir(base::FilePath dir) {
} }
} }
std::string app_url_str; value = dict->FindKeyOfType(kAppUrl, base::Value::Type::STRING);
if (!dict_value->GetString(kAppUrl, &app_url_str) || app_url_str.empty()) { if (!value) {
LOG(ERROR) << file.value() << " had an invalid " << kAppUrl; LOG(ERROR) << file.value() << " had a missing " << kAppUrl;
continue; continue;
} }
GURL app_url(app_url_str); GURL app_url(value->GetString());
if (!app_url.is_valid()) { if (!app_url.is_valid()) {
LOG(ERROR) << file.value() << " had an invalid " << kAppUrl; LOG(ERROR) << file.value() << " had an invalid " << kAppUrl;
continue; continue;
} }
bool create_shortcuts = false; bool create_shortcuts = false;
if (dict_value->HasKey(kCreateShortcuts) && value = dict->FindKey(kCreateShortcuts);
!dict_value->GetBoolean(kCreateShortcuts, &create_shortcuts)) { if (value) {
if (!value->is_bool()) {
LOG(ERROR) << file.value() << " had an invalid " << kCreateShortcuts; LOG(ERROR) << file.value() << " had an invalid " << kCreateShortcuts;
continue; continue;
} }
create_shortcuts = value->GetBool();
}
auto launch_container = web_app::LaunchContainer::kTab; value = dict->FindKeyOfType(kLaunchContainer, base::Value::Type::STRING);
std::string launch_container_str; if (!value) {
if (!dict_value->GetString(kLaunchContainer, &launch_container_str)) {
LOG(ERROR) << file.value() << " had an invalid " << kLaunchContainer; LOG(ERROR) << file.value() << " had an invalid " << kLaunchContainer;
continue; continue;
} }
std::string launch_container_str = value->GetString();
auto launch_container = web_app::LaunchContainer::kTab;
if (launch_container_str == kLaunchContainerTab) { if (launch_container_str == kLaunchContainerTab) {
launch_container = web_app::LaunchContainer::kTab; launch_container = web_app::LaunchContainer::kTab;
} else if (launch_container_str == kLaunchContainerWindow) { } else if (launch_container_str == kLaunchContainerWindow) {
......
{
"app_url": "",
"create_shortcuts": true,
"launch_container": "tab"
}
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