Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: ui/aura/mus/property_converter_unittest.cc

Issue 2702423004: Validate incoming window properties. (Closed)
Patch Set: sky comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/mus/property_converter.cc ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/property_converter_unittest.cc
diff --git a/ui/aura/mus/property_converter_unittest.cc b/ui/aura/mus/property_converter_unittest.cc
index e39c827a37427e5328f714eb8539e7fe202a41fb..c5c28ed0ee1bd42846f8e8ad5bcb0c91c598f334 100644
--- a/ui/aura/mus/property_converter_unittest.cc
+++ b/ui/aura/mus/property_converter_unittest.cc
@@ -77,7 +77,8 @@ void TestPrimitiveProperty(PropertyConverter* property_converter,
const char* transport_name,
T value_1,
T value_2) {
- property_converter->RegisterProperty(key, transport_name);
+ property_converter->RegisterProperty(
+ key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback());
EXPECT_EQ(transport_name,
property_converter->GetTransportNameForPropertyKey(key));
EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name));
@@ -112,6 +113,10 @@ void TestPrimitiveProperty(PropertyConverter* property_converter,
EXPECT_EQ(value_2, static_cast<T>(decoded_value_2));
}
+bool OnlyAllowNegativeNumbers(int64_t number) {
+ return number < 0;
+}
+
} // namespace
using PropertyConverterTest = test::AuraTestBase;
@@ -165,6 +170,30 @@ TEST_F(PropertyConverterTest, PrimitiveProperties) {
kTestPropertyServerKey9, value_9a, value_9b);
}
+TEST_F(PropertyConverterTest, TestPrimitiveVerifier) {
+ std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
+
+ PropertyConverter property_converter;
+ property_converter.RegisterProperty(kTestPropertyKey8,
+ kTestPropertyServerKey8,
+ base::Bind(&OnlyAllowNegativeNumbers));
+
+ // Test that we reject invalid TransportValues during
+ // GetPropertyValueFromTransportValue().
+ int64_t int_value = 5;
+ std::vector<uint8_t> transport =
+ mojo::ConvertTo<std::vector<uint8_t>>(int_value);
+ EXPECT_FALSE(property_converter.GetPropertyValueFromTransportValue(
+ kTestPropertyServerKey8, transport, &int_value));
+
+ // Test that we reject invalid TransportValues during
+ // SetPropertyFromTransportValue().
+ EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8));
+ property_converter.SetPropertyFromTransportValue(
+ window.get(), kTestPropertyServerKey8, &transport);
+ EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8));
+}
+
// Verifies property setting behavior for a gfx::ImageSkia* property.
TEST_F(PropertyConverterTest, ImageSkiaProperty) {
PropertyConverter property_converter;
« no previous file with comments | « ui/aura/mus/property_converter.cc ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698