Home | History | Annotate | Download | only in notifications
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/test/automation/browser_proxy.h"
      6 #include "chrome/test/automation/tab_proxy.h"
      7 #include "chrome/test/ui/ui_test.h"
      8 #include "net/base/net_util.h"
      9 #include "net/test/test_server.h"
     10 
     11 class NotificationsPermissionTest : public UITest {
     12  public:
     13   NotificationsPermissionTest() {
     14     dom_automation_enabled_ = true;
     15     show_window_ = true;
     16   }
     17 };
     18 
     19 // Flaky, http://crbug.com/62311 and http://crbug.com/74428.
     20 TEST_F(NotificationsPermissionTest, DISABLED_TestUserGestureInfobar) {
     21   net::TestServer test_server(net::TestServer::TYPE_HTTP,
     22                               FilePath(FILE_PATH_LITERAL("chrome/test/data")));
     23   ASSERT_TRUE(test_server.Start());
     24 
     25   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
     26   ASSERT_TRUE(browser.get());
     27   scoped_refptr<TabProxy> tab(browser->GetActiveTab());
     28   ASSERT_TRUE(tab.get());
     29   ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
     30             tab->NavigateToURL(test_server.GetURL(
     31                 "files/notifications/notifications_request_function.html")));
     32   WaitUntilTabCount(1);
     33 
     34   // Request permission by calling request() while eval'ing an inline script;
     35   // That's considered a user gesture to webkit, and should produce an infobar.
     36   bool result;
     37   ASSERT_TRUE(tab->ExecuteAndExtractBool(
     38       L"",
     39       L"window.domAutomationController.send(request());",
     40       &result));
     41   EXPECT_TRUE(result);
     42 
     43   EXPECT_TRUE(tab->WaitForInfoBarCount(1));
     44 }
     45 
     46 // Flaky, http://crbug.com/62311.
     47 TEST_F(NotificationsPermissionTest, FLAKY_TestNoUserGestureInfobar) {
     48   net::TestServer test_server(net::TestServer::TYPE_HTTP,
     49                               FilePath(FILE_PATH_LITERAL("chrome/test/data")));
     50   ASSERT_TRUE(test_server.Start());
     51 
     52   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
     53   ASSERT_TRUE(browser.get());
     54   scoped_refptr<TabProxy> tab(browser->GetActiveTab());
     55   ASSERT_TRUE(tab.get());
     56 
     57   // Load a page which just does a request; no user gesture should result
     58   // in no infobar.
     59   ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
     60             tab->NavigateToURL(test_server.GetURL(
     61                 "files/notifications/notifications_request_inline.html")));
     62   WaitUntilTabCount(1);
     63 
     64   size_t info_bar_count;
     65   ASSERT_TRUE(tab->GetInfoBarCount(&info_bar_count));
     66   EXPECT_EQ(0U, info_bar_count);
     67 }
     68