summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xchrome/browser/notifications/notifications_uitest.cc65
-rwxr-xr-xchrome/chrome.gyp1
-rw-r--r--chrome/common/desktop_notifications/active_notification_tracker.cc14
-rw-r--r--chrome/renderer/notification_provider.cc4
-rw-r--r--chrome/test/automation/tab_proxy.cc13
-rw-r--r--chrome/test/automation/tab_proxy.h5
-rw-r--r--chrome/test/data/notifications/notifications_request_function.html13
-rw-r--r--chrome/test/data/notifications/notifications_request_inline.html10
8 files changed, 118 insertions, 7 deletions
diff --git a/chrome/browser/notifications/notifications_uitest.cc b/chrome/browser/notifications/notifications_uitest.cc
new file mode 100755
index 0000000..9fa61ff
--- /dev/null
+++ b/chrome/browser/notifications/notifications_uitest.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_path.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+#include "net/base/net_util.h"
+#include "net/url_request/url_request_unittest.h"
+
+class NotificationsPermissionTest : public UITest {
+ public:
+ NotificationsPermissionTest() {
+ launch_arguments_.AppendSwitch(switches::kEnableDesktopNotifications);
+ dom_automation_enabled_ = true;
+ show_window_ = true;
+ }
+};
+
+#if defined(OS_WIN)
+TEST_F(NotificationsPermissionTest, FLAKY_TestUserGestureInfobar) {
+ const wchar_t kDocRoot[] = L"chrome/test/data";
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot, NULL);
+ ASSERT_TRUE(server.get() != NULL);
+
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ scoped_refptr<TabProxy> tab(browser->GetActiveTab());
+ tab->NavigateToURL(server->TestServerPageW(
+ L"files/notifications/notifications_request_function.html"));
+ WaitUntilTabCount(1);
+
+ // Request permission by calling request() while eval'ing an inline script;
+ // That's considered a user gesture to webkit, and should produce an infobar.
+ bool result;
+ tab->ExecuteAndExtractBool(L"",
+ L"window.domAutomationController.send(request());",
+ &result);
+ EXPECT_TRUE(result);
+
+ EXPECT_TRUE(tab->WaitForInfoBarCount(1, action_max_timeout_ms()));
+}
+
+TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) {
+ const wchar_t kDocRoot[] = L"chrome/test/data";
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot, NULL);
+ ASSERT_TRUE(server.get() != NULL);
+
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ scoped_refptr<TabProxy> tab(browser->GetActiveTab());
+
+ // Load a page which just does a request; no user gesture should result
+ // in no infobar.
+ tab->NavigateToURL(server->TestServerPageW(
+ L"files/notifications/notifications_request_inline.html"));
+ WaitUntilTabCount(1);
+
+ int info_bar_count;
+ tab->GetInfoBarCount(&info_bar_count);
+ EXPECT_EQ(0, info_bar_count);
+}
+#endif // OS_WIN
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index fa6d8a7..5cc7e42 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -4279,6 +4279,7 @@
'browser/login_prompt_uitest.cc',
'browser/media_uitest.cc',
'browser/metrics/metrics_service_uitest.cc',
+ 'browser/notifications/notifications_uitest.cc',
'browser/printing/printing_layout_uitest.cc',
'browser/process_singleton_linux_uitest.cc',
'browser/renderer_host/resource_dispatcher_host_uitest.cc',
diff --git a/chrome/common/desktop_notifications/active_notification_tracker.cc b/chrome/common/desktop_notifications/active_notification_tracker.cc
index 3357ab3..d3d50cd 100644
--- a/chrome/common/desktop_notifications/active_notification_tracker.cc
+++ b/chrome/common/desktop_notifications/active_notification_tracker.cc
@@ -13,7 +13,7 @@ using WebKit::WebNotificationPermissionCallback;
bool ActiveNotificationTracker::GetId(
const WebNotification& notification, int& id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
ReverseTable::iterator iter = reverse_notification_table_.find(notification);
if (iter == reverse_notification_table_.end())
return false;
@@ -23,7 +23,7 @@ bool ActiveNotificationTracker::GetId(
bool ActiveNotificationTracker::GetNotification(
int id, WebNotification* notification) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
WebNotification* lookup = notification_table_.Lookup(id);
if (!lookup)
return false;
@@ -34,7 +34,7 @@ bool ActiveNotificationTracker::GetNotification(
int ActiveNotificationTracker::RegisterNotification(
const WebKit::WebNotification& proxy) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
WebNotification* notification = new WebNotification(proxy);
int id = notification_table_.Add(notification);
reverse_notification_table_[proxy] = id;
@@ -42,7 +42,7 @@ int ActiveNotificationTracker::RegisterNotification(
}
void ActiveNotificationTracker::UnregisterNotification(int id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
// We want to free the notification after removing it from the table.
scoped_ptr<WebNotification> notification(notification_table_.Lookup(id));
notification_table_.Remove(id);
@@ -53,17 +53,17 @@ void ActiveNotificationTracker::UnregisterNotification(int id) {
WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback(
int id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
return callback_table_.Lookup(id);
}
int ActiveNotificationTracker::RegisterPermissionRequest(
WebNotificationPermissionCallback* callback) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
return callback_table_.Add(callback);
}
void ActiveNotificationTracker::OnPermissionRequestComplete(int id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT);
callback_table_.Remove(id);
}
diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc
index 9510cab..6746350 100644
--- a/chrome/renderer/notification_provider.cc
+++ b/chrome/renderer/notification_provider.cc
@@ -55,6 +55,10 @@ WebNotificationPresenter::Permission NotificationProvider::checkPermission(
void NotificationProvider::requestPermission(
const WebString& origin, WebNotificationPermissionCallback* callback) {
+ // We only request permission in response to a user gesture.
+ if (!view_->webview()->mainFrame()->isProcessingUserGesture())
+ return;
+
int id = manager_.RegisterPermissionRequest(callback);
Send(new ViewHostMsg_RequestNotificationPermission(view_->routing_id(),
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index c16044f..1b9b62d 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -618,6 +618,19 @@ bool TabProxy::GetInfoBarCount(int* count) {
return sender_->Send(new AutomationMsg_GetInfoBarCount(0, handle_, count));
}
+bool TabProxy::WaitForInfoBarCount(int target_count, int wait_timeout) {
+ int intervals = std::min(wait_timeout/automation::kSleepTime, 1);
+ for (int i = 0; i < intervals; ++i) {
+ PlatformThread::Sleep(automation::kSleepTime);
+ int new_count = -1;
+ if (!GetInfoBarCount(&new_count))
+ return false;
+ if (target_count == new_count)
+ return true;
+ }
+ return false;
+}
+
bool TabProxy::ClickInfoBarAccept(int info_bar_index,
bool wait_for_navigation) {
if (!is_valid())
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 9a5be9c..61ab571 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -318,6 +318,11 @@ class TabProxy : public AutomationResourceProxy {
// Retrieves the number of info-bars currently showing in |count|.
bool GetInfoBarCount(int* count);
+ // Waits for up to |wait_timeout| ms until the infobar count is |count|.
+ // Returns false if a timeout occurred before the count matched, or an
+ // error occurred retrieving the count.
+ bool WaitForInfoBarCount(int count, int wait_timeout);
+
// Causes a click on the "accept" button of the info-bar at |info_bar_index|.
// If |wait_for_navigation| is true, this call does not return until a
// navigation has occured.
diff --git a/chrome/test/data/notifications/notifications_request_function.html b/chrome/test/data/notifications/notifications_request_function.html
new file mode 100644
index 0000000..082a724
--- /dev/null
+++ b/chrome/test/data/notifications/notifications_request_function.html
@@ -0,0 +1,13 @@
+<html>
+<head>
+<script>
+function request() {
+ window.webkitNotifications.requestPermission();
+ return true;
+}
+</script>
+</head>
+<body>
+Standing by to request permission...
+</body>
+</html>
diff --git a/chrome/test/data/notifications/notifications_request_inline.html b/chrome/test/data/notifications/notifications_request_inline.html
new file mode 100644
index 0000000..1e47c61
--- /dev/null
+++ b/chrome/test/data/notifications/notifications_request_inline.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+</head>
+<body>
+Requesting permission...
+</body>
+<script>
+window.webkitNotifications.requestPermission();
+</script>
+</html>