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