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/browser/infobars/infobar_tab_helper.h" | 5 #include "chrome/browser/infobars/infobar_tab_helper.h" |
6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_tabstrip.h" |
7 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
8 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
11 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
12 #include "net/test/test_server.h" | 13 #include "net/test/test_server.h" |
13 | 14 |
14 class NotificationsPermissionTest : public InProcessBrowserTest { | 15 class NotificationsPermissionTest : public InProcessBrowserTest { |
15 public: | 16 public: |
16 NotificationsPermissionTest() { | 17 NotificationsPermissionTest() { |
17 EnableDOMAutomation(); | 18 EnableDOMAutomation(); |
18 } | 19 } |
19 }; | 20 }; |
20 | 21 |
21 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. | 22 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. |
22 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { | 23 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { |
23 ASSERT_TRUE(test_server()->Start()); | 24 ASSERT_TRUE(test_server()->Start()); |
24 | 25 |
25 ui_test_utils::NavigateToURL( | 26 ui_test_utils::NavigateToURL( |
26 browser(), | 27 browser(), |
27 test_server()->GetURL( | 28 test_server()->GetURL( |
28 "files/notifications/notifications_request_function.html")); | 29 "files/notifications/notifications_request_function.html")); |
29 | 30 |
30 // Request permission by calling request() while eval'ing an inline script; | 31 // Request permission by calling request() while eval'ing an inline script; |
31 // That's considered a user gesture to webkit, and should produce an infobar. | 32 // That's considered a user gesture to webkit, and should produce an infobar. |
32 bool result; | 33 bool result; |
33 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 34 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
34 browser()->GetActiveWebContents()->GetRenderViewHost(), | 35 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
35 L"", | 36 L"", |
36 L"window.domAutomationController.send(request());", | 37 L"window.domAutomationController.send(request());", |
37 &result)); | 38 &result)); |
38 EXPECT_TRUE(result); | 39 EXPECT_TRUE(result); |
39 | 40 |
40 EXPECT_EQ(1U, browser()->GetTabContentsAt(0)->infobar_tab_helper()-> | 41 EXPECT_EQ(1U, chrome::GetTabContentsAt(browser(), 0)->infobar_tab_helper()-> |
41 infobar_count()); | 42 infobar_count()); |
42 } | 43 } |
43 | 44 |
44 // If this flakes, use http://crbug.com/62311. | 45 // If this flakes, use http://crbug.com/62311. |
45 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { | 46 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { |
46 ASSERT_TRUE(test_server()->Start()); | 47 ASSERT_TRUE(test_server()->Start()); |
47 | 48 |
48 // Load a page which just does a request; no user gesture should result | 49 // Load a page which just does a request; no user gesture should result |
49 // in no infobar. | 50 // in no infobar. |
50 ui_test_utils::NavigateToURL( | 51 ui_test_utils::NavigateToURL( |
51 browser(), | 52 browser(), |
52 test_server()->GetURL( | 53 test_server()->GetURL( |
53 "files/notifications/notifications_request_inline.html")); | 54 "files/notifications/notifications_request_inline.html")); |
54 | 55 |
55 EXPECT_EQ(0U, browser()->GetTabContentsAt(0)->infobar_tab_helper()-> | 56 EXPECT_EQ(0U, chrome::GetTabContentsAt(browser(), 0)->infobar_tab_helper()-> |
56 infobar_count()); | 57 infobar_count()); |
57 } | 58 } |
OLD | NEW |