| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/render_messages_params.h" | 9 #include "chrome/common/render_messages_params.h" |
| 10 | 10 |
| 11 // static | 11 // static |
| 12 const int MockBalloonCollection::kMockBalloonSpace = 5; | 12 const int MockBalloonCollection::kMockBalloonSpace = 5; |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 std::string DesktopNotificationsTest::log_output_; | 15 std::string DesktopNotificationsTest::log_output_; |
| 16 | 16 |
| 17 void MockBalloonCollection::Add(const Notification& notification, | 17 void MockBalloonCollection::Add(const Notification& notification, |
| 18 Profile* profile) { | 18 Profile* profile) { |
| 19 // Swap in the logging proxy for the purpose of logging calls that | 19 // Swap in a logging proxy for the purpose of logging calls that |
| 20 // would be made into javascript, then pass this down to the | 20 // would be made into javascript, then pass this down to the |
| 21 // balloon collection. | 21 // balloon collection. |
| 22 Notification test_notification(notification.origin_url(), | 22 Notification test_notification( |
| 23 notification.content_url(), | 23 notification.origin_url(), |
| 24 notification.display_source(), | 24 notification.content_url(), |
| 25 string16(), /* replace_id */ | 25 notification.display_source(), |
| 26 log_proxy_.get()); | 26 notification.replace_id(), |
| 27 new LoggingNotificationProxy(notification.notification_id())); |
| 27 BalloonCollectionImpl::Add(test_notification, profile); | 28 BalloonCollectionImpl::Add(test_notification, profile); |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool MockBalloonCollection::Remove(const Notification& notification) { | |
| 31 Notification test_notification(notification.origin_url(), | |
| 32 notification.content_url(), | |
| 33 notification.display_source(), | |
| 34 string16(), /* replace_id */ | |
| 35 log_proxy_.get()); | |
| 36 return BalloonCollectionImpl::Remove(test_notification); | |
| 37 } | |
| 38 | |
| 39 Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification, | 31 Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification, |
| 40 Profile* profile) { | 32 Profile* profile) { |
| 41 // Start with a normal balloon but mock out the view. | 33 // Start with a normal balloon but mock out the view. |
| 42 Balloon* balloon = BalloonCollectionImpl::MakeBalloon(notification, profile); | 34 Balloon* balloon = BalloonCollectionImpl::MakeBalloon(notification, profile); |
| 43 balloon->set_view(new MockBalloonView(balloon)); | 35 balloon->set_view(new MockBalloonView(balloon)); |
| 44 balloons_.push_back(balloon); | 36 balloons_.push_back(balloon); |
| 45 return balloon; | 37 return balloon; |
| 46 } | 38 } |
| 47 | 39 |
| 48 void MockBalloonCollection::OnBalloonClosed(Balloon* source) { | 40 void MockBalloonCollection::OnBalloonClosed(Balloon* source) { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 MessageLoopForUI::current()->RunAllPending(); | 313 MessageLoopForUI::current()->RunAllPending(); |
| 322 EXPECT_EQ(1, balloon_collection_->count()); | 314 EXPECT_EQ(1, balloon_collection_->count()); |
| 323 Balloon* balloon = (*balloon_collection_->balloons().begin()); | 315 Balloon* balloon = (*balloon_collection_->balloons().begin()); |
| 324 GURL data_url = balloon->notification().content_url(); | 316 GURL data_url = balloon->notification().content_url(); |
| 325 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); | 317 EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); |
| 326 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); | 318 EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); |
| 327 // URL-encoded versions of tags should also not be found. | 319 // URL-encoded versions of tags should also not be found. |
| 328 EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e")); | 320 EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e")); |
| 329 EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e")); | 321 EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e")); |
| 330 } | 322 } |
| OLD | NEW |