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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/content_settings/cookie_settings.h" | 9 #include "chrome/browser/content_settings/cookie_settings.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
15 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
21 #include "net/test/test_server.h" | 22 #include "net/test/test_server.h" |
22 | 23 |
23 // Regression test for http://crbug.com/63649. | 24 // Regression test for http://crbug.com/63649. |
24 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectLoopCookies) { | 25 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectLoopCookies) { |
25 ASSERT_TRUE(test_server()->Start()); | 26 ASSERT_TRUE(test_server()->Start()); |
26 | 27 |
27 GURL test_url = test_server()->GetURL("files/redirect-loop.html"); | 28 GURL test_url = test_server()->GetURL("files/redirect-loop.html"); |
28 | 29 |
29 CookieSettings::Factory::GetForProfile(browser()->profile())-> | 30 CookieSettings::Factory::GetForProfile(browser()->profile())-> |
30 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 31 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
31 | 32 |
32 ui_test_utils::NavigateToURL(browser(), test_url); | 33 ui_test_utils::NavigateToURL(browser(), test_url); |
33 | 34 |
34 TabContents* tab_contents = browser()->GetActiveTabContents(); | 35 TabContents* tab_contents = chrome::GetActiveTabContents(browser()); |
35 ASSERT_EQ(UTF8ToUTF16(test_url.spec() + " failed to load"), | 36 ASSERT_EQ(UTF8ToUTF16(test_url.spec() + " failed to load"), |
36 tab_contents->web_contents()->GetTitle()); | 37 tab_contents->web_contents()->GetTitle()); |
37 | 38 |
38 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( | 39 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( |
39 CONTENT_SETTINGS_TYPE_COOKIES)); | 40 CONTENT_SETTINGS_TYPE_COOKIES)); |
40 } | 41 } |
41 | 42 |
42 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, ContentSettingsBlockDataURLs) { | 43 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, ContentSettingsBlockDataURLs) { |
43 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>"); | 44 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>"); |
44 | 45 |
45 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 46 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
46 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 47 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
47 | 48 |
48 ui_test_utils::NavigateToURL(browser(), url); | 49 ui_test_utils::NavigateToURL(browser(), url); |
49 | 50 |
50 TabContents* tab_contents = browser()->GetActiveTabContents(); | 51 TabContents* tab_contents = chrome::GetActiveTabContents(browser()); |
51 ASSERT_EQ(UTF8ToUTF16("Data URL"), tab_contents->web_contents()->GetTitle()); | 52 ASSERT_EQ(UTF8ToUTF16("Data URL"), tab_contents->web_contents()->GetTitle()); |
52 | 53 |
53 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( | 54 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( |
54 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 55 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
55 } | 56 } |
56 | 57 |
57 // Tests that if redirect across origins occurs, the new process still gets the | 58 // Tests that if redirect across origins occurs, the new process still gets the |
58 // content settings before the resource headers. | 59 // content settings before the resource headers. |
59 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectCrossOrigin) { | 60 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectCrossOrigin) { |
60 ASSERT_TRUE(test_server()->Start()); | 61 ASSERT_TRUE(test_server()->Start()); |
61 | 62 |
62 net::HostPortPair host_port = test_server()->host_port_pair(); | 63 net::HostPortPair host_port = test_server()->host_port_pair(); |
63 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); | 64 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); |
64 | 65 |
65 std::string redirect(base::StringPrintf( | 66 std::string redirect(base::StringPrintf( |
66 "http://localhost:%d/files/redirect-cross-origin.html", | 67 "http://localhost:%d/files/redirect-cross-origin.html", |
67 host_port.port())); | 68 host_port.port())); |
68 GURL test_url = test_server()->GetURL("server-redirect?" + redirect); | 69 GURL test_url = test_server()->GetURL("server-redirect?" + redirect); |
69 | 70 |
70 CookieSettings::Factory::GetForProfile(browser()->profile())-> | 71 CookieSettings::Factory::GetForProfile(browser()->profile())-> |
71 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 72 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
72 | 73 |
73 ui_test_utils::NavigateToURL(browser(), test_url); | 74 ui_test_utils::NavigateToURL(browser(), test_url); |
74 | 75 |
75 TabContents* tab_contents = browser()->GetActiveTabContents(); | 76 TabContents* tab_contents = chrome::GetActiveTabContents(browser()); |
76 | 77 |
77 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( | 78 EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked( |
78 CONTENT_SETTINGS_TYPE_COOKIES)); | 79 CONTENT_SETTINGS_TYPE_COOKIES)); |
79 } | 80 } |
80 | 81 |
81 #if !defined(USE_AURA) // No NPAPI plugins with Aura. | 82 #if !defined(USE_AURA) // No NPAPI plugins with Aura. |
82 | 83 |
83 class ClickToPlayPluginTest : public InProcessBrowserTest { | 84 class ClickToPlayPluginTest : public InProcessBrowserTest { |
84 public: | 85 public: |
85 ClickToPlayPluginTest() { | 86 ClickToPlayPluginTest() { |
(...skipping 16 matching lines...) Expand all Loading... |
102 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 103 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
103 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 104 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
104 | 105 |
105 GURL url = ui_test_utils::GetTestUrl( | 106 GURL url = ui_test_utils::GetTestUrl( |
106 FilePath().AppendASCII("npapi"), | 107 FilePath().AppendASCII("npapi"), |
107 FilePath().AppendASCII("clicktoplay.html")); | 108 FilePath().AppendASCII("clicktoplay.html")); |
108 ui_test_utils::NavigateToURL(browser(), url); | 109 ui_test_utils::NavigateToURL(browser(), url); |
109 | 110 |
110 string16 expected_title(ASCIIToUTF16("OK")); | 111 string16 expected_title(ASCIIToUTF16("OK")); |
111 ui_test_utils::TitleWatcher title_watcher( | 112 ui_test_utils::TitleWatcher title_watcher( |
112 browser()->GetActiveWebContents(), expected_title); | 113 chrome::GetActiveWebContents(browser()), expected_title); |
113 | 114 |
114 content::RenderViewHost* host = | 115 content::RenderViewHost* host = |
115 browser()->GetActiveWebContents()->GetRenderViewHost(); | 116 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
116 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 117 host->Send(new ChromeViewMsg_LoadBlockedPlugins( |
117 host->GetRoutingID(), std::string())); | 118 host->GetRoutingID(), std::string())); |
118 | 119 |
119 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 120 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
120 } | 121 } |
121 | 122 |
122 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) { | 123 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, LoadAllBlockedPlugins) { |
123 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 124 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
124 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 125 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
125 | 126 |
126 GURL url = ui_test_utils::GetTestUrl( | 127 GURL url = ui_test_utils::GetTestUrl( |
127 FilePath().AppendASCII("npapi"), | 128 FilePath().AppendASCII("npapi"), |
128 FilePath().AppendASCII("load_all_blocked_plugins.html")); | 129 FilePath().AppendASCII("load_all_blocked_plugins.html")); |
129 ui_test_utils::NavigateToURL(browser(), url); | 130 ui_test_utils::NavigateToURL(browser(), url); |
130 | 131 |
131 string16 expected_title1(ASCIIToUTF16("1")); | 132 string16 expected_title1(ASCIIToUTF16("1")); |
132 ui_test_utils::TitleWatcher title_watcher1( | 133 ui_test_utils::TitleWatcher title_watcher1( |
133 browser()->GetActiveWebContents(), expected_title1); | 134 chrome::GetActiveWebContents(browser()), expected_title1); |
134 | 135 |
135 content::RenderViewHost* host = | 136 content::RenderViewHost* host = |
136 browser()->GetActiveWebContents()->GetRenderViewHost(); | 137 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
137 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 138 host->Send(new ChromeViewMsg_LoadBlockedPlugins( |
138 host->GetRoutingID(), std::string())); | 139 host->GetRoutingID(), std::string())); |
139 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); | 140 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); |
140 | 141 |
141 string16 expected_title2(ASCIIToUTF16("2")); | 142 string16 expected_title2(ASCIIToUTF16("2")); |
142 ui_test_utils::TitleWatcher title_watcher2( | 143 ui_test_utils::TitleWatcher title_watcher2( |
143 browser()->GetActiveWebContents(), expected_title2); | 144 chrome::GetActiveWebContents(browser()), expected_title2); |
144 | 145 |
145 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 146 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
146 browser()->GetActiveWebContents()->GetRenderViewHost(), | 147 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
147 L"", L"window.inject()")); | 148 L"", L"window.inject()")); |
148 | 149 |
149 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); | 150 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); |
150 } | 151 } |
151 | 152 |
152 // If this flakes, use http://crbug.com/113057. | 153 // If this flakes, use http://crbug.com/113057. |
153 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { | 154 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { |
154 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 155 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
155 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 156 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
156 | 157 |
157 GURL url("data:application/vnd.npapi-test,CallOnStartup();"); | 158 GURL url("data:application/vnd.npapi-test,CallOnStartup();"); |
158 ui_test_utils::NavigateToURL(browser(), url); | 159 ui_test_utils::NavigateToURL(browser(), url); |
159 | 160 |
160 // Inject the callback function into the HTML page generated by the browser. | 161 // Inject the callback function into the HTML page generated by the browser. |
161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 162 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
162 browser()->GetActiveWebContents()->GetRenderViewHost(), | 163 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
163 L"", L"CallOnStartup = function() { document.title = \"OK\"; }")); | 164 L"", L"CallOnStartup = function() { document.title = \"OK\"; }")); |
164 | 165 |
165 string16 expected_title(ASCIIToUTF16("OK")); | 166 string16 expected_title(ASCIIToUTF16("OK")); |
166 ui_test_utils::TitleWatcher title_watcher( | 167 ui_test_utils::TitleWatcher title_watcher( |
167 browser()->GetActiveWebContents(), expected_title); | 168 chrome::GetActiveWebContents(browser()), expected_title); |
168 | 169 |
169 content::RenderViewHost* host = | 170 content::RenderViewHost* host = |
170 browser()->GetActiveWebContents()->GetRenderViewHost(); | 171 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
171 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 172 host->Send(new ChromeViewMsg_LoadBlockedPlugins( |
172 host->GetRoutingID(), std::string())); | 173 host->GetRoutingID(), std::string())); |
173 | 174 |
174 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 175 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
175 } | 176 } |
176 | 177 |
177 #endif // !defined(USE_AURA) | 178 #endif // !defined(USE_AURA) |
OLD | NEW |