OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "chrome/common/chrome_switches.h" | 6 #include "chrome/common/chrome_switches.h" |
7 #include "chrome/test/automation/browser_proxy.h" | 7 #include "chrome/test/automation/browser_proxy.h" |
8 #include "chrome/test/automation/tab_proxy.h" | 8 #include "chrome/test/automation/tab_proxy.h" |
9 #include "chrome/test/ui/ui_test.h" | 9 #include "chrome/test/ui/ui_test.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
11 #include "net/url_request/url_request_unittest.h" | 11 #include "net/url_request/url_request_unittest.h" |
12 | 12 |
13 class NotificationsPermissionTest : public UITest { | 13 class NotificationsPermissionTest : public UITest { |
14 public: | 14 public: |
15 NotificationsPermissionTest() { | 15 NotificationsPermissionTest() { |
16 dom_automation_enabled_ = true; | 16 dom_automation_enabled_ = true; |
17 show_window_ = true; | 17 show_window_ = true; |
18 } | 18 } |
19 }; | 19 }; |
20 | 20 |
21 TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { | 21 TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { |
22 const wchar_t kDocRoot[] = L"chrome/test/data"; | 22 const wchar_t kDocRoot[] = L"chrome/test/data"; |
23 scoped_refptr<HTTPTestServer> server = | 23 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); |
24 HTTPTestServer::CreateServer(kDocRoot, NULL); | |
25 ASSERT_TRUE(server.get() != NULL); | 24 ASSERT_TRUE(server.get() != NULL); |
26 | 25 |
27 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 26 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
28 ASSERT_TRUE(browser.get()); | 27 ASSERT_TRUE(browser.get()); |
29 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); | 28 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); |
30 ASSERT_TRUE(tab.get()); | 29 ASSERT_TRUE(tab.get()); |
31 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 30 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
32 tab->NavigateToURL(server->TestServerPage( | 31 tab->NavigateToURL(server->TestServerPage( |
33 "files/notifications/notifications_request_function.html"))); | 32 "files/notifications/notifications_request_function.html"))); |
34 WaitUntilTabCount(1); | 33 WaitUntilTabCount(1); |
35 | 34 |
36 // Request permission by calling request() while eval'ing an inline script; | 35 // 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. | 36 // That's considered a user gesture to webkit, and should produce an infobar. |
38 bool result; | 37 bool result; |
39 ASSERT_TRUE(tab->ExecuteAndExtractBool( | 38 ASSERT_TRUE(tab->ExecuteAndExtractBool( |
40 L"", | 39 L"", |
41 L"window.domAutomationController.send(request());", | 40 L"window.domAutomationController.send(request());", |
42 &result)); | 41 &result)); |
43 EXPECT_TRUE(result); | 42 EXPECT_TRUE(result); |
44 | 43 |
45 EXPECT_TRUE(tab->WaitForInfoBarCount(1, action_max_timeout_ms())); | 44 EXPECT_TRUE(tab->WaitForInfoBarCount(1, action_max_timeout_ms())); |
46 } | 45 } |
47 | 46 |
48 TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { | 47 TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { |
49 const wchar_t kDocRoot[] = L"chrome/test/data"; | 48 const wchar_t kDocRoot[] = L"chrome/test/data"; |
50 scoped_refptr<HTTPTestServer> server = | 49 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); |
51 HTTPTestServer::CreateServer(kDocRoot, NULL); | |
52 ASSERT_TRUE(server.get() != NULL); | 50 ASSERT_TRUE(server.get() != NULL); |
53 | 51 |
54 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 52 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
55 ASSERT_TRUE(browser.get()); | 53 ASSERT_TRUE(browser.get()); |
56 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); | 54 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); |
57 ASSERT_TRUE(tab.get()); | 55 ASSERT_TRUE(tab.get()); |
58 | 56 |
59 // Load a page which just does a request; no user gesture should result | 57 // Load a page which just does a request; no user gesture should result |
60 // in no infobar. | 58 // in no infobar. |
61 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 59 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
62 tab->NavigateToURL(server->TestServerPage( | 60 tab->NavigateToURL(server->TestServerPage( |
63 "files/notifications/notifications_request_inline.html"))); | 61 "files/notifications/notifications_request_inline.html"))); |
64 WaitUntilTabCount(1); | 62 WaitUntilTabCount(1); |
65 | 63 |
66 int info_bar_count; | 64 int info_bar_count; |
67 ASSERT_TRUE(tab->GetInfoBarCount(&info_bar_count)); | 65 ASSERT_TRUE(tab->GetInfoBarCount(&info_bar_count)); |
68 EXPECT_EQ(0, info_bar_count); | 66 EXPECT_EQ(0, info_bar_count); |
69 } | 67 } |
OLD | NEW |