15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "jingle/notifier/listener/notification_defines.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace notifier { 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NotificationTest : public testing::Test {}; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create a notification with binary data in the data field. 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Converting it to string shouldn't cause a crash. 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(NotificationTest, BinaryData) { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char kNonUtf8Data[] = { '\xff', '\0' }; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(IsStringUTF8(kNonUtf8Data)); 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Notification notification; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) notification.data = kNonUtf8Data; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("{ channel: \"\", data: \"\\u00FF\" }", notification.ToString()); 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace notifier 28