-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds round trip fuzz testing for desk templates. TESED: desk_template_fuzzer Bug: b/228367971 Change-Id: I16d2c120d072bb7d2113afff76e9be9206de2877 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4804063 Commit-Queue: Avynn Donaghe <avynn@google.com> Reviewed-by: Yanzhu Du <yzd@google.com> Cr-Commit-Position: refs/heads/main@{#1187466}
- Loading branch information
avynn
authored and
Chromium LUCI CQ
committed
Aug 23, 2023
1 parent
8e6b882
commit af8cfb9
Showing
8 changed files
with
195 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/json/json_string_value_serializer.h" | ||
#include "components/account_id/account_id.h" | ||
#include "components/desks_storage/core/desk_template_conversion.h" | ||
#include "components/desks_storage/core/desk_template_util.h" | ||
#include "components/desks_storage/core/desk_test_util.h" | ||
#include "components/services/app_service/public/cpp/app_registry_cache.h" | ||
#include "components/sync/protocol/workspace_desk_specifics.pb.h" | ||
#include "testing/libfuzzer/proto/lpm_interface.h" | ||
|
||
namespace desks_storage { | ||
|
||
// Attempts to parse proto from fuzz data, if succeeds verifies semantic | ||
// equivalency between the various formats. | ||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | ||
// parse string into value. | ||
std::string str = std::string(reinterpret_cast<const char*>(data), size); | ||
std::string error_message; | ||
int error_code; | ||
std::unique_ptr<base::Value> desk_template_value = | ||
JSONStringValueDeserializer(str).Deserialize(&error_code, &error_message); | ||
|
||
if (desk_template_value == nullptr) { | ||
return 0; | ||
} | ||
|
||
// Init dependencies for conversion. | ||
AccountId account_id; | ||
std::unique_ptr<apps::AppRegistryCache> apps_cache = | ||
std::make_unique<apps::AppRegistryCache>(); | ||
desk_test_util::PopulateAppRegistryCache(account_id, apps_cache.get()); | ||
|
||
desk_template_conversion::ParseSavedDeskResult desk_template_result = | ||
desk_template_conversion::ParseDeskTemplateFromBaseValue( | ||
*desk_template_value, ash::DeskTemplateSource::kUser); | ||
|
||
if (!desk_template_result.has_value()) { | ||
return 0; | ||
} | ||
|
||
std::unique_ptr<ash::DeskTemplate> desk_template = | ||
std::move(desk_template_result.value()); | ||
|
||
// Round trip for sync protos. | ||
sync_pb::WorkspaceDeskSpecifics template_to_proto = | ||
desk_template_conversion::ToSyncProto(desk_template.get(), | ||
apps_cache.get()); | ||
std::unique_ptr<ash::DeskTemplate> proto_to_template = | ||
desk_template_conversion::FromSyncProto(template_to_proto); | ||
|
||
CHECK(desk_template_util::AreDeskTemplatesEqual(desk_template.get(), | ||
proto_to_template.get())); | ||
|
||
// Round trip for JSON format. | ||
base::Value template_to_value = | ||
desk_template_conversion::SerializeDeskTemplateAsBaseValue( | ||
desk_template.get(), apps_cache.get()); | ||
desk_template_conversion::ParseSavedDeskResult parse_result = | ||
desk_template_conversion::ParseDeskTemplateFromBaseValue( | ||
template_to_value, desk_template->source()); | ||
|
||
CHECK(parse_result.has_value()); | ||
CHECK(desk_template_util::AreDeskTemplatesEqual(desk_template.get(), | ||
parse_result.value().get())); | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace desks_storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"auto_launch_on_startup": false, | ||
"version": 1, | ||
"uuid": "040b6112-67f2-4d3c-8ba8-53a117272eba", | ||
"name": "BrowserTest", | ||
"created_time_usec": "1633535632", | ||
"updated_time_usec": "1633535632", | ||
"desk_type": "TEMPLATE", | ||
"desk": { | ||
"apps": [ | ||
{ | ||
"window_bound": { | ||
"left": 0, | ||
"top": 1, | ||
"height": 121, | ||
"width": 120 | ||
}, | ||
"window_state": "NORMAL", | ||
"z_index": 1, | ||
"app_type": "BROWSER", | ||
"tabs": [ | ||
{ | ||
"url": "https://example.com/" | ||
}, | ||
{ | ||
"url": "https://example.com/2" | ||
} | ||
], | ||
"tab_groups": [ | ||
{ | ||
"first_index": 1, | ||
"last_index": 2, | ||
"title": "sample_tab_group", | ||
"color": "GREY", | ||
"is_collapsed": false | ||
} | ||
], | ||
"active_tab_index": 1, | ||
"first_non_pinned_tab_index": 1, | ||
"window_id": 0, | ||
"display_id": "100", | ||
"event_flag": 0 | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"auto_launch_on_startup": false,"version":1,"uuid":"040b6112-67f2-4d3c-8ba8-53a117272eba","name":"BrowserTest","created_time_usec":"1633535632","updated_time_usec":"1633535632","desk_type":"TEMPLATE","desk":{"apps":[{"window_bound":{"left":0,"top":1,"height":121,"width":120},"window_state":"MINIMIZED","z_index":1,"app_type":"BROWSER","tabs":[{"url":"https://example.com/"},{"url":"https://example.com/2"}],"tab_groups":[{"first_index":1,"last_index":2,"title":"sample_tab_group","color":"GREY","is_collapsed":false}],"active_tab_index":1,"first_non_pinned_tab_index":1,"window_id":0,"display_id":"100","event_flag":0,"pre_minimized_window_state":"NORMAL"}]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"auto_launch_on_startup": false,"version":1,"uuid":"7f4b7ff0-970a-41bb-aa91-f6c3e2724207","name":"ChromeAppTest","created_time_usec":"1633535632000","updated_time_usec": "1633535632","desk_type":"SAVE_AND_RECALL","desk":{"apps":[{"window_bound":{"left":200,"top":200,"height":1000,"width":1000},"window_state":"PRIMARY_SNAPPED","z_index":2,"app_type":"CHROME_APP","app_id":"test_chrome_app_1","window_id":0,"display_id":"100","event_flag":0, "snap_percent":75,"override_url":"https://example.com/"},{"window_bound":{"left":0,"top":0,"height":120,"width":120},"window_state":"NORMAL","z_index":1,"app_type":"CHROME_APP","app_id":"test_pwa_app_1","window_id":1,"display_id":"100","event_flag":0,"override_url":"https://example.com/"}]}} |