| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/notifications/desktop_notifications_unittest.h" | 5 #include "chrome/browser/notifications/desktop_notifications_unittest.h" |
| 6 | 6 |
| 7 // static | 7 // static |
| 8 const int MockBalloonCollection::kMockBalloonSpace = 5; | 8 const int MockBalloonCollection::kMockBalloonSpace = 5; |
| 9 | 9 |
| 10 // static | 10 // static |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // Create some toasts and then prematurely delete the notification service, | 243 // Create some toasts and then prematurely delete the notification service, |
| 244 // just to make sure nothing crashes/leaks. | 244 // just to make sure nothing crashes/leaks. |
| 245 for (int id = 0; id <= 3; ++id) { | 245 for (int id = 0; id <= 3; ++id) { |
| 246 EXPECT_TRUE(service_->ShowDesktopNotificationText( | 246 EXPECT_TRUE(service_->ShowDesktopNotificationText( |
| 247 GURL("http://www.google.com"), | 247 GURL("http://www.google.com"), |
| 248 GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), | 248 GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), |
| 249 0, 0, DesktopNotificationService::PageNotification, id)); | 249 0, 0, DesktopNotificationService::PageNotification, id)); |
| 250 } | 250 } |
| 251 service_.reset(NULL); | 251 service_.reset(NULL); |
| 252 } | 252 } |
| 253 |
| 254 TEST_F(DesktopNotificationsTest, TestUserInputEscaping) { |
| 255 // Create a test script with some HTML; assert that it doesn't get into the |
| 256 // data:// URL that's produced for the balloon. |
| 257 EXPECT_TRUE(service_->ShowDesktopNotificationText( |
| 258 GURL("http://www.google.com"), |
| 259 GURL("/icon.png"), ASCIIToUTF16("<script>window.alert('uh oh');</script>")
, |
| 260 ASCIIToUTF16("<i>this text is in italics</i>"), |
| 261 0, 0, DesktopNotificationService::PageNotification, 1)); |
| 262 |
| 263 MessageLoopForUI::current()->RunAllPending(); |
| 264 EXPECT_EQ(1, balloon_collection_->count()); |
| 265 Balloon* balloon = (*balloon_collection_->balloons().begin()); |
| 266 GURL data_url = balloon->notification().content_url(); |
| 267 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); |
| 268 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); |
| 269 } |
| 270 |
| OLD | NEW |