Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: chrome/browser/notifications/notification_browsertest.cc

Issue 11359174: Convert HTML5 notification pyauto tests to browser_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from Ken. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/notifications/notification_tester.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_browsertest.cc
diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc
index 3a693da62ab1bc75aa4622195efb5b80c72b9247..a402b498fe221f958fa843f5e9a824df6bac4a25 100644
--- a/chrome/browser/notifications/notification_browsertest.cc
+++ b/chrome/browser/notifications/notification_browsertest.cc
@@ -2,25 +2,570 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
+#include "chrome/browser/api/infobars/infobar_delegate.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/infobars/infobar_tab_helper.h"
+#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/balloon_collection.h"
+#include "chrome/browser/notifications/balloon_host.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/desktop_notification_service_factory.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
#include "net/test/test_server.h"
+#include "webkit/glue/window_open_disposition.h"
-class NotificationsPermissionTest : public InProcessBrowserTest {
+#if defined(OS_WIN)
+#include "base/win/windows_version.h"
+#endif
+
+namespace {
+ const std::string kReference = "preference";
kkania 2012/11/15 16:29:07 don't indent stuff inside namespace, but leave new
kkania 2012/11/15 16:29:07 http://google-styleguide.googlecode.com/svn/trunk/
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
+ const std::string kExpectedIconUrl = "files/notifications/no_such_file.png";
kkania 2012/11/15 16:29:07 http://google-styleguide.googlecode.com/svn/trunk/
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
+
+ enum InfobarAction {
+ DISMISS = 0,
+ ALLOW = 1,
+ DENY = 2,
+ };
+
+ class BrowserOpenedNotificationObserver :
+ public content::NotificationObserver {
+ public:
+ BrowserOpenedNotificationObserver();
+ virtual ~BrowserOpenedNotificationObserver();
+
+ void Wait();
+ Browser* new_browser() { return new_browser_; }
+
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+ private:
+ content::NotificationRegistrar registrar_;
+ Browser* new_browser_;
+ int new_window_id_;
+ bool done_;
+ bool running_;
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver);
+ };
+}
+
+class NotificationsPermissionTest : public InProcessBrowserTest,
+ public content::NotificationObserver {
public:
- NotificationsPermissionTest() {}
+ NotificationsPermissionTest();
+
+ protected:
+ // Overriden from InProcessBrowserTest:
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
+
+ // Overriden from content::NotificationObserver:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ DesktopNotificationService* GetDesktopNotificationService();
+ const std::deque<Balloon*>& GetActiveBalloons();
+ int GetNotificationCount();
+
+ bool CloseNotificationAndWait(const Notification& notification);
+ bool WaitForInfoBarCount(Browser* browser,
+ size_t count,
+ int index,
+ bool increasing);
+ Browser* CreateBrowserWindow(Browser* source_browser, bool is_incognito);
+ void CloseBrowserWindow(Browser* browser);
+ void CrashTab(Browser* browser, int index);
+ void CrashNotification(Balloon* balloon);
+
+ void SetDefaultPermissionSetting(ContentSetting setting);
+ ContentSetting GetDefaultPermissionSetting();
+ void GetDeniedOrigins(ContentSettingsForOneType* settings);
+ void GetAllowedOrigins(ContentSettingsForOneType* settings);
+ void SetDeniedOrigins(const std::vector<GURL>& new_origins);
+ void SetAllowedOrigins(const std::vector<GURL>& new_origins);
+ void DenyOrigin(const GURL& origin);
+ void AllowOrigin(const GURL& origin);
+ void DropOriginPreference(const GURL& origin);
+ void AllowAllOrigins();
+
+ void VerifyInfobar(const Browser* browser,
+ const std::string& origin,
+ int index);
+ std::string CreateNotification(Browser* browser,
+ bool waiting,
+ const char* icon,
+ const char* title,
+ const char* body,
+ const char* replace_id);
+ std::string CreateSimpleNotification(Browser* browser, bool waiting);
+ bool RequestPermission(Browser* browser);
+ bool CancelNotification(const char* notification_id, Browser* browser);
+ bool PerformActionOnInfobar(Browser* browser,
+ InfobarAction action,
+ int infobar_index,
+ int tab_index);
+ bool CheckOriginInSetting(const ContentSettingsForOneType & settings,
+ const GURL & origin);
+
+ GURL EMPTY_PAGE_URL;
kkania 2012/11/15 16:29:07 constants are kEmptyPageUrl style. There is no con
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
+ GURL TEST_PAGE_URL;
+
+ private:
+ size_t target_infobar_count_;
+ size_t target_balloon_count_;
+
+ void GetPrefsByContentSetting(ContentSetting setting,
+ ContentSettingsForOneType* settings);
};
-// If this flakes, use http://crbug.com/62311 and http://crbug.com/74428.
-IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) {
+BrowserOpenedNotificationObserver::BrowserOpenedNotificationObserver()
+ : new_browser_(NULL),
+ new_window_id_(-1),
+ done_(false),
+ running_(false) {
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
+ content::NotificationService::AllBrowserContextsAndSources());
+ registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
+ content::NotificationService::AllBrowserContextsAndSources());
+}
+
+BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() {}
+
+void BrowserOpenedNotificationObserver::Wait() {
+ if (done_)
+ return;
+
+ running_ = true;
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ EXPECT_TRUE(done_);
+}
+
+void BrowserOpenedNotificationObserver::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ if (type == chrome::NOTIFICATION_BROWSER_OPENED) {
+ // Store the new browser ID and continue waiting for a new tab within it
+ // to stop loading.
+ new_browser_ = content::Source<Browser>(source).ptr();
+ new_window_id_ = new_browser_->session_id().id();
+ } else {
+ DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type);
+ content::NavigationController* controller =
+ content::Source<content::NavigationController>(source).ptr();
+ SessionTabHelper* session_tab_helper =
+ SessionTabHelper::FromWebContents(controller->GetWebContents());
+ int window_id = session_tab_helper ? session_tab_helper->window_id().id()
+ : -1;
+ if (window_id == new_window_id_) {
+ registrar_.RemoveAll();
+ done_ = true;
+ if (!running_)
+ return;
+
+ message_loop_runner_->Quit();
+ running_ = false;
+ }
+ }
+}
+
+NotificationsPermissionTest::NotificationsPermissionTest()
+ : target_infobar_count_(0U),
+ target_balloon_count_(0U) {
+}
+
+void NotificationsPermissionTest::SetUpInProcessBrowserTestFixture() {
+ InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
+
ASSERT_TRUE(test_server()->Start());
+ EMPTY_PAGE_URL = test_server()->GetURL("files/empty.html");
+ TEST_PAGE_URL = test_server()->GetURL(
+ "files/notifications/notification_tester.html");
+}
+
+void NotificationsPermissionTest::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_BROWSER_CLOSED: {
+ MessageLoopForUI::current()->Quit();
+ break;
+ }
+ case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED:
+ case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: {
+ const InfoBarTabHelper* infoBarTabHelper =
+ content::Source<const InfoBarTabHelper>(source).ptr();
+ if (infoBarTabHelper->GetInfoBarCount() == target_infobar_count_) {
+ target_infobar_count_ = 0U;
+ MessageLoopForUI::current()->Quit();
+ }
+ break;
+ }
+ case chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED:
+ case chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED: {
+ size_t current_balloon_count = GetActiveBalloons().size();
+ if (current_balloon_count == target_balloon_count_) {
+ target_balloon_count_ = 0U;
+ MessageLoopForUI::current()->Quit();
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+DesktopNotificationService*
+ NotificationsPermissionTest::GetDesktopNotificationService() {
+ Profile* profile = browser()->profile();
+ return DesktopNotificationServiceFactory::GetForProfile(profile);
+}
+
+const std::deque<Balloon*>& NotificationsPermissionTest::GetActiveBalloons() {
+ NotificationUIManager* manager = g_browser_process->notification_ui_manager();
+ return manager->balloon_collection()->GetActiveBalloons();
+}
+
+int NotificationsPermissionTest::GetNotificationCount() {
+ NotificationUIManager* manager = g_browser_process->notification_ui_manager();
+ return manager->balloon_collection()->GetActiveBalloons().size();
+}
+
+bool NotificationsPermissionTest::CloseNotificationAndWait(
+ const Notification& notification) {
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED,
+ content::NotificationService::AllSources());
+ NotificationUIManager* manager = g_browser_process->notification_ui_manager();
+ bool flag = manager->CancelById(notification.notification_id());
+ observer.Wait();
+ return flag;
+}
+
+bool NotificationsPermissionTest::WaitForInfoBarCount(
+ Browser* browser,
+ size_t count,
+ int index,
+ bool increasing) {
kkania 2012/11/15 16:29:07 instead of passing in increasing arg, how about we
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Function removed.
+ size_t current_count = InfoBarTabHelper::FromWebContents(
+ chrome::GetWebContentsAt(browser, 0))->GetInfoBarCount();
kkania 2012/11/15 16:29:07 indent
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
+ if (count != current_count) {
+ target_infobar_count_ = count;
+ ui_test_utils::RegisterAndWait(
kkania 2012/11/15 16:29:07 how about usr for loop and use content::WindowedOb
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Move logic of waiting to function RequestPermissio
+ this,
+ increasing ? chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
+ : chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
+ content::NotificationService::AllSources());
+ }
+ current_count = InfoBarTabHelper::FromWebContents(
+ chrome::GetWebContentsAt(browser, 0))->GetInfoBarCount();
kkania 2012/11/15 16:29:07 fix all indents
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
+ return count == current_count;
+}
+
+Browser* NotificationsPermissionTest::CreateBrowserWindow(
+ Browser* source_browser,
+ bool is_incognito) {
+ BrowserOpenedNotificationObserver observer;
kkania 2012/11/15 16:29:07 You should use option A and find the underlying pr
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Use solution A.
+ if (is_incognito)
+ chrome::ExecuteCommand(source_browser, IDC_NEW_INCOGNITO_WINDOW);
+ else
+ chrome::ExecuteCommand(source_browser, IDC_NEW_WINDOW);
+ observer.Wait();
+ return observer.new_browser();
+}
+
+void NotificationsPermissionTest::CloseBrowserWindow(Browser* browser) {
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser));
+ browser->window()->Close();
+ observer.Wait();
+}
+
+void NotificationsPermissionTest::CrashTab(Browser* browser, int index) {
+ content::CrashTab(chrome::GetWebContentsAt(browser, index));
+}
+
+void NotificationsPermissionTest::CrashNotification(Balloon* balloon) {
+ content::CrashTab(balloon->balloon_view()->GetHost()->web_contents());
+}
+
+bool NotificationsPermissionTest::CheckOriginInSetting(
+ const ContentSettingsForOneType & settings,
+ const GURL & origin) {
+ ContentSettingsPattern pattern = ContentSettingsPattern::FromURLNoWildcard(
+ origin);
+ for (ContentSettingsForOneType::const_iterator it = settings.begin();
+ it != settings.end(); ++it) {
+ if (it->primary_pattern == pattern) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void NotificationsPermissionTest::SetDefaultPermissionSetting(
+ ContentSetting setting) {
+ DesktopNotificationService* service = GetDesktopNotificationService();
+ service->SetDefaultContentSetting(setting);
+}
+
+ContentSetting NotificationsPermissionTest::GetDefaultPermissionSetting() {
+ DesktopNotificationService* service = GetDesktopNotificationService();
+ return service->GetDefaultContentSetting(NULL);
+}
+
+void NotificationsPermissionTest::GetDeniedOrigins(
+ ContentSettingsForOneType* settings) {
+ GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, settings);
+}
+
+void NotificationsPermissionTest::GetAllowedOrigins(
+ ContentSettingsForOneType* settings) {
+ GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, settings);
+}
+
+void NotificationsPermissionTest::SetDeniedOrigins(
+ const std::vector<GURL>& new_origins) {
+ // clear original denied origin list.
+ ContentSettingsForOneType old_origins;
+ GetDeniedOrigins(&old_origins);
+ for (ContentSettingsForOneType::const_iterator it = old_origins.begin();
+ it != old_origins.end(); ++it) {
+ GetDesktopNotificationService()->ClearSetting(it->primary_pattern);
+ }
+ // set new origins.
+ for (std::vector<GURL>::const_iterator it = new_origins.begin();
+ it != new_origins.end(); ++it) {
+ DenyOrigin(*it);
+ }
+}
+void NotificationsPermissionTest::SetAllowedOrigins(
+ const std::vector<GURL>& new_origins) {
+ // clear original allowed origin list.
+ ContentSettingsForOneType old_origins;
+ GetAllowedOrigins(&old_origins);
+ for (ContentSettingsForOneType::const_iterator it = old_origins.begin();
+ it != old_origins.end(); ++it) {
+ GetDesktopNotificationService()->ClearSetting(it->primary_pattern);
+ }
+ // set new origins.
+ for (std::vector<GURL>::const_iterator it = new_origins.begin();
+ it != new_origins.end(); ++it) {
+ AllowOrigin(*it);
+ }
+}
+void NotificationsPermissionTest::DenyOrigin(const GURL& origin) {
+ DropOriginPreference(origin);
+ GetDesktopNotificationService()->DenyPermission(origin);
+}
+void NotificationsPermissionTest::AllowOrigin(const GURL& origin) {
+ DropOriginPreference(origin);
+ GetDesktopNotificationService()->GrantPermission(origin);
+}
+void NotificationsPermissionTest::DropOriginPreference(const GURL& origin) {
+ GetDesktopNotificationService()->ClearSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin));
+}
+void NotificationsPermissionTest::AllowAllOrigins() {
+ GetDesktopNotificationService()->ResetAllOrigins();
+ GetDesktopNotificationService()->SetDefaultContentSetting(
+ CONTENT_SETTING_ALLOW);
+}
+
+void NotificationsPermissionTest::VerifyInfobar(
+ const Browser* browser,
+ const std::string& origin,
+ int index) {
+ InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
+ chrome::GetWebContentsAt(browser, index));
+
+ ASSERT_EQ(1U, infobar_helper->GetInfoBarCount());
+ InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(0);
+ ASSERT_TRUE(infobar->AsConfirmInfoBarDelegate());
+ ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate();
+ int buttons = confirm_infobar->GetButtons();
+ if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) {
+ EXPECT_EQ(
+ ASCIIToUTF16("Allow"),
+ confirm_infobar->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
+ } else {
+ EXPECT_TRUE(false);
+ }
+ if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
+ EXPECT_EQ(
+ ASCIIToUTF16("Deny"),
+ confirm_infobar->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
+ } else {
+ EXPECT_TRUE(false);
+ }
+ std::string text("Allow ");
+ text.append(origin);
+ text.append(" to show desktop notifications?");
+ EXPECT_EQ(UTF8ToUTF16(text), confirm_infobar->GetMessageText());
+}
+
+std::string NotificationsPermissionTest::CreateNotification(
+ Browser* browser,
+ bool waiting,
+ const char* icon,
+ const char* title,
+ const char* body,
+ const char* replace_id) {
+ std::string result;
+
+ std::string script = base::StringPrintf(
+ "createNotification('%s', '%s', '%s', '%s');",
+ icon,
+ title,
+ body,
+ replace_id);
+
+ bool flag = false;
+ if (!waiting) {
+ flag = content::ExecuteJavaScriptAndExtractString(
+ chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
+ L"",
+ UTF8ToWide(script),
+ &result);
+ } else {
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED,
+ content::NotificationService::AllSources());
+ flag = content::ExecuteJavaScriptAndExtractString(
+ chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
+ L"",
+ UTF8ToWide(script),
+ &result);
+ observer.Wait();
+ }
+ EXPECT_TRUE(flag);
+
+ content::RunAllPendingInMessageLoop();
+ return result;
+}
+
+std::string NotificationsPermissionTest::CreateSimpleNotification(
+ Browser* browser,
+ bool waiting) {
+ return CreateNotification(
+ browser,
+ waiting,
+ "no_such_file.png",
+ "My Title",
+ "My Body",
+ "");
+}
+
+bool NotificationsPermissionTest::RequestPermission(Browser* browser) {
+ std::string result;
+ bool flag = content::ExecuteJavaScriptAndExtractString(
+ chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
+ L"",
+ L"requestPermission();",
+ &result);
+ return flag ? (result == "1") : false;
+}
+
+bool NotificationsPermissionTest::CancelNotification(
+ const char* notification_id,
+ Browser* browser) {
+ std::string script = base::StringPrintf(
+ "cancelNotification('%s');",
+ notification_id);
+
+ std::string result;
+ bool flag = content::ExecuteJavaScriptAndExtractString(
+ chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
+ L"",
+ UTF8ToWide(script),
+ &result);
+ return flag ? (result == "1") : false;
+}
+
+bool NotificationsPermissionTest::PerformActionOnInfobar(
+ Browser* browser,
+ InfobarAction action,
+ int infobar_index,
+ int tab_index) {
+ InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
+ chrome::GetWebContentsAt(browser, tab_index));
+
+ InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(
+ infobar_index);
+ switch (action) {
+ case DISMISS: {
+ infobar->InfoBarDismissed();
+ infobar_helper->RemoveInfoBar(infobar);
+ return true;
+ }
+ case ALLOW: {
+ ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate();
+ if (confirm_bar->Accept()) {
+ infobar_helper->RemoveInfoBar(infobar);
+ return true;
+ }
+ }
+ case DENY: {
+ ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate();
+ if (confirm_bar->Cancel()) {
+ infobar_helper->RemoveInfoBar(infobar);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+void NotificationsPermissionTest::GetPrefsByContentSetting(
+ ContentSetting setting,
+ ContentSettingsForOneType* settings) {
+ ASSERT_TRUE(settings != NULL);
+ DesktopNotificationService* service = GetDesktopNotificationService();
+ service->GetNotificationsSettings(settings);
+ for (ContentSettingsForOneType::iterator it = settings->begin();
+ it != settings->end();) {
+ if (it->setting != setting || it->source.compare(kReference) != 0) {
+ it = settings->erase(it);
+ } else {
+ ++it;
+ }
+ }
+}
+
+// If this flakes, use http://crbug.com/62311 and http://crbug.com/74428.
+IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) {
ui_test_utils::NavigateToURL(
browser(),
test_server()->GetURL(
@@ -42,8 +587,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) {
// If this flakes, use http://crbug.com/62311.
IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) {
- ASSERT_TRUE(test_server()->Start());
-
// Load a page which just does a request; no user gesture should result
// in no infobar.
ui_test_utils::NavigateToURL(
@@ -54,3 +597,501 @@ IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) {
EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestCreateSimpleNotification) {
+ // Creates a simple notification.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_EQ(1U, balloons.size());
+ Balloon* balloon = balloons[0];
+ const Notification& notification = balloon->notification();
+ GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
+ EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
+ EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title());
+ EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body());
+}
+
+IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestCloseNotification) {
+ // Creates a notification and closes it.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_EQ(1U, balloons.size());
+ EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification()));
+ ASSERT_EQ(0, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestCancelNotification) {
+ // Creates a notification and cancels it in the origin page.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string note_id = CreateSimpleNotification(browser(), true);
+ EXPECT_NE(note_id, "-1");
+
+ ASSERT_EQ(1, GetNotificationCount());
+ ASSERT_TRUE(CancelNotification(note_id.c_str(), browser()));
+ ASSERT_EQ(0, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestPermissionInfobarAppears) {
+ // Requests notification privileges and verifies the infobar appears.
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+
+ ASSERT_EQ(0, GetNotificationCount());
+ VerifyInfobar(browser(), TEST_PAGE_URL.host(), 0);
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestAllowOnPermissionInfobar) {
+ // Tries to create a notification and clicks allow on the infobar.
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ // This notification should not be shown because we do not have permission.
+ CreateSimpleNotification(browser(), false);
+ ASSERT_EQ(0, GetNotificationCount());
+
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0));
+
+ CreateSimpleNotification(browser(), true);
+ EXPECT_EQ(1, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
kkania 2012/11/15 16:29:07 I'm thinking we should perhaps remove this functio
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Agree. It is more like a unit test. Removed. On 2
+ NotificationsPermissionTest,
+ TestOriginPreferencesBasic) {
+ // Tests that we can allow and deny origins.
+ GURL altavista("http://www.altavista.com");
+ GURL gmail("http://www.gmail.com");
+ GURL yahoo("http://www.yahoo.com");
+
+ std::vector<GURL> origins;
+ ContentSettingsForOneType settings;
+
+ origins.push_back(altavista);
+ origins.push_back(gmail);
+
+ SetDeniedOrigins(origins);
+ GetDeniedOrigins(&settings);
+ EXPECT_EQ(2U, settings.size());
+ EXPECT_TRUE(CheckOriginInSetting(settings, altavista));
+ EXPECT_TRUE(CheckOriginInSetting(settings, gmail));
+ DenyOrigin(yahoo);
+ GetDeniedOrigins(&settings);
+ EXPECT_EQ(3U, settings.size());
+ EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
+ DropOriginPreference(gmail);
+ GetDeniedOrigins(&settings);
+ EXPECT_EQ(2U, settings.size());
+ EXPECT_FALSE(CheckOriginInSetting(settings, gmail));
+
+ AllowOrigin(yahoo);
+ GetDeniedOrigins(&settings);
+ EXPECT_EQ(1U, settings.size());
+ EXPECT_FALSE(CheckOriginInSetting(settings, yahoo));
+ GetAllowedOrigins(&settings);
+ EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
+
+ origins.clear();
+ origins.push_back(altavista);
+ origins.push_back(gmail);
+ SetAllowedOrigins(origins);
+ origins.clear();
+ SetDeniedOrigins(origins);
+ GetAllowedOrigins(&settings);
+ EXPECT_TRUE(CheckOriginInSetting(settings, altavista));
+ EXPECT_TRUE(CheckOriginInSetting(settings, gmail));
+ AllowOrigin(yahoo);
+ GetAllowedOrigins(&settings);
+ EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
+ EXPECT_EQ(3U, settings.size());
+ DropOriginPreference(gmail);
+ GetAllowedOrigins(&settings);
+ EXPECT_EQ(2U, settings.size());
+ EXPECT_FALSE(CheckOriginInSetting(settings, gmail));
+
+ DenyOrigin(yahoo);
+ GetAllowedOrigins(&settings);
+ EXPECT_EQ(1U, settings.size());
+ EXPECT_FALSE(CheckOriginInSetting(settings, yahoo));
+ GetDeniedOrigins(&settings);
+ EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestDenyOnPermissionInfobar) {
+ // Test that no notification is created
+ // when Deny is chosen from permission infobar.
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ PerformActionOnInfobar(browser(), DENY, 0, 0);
+ CreateSimpleNotification(browser(), false);
+ ASSERT_EQ(0, GetNotificationCount());
+ ContentSettingsForOneType settings;
+ GetDeniedOrigins(&settings);
+ EXPECT_TRUE(CheckOriginInSetting(settings, TEST_PAGE_URL));
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestClosePermissionInfobar) {
+ // Test that no notification is created when permission infobar is dismissed.
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ PerformActionOnInfobar(browser(), DISMISS, 0, 0);
+ CreateSimpleNotification(browser(), false);
+ ASSERT_EQ(0, GetNotificationCount());
+ ContentSettingsForOneType settings;
+ GetDeniedOrigins(&settings);
+ EXPECT_EQ(0U, settings.size());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestNotificationWithPropertyMissing) {
+ // Test that a notification can be created if one property is missing.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_EQ(1U, balloons.size());
+ Balloon* balloon = balloons[0];
+ const Notification& notification = balloon->notification();
+ GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
+ EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
+ EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestAllowNotificationsFromAllSites) {
+ // Verify that all domains can be allowed to show notifications.
+ SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ ASSERT_EQ(1, GetNotificationCount());
+ EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
+ chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestDenyNotificationsFromAllSites) {
+ // Verify that no domain can show notifications.
+ SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), false);
+ EXPECT_EQ("-1", result);
+
+ ASSERT_EQ(0, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestDenyDomainAndAllowAll) {
+ // Verify that denying a domain and allowing all shouldn't show
+ // notifications from the denied domain.
+ DenyOrigin(TEST_PAGE_URL.GetOrigin());
+ SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
+
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), false);
+ EXPECT_EQ("-1", result);
+
+ ASSERT_EQ(0, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestAllowDomainAndDenyAll) {
+ // Verify that allowing a domain and denying all others should show
+ // notifications from the allowed domain.
+ AllowOrigin(TEST_PAGE_URL.GetOrigin());
+ SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
+
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ ASSERT_EQ(1, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestDenyAndThenAllowDomain) {
+ // Verify that denying and again allowing should show notifications.
+ DenyOrigin(TEST_PAGE_URL.GetOrigin());
+
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateSimpleNotification(browser(), false);
+ EXPECT_EQ("-1", result);
+
+ ASSERT_EQ(0, GetNotificationCount());
+
+ AllowOrigin(TEST_PAGE_URL.GetOrigin());
+ result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ ASSERT_EQ(1, GetNotificationCount());
+ EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
+ chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestCreateDenyCloseNotifications) {
+ // Verify able to create, deny, and close the notification.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ CreateSimpleNotification(browser(), true);
+ ASSERT_EQ(1, GetNotificationCount());
+
+ DenyOrigin(TEST_PAGE_URL.GetOrigin());
+ ContentSettingsForOneType settings;
+ GetDeniedOrigins(&settings);
+ ASSERT_TRUE(CheckOriginInSetting(settings, TEST_PAGE_URL.GetOrigin()));
+
+ const std::deque<Balloon*>& balloons1 = GetActiveBalloons();
+ EXPECT_EQ(1U, balloons1.size());
+ ASSERT_TRUE(CloseNotificationAndWait(balloons1[0]->notification()));
+ ASSERT_EQ(0, GetNotificationCount());
+}
+
+// Crashes on Linux/Win. See http://crbug.com/160657.
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ DISABLED_TestOriginPrefsNotSavedInIncognito) {
+ // Verify that allow/deny origin preferences are not saved in incognito.
+ Browser* incognito = CreateBrowserWindow(browser(), true);
+ ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(incognito));
+ ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true));
+ PerformActionOnInfobar(incognito, DENY, 0, 0);
+ CloseBrowserWindow(incognito);
+
+ incognito = CreateBrowserWindow(browser(), true);
+ ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(incognito));
+ ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true));
+ PerformActionOnInfobar(incognito, ALLOW, 0, 0);
+ CreateSimpleNotification(incognito, true);
+ ASSERT_EQ(1, GetNotificationCount());
+ CloseBrowserWindow(incognito);
+
+ incognito = CreateBrowserWindow(browser(), true);
+ ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(incognito));
+ ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true));
+
+ ContentSettingsForOneType settings;
+ GetDeniedOrigins(&settings);
+ EXPECT_EQ(0U, settings.size());
+ GetAllowedOrigins(&settings);
+ EXPECT_EQ(0U, settings.size());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestExitBrowserWithInfobar) {
+ // Exit the browser window, when the infobar appears.
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestCrashTabWithPermissionInfobar) {
+ // Test crashing the tab with permission infobar doesn't crash Chrome.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ EMPTY_PAGE_URL,
+ NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ chrome::ActivateTabAt(browser(), 0, true);
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ CrashTab(browser(), 0);
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestKillNotificationProcess) {
+ // Test killing a notification doesn't crash Chrome.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ CreateSimpleNotification(browser(), true);
+ ASSERT_EQ(1, GetNotificationCount());
+
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_EQ(1U, balloons.size());
+ CrashNotification(balloons[0]);
+ ASSERT_EQ(0, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestIncognitoNotification) {
+ // Test notifications in incognito window.
+ Browser* browser = CreateIncognitoBrowser();
+ ui_test_utils::NavigateToURL(browser, TEST_PAGE_URL);
+ chrome::ActivateTabAt(browser, 0, true);
+ ASSERT_TRUE(RequestPermission(browser));
+ ASSERT_TRUE(WaitForInfoBarCount(browser, 1, 0, true));
+ PerformActionOnInfobar(browser, ALLOW, 0, 0);
+ CreateSimpleNotification(browser, true);
+ ASSERT_EQ(1, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestCloseTabWithPermissionInfobar) {
+ // Test that user can close tab when infobar present.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL("about:blank"),
+ NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ chrome::ActivateTabAt(browser(), 0, true);
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ content::WindowedNotificationObserver observer(
+ content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
+ content::NotificationService::AllSources());
+ chrome::CloseWebContents(browser(), chrome::GetWebContentsAt(browser(), 0));
+ observer.Wait();
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestNavigateAwayWithPermissionInfobar) {
+ // Test navigating away when an infobar is present,
+ // then trying to create a notification from the same page.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL("about:blank"),
+ NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ chrome::ActivateTabAt(browser(), 0, true);
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ ASSERT_TRUE(RequestPermission(browser()));
+ ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
+ PerformActionOnInfobar(browser(), ALLOW, 0, 0);
+ CreateSimpleNotification(browser(), true);
+ ASSERT_EQ(1, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestCrashRendererNotificationRemain) {
+ // Test crashing renderer does not close or crash notification.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL("about:blank"),
+ NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ chrome::ActivateTabAt(browser(), 0, true);
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+ CreateSimpleNotification(browser(), true);
+ ASSERT_EQ(1, GetNotificationCount());
+ CrashTab(browser(), 0);
+ ASSERT_EQ(1, GetNotificationCount());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestNotificationOrderAfterClosingOne) {
+ // Tests that closing a notification leaves the rest
+ // of the notifications in the correct order.
+ // Check for Win7.
+#if defined(OS_WIN)
+ if (base::win::GetVersion() == VERSION_WIN7) {
+ return; // crbug.com/66072
+ }
+#endif
+
+ AllowAllOrigins();
+
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ CreateNotification(browser(), true, "", "Title1", "", "1");
+ CreateNotification(browser(), true, "", "Title2", "", "2");
+ CreateNotification(browser(), true, "", "Title3", "", "3");
+
+ ASSERT_EQ(3, GetNotificationCount());
+ const std::deque<Balloon*>& old_balloons = GetActiveBalloons();
+
+ ASSERT_TRUE(CloseNotificationAndWait(old_balloons[1]->notification()));
+
+ const std::deque<Balloon*>& new_balloons = GetActiveBalloons();
+ ASSERT_EQ(2U, new_balloons.size());
+ EXPECT_EQ(old_balloons[0]->notification().notification_id(),
+ new_balloons[0]->notification().notification_id());
+ EXPECT_EQ(old_balloons[2]->notification().notification_id(),
+ new_balloons[1]->notification().notification_id());
+}
+
+IN_PROC_BROWSER_TEST_F(
+ NotificationsPermissionTest,
+ TestNotificationReplacement) {
+ // Test that we can replace a notification using the replaceId.
+ AllowAllOrigins();
+
+ ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
+
+ std::string result = CreateNotification(
+ browser(),
kkania 2012/11/15 16:29:07 4, not 5
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
+ true,
+ "",
+ "Title2",
+ "",
+ "chat");
+ EXPECT_NE("-1", result);
+
+ ASSERT_EQ(1, GetNotificationCount());
+
+ result = CreateNotification(
kkania 2012/11/15 16:29:07 are we guaranteed that this func waits until the r
chrisgao (Use stgao instead) 2012/11/16 00:23:30 According to my test, Chrome supports notification
+ browser(),
+ false,
+ "no_such_file.png",
+ "",
+ "",
+ "chat");
+ EXPECT_NE("-1", result);
+
+ const std::deque<Balloon*>& balloons2 = GetActiveBalloons();
+ EXPECT_EQ(1U, balloons2.size());
+ GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
+ const Notification& notification = balloons2[0]->notification();
+ EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
+}
« no previous file with comments | « no previous file | chrome/test/data/notifications/notification_tester.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698