diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-23 06:55:22 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-23 06:55:22 +0000 |
commit | ca72ff29277e39031e2b409e2a593b25d0066e8a (patch) | |
tree | bfadc8aeb37312310f8743ae4ff5e9a631c1c625 /dbus/message_unittest.cc | |
parent | f9cb2108d32497ca7688db99f144e0dbe73537da (diff) | |
download | chromium_src-ca72ff29277e39031e2b409e2a593b25d0066e8a.zip chromium_src-ca72ff29277e39031e2b409e2a593b25d0066e8a.tar.gz chromium_src-ca72ff29277e39031e2b409e2a593b25d0066e8a.tar.bz2 |
Change setters of dbus::Message to return false instead of aborting on errors
With this change, we can safely return error for invalid object path and service name.
It still crashes on invalid method name and interface name if we use MethodCall::MethodCall for setting those parameters.
BUG=128967
TEST=dbus_unittests
Review URL: https://chromiumcodereview.appspot.com/10409065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/message_unittest.cc')
-rw-r--r-- | dbus/message_unittest.cc | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc index 9d87c2a..d78d90f2 100644 --- a/dbus/message_unittest.cc +++ b/dbus/message_unittest.cc @@ -565,12 +565,12 @@ TEST(MessageTest, GetAndSetHeaders) { EXPECT_EQ(0U, message->GetSerial()); EXPECT_EQ(0U, message->GetReplySerial()); - message->SetDestination("org.chromium.destination"); - message->SetPath(dbus::ObjectPath("/org/chromium/path")); - message->SetInterface("org.chromium.interface"); - message->SetMember("member"); - message->SetErrorName("org.chromium.error"); - message->SetSender(":1.2"); + EXPECT_TRUE(message->SetDestination("org.chromium.destination")); + EXPECT_TRUE(message->SetPath(dbus::ObjectPath("/org/chromium/path"))); + EXPECT_TRUE(message->SetInterface("org.chromium.interface")); + EXPECT_TRUE(message->SetMember("member")); + EXPECT_TRUE(message->SetErrorName("org.chromium.error")); + EXPECT_TRUE(message->SetSender(":1.2")); message->SetSerial(123); message->SetReplySerial(456); @@ -583,3 +583,33 @@ TEST(MessageTest, GetAndSetHeaders) { EXPECT_EQ(123U, message->GetSerial()); EXPECT_EQ(456U, message->GetReplySerial()); } + +TEST(MessageTest, SetInvalidHeaders) { + scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); + EXPECT_EQ("", message->GetDestination()); + EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); + EXPECT_EQ("", message->GetInterface()); + EXPECT_EQ("", message->GetMember()); + EXPECT_EQ("", message->GetErrorName()); + EXPECT_EQ("", message->GetSender()); + + // Empty element between periods. + EXPECT_FALSE(message->SetDestination("org..chromium")); + // Trailing '/' is only allowed for the root path. + EXPECT_FALSE(message->SetPath(dbus::ObjectPath("/org/chromium/"))); + // Interface name cannot contain '/'. + EXPECT_FALSE(message->SetInterface("org/chromium/interface")); + // Member name cannot begin with a digit. + EXPECT_FALSE(message->SetMember("1member")); + // Error name cannot begin with a period. + EXPECT_FALSE(message->SetErrorName(".org.chromium.error")); + // Disallowed characters. + EXPECT_FALSE(message->SetSender("?!#*")); + + EXPECT_EQ("", message->GetDestination()); + EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); + EXPECT_EQ("", message->GetInterface()); + EXPECT_EQ("", message->GetMember()); + EXPECT_EQ("", message->GetErrorName()); + EXPECT_EQ("", message->GetSender()); +} |