diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 22:43:52 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 22:43:52 +0000 |
commit | 83ab5f200ee5c9601bfa60d1786f99c77ff1a88a (patch) | |
tree | 18ef37d863f7789d45b4a86863fd6619b9e6f293 /chrome/browser/notifications | |
parent | 3e7fdb8e84bebac34195fa298330cabdf383e26e (diff) | |
download | chromium_src-83ab5f200ee5c9601bfa60d1786f99c77ff1a88a.zip chromium_src-83ab5f200ee5c9601bfa60d1786f99c77ff1a88a.tar.gz chromium_src-83ab5f200ee5c9601bfa60d1786f99c77ff1a88a.tar.bz2 |
Notifications permission infobar should only be shown in response to a user gesture, not arbitrary script.
Includes UI test which verify the infobar is shown from a gesture, and not shown from raw script.
BUG=27215
TEST=included
Review URL: http://codereview.chromium.org/387011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
-rwxr-xr-x | chrome/browser/notifications/notifications_uitest.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/chrome/browser/notifications/notifications_uitest.cc b/chrome/browser/notifications/notifications_uitest.cc new file mode 100755 index 0000000..22284bc --- /dev/null +++ b/chrome/browser/notifications/notifications_uitest.cc @@ -0,0 +1,67 @@ +// 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, 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); + + int info_bar_count; + tab->GetInfoBarCount(&info_bar_count); + EXPECT_EQ(1, info_bar_count); +} + +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 |