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