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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 const std::string host_; | 287 const std::string host_; |
288 }; | 288 }; |
289 | 289 |
290 // Verifies that the given url |spec| can be opened. This assumes that |spec| | 290 // Verifies that the given url |spec| can be opened. This assumes that |spec| |
291 // points at empty.html in the test data dir. | 291 // points at empty.html in the test data dir. |
292 void CheckCanOpenURL(Browser* browser, const char* spec) { | 292 void CheckCanOpenURL(Browser* browser, const char* spec) { |
293 GURL url(spec); | 293 GURL url(spec); |
294 ui_test_utils::NavigateToURL(browser, url); | 294 ui_test_utils::NavigateToURL(browser, url); |
295 content::WebContents* contents = | 295 content::WebContents* contents = |
296 browser->tab_strip_model()->GetActiveWebContents(); | 296 browser->tab_strip_model()->GetActiveWebContents(); |
297 ASSERT_EQ(url, contents->GetURL()); | 297 EXPECT_EQ(url, contents->GetURL()); |
298 base::string16 spec16 = base::UTF8ToUTF16(url.spec()); | 298 base::string16 spec16 = base::UTF8ToUTF16(url.spec()); |
299 base::string16 title = | 299 base::string16 title = |
300 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_BLOCKED, spec16); | 300 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_BLOCKED, spec16); |
301 ASSERT_NE(title, contents->GetTitle()); | 301 EXPECT_NE(title, contents->GetTitle()); |
302 } | 302 } |
303 | 303 |
304 // Verifies that access to the given url |spec| is blocked. | 304 // Verifies that access to the given url |spec| is blocked. |
305 void CheckURLIsBlocked(Browser* browser, const char* spec) { | 305 void CheckURLIsBlocked(Browser* browser, const char* spec) { |
306 GURL url(spec); | 306 GURL url(spec); |
307 ui_test_utils::NavigateToURL(browser, url); | 307 ui_test_utils::NavigateToURL(browser, url); |
308 content::WebContents* contents = | 308 content::WebContents* contents = |
309 browser->tab_strip_model()->GetActiveWebContents(); | 309 browser->tab_strip_model()->GetActiveWebContents(); |
310 ASSERT_EQ(url, contents->GetURL()); | 310 EXPECT_EQ(url, contents->GetURL()); |
311 base::string16 spec16 = base::UTF8ToUTF16(url.spec()); | 311 base::string16 spec16 = base::UTF8ToUTF16(url.spec()); |
312 base::string16 title = | 312 base::string16 title = |
313 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_BLOCKED, spec16); | 313 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_BLOCKED, spec16); |
314 ASSERT_EQ(title, contents->GetTitle()); | 314 EXPECT_EQ(title, contents->GetTitle()); |
315 | 315 |
316 // Verify that the expected error page is being displayed. | 316 // Verify that the expected error page is being displayed. |
317 bool result = false; | 317 bool result = false; |
318 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 318 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
319 contents, | 319 contents, |
320 "var textContent = document.body.textContent;" | 320 "var textContent = document.body.textContent;" |
321 "var hasError = textContent.indexOf('ERR_BLOCKED_BY_ADMINISTRATOR') >= 0;" | 321 "var hasError = textContent.indexOf('ERR_BLOCKED_BY_ADMINISTRATOR') >= 0;" |
322 "domAutomationController.send(hasError);", | 322 "domAutomationController.send(hasError);", |
323 &result)); | 323 &result)); |
324 ASSERT_TRUE(result); | 324 EXPECT_TRUE(result); |
325 } | 325 } |
326 | 326 |
327 // Downloads a file named |file| and expects it to be saved to |dir|, which | 327 // Downloads a file named |file| and expects it to be saved to |dir|, which |
328 // must be empty. | 328 // must be empty. |
329 void DownloadAndVerifyFile( | 329 void DownloadAndVerifyFile( |
330 Browser* browser, const base::FilePath& dir, const base::FilePath& file) { | 330 Browser* browser, const base::FilePath& dir, const base::FilePath& file) { |
331 content::DownloadManager* download_manager = | 331 content::DownloadManager* download_manager = |
332 content::BrowserContext::GetDownloadManager(browser->profile()); | 332 content::BrowserContext::GetDownloadManager(browser->profile()); |
333 content::DownloadTestObserverTerminal observer( | 333 content::DownloadTestObserverTerminal observer( |
334 download_manager, 1, | 334 download_manager, 1, |
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 { | 2092 { |
2093 base::RunLoop loop; | 2093 base::RunLoop loop; |
2094 BrowserThread::PostTaskAndReply( | 2094 BrowserThread::PostTaskAndReply( |
2095 BrowserThread::IO, FROM_HERE, | 2095 BrowserThread::IO, FROM_HERE, |
2096 base::Bind(RedirectHostsToTestData, kURLS, arraysize(kURLS)), | 2096 base::Bind(RedirectHostsToTestData, kURLS, arraysize(kURLS)), |
2097 loop.QuitClosure()); | 2097 loop.QuitClosure()); |
2098 loop.Run(); | 2098 loop.Run(); |
2099 } | 2099 } |
2100 | 2100 |
2101 // Verify that "bbb.com" opens before applying the blacklist. | 2101 // Verify that "bbb.com" opens before applying the blacklist. |
2102 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), kURLS[1])); | 2102 CheckCanOpenURL(browser(), kURLS[1]); |
2103 | 2103 |
2104 // Set a blacklist. | 2104 // Set a blacklist. |
2105 base::ListValue blacklist; | 2105 base::ListValue blacklist; |
2106 blacklist.Append(new base::StringValue("bbb.com")); | 2106 blacklist.Append(new base::StringValue("bbb.com")); |
2107 PolicyMap policies; | 2107 PolicyMap policies; |
2108 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2108 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
2109 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2109 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
2110 UpdateProviderPolicy(policies); | 2110 UpdateProviderPolicy(policies); |
2111 FlushBlacklistPolicy(); | 2111 FlushBlacklistPolicy(); |
2112 // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. | 2112 // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. |
2113 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), kURLS[0])); | 2113 CheckCanOpenURL(browser(), kURLS[0]); |
2114 for (size_t i = 1; i < arraysize(kURLS); ++i) { | 2114 for (size_t i = 1; i < arraysize(kURLS); ++i) |
2115 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), kURLS[i])); | 2115 CheckURLIsBlocked(browser(), kURLS[i]); |
2116 } | |
2117 | 2116 |
2118 // Whitelist some sites of bbb.com. | 2117 // Whitelist some sites of bbb.com. |
2119 base::ListValue whitelist; | 2118 base::ListValue whitelist; |
2120 whitelist.Append(new base::StringValue("sub.bbb.com")); | 2119 whitelist.Append(new base::StringValue("sub.bbb.com")); |
2121 whitelist.Append(new base::StringValue("bbb.com/policy")); | 2120 whitelist.Append(new base::StringValue("bbb.com/policy")); |
2122 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, | 2121 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, |
2123 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); | 2122 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); |
2124 UpdateProviderPolicy(policies); | 2123 UpdateProviderPolicy(policies); |
2125 FlushBlacklistPolicy(); | 2124 FlushBlacklistPolicy(); |
2126 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), kURLS[1])); | 2125 CheckURLIsBlocked(browser(), kURLS[1]); |
2127 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), kURLS[2])); | 2126 CheckCanOpenURL(browser(), kURLS[2]); |
2128 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), kURLS[3])); | 2127 CheckCanOpenURL(browser(), kURLS[3]); |
2129 | 2128 |
2130 { | 2129 { |
2131 base::RunLoop loop; | 2130 base::RunLoop loop; |
2132 BrowserThread::PostTaskAndReply( | 2131 BrowserThread::PostTaskAndReply( |
2133 BrowserThread::IO, FROM_HERE, | 2132 BrowserThread::IO, FROM_HERE, |
2134 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), | 2133 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), |
2135 loop.QuitClosure()); | 2134 loop.QuitClosure()); |
2136 loop.Run(); | 2135 loop.Run(); |
2137 } | 2136 } |
2138 } | 2137 } |
2139 | 2138 |
2140 IN_PROC_BROWSER_TEST_F(PolicyTest, FileURLBlacklist) { | 2139 #if defined(OS_MACOSX) |
| 2140 // http://crbug.com/339240 |
| 2141 #define MAYBE_FileURLBlacklist DISABLED_FileURLBlacklist |
| 2142 #else |
| 2143 #define MAYBE_FileURLBlacklist FileURLBlacklist |
| 2144 #endif |
| 2145 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_FileURLBlacklist) { |
2141 // Check that FileURLs can be blacklisted and DisabledSchemes works together | 2146 // Check that FileURLs can be blacklisted and DisabledSchemes works together |
2142 // with URLblacklisting and URLwhitelisting. | 2147 // with URLblacklisting and URLwhitelisting. |
2143 | 2148 |
2144 base::FilePath test_path; | 2149 base::FilePath test_path; |
2145 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 2150 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
2146 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; | 2151 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; |
2147 const std::string folder_path = base_path + "apptest/"; | 2152 const std::string folder_path = base_path + "apptest/"; |
2148 const std::string file_path1 = base_path + "title1.html"; | 2153 const std::string file_path1 = base_path + "title1.html"; |
2149 const std::string file_path2 = folder_path + "basic.html"; | 2154 const std::string file_path2 = folder_path + "basic.html"; |
2150 | 2155 |
2151 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), file_path1.c_str())); | 2156 CheckCanOpenURL(browser(), file_path1.c_str()); |
2152 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), file_path2.c_str())); | 2157 CheckCanOpenURL(browser(), file_path2.c_str()); |
2153 | 2158 |
2154 // Set a blacklist for all the files. | 2159 // Set a blacklist for all the files. |
2155 base::ListValue blacklist; | 2160 base::ListValue blacklist; |
2156 blacklist.Append(new base::StringValue("file://*")); | 2161 blacklist.Append(new base::StringValue("file://*")); |
2157 PolicyMap policies; | 2162 PolicyMap policies; |
2158 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2163 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
2159 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2164 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
2160 UpdateProviderPolicy(policies); | 2165 UpdateProviderPolicy(policies); |
2161 FlushBlacklistPolicy(); | 2166 FlushBlacklistPolicy(); |
2162 | 2167 |
2163 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), file_path1.c_str())); | 2168 CheckURLIsBlocked(browser(), file_path1.c_str()); |
2164 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), file_path2.c_str())); | 2169 CheckURLIsBlocked(browser(), file_path2.c_str()); |
2165 | 2170 |
2166 // Replace the URLblacklist with disabling the file scheme. | 2171 // Replace the URLblacklist with disabling the file scheme. |
2167 blacklist.Remove(base::StringValue("file://*"), NULL); | 2172 blacklist.Remove(base::StringValue("file://*"), NULL); |
2168 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2173 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
2169 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2174 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
2170 UpdateProviderPolicy(policies); | 2175 UpdateProviderPolicy(policies); |
2171 FlushBlacklistPolicy(); | 2176 FlushBlacklistPolicy(); |
2172 | 2177 |
2173 PrefService* prefs = browser()->profile()->GetPrefs(); | 2178 PrefService* prefs = browser()->profile()->GetPrefs(); |
2174 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); | 2179 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); |
(...skipping 15 matching lines...) Expand all Loading... |
2190 base::ListValue whitelist; | 2195 base::ListValue whitelist; |
2191 whitelist.Append(new base::StringValue(base_path)); | 2196 whitelist.Append(new base::StringValue(base_path)); |
2192 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, | 2197 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, |
2193 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); | 2198 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); |
2194 blacklist.Append(new base::StringValue(folder_path)); | 2199 blacklist.Append(new base::StringValue(folder_path)); |
2195 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2200 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
2196 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2201 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
2197 UpdateProviderPolicy(policies); | 2202 UpdateProviderPolicy(policies); |
2198 FlushBlacklistPolicy(); | 2203 FlushBlacklistPolicy(); |
2199 | 2204 |
2200 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), file_path1.c_str())); | 2205 CheckCanOpenURL(browser(), file_path1.c_str()); |
2201 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), file_path2.c_str())); | 2206 CheckURLIsBlocked(browser(), file_path2.c_str()); |
2202 } | 2207 } |
2203 | 2208 |
2204 #if !defined(OS_MACOSX) | 2209 #if !defined(OS_MACOSX) |
2205 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { | 2210 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { |
2206 PolicyMap policies; | 2211 PolicyMap policies; |
2207 policies.Set(key::kFullscreenAllowed, | 2212 policies.Set(key::kFullscreenAllowed, |
2208 POLICY_LEVEL_MANDATORY, | 2213 POLICY_LEVEL_MANDATORY, |
2209 POLICY_SCOPE_USER, | 2214 POLICY_SCOPE_USER, |
2210 new base::FundamentalValue(false), | 2215 new base::FundamentalValue(false), |
2211 NULL); | 2216 NULL); |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3227 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3232 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
3228 browser2->tab_strip_model()->GetActiveWebContents(), | 3233 browser2->tab_strip_model()->GetActiveWebContents(), |
3229 "domAutomationController.send(window.showModalDialog !== undefined);", | 3234 "domAutomationController.send(window.showModalDialog !== undefined);", |
3230 &result)); | 3235 &result)); |
3231 EXPECT_TRUE(result); | 3236 EXPECT_TRUE(result); |
3232 } | 3237 } |
3233 | 3238 |
3234 #endif // !defined(CHROME_OS) | 3239 #endif // !defined(CHROME_OS) |
3235 | 3240 |
3236 } // namespace policy | 3241 } // namespace policy |
OLD | NEW |