| 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 <deque> | 5 #include <deque> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | |
| 11 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 14 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 16 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/notifications/balloon.h" | 18 #include "chrome/browser/notifications/balloon.h" |
| 20 #include "chrome/browser/notifications/balloon_collection.h" | 19 #include "chrome/browser/notifications/balloon_collection.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 38 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
| 39 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
| 42 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
| 43 #include "googleurl/src/gurl.h" | 42 #include "googleurl/src/gurl.h" |
| 44 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
| 45 #include "net/test/spawned_test_server/spawned_test_server.h" | 44 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "ui/base/window_open_disposition.h" | 46 #include "ui/base/window_open_disposition.h" |
| 48 #include "ui/message_center/message_center.h" | |
| 49 #include "ui/message_center/message_center_observer.h" | |
| 50 #include "ui/message_center/message_center_switches.h" | |
| 51 #include "ui/message_center/message_center_util.h" | |
| 52 | 47 |
| 53 // TODO(kbr): remove: http://crbug.com/222296 | 48 // TODO(kbr): remove: http://crbug.com/222296 |
| 54 #if defined(OS_MACOSX) | 49 #if defined(OS_MACOSX) |
| 55 #import "base/mac/mac_util.h" | 50 #import "base/mac/mac_util.h" |
| 56 #endif | 51 #endif |
| 57 | 52 |
| 53 #if defined(ENABLE_MESSAGE_CENTER) |
| 54 #include "base/command_line.h" |
| 55 #include "ui/message_center/message_center.h" |
| 56 #include "ui/message_center/message_center_observer.h" |
| 57 #include "ui/message_center/message_center_switches.h" |
| 58 #endif |
| 59 |
| 60 // Mac implementation of message_center is incomplete. The code builds, but |
| 61 // the tests do not pass <http://crbug.com/179904>. |
| 62 #if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX) |
| 63 #define ENABLE_MESSAGE_CENTER_TESTING 1 |
| 64 #else |
| 65 #define ENABLE_MESSAGE_CENTER_TESTING 0 |
| 66 #endif |
| 67 |
| 58 namespace { | 68 namespace { |
| 59 | 69 |
| 60 const char kExpectedIconUrl[] = "files/notifications/no_such_file.png"; | 70 const char kExpectedIconUrl[] = "files/notifications/no_such_file.png"; |
| 61 | 71 |
| 62 enum InfobarAction { | 72 enum InfobarAction { |
| 63 DISMISS = 0, | 73 DISMISS = 0, |
| 64 ALLOW, | 74 ALLOW, |
| 65 DENY, | 75 DENY, |
| 66 }; | 76 }; |
| 67 | 77 |
| 68 class NotificationChangeObserver { | 78 #if ENABLE_MESSAGE_CENTER_TESTING |
| 69 public: | |
| 70 virtual ~NotificationChangeObserver() {} | |
| 71 virtual bool Wait() = 0; | |
| 72 }; | |
| 73 | |
| 74 class MessageCenterChangeObserver | 79 class MessageCenterChangeObserver |
| 75 : public message_center::MessageCenterObserver, | 80 : public message_center::MessageCenterObserver { |
| 76 public NotificationChangeObserver { | |
| 77 public: | 81 public: |
| 78 MessageCenterChangeObserver() | 82 MessageCenterChangeObserver() |
| 79 : notification_received_(false) { | 83 : notification_received_(false) { |
| 80 message_center::MessageCenter::Get()->AddObserver(this); | 84 message_center::MessageCenter::Get()->AddObserver(this); |
| 81 } | 85 } |
| 82 | 86 |
| 83 virtual ~MessageCenterChangeObserver() { | 87 virtual ~MessageCenterChangeObserver() { |
| 84 message_center::MessageCenter::Get()->RemoveObserver(this); | 88 message_center::MessageCenter::Get()->RemoveObserver(this); |
| 85 } | 89 } |
| 86 | 90 |
| 87 // NotificationChangeObserver: | 91 bool Wait() { |
| 88 virtual bool Wait() OVERRIDE { | |
| 89 if (notification_received_) | 92 if (notification_received_) |
| 90 return true; | 93 return true; |
| 91 | 94 |
| 92 message_loop_runner_ = new content::MessageLoopRunner; | 95 message_loop_runner_ = new content::MessageLoopRunner; |
| 93 message_loop_runner_->Run(); | 96 message_loop_runner_->Run(); |
| 94 return notification_received_; | 97 return notification_received_; |
| 95 } | 98 } |
| 96 | 99 |
| 97 // message_center::MessageCenterObserver: | 100 // overridden from message_center::MessageCenterObserver: |
| 98 virtual void OnNotificationAdded( | 101 virtual void OnNotificationAdded( |
| 99 const std::string& notification_id) OVERRIDE { | 102 const std::string& notification_id) OVERRIDE { |
| 100 OnMessageCenterChanged(); | 103 OnMessageCenterChanged(); |
| 101 } | 104 } |
| 102 | |
| 103 virtual void OnNotificationRemoved(const std::string& notification_id, | 105 virtual void OnNotificationRemoved(const std::string& notification_id, |
| 104 bool by_user) OVERRIDE { | 106 bool by_user) OVERRIDE { |
| 105 OnMessageCenterChanged(); | 107 OnMessageCenterChanged(); |
| 106 } | 108 } |
| 107 | |
| 108 virtual void OnNotificationUpdated( | 109 virtual void OnNotificationUpdated( |
| 109 const std::string& notification_id) OVERRIDE { | 110 const std::string& notification_id) OVERRIDE { |
| 110 OnMessageCenterChanged(); | 111 OnMessageCenterChanged(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void OnMessageCenterChanged() { | 114 void OnMessageCenterChanged() { |
| 114 notification_received_ = true; | 115 notification_received_ = true; |
| 115 if (message_loop_runner_) | 116 if (message_loop_runner_) |
| 116 message_loop_runner_->Quit(); | 117 message_loop_runner_->Quit(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool notification_received_; | 120 bool notification_received_; |
| 120 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 121 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 121 | 122 |
| 122 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); | 123 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 class NotificationBalloonChangeObserver | 126 typedef MessageCenterChangeObserver NotificationChangeObserver; |
| 126 : public content::NotificationObserver, | 127 |
| 127 public NotificationChangeObserver { | 128 #else |
| 129 |
| 130 class NotificationBalloonChangeObserver : public content::NotificationObserver { |
| 128 public: | 131 public: |
| 129 NotificationBalloonChangeObserver() | 132 NotificationBalloonChangeObserver() |
| 130 : collection_(BalloonNotificationUIManager::GetInstanceForTesting()-> | 133 : collection_(BalloonNotificationUIManager::GetInstanceForTesting()-> |
| 131 balloon_collection()), | 134 balloon_collection()), |
| 132 collection_changed_(false), | 135 collection_changed_(false), |
| 133 notification_received_(false), | 136 notification_received_(false), |
| 134 running_(false), | 137 running_(false), |
| 135 done_(false) { | 138 done_(false) { |
| 136 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, | 139 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, |
| 137 content::NotificationService::AllSources()); | 140 content::NotificationService::AllSources()); |
| 138 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, | 141 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, |
| 139 content::NotificationService::AllSources()); | 142 content::NotificationService::AllSources()); |
| 140 collection_->set_on_collection_changed_callback( | 143 collection_->set_on_collection_changed_callback( |
| 141 base::Bind(&NotificationBalloonChangeObserver::OnCollectionChanged, | 144 base::Bind(&NotificationBalloonChangeObserver::OnCollectionChanged, |
| 142 base::Unretained(this))); | 145 base::Unretained(this))); |
| 143 } | 146 } |
| 144 | 147 |
| 145 virtual ~NotificationBalloonChangeObserver() { | 148 virtual ~NotificationBalloonChangeObserver() { |
| 146 collection_->set_on_collection_changed_callback(base::Closure()); | 149 collection_->set_on_collection_changed_callback(base::Closure()); |
| 147 } | 150 } |
| 148 | 151 |
| 149 // NotificationChangeObserver: | 152 bool Wait() { |
| 150 virtual bool Wait() OVERRIDE { | |
| 151 if (!Check()) { | 153 if (!Check()) { |
| 152 running_ = true; | 154 running_ = true; |
| 153 message_loop_runner_ = new content::MessageLoopRunner; | 155 message_loop_runner_ = new content::MessageLoopRunner; |
| 154 message_loop_runner_->Run(); | 156 message_loop_runner_->Run(); |
| 155 EXPECT_TRUE(done_); | 157 EXPECT_TRUE(done_); |
| 156 } | 158 } |
| 157 return done_; | 159 return done_; |
| 158 } | 160 } |
| 159 | 161 |
| 160 bool Check() { | 162 bool Check() { |
| 161 if (done_) | 163 if (done_) |
| 162 return true; | 164 return true; |
| 163 | 165 |
| 164 if (collection_changed_ && notification_received_) { | 166 if (collection_changed_ && notification_received_) { |
| 165 done_ = true; | 167 done_ = true; |
| 166 if (running_) { | 168 if (running_) { |
| 167 message_loop_runner_->Quit(); | 169 message_loop_runner_->Quit(); |
| 168 running_ = false; | 170 running_ = false; |
| 169 } | 171 } |
| 170 } | 172 } |
| 171 return done_; | 173 return done_; |
| 172 } | 174 } |
| 173 | 175 |
| 174 void OnCollectionChanged() { | 176 void OnCollectionChanged() { |
| 175 collection_changed_ = true; | 177 collection_changed_ = true; |
| 176 Check(); | 178 Check(); |
| 177 } | 179 } |
| 178 | 180 |
| 179 // content::NotificationObserver: | 181 // Overridden from content::NotificationObserver: |
| 180 virtual void Observe(int type, | 182 virtual void Observe(int type, |
| 181 const content::NotificationSource& source, | 183 const content::NotificationSource& source, |
| 182 const content::NotificationDetails& details) OVERRIDE { | 184 const content::NotificationDetails& details) OVERRIDE { |
| 183 DCHECK(type == chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED || | 185 DCHECK(type == chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED || |
| 184 type == chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED); | 186 type == chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED); |
| 185 notification_received_ = true; | 187 notification_received_ = true; |
| 186 Check(); | 188 Check(); |
| 187 } | 189 } |
| 188 | 190 |
| 189 private: | 191 private: |
| 190 content::NotificationRegistrar registrar_; | 192 content::NotificationRegistrar registrar_; |
| 191 BalloonCollection* collection_; | 193 BalloonCollection* collection_; |
| 192 | 194 |
| 193 bool collection_changed_; | 195 bool collection_changed_; |
| 194 bool notification_received_; | 196 bool notification_received_; |
| 195 bool running_; | 197 bool running_; |
| 196 bool done_; | 198 bool done_; |
| 197 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 199 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 198 | 200 |
| 199 DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); | 201 DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); |
| 200 }; | 202 }; |
| 201 | 203 |
| 204 typedef NotificationBalloonChangeObserver NotificationChangeObserver; |
| 205 |
| 206 #endif // ENABLE_MESSAGE_CENTER |
| 207 |
| 202 } // namespace | 208 } // namespace |
| 203 | 209 |
| 204 class NotificationsTest : public InProcessBrowserTest { | 210 class NotificationsTest : public InProcessBrowserTest { |
| 205 public: | 211 public: |
| 206 NotificationsTest() {} | 212 NotificationsTest() {} |
| 207 | 213 |
| 208 protected: | 214 protected: |
| 209 // Overriden from InProcessBrowserTest: | 215 // Overriden from InProcessBrowserTest: |
| 210 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | 216 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; |
| 211 | 217 |
| 212 int GetNotificationCount(); | 218 int GetNotificationCount(); |
| 213 | 219 |
| 214 NotificationChangeObserver* CreateObserver(); | |
| 215 | |
| 216 void CloseBrowserWindow(Browser* browser); | 220 void CloseBrowserWindow(Browser* browser); |
| 217 void CrashTab(Browser* browser, int index); | 221 void CrashTab(Browser* browser, int index); |
| 222 #if ENABLE_MESSAGE_CENTER_TESTING |
| 223 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; |
| 224 #else |
| 218 const std::deque<Balloon*>& GetActiveBalloons(); | 225 const std::deque<Balloon*>& GetActiveBalloons(); |
| 219 void CrashNotification(Balloon* balloon); | 226 void CrashNotification(Balloon* balloon); |
| 220 bool CloseNotificationAndWait(const Notification& notification); | 227 bool CloseNotificationAndWait(const Notification& notification); |
| 228 #endif |
| 221 | 229 |
| 222 void SetDefaultPermissionSetting(ContentSetting setting); | 230 void SetDefaultPermissionSetting(ContentSetting setting); |
| 223 void DenyOrigin(const GURL& origin); | 231 void DenyOrigin(const GURL& origin); |
| 224 void AllowOrigin(const GURL& origin); | 232 void AllowOrigin(const GURL& origin); |
| 225 void AllowAllOrigins(); | 233 void AllowAllOrigins(); |
| 226 | 234 |
| 227 void VerifyInfobar(const Browser* browser, int index); | 235 void VerifyInfobar(const Browser* browser, int index); |
| 228 std::string CreateNotification(Browser* browser, | 236 std::string CreateNotification(Browser* browser, |
| 229 bool wait_for_new_balloon, | 237 bool wait_for_new_balloon, |
| 230 const char* icon, | 238 const char* icon, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 255 void NotificationsTest::SetUpInProcessBrowserTestFixture() { | 263 void NotificationsTest::SetUpInProcessBrowserTestFixture() { |
| 256 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 264 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 257 | 265 |
| 258 ASSERT_TRUE(test_server()->Start()); | 266 ASSERT_TRUE(test_server()->Start()); |
| 259 empty_page_url_ = test_server()->GetURL("files/empty.html"); | 267 empty_page_url_ = test_server()->GetURL("files/empty.html"); |
| 260 test_page_url_ = test_server()->GetURL( | 268 test_page_url_ = test_server()->GetURL( |
| 261 "files/notifications/notification_tester.html"); | 269 "files/notifications/notification_tester.html"); |
| 262 } | 270 } |
| 263 | 271 |
| 264 int NotificationsTest::GetNotificationCount() { | 272 int NotificationsTest::GetNotificationCount() { |
| 265 if (message_center::IsRichNotificationEnabled()) { | 273 #if ENABLE_MESSAGE_CENTER_TESTING |
| 266 return message_center::MessageCenter::Get()->NotificationCount(); | 274 return message_center::MessageCenter::Get()->NotificationCount(); |
| 267 } else { | 275 #else |
| 268 return BalloonNotificationUIManager::GetInstanceForTesting()-> | 276 return BalloonNotificationUIManager::GetInstanceForTesting()-> |
| 269 balloon_collection()->GetActiveBalloons().size(); | 277 balloon_collection()->GetActiveBalloons().size(); |
| 270 } | 278 #endif // ENABLE_MESSAGE_CENTER_TESTING |
| 271 } | |
| 272 | |
| 273 NotificationChangeObserver* NotificationsTest::CreateObserver() { | |
| 274 if (message_center::IsRichNotificationEnabled()) | |
| 275 return new MessageCenterChangeObserver(); | |
| 276 else | |
| 277 return new NotificationBalloonChangeObserver(); | |
| 278 } | 279 } |
| 279 | 280 |
| 280 void NotificationsTest::CloseBrowserWindow(Browser* browser) { | 281 void NotificationsTest::CloseBrowserWindow(Browser* browser) { |
| 281 content::WindowedNotificationObserver observer( | 282 content::WindowedNotificationObserver observer( |
| 282 chrome::NOTIFICATION_BROWSER_CLOSED, | 283 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 283 content::Source<Browser>(browser)); | 284 content::Source<Browser>(browser)); |
| 284 browser->window()->Close(); | 285 browser->window()->Close(); |
| 285 observer.Wait(); | 286 observer.Wait(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 void NotificationsTest::CrashTab(Browser* browser, int index) { | 289 void NotificationsTest::CrashTab(Browser* browser, int index) { |
| 289 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); | 290 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); |
| 290 } | 291 } |
| 291 | 292 |
| 293 #if ENABLE_MESSAGE_CENTER_TESTING |
| 294 // Overriden from InProcessBrowserTest: |
| 295 void NotificationsTest::SetUpCommandLine(CommandLine* command_line) { |
| 296 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 297 command_line->AppendSwitch( |
| 298 message_center::switches::kEnableRichNotifications); |
| 299 } |
| 300 #else |
| 301 |
| 292 const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() { | 302 const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() { |
| 293 return BalloonNotificationUIManager::GetInstanceForTesting()-> | 303 return BalloonNotificationUIManager::GetInstanceForTesting()-> |
| 294 balloon_collection()->GetActiveBalloons(); | 304 balloon_collection()->GetActiveBalloons(); |
| 295 } | 305 } |
| 296 | 306 |
| 297 void NotificationsTest::CrashNotification(Balloon* balloon) { | 307 void NotificationsTest::CrashNotification(Balloon* balloon) { |
| 298 content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); | 308 content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); |
| 299 } | 309 } |
| 300 | 310 |
| 301 bool NotificationsTest::CloseNotificationAndWait( | 311 bool NotificationsTest::CloseNotificationAndWait( |
| 302 const Notification& notification) { | 312 const Notification& notification) { |
| 303 scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); | 313 NotificationChangeObserver observer; |
| 304 bool success = g_browser_process->notification_ui_manager()-> | 314 bool success = g_browser_process->notification_ui_manager()-> |
| 305 CancelById(notification.notification_id()); | 315 CancelById(notification.notification_id()); |
| 306 if (success) | 316 if (success) |
| 307 return observer->Wait(); | 317 return observer.Wait(); |
| 308 return false; | 318 return false; |
| 309 } | 319 } |
| 310 | 320 |
| 321 #endif // !ENABLE_MESSAGE_CENTER_TESTING |
| 322 |
| 311 void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { | 323 void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { |
| 312 DesktopNotificationService* service = GetDesktopNotificationService(); | 324 DesktopNotificationService* service = GetDesktopNotificationService(); |
| 313 service->SetDefaultContentSetting(setting); | 325 service->SetDefaultContentSetting(setting); |
| 314 } | 326 } |
| 315 | 327 |
| 316 void NotificationsTest::DenyOrigin(const GURL& origin) { | 328 void NotificationsTest::DenyOrigin(const GURL& origin) { |
| 317 DropOriginPreference(origin); | 329 DropOriginPreference(origin); |
| 318 GetDesktopNotificationService()->DenyPermission(origin); | 330 GetDesktopNotificationService()->DenyPermission(origin); |
| 319 } | 331 } |
| 320 | 332 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 346 Browser* browser, | 358 Browser* browser, |
| 347 bool wait_for_new_balloon, | 359 bool wait_for_new_balloon, |
| 348 const char* icon, | 360 const char* icon, |
| 349 const char* title, | 361 const char* title, |
| 350 const char* body, | 362 const char* body, |
| 351 const char* replace_id) { | 363 const char* replace_id) { |
| 352 std::string script = base::StringPrintf( | 364 std::string script = base::StringPrintf( |
| 353 "createNotification('%s', '%s', '%s', '%s');", | 365 "createNotification('%s', '%s', '%s', '%s');", |
| 354 icon, title, body, replace_id); | 366 icon, title, body, replace_id); |
| 355 | 367 |
| 356 scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); | 368 NotificationChangeObserver observer; |
| 357 std::string result; | 369 std::string result; |
| 358 bool success = content::ExecuteScriptAndExtractString( | 370 bool success = content::ExecuteScriptAndExtractString( |
| 359 browser->tab_strip_model()->GetActiveWebContents(), | 371 browser->tab_strip_model()->GetActiveWebContents(), |
| 360 script, | 372 script, |
| 361 &result); | 373 &result); |
| 362 if (success && result != "-1" && wait_for_new_balloon) | 374 if (success && result != "-1" && wait_for_new_balloon) |
| 363 success = observer->Wait(); | 375 success = observer.Wait(); |
| 364 EXPECT_TRUE(success); | 376 EXPECT_TRUE(success); |
| 365 | 377 |
| 366 return result; | 378 return result; |
| 367 } | 379 } |
| 368 | 380 |
| 369 std::string NotificationsTest::CreateSimpleNotification( | 381 std::string NotificationsTest::CreateSimpleNotification( |
| 370 Browser* browser, | 382 Browser* browser, |
| 371 bool wait_for_new_balloon) { | 383 bool wait_for_new_balloon) { |
| 372 return CreateNotification( | 384 return CreateNotification( |
| 373 browser, wait_for_new_balloon, | 385 browser, wait_for_new_balloon, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 return true; | 403 return true; |
| 392 } | 404 } |
| 393 | 405 |
| 394 bool NotificationsTest::CancelNotification( | 406 bool NotificationsTest::CancelNotification( |
| 395 const char* notification_id, | 407 const char* notification_id, |
| 396 Browser* browser) { | 408 Browser* browser) { |
| 397 std::string script = base::StringPrintf( | 409 std::string script = base::StringPrintf( |
| 398 "cancelNotification('%s');", | 410 "cancelNotification('%s');", |
| 399 notification_id); | 411 notification_id); |
| 400 | 412 |
| 401 scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); | 413 NotificationChangeObserver observer; |
| 402 std::string result; | 414 std::string result; |
| 403 bool success = content::ExecuteScriptAndExtractString( | 415 bool success = content::ExecuteScriptAndExtractString( |
| 404 browser->tab_strip_model()->GetActiveWebContents(), | 416 browser->tab_strip_model()->GetActiveWebContents(), |
| 405 script, | 417 script, |
| 406 &result); | 418 &result); |
| 407 if (!success || result != "1") | 419 if (!success || result != "1") |
| 408 return false; | 420 return false; |
| 409 return observer->Wait(); | 421 return observer.Wait(); |
| 410 } | 422 } |
| 411 | 423 |
| 412 bool NotificationsTest::PerformActionOnInfobar( | 424 bool NotificationsTest::PerformActionOnInfobar( |
| 413 Browser* browser, | 425 Browser* browser, |
| 414 InfobarAction action, | 426 InfobarAction action, |
| 415 int infobar_index, | 427 int infobar_index, |
| 416 int tab_index) { | 428 int tab_index) { |
| 417 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 429 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 418 browser->tab_strip_model()->GetWebContentsAt(tab_index)); | 430 browser->tab_strip_model()->GetWebContentsAt(tab_index)); |
| 419 | 431 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 535 |
| 524 // Creates a simple notification. | 536 // Creates a simple notification. |
| 525 AllowAllOrigins(); | 537 AllowAllOrigins(); |
| 526 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 538 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
| 527 | 539 |
| 528 std::string result = CreateSimpleNotification(browser(), true); | 540 std::string result = CreateSimpleNotification(browser(), true); |
| 529 EXPECT_NE("-1", result); | 541 EXPECT_NE("-1", result); |
| 530 | 542 |
| 531 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 543 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
| 532 ASSERT_EQ(1, GetNotificationCount()); | 544 ASSERT_EQ(1, GetNotificationCount()); |
| 533 if (message_center::IsRichNotificationEnabled()) { | 545 #if ENABLE_MESSAGE_CENTER_TESTING |
| 534 message_center::NotificationList::Notifications notifications = | 546 message_center::NotificationList::Notifications notifications = |
| 535 message_center::MessageCenter::Get()->GetNotifications(); | 547 message_center::MessageCenter::Get()->GetNotifications(); |
| 536 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); | 548 EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title()); |
| 537 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); | 549 EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message()); |
| 538 } else { | 550 #else |
| 539 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 551 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 540 ASSERT_EQ(1U, balloons.size()); | 552 ASSERT_EQ(1U, balloons.size()); |
| 541 Balloon* balloon = balloons[0]; | 553 Balloon* balloon = balloons[0]; |
| 542 const Notification& notification = balloon->notification(); | 554 const Notification& notification = balloon->notification(); |
| 543 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 555 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 544 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); | 556 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title()); |
| 545 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); | 557 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body()); |
| 546 } | 558 #endif |
| 547 } | 559 } |
| 548 | 560 |
| 549 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { | 561 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { |
| 550 #if defined(OS_MACOSX) | 562 #if defined(OS_MACOSX) |
| 551 // TODO(kbr): re-enable: http://crbug.com/222296 | 563 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 552 if (base::mac::IsOSMountainLionOrLater()) | 564 if (base::mac::IsOSMountainLionOrLater()) |
| 553 return; | 565 return; |
| 554 #endif | 566 #endif |
| 555 | 567 |
| 556 // Creates a notification and closes it. | 568 // Creates a notification and closes it. |
| 557 AllowAllOrigins(); | 569 AllowAllOrigins(); |
| 558 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 570 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
| 559 | 571 |
| 560 std::string result = CreateSimpleNotification(browser(), true); | 572 std::string result = CreateSimpleNotification(browser(), true); |
| 561 EXPECT_NE("-1", result); | 573 EXPECT_NE("-1", result); |
| 562 ASSERT_EQ(1, GetNotificationCount()); | 574 ASSERT_EQ(1, GetNotificationCount()); |
| 563 | 575 |
| 564 if (message_center::IsRichNotificationEnabled()) { | 576 #if ENABLE_MESSAGE_CENTER_TESTING |
| 565 message_center::NotificationList::Notifications notifications = | 577 message_center::NotificationList::Notifications notifications = |
| 566 message_center::MessageCenter::Get()->GetNotifications(); | 578 message_center::MessageCenter::Get()->GetNotifications(); |
| 567 message_center::MessageCenter::Get()->RemoveNotification( | 579 message_center::MessageCenter::Get()->RemoveNotification( |
| 568 (*notifications.rbegin())->id(), | 580 (*notifications.rbegin())->id(), |
| 569 true); // by_user | 581 true); // by_user |
| 570 } else { | 582 #else |
| 571 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 583 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 572 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | 584 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
| 573 } | 585 #endif // ENABLE_MESSAGE_CENTER_TESTING |
| 574 | 586 |
| 575 ASSERT_EQ(0, GetNotificationCount()); | 587 ASSERT_EQ(0, GetNotificationCount()); |
| 576 } | 588 } |
| 577 | 589 |
| 578 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { | 590 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { |
| 579 #if defined(OS_MACOSX) | 591 #if defined(OS_MACOSX) |
| 580 // TODO(kbr): re-enable: http://crbug.com/222296 | 592 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 581 if (base::mac::IsOSMountainLionOrLater()) | 593 if (base::mac::IsOSMountainLionOrLater()) |
| 582 return; | 594 return; |
| 583 #endif | 595 #endif |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 758 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
| 747 CreateSimpleNotification(browser(), true); | 759 CreateSimpleNotification(browser(), true); |
| 748 ASSERT_EQ(1, GetNotificationCount()); | 760 ASSERT_EQ(1, GetNotificationCount()); |
| 749 | 761 |
| 750 DenyOrigin(test_page_url_.GetOrigin()); | 762 DenyOrigin(test_page_url_.GetOrigin()); |
| 751 ContentSettingsForOneType settings; | 763 ContentSettingsForOneType settings; |
| 752 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); | 764 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| 753 ASSERT_TRUE(CheckOriginInSetting(settings, test_page_url_.GetOrigin())); | 765 ASSERT_TRUE(CheckOriginInSetting(settings, test_page_url_.GetOrigin())); |
| 754 | 766 |
| 755 EXPECT_EQ(1, GetNotificationCount()); | 767 EXPECT_EQ(1, GetNotificationCount()); |
| 756 if (message_center::IsRichNotificationEnabled()) { | 768 #if ENABLE_MESSAGE_CENTER_TESTING |
| 757 message_center::NotificationList::Notifications notifications = | 769 message_center::NotificationList::Notifications notifications = |
| 758 message_center::MessageCenter::Get()->GetNotifications(); | 770 message_center::MessageCenter::Get()->GetNotifications(); |
| 759 message_center::MessageCenter::Get()->RemoveNotification( | 771 message_center::MessageCenter::Get()->RemoveNotification( |
| 760 (*notifications.rbegin())->id(), | 772 (*notifications.rbegin())->id(), |
| 761 true); // by_user | 773 true); // by_user |
| 762 } else { | 774 #else |
| 763 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 775 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 764 ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); | 776 ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
| 765 } | 777 #endif // ENABLE_MESSAGE_CENTER_TESTING |
| 766 ASSERT_EQ(0, GetNotificationCount()); | 778 ASSERT_EQ(0, GetNotificationCount()); |
| 767 } | 779 } |
| 768 | 780 |
| 769 // Crashes on Linux/Win. See http://crbug.com/160657. | 781 // Crashes on Linux/Win. See http://crbug.com/160657. |
| 770 IN_PROC_BROWSER_TEST_F( | 782 IN_PROC_BROWSER_TEST_F( |
| 771 NotificationsTest, | 783 NotificationsTest, |
| 772 DISABLED_TestOriginPrefsNotSavedInIncognito) { | 784 DISABLED_TestOriginPrefsNotSavedInIncognito) { |
| 773 // Verify that allow/deny origin preferences are not saved in incognito. | 785 // Verify that allow/deny origin preferences are not saved in incognito. |
| 774 Browser* incognito = CreateIncognitoBrowser(); | 786 Browser* incognito = CreateIncognitoBrowser(); |
| 775 ui_test_utils::NavigateToURL(incognito, test_page_url_); | 787 ui_test_utils::NavigateToURL(incognito, test_page_url_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 browser(), | 829 browser(), |
| 818 empty_page_url_, | 830 empty_page_url_, |
| 819 NEW_BACKGROUND_TAB, | 831 NEW_BACKGROUND_TAB, |
| 820 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 832 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 821 browser()->tab_strip_model()->ActivateTabAt(0, true); | 833 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 822 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 834 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
| 823 ASSERT_TRUE(RequestPermissionAndWait(browser())); | 835 ASSERT_TRUE(RequestPermissionAndWait(browser())); |
| 824 CrashTab(browser(), 0); | 836 CrashTab(browser(), 0); |
| 825 } | 837 } |
| 826 | 838 |
| 839 // Notifications don't have their own process with the message center. |
| 840 #if !ENABLE_MESSAGE_CENTER_TESTING |
| 827 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { | 841 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { |
| 828 // Notifications don't have their own process with the message center. | |
| 829 if (message_center::IsRichNotificationEnabled()) | |
| 830 return; | |
| 831 | |
| 832 #if defined(OS_MACOSX) | 842 #if defined(OS_MACOSX) |
| 833 // TODO(kbr): re-enable: http://crbug.com/222296 | 843 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 834 if (base::mac::IsOSMountainLionOrLater()) | 844 if (base::mac::IsOSMountainLionOrLater()) |
| 835 return; | 845 return; |
| 836 #endif | 846 #endif |
| 837 // Test killing a notification doesn't crash Chrome. | 847 // Test killing a notification doesn't crash Chrome. |
| 838 AllowAllOrigins(); | 848 AllowAllOrigins(); |
| 839 ui_test_utils::NavigateToURL(browser(), test_page_url_); | 849 ui_test_utils::NavigateToURL(browser(), test_page_url_); |
| 840 CreateSimpleNotification(browser(), true); | 850 CreateSimpleNotification(browser(), true); |
| 841 ASSERT_EQ(1, GetNotificationCount()); | 851 ASSERT_EQ(1, GetNotificationCount()); |
| 842 | 852 |
| 843 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 853 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 844 ASSERT_EQ(1U, balloons.size()); | 854 ASSERT_EQ(1U, balloons.size()); |
| 845 CrashNotification(balloons[0]); | 855 CrashNotification(balloons[0]); |
| 846 ASSERT_EQ(0, GetNotificationCount()); | 856 ASSERT_EQ(0, GetNotificationCount()); |
| 847 } | 857 } |
| 858 #endif |
| 848 | 859 |
| 849 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { | 860 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { |
| 850 #if defined(OS_MACOSX) | 861 #if defined(OS_MACOSX) |
| 851 // TODO(kbr): re-enable: http://crbug.com/222296 | 862 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 852 if (base::mac::IsOSMountainLionOrLater()) | 863 if (base::mac::IsOSMountainLionOrLater()) |
| 853 return; | 864 return; |
| 854 #endif | 865 #endif |
| 855 // Test notifications in incognito window. | 866 // Test notifications in incognito window. |
| 856 Browser* browser = CreateIncognitoBrowser(); | 867 Browser* browser = CreateIncognitoBrowser(); |
| 857 ui_test_utils::NavigateToURL(browser, test_page_url_); | 868 ui_test_utils::NavigateToURL(browser, test_page_url_); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 std::string result = CreateNotification( | 951 std::string result = CreateNotification( |
| 941 browser(), true, "abc.png", "Title1", "Body1", "chat"); | 952 browser(), true, "abc.png", "Title1", "Body1", "chat"); |
| 942 EXPECT_NE("-1", result); | 953 EXPECT_NE("-1", result); |
| 943 | 954 |
| 944 ASSERT_EQ(1, GetNotificationCount()); | 955 ASSERT_EQ(1, GetNotificationCount()); |
| 945 | 956 |
| 946 result = CreateNotification( | 957 result = CreateNotification( |
| 947 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); | 958 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); |
| 948 EXPECT_NE("-1", result); | 959 EXPECT_NE("-1", result); |
| 949 | 960 |
| 950 if (message_center::IsRichNotificationEnabled()) { | 961 #if ENABLE_MESSAGE_CENTER_TESTING |
| 951 ASSERT_EQ(1, GetNotificationCount()); | 962 ASSERT_EQ(1, GetNotificationCount()); |
| 952 message_center::NotificationList::Notifications notifications = | 963 message_center::NotificationList::Notifications notifications = |
| 953 message_center::MessageCenter::Get()->GetNotifications(); | 964 message_center::MessageCenter::Get()->GetNotifications(); |
| 954 EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); | 965 EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); |
| 955 EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message()); | 966 EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message()); |
| 956 } else { | 967 #else |
| 957 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 968 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 958 ASSERT_EQ(1U, balloons.size()); | 969 ASSERT_EQ(1U, balloons.size()); |
| 959 Balloon* balloon = balloons[0]; | 970 Balloon* balloon = balloons[0]; |
| 960 const Notification& notification = balloon->notification(); | 971 const Notification& notification = balloon->notification(); |
| 961 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 972 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
| 962 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 973 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 963 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 974 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
| 964 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); | 975 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); |
| 965 } | 976 #endif |
| 966 } | 977 } |
| OLD | NEW |