15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <deque> 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback.h" 10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/command_line.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/run_loop.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/test/simple_test_clock.h" 17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/time/clock.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/browser_process.h" 197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h" 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/content_settings/host_content_settings_map.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/infobar_service.h" 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/notifications/desktop_notification_profile_util.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/notifications/notification.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_tabstrip.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_window.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/content_settings/core/common/content_settings.h" 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/content_settings/core/common/content_settings_pattern.h" 33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/infobars/core/confirm_infobar_delegate.h" 340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/infobars/core/infobar.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_service.h" 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_source.h" 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_types.h" 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/render_view_host.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/test_utils.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_util.h" 43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/test/embedded_test_server/embedded_test_server.h" 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h" 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/message_center.h" 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/message_center/message_center_observer.h" 48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h" 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kExpectedIconUrl[] = "/notifications/no_such_file.png"; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)enum InfobarAction { 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISMISS = 0, 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ALLOW, 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DENY, 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class NotificationChangeObserver { 61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)public: 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual ~NotificationChangeObserver() {} 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool Wait() = 0; 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}; 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MessageCenterChangeObserver 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) : public message_center::MessageCenterObserver, 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public NotificationChangeObserver { 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MessageCenterChangeObserver() 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : notification_received_(false) { 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_center::MessageCenter::Get()->AddObserver(this); 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~MessageCenterChangeObserver() { 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_center::MessageCenter::Get()->RemoveObserver(this); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // NotificationChangeObserver: 80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool Wait() OVERRIDE { 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (notification_received_) 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_runner_ = new content::MessageLoopRunner; 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_runner_->Run(); 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return notification_received_; 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 89a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // message_center::MessageCenterObserver: 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnNotificationAdded( 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& notification_id) OVERRIDE { 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnMessageCenterChanged(); 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 94a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnNotificationRemoved(const std::string& notification_id, 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool by_user) OVERRIDE { 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnMessageCenterChanged(); 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 99a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnNotificationUpdated( 101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& notification_id) OVERRIDE { 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnMessageCenterChanged(); 103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void OnMessageCenterChanged() { 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_received_ = true; 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (message_loop_runner_.get()) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_runner_->Quit(); 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool notification_received_; 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NotificationsTest : public InProcessBrowserTest { 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsTest() {} 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int GetNotificationCount(); 1255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int GetNotificationPopupCount(); 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CloseBrowserWindow(Browser* browser); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CrashTab(Browser* browser, int index); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DenyOrigin(const GURL& origin); 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void AllowOrigin(const GURL& origin); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void AllowAllOrigins(); 1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void SetDefaultContentSetting(ContentSetting setting); 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 135bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch void VerifyInfoBar(const Browser* browser, int index); 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string CreateNotification(Browser* browser, 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool wait_for_new_balloon, 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* icon, 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* title, 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* body, 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* replace_id); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string CreateSimpleNotification(Browser* browser, 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool wait_for_new_balloon); 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool RequestPermissionAndWait(Browser* browser); 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool CancelNotification(const char* notification_id, Browser* browser); 146bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch bool PerformActionOnInfoBar(Browser* browser, 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InfobarAction action, 148bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch size_t infobar_index, 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int tab_index); 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GetPrefsByContentSetting(ContentSetting setting, 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsForOneType* settings); 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool CheckOriginInSetting(const ContentSettingsForOneType& settings, 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& origin); 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL GetTestPageURL() const { 156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return embedded_test_server()->GetURL( 157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch "/notifications/notification_tester.html"); 158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DropOriginPreference(const GURL& origin); 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int NotificationsTest::GetNotificationCount() { 165a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return message_center::MessageCenter::Get()->NotificationCount(); 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)int NotificationsTest::GetNotificationPopupCount() { 1695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return message_center::MessageCenter::Get()->GetPopupNotifications().size(); 1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::CloseBrowserWindow(Browser* browser) { 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WindowedNotificationObserver observer( 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NOTIFICATION_BROWSER_CLOSED, 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::Source<Browser>(browser)); 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->window()->Close(); 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) observer.Wait(); 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::CrashTab(Browser* browser, int index) { 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::DenyOrigin(const GURL& origin) { 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DropOriginPreference(origin); 1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DesktopNotificationProfileUtil::DenyPermission(browser()->profile(), origin); 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::AllowOrigin(const GURL& origin) { 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DropOriginPreference(origin); 1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::AllowAllOrigins() { 1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Reset all origins 1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType( 1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetDefaultContentSetting(CONTENT_SETTING_ALLOW); 1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void NotificationsTest::SetDefaultContentSetting(ContentSetting setting) { 2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 2035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 206bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InfoBarService* infobar_service = InfoBarService::FromWebContents( 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetWebContentsAt(index)); 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 210a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ASSERT_EQ(1U, infobar_service->infobar_count()); 211bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ConfirmInfoBarDelegate* confirm_infobar = 212a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(confirm_infobar); 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int buttons = confirm_infobar->GetButtons(); 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string NotificationsTest::CreateNotification( 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* browser, 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool wait_for_new_balloon, 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* icon, 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* title, 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* body, 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* replace_id) { 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string script = base::StringPrintf( 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "createNotification('%s', '%s', '%s', '%s');", 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) icon, title, body, replace_id); 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 230a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MessageCenterChangeObserver observer; 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result; 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool success = content::ExecuteScriptAndExtractString( 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetActiveWebContents(), 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) script, 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &result); 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (success && result != "-1" && wait_for_new_balloon) 237a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch success = observer.Wait(); 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(success); 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return result; 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string NotificationsTest::CreateSimpleNotification( 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* browser, 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool wait_for_new_balloon) { 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return CreateNotification( 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser, wait_for_new_balloon, 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "no_such_file.png", "My Title", "My Body", ""); 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InfoBarService* infobar_service = InfoBarService::FromWebContents( 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetActiveWebContents()); 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WindowedNotificationObserver observer( 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::Source<InfoBarService>(infobar_service)); 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result; 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool success = content::ExecuteScriptAndExtractString( 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetActiveWebContents(), 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "requestPermission();", 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &result); 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!success || result != "1") 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) observer.Wait(); 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NotificationsTest::CancelNotification( 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char* notification_id, 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* browser) { 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string script = base::StringPrintf( 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "cancelNotification('%s');", 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_id); 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 275a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MessageCenterChangeObserver observer; 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result; 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool success = content::ExecuteScriptAndExtractString( 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetActiveWebContents(), 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) script, 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &result); 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!success || result != "1") 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 283a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return observer.Wait(); 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 286bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochbool NotificationsTest::PerformActionOnInfoBar( 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* browser, 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InfobarAction action, 289bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch size_t infobar_index, 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int tab_index) { 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InfoBarService* infobar_service = InfoBarService::FromWebContents( 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetWebContentsAt(tab_index)); 293a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (infobar_index >= infobar_service->infobar_count()) { 294bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ADD_FAILURE(); 295bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch return false; 296bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch } 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch infobars::InfoBar* infobar = infobar_service->infobar_at(infobar_index); 2990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch infobars::InfoBarDelegate* infobar_delegate = infobar->delegate(); 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) switch (action) { 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case DISMISS: 302bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch infobar_delegate->InfoBarDismissed(); 303a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_service->RemoveInfoBar(infobar); 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case ALLOW: { 307bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ConfirmInfoBarDelegate* confirm_infobar_delegate = 308bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch infobar_delegate->AsConfirmInfoBarDelegate(); 309bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch if (!confirm_infobar_delegate) { 310bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ADD_FAILURE(); 311bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch } else if (confirm_infobar_delegate->Accept()) { 312a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_service->RemoveInfoBar(infobar); 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case DENY: { 318bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ConfirmInfoBarDelegate* confirm_infobar_delegate = 319bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch infobar_delegate->AsConfirmInfoBarDelegate(); 320bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch if (!confirm_infobar_delegate) { 321bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ADD_FAILURE(); 322bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch } else if (confirm_infobar_delegate->Cancel()) { 323a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch infobar_service->RemoveInfoBar(infobar); 3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::GetPrefsByContentSetting( 3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSetting setting, 3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsForOneType* settings) { 3355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DesktopNotificationProfileUtil::GetNotificationsSettings( 3365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser()->profile(), settings); 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (ContentSettingsForOneType::iterator it = settings->begin(); 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it != settings->end(); ) { 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (it->setting != setting || it->source.compare("preference") != 0) 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it = settings->erase(it); 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ++it; 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NotificationsTest::CheckOriginInSetting( 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ContentSettingsForOneType& settings, 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& origin) { 3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsPattern pattern = 3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsPattern::FromURLNoWildcard(origin); 3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (ContentSettingsForOneType::const_iterator it = settings.begin(); 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it != settings.end(); ++it) { 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (it->primary_pattern == pattern) 3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NotificationsTest::DropOriginPreference(const GURL& origin) { 3605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsPattern::FromURLNoWildcard(origin)); 3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. 3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { 366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL( 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch embedded_test_server()->GetURL( 371eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch "/notifications/notifications_request_function.html")); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request permission by calling request() while eval'ing an inline script; 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // That's considered a user gesture to webkit, and should produce an infobar. 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool result; 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(), 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "window.domAutomationController.send(request());", 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &result)); 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(result); 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 382e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch InfoBarService* infobar_service = InfoBarService::FromWebContents( 383e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch browser()->tab_strip_model()->GetWebContentsAt(0)); 384a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(1U, infobar_service->infobar_count()); 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { 388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates a simple notification. 3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AllowAllOrigins(); 392eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), true); 3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 397eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); 3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 399a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::NotificationList::Notifications notifications = 400a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::MessageCenter::Get()->GetVisibleNotifications(); 401a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(base::ASCIIToUTF16("My Title"), 402a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (*notifications.rbegin())->title()); 403a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(base::ASCIIToUTF16("My Body"), 404a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (*notifications.rbegin())->message()); 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { 408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates a notification and closes it. 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AllowAllOrigins(); 412eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), true); 4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 418a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::NotificationList::Notifications notifications = 419a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::MessageCenter::Get()->GetVisibleNotifications(); 420a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::MessageCenter::Get()->RemoveNotification( 421a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (*notifications.rbegin())->id(), 422a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch true); // by_user 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCancelNotification) { 428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates a notification and cancels it in the origin page. 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AllowAllOrigins(); 432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string note_id = CreateSimpleNotification(browser(), true); 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE(note_id, "-1"); 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { 443eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 444eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Requests notification privileges and verifies the infobar appears. 446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 450bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ASSERT_NO_FATAL_FAILURE(VerifyInfoBar(browser(), 0)); 4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { 454eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 455eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Tries to create a notification and clicks allow on the infobar. 457eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This notification should not be shown because we do not have permission. 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), false); 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 463bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ASSERT_TRUE(PerformActionOnInfoBar(browser(), ALLOW, 0, 0)); 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), true); 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetNotificationCount()); 4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionInfobar) { 470eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 471eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test that no notification is created 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // when Deny is chosen from permission infobar. 474eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 476bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PerformActionOnInfoBar(browser(), DENY, 0, 0); 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), false); 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsForOneType settings; 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 481eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL())); 4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionInfobar) { 485eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 486eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test that no notification is created when permission infobar is dismissed. 488eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 490bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PerformActionOnInfoBar(browser(), DISMISS, 0, 0); 4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), false); 4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsForOneType settings; 4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0U, settings.size()); 4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { 499eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 500eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify that all domains can be allowed to show notifications. 5025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetDefaultContentSetting(CONTENT_SETTING_ALLOW); 503eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), true); 5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 509e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch InfoBarService* infobar_service = InfoBarService::FromWebContents( 510e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch browser()->tab_strip_model()->GetWebContentsAt(0)); 511a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(0U, infobar_service->infobar_count()); 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { 515eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 516eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify that no domain can show notifications. 5185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetDefaultContentSetting(CONTENT_SETTING_BLOCK); 519eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), false); 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ("-1", result); 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyDomainAndAllowAll) { 528eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 529eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify that denying a domain and allowing all shouldn't show 5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // notifications from the denied domain. 532eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DenyOrigin(GetTestPageURL().GetOrigin()); 5335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetDefaultContentSetting(CONTENT_SETTING_ALLOW); 5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 535eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), false); 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ("-1", result); 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowDomainAndDenyAll) { 544eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 545eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify that allowing a domain and denying all others should show 5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // notifications from the allowed domain. 548eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AllowOrigin(GetTestPageURL().GetOrigin()); 5495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetDefaultContentSetting(CONTENT_SETTING_BLOCK); 5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 551eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), true); 5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyAndThenAllowDomain) { 560eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 561eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify that denying and again allowing should show notifications. 563eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DenyOrigin(GetTestPageURL().GetOrigin()); 5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 565eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateSimpleNotification(browser(), false); 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ("-1", result); 5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 572eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AllowOrigin(GetTestPageURL().GetOrigin()); 5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result = CreateSimpleNotification(browser(), true); 5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 577e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch InfoBarService* infobar_service = InfoBarService::FromWebContents( 578e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch browser()->tab_strip_model()->GetWebContentsAt(0)); 579a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(0U, infobar_service->infobar_count()); 5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { 583eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 584eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify able to create, deny, and close the notification. 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AllowAllOrigins(); 587eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), true); 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 591eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DenyOrigin(GetTestPageURL().GetOrigin()); 5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsForOneType settings; 5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 594eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); 5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, GetNotificationCount()); 597a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::NotificationList::Notifications notifications = 598a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::MessageCenter::Get()->GetVisibleNotifications(); 599a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::MessageCenter::Get()->RemoveNotification( 600a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (*notifications.rbegin())->id(), 601a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch true); // by_user 6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, GetNotificationCount()); 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Crashes on Linux/Win. See http://crbug.com/160657. 6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F( 6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsTest, 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISABLED_TestOriginPrefsNotSavedInIncognito) { 609eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 610eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Verify that allow/deny origin preferences are not saved in incognito. 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* incognito = CreateIncognitoBrowser(); 613eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(incognito)); 615bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PerformActionOnInfoBar(incognito, DENY, 0, 0); 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CloseBrowserWindow(incognito); 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) incognito = CreateIncognitoBrowser(); 619eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); 6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(incognito)); 621bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PerformActionOnInfoBar(incognito, ALLOW, 0, 0); 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(incognito, true); 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CloseBrowserWindow(incognito); 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) incognito = CreateIncognitoBrowser(); 627eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); 6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(incognito)); 6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContentSettingsForOneType settings; 6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0U, settings.size()); 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, &settings); 6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0U, settings.size()); 6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestExitBrowserWithInfobar) { 638eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 639eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Exit the browser window, when the infobar appears. 641eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Times out on Windows and Linux. http://crbug.com/168976 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) || defined(OS_LINUX) 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_TestCrashTabWithPermissionInfobar \ 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISABLED_TestCrashTabWithPermissionInfobar 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_TestCrashTabWithPermissionInfobar \ 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestCrashTabWithPermissionInfobar 6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MAYBE_TestCrashTabWithPermissionInfobar) { 655eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 656eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test crashing the tab with permission infobar doesn't crash Chrome. 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), 660eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch embedded_test_server()->GetURL("/empty.html"), 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NEW_BACKGROUND_TAB, 6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->ActivateTabAt(0, true); 664eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CrashTab(browser(), 0); 6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { 670eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 671eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test notifications in incognito window. 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* browser = CreateIncognitoBrowser(); 674eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser, GetTestPageURL()); 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->ActivateTabAt(0, true); 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser)); 677bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PerformActionOnInfoBar(browser, ALLOW, 0, 0); 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser, true); 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) { 683eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 684eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test that user can close tab when infobar present. 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("about:blank"), 6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NEW_BACKGROUND_TAB, 6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->ActivateTabAt(0, true); 692eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 6948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::WebContentsDestroyedWatcher destroyed_watcher( 6958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) browser()->tab_strip_model()->GetWebContentsAt(0)); 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->CloseWebContentsAt(0, 6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TabStripModel::CLOSE_NONE); 6988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) destroyed_watcher.Wait(); 6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F( 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsTest, 7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestNavigateAwayWithPermissionInfobar) { 704eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 705eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test navigating away when an infobar is present, 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // then trying to create a notification from the same page. 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("about:blank"), 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NEW_BACKGROUND_TAB, 7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->ActivateTabAt(0, true); 714eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 716eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RequestPermissionAndWait(browser())); 718bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PerformActionOnInfoBar(browser(), ALLOW, 0, 0); 7192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), true); 7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7235e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)// See crbug.com/248470 7245e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#if defined(OS_LINUX) 7255e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#define MAYBE_TestCrashRendererNotificationRemain \ 7265e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles) DISABLED_TestCrashRendererNotificationRemain 7275e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#else 7285e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#define MAYBE_TestCrashRendererNotificationRemain \ 7295e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles) TestCrashRendererNotificationRemain 7305e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#endif 7315e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles) 7325e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, 7335e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles) MAYBE_TestCrashRendererNotificationRemain) { 734eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 735eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test crashing renderer does not close or crash notification. 7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AllowAllOrigins(); 7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), 7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("about:blank"), 7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NEW_BACKGROUND_TAB, 7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->ActivateTabAt(0, true); 744eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateSimpleNotification(browser(), true); 7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CrashTab(browser(), 0); 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { 752eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 753eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test that we can replace a notification using the replaceId. 7552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AllowAllOrigins(); 7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 757eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string result = CreateNotification( 7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), true, "abc.png", "Title1", "Body1", "chat"); 7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 7622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, GetNotificationCount()); 7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result = CreateNotification( 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_NE("-1", result); 7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 769a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ASSERT_EQ(1, GetNotificationCount()); 770a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::NotificationList::Notifications notifications = 771a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch message_center::MessageCenter::Get()->GetVisibleNotifications(); 772a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); 773a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(base::ASCIIToUTF16("Body2"), 774a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (*notifications.rbegin())->message()); 7752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 776116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 777116680a4aac90f2aa7413d9095a592090648e557Ben MurdochIN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) { 778116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 779116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 780116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch HostContentSettingsMap* settings_map = 781116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch browser()->profile()->GetHostContentSettingsMap(); 782116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::SimpleTestClock* clock = new base::SimpleTestClock(); 783116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch settings_map->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock)); 784116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch clock->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); 785116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 786116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Creates a simple notification. 787116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AllowAllOrigins(); 788116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 789116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 790116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::string result = CreateSimpleNotification(browser(), true); 791116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_NE("-1", result); 792116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 793116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(), 794116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GetTestPageURL().GetOrigin(), 795116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch CONTENT_SETTINGS_TYPE_NOTIFICATIONS) 796116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch .ToDoubleT(), 797116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 10); 798116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 799116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch clock->Advance(base::TimeDelta::FromSeconds(3)); 800116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 801116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch result = CreateSimpleNotification(browser(), true); 802116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_NE("-1", result); 803116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 804116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(), 805116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GetTestPageURL().GetOrigin(), 806116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch CONTENT_SETTINGS_TYPE_NOTIFICATIONS) 807116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch .ToDoubleT(), 808116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 13); 809116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 8105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NotificationsTest, 8125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TestNotificationReplacementReappearance) { 8135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 8145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Test that we can replace a notification using the tag, and that it will 8165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // cause the notification to reappear as a popup again. 8175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) AllowAllOrigins(); 8185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 8205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ASSERT_EQ(0, GetNotificationPopupCount()); 8225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string result = CreateNotification( 8245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser(), true, "abc.png", "Title1", "Body1", "chat"); 8255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_NE("-1", result); 8265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ASSERT_EQ(1, GetNotificationPopupCount()); 8285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) message_center::NotificationList::Notifications notifications = 8305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) message_center::MessageCenter::Get()->GetVisibleNotifications(); 8315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) message_center::MessageCenter::Get()->ClickOnNotification( 8325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) (*notifications.rbegin())->id()); 8335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ASSERT_EQ(0, GetNotificationPopupCount()); 8355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) result = CreateNotification( 8375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser(), true, "abc.png", "Title2", "Body2", "chat"); 8385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_NE("-1", result); 8395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 8405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ASSERT_EQ(1, GetNotificationPopupCount()); 8415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 842