| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prefs/testing_pref_service.h" | 7 #include "base/prefs/testing_pref_service.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 10 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 ui::TerminateContextFactoryForTests(); | 138 ui::TerminateContextFactoryForTests(); |
| 139 #endif | 139 #endif |
| 140 ui::ShutdownInputMethodForTesting(); | 140 ui::ShutdownInputMethodForTesting(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 content::ShowDesktopNotificationHostMsgParams | 143 content::ShowDesktopNotificationHostMsgParams |
| 144 DesktopNotificationsTest::StandardTestNotification() { | 144 DesktopNotificationsTest::StandardTestNotification() { |
| 145 content::ShowDesktopNotificationHostMsgParams params; | 145 content::ShowDesktopNotificationHostMsgParams params; |
| 146 params.notification_id = 0; | 146 params.notification_id = 0; |
| 147 params.origin = GURL("http://www.google.com"); | 147 params.origin = GURL("http://www.google.com"); |
| 148 params.is_html = false; | |
| 149 params.icon_url = GURL("/icon.png"); | 148 params.icon_url = GURL("/icon.png"); |
| 150 params.title = ASCIIToUTF16("Title"); | 149 params.title = ASCIIToUTF16("Title"); |
| 151 params.body = ASCIIToUTF16("Text"); | 150 params.body = ASCIIToUTF16("Text"); |
| 152 params.direction = blink::WebTextDirectionDefault; | 151 params.direction = blink::WebTextDirectionDefault; |
| 153 return params; | 152 return params; |
| 154 } | 153 } |
| 155 | 154 |
| 156 TEST_F(DesktopNotificationsTest, TestShow) { | 155 TEST_F(DesktopNotificationsTest, TestShow) { |
| 157 content::ShowDesktopNotificationHostMsgParams params = | 156 content::ShowDesktopNotificationHostMsgParams params = |
| 158 StandardTestNotification(); | 157 StandardTestNotification(); |
| 159 params.notification_id = 1; | 158 params.notification_id = 1; |
| 160 | 159 |
| 161 EXPECT_TRUE(service_->ShowDesktopNotification( | 160 EXPECT_TRUE(service_->ShowDesktopNotification( |
| 162 params, 0, 0, DesktopNotificationService::PageNotification)); | 161 params, 0, 0, DesktopNotificationService::PageNotification)); |
| 163 base::MessageLoopForUI::current()->RunUntilIdle(); | 162 base::MessageLoopForUI::current()->RunUntilIdle(); |
| 164 EXPECT_EQ(1, balloon_collection_->count()); | 163 EXPECT_EQ(1, balloon_collection_->count()); |
| 165 | 164 |
| 166 content::ShowDesktopNotificationHostMsgParams params2; | 165 content::ShowDesktopNotificationHostMsgParams params2 = |
| 166 StandardTestNotification(); |
| 167 params2.notification_id = 2; |
| 167 params2.origin = GURL("http://www.google.com"); | 168 params2.origin = GURL("http://www.google.com"); |
| 168 params2.is_html = true; | 169 params2.body = ASCIIToUTF16("Text"); |
| 169 params2.contents_url = GURL("http://www.google.com/notification.html"); | |
| 170 params2.notification_id = 2; | |
| 171 | 170 |
| 172 EXPECT_TRUE(service_->ShowDesktopNotification( | 171 EXPECT_TRUE(service_->ShowDesktopNotification( |
| 173 params2, 0, 0, DesktopNotificationService::PageNotification)); | 172 params2, 0, 0, DesktopNotificationService::PageNotification)); |
| 174 base::MessageLoopForUI::current()->RunUntilIdle(); | 173 base::MessageLoopForUI::current()->RunUntilIdle(); |
| 175 EXPECT_EQ(2, balloon_collection_->count()); | 174 EXPECT_EQ(2, balloon_collection_->count()); |
| 176 | 175 |
| 177 EXPECT_EQ("notification displayed\n" | 176 EXPECT_EQ("notification displayed\n" |
| 178 "notification displayed\n", | 177 "notification displayed\n", |
| 179 log_output_); | 178 log_output_); |
| 180 } | 179 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 EXPECT_LE(top, last_top - balloon_collection_->MinHeight()); | 246 EXPECT_LE(top, last_top - balloon_collection_->MinHeight()); |
| 248 last_top = top; | 247 last_top = top; |
| 249 } | 248 } |
| 250 | 249 |
| 251 EXPECT_EQ(expected_log, log_output_); | 250 EXPECT_EQ(expected_log, log_output_); |
| 252 } | 251 } |
| 253 | 252 |
| 254 TEST_F(DesktopNotificationsTest, TestVariableSize) { | 253 TEST_F(DesktopNotificationsTest, TestVariableSize) { |
| 255 content::ShowDesktopNotificationHostMsgParams params; | 254 content::ShowDesktopNotificationHostMsgParams params; |
| 256 params.origin = GURL("http://long.google.com"); | 255 params.origin = GURL("http://long.google.com"); |
| 257 params.is_html = false; | |
| 258 params.icon_url = GURL("/icon.png"); | 256 params.icon_url = GURL("/icon.png"); |
| 259 params.title = ASCIIToUTF16("Really Really Really Really Really Really " | 257 params.title = ASCIIToUTF16("Really Really Really Really Really Really " |
| 260 "Really Really Really Really Really Really " | 258 "Really Really Really Really Really Really " |
| 261 "Really Really Really Really Really Really " | 259 "Really Really Really Really Really Really " |
| 262 "Really Long Title"), | 260 "Really Long Title"), |
| 263 params.body = ASCIIToUTF16("Text"); | 261 params.body = ASCIIToUTF16("Text"); |
| 264 params.notification_id = 0; | 262 params.notification_id = 0; |
| 265 | 263 |
| 266 std::string expected_log; | 264 std::string expected_log; |
| 267 // Create some toasts. After each but the first, make sure there | 265 // Create some toasts. After each but the first, make sure there |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 565 } |
| 568 | 566 |
| 569 // Now change the position to upper left. Confirm that the X value for the | 567 // Now change the position to upper left. Confirm that the X value for the |
| 570 // balloons gets smaller. | 568 // balloons gets smaller. |
| 571 local_state_.SetInteger(prefs::kDesktopNotificationPosition, | 569 local_state_.SetInteger(prefs::kDesktopNotificationPosition, |
| 572 BalloonCollection::UPPER_LEFT); | 570 BalloonCollection::UPPER_LEFT); |
| 573 | 571 |
| 574 int current_x = (*balloons.begin())->GetPosition().x(); | 572 int current_x = (*balloons.begin())->GetPosition().x(); |
| 575 EXPECT_LT(current_x, last_x); | 573 EXPECT_LT(current_x, last_x); |
| 576 } | 574 } |
| OLD | NEW |