| 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 EXPECT_EQ(url, contents->GetURL()); | 297 ASSERT_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 EXPECT_NE(title, contents->GetTitle()); | 301 ASSERT_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 EXPECT_EQ(url, contents->GetURL()); | 310 ASSERT_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 EXPECT_EQ(title, contents->GetTitle()); | 314 ASSERT_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 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 318 ASSERT_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 EXPECT_TRUE(result); | 324 ASSERT_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 CheckCanOpenURL(browser(), kURLS[1]); | 2102 EXPECT_NO_FATAL_FAILURE(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 CheckCanOpenURL(browser(), kURLS[0]); | 2113 EXPECT_NO_FATAL_FAILURE(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 CheckURLIsBlocked(browser(), kURLS[i]); | 2115 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), kURLS[i])); |
| 2116 } |
| 2116 | 2117 |
| 2117 // Whitelist some sites of bbb.com. | 2118 // Whitelist some sites of bbb.com. |
| 2118 base::ListValue whitelist; | 2119 base::ListValue whitelist; |
| 2119 whitelist.Append(new base::StringValue("sub.bbb.com")); | 2120 whitelist.Append(new base::StringValue("sub.bbb.com")); |
| 2120 whitelist.Append(new base::StringValue("bbb.com/policy")); | 2121 whitelist.Append(new base::StringValue("bbb.com/policy")); |
| 2121 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, | 2122 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, |
| 2122 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); | 2123 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); |
| 2123 UpdateProviderPolicy(policies); | 2124 UpdateProviderPolicy(policies); |
| 2124 FlushBlacklistPolicy(); | 2125 FlushBlacklistPolicy(); |
| 2125 CheckURLIsBlocked(browser(), kURLS[1]); | 2126 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), kURLS[1])); |
| 2126 CheckCanOpenURL(browser(), kURLS[2]); | 2127 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), kURLS[2])); |
| 2127 CheckCanOpenURL(browser(), kURLS[3]); | 2128 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), kURLS[3])); |
| 2128 | 2129 |
| 2129 { | 2130 { |
| 2130 base::RunLoop loop; | 2131 base::RunLoop loop; |
| 2131 BrowserThread::PostTaskAndReply( | 2132 BrowserThread::PostTaskAndReply( |
| 2132 BrowserThread::IO, FROM_HERE, | 2133 BrowserThread::IO, FROM_HERE, |
| 2133 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), | 2134 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), |
| 2134 loop.QuitClosure()); | 2135 loop.QuitClosure()); |
| 2135 loop.Run(); | 2136 loop.Run(); |
| 2136 } | 2137 } |
| 2137 } | 2138 } |
| 2138 | 2139 |
| 2139 #if defined(OS_MACOSX) | 2140 IN_PROC_BROWSER_TEST_F(PolicyTest, FileURLBlacklist) { |
| 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) { | |
| 2146 // Check that FileURLs can be blacklisted and DisabledSchemes works together | 2141 // Check that FileURLs can be blacklisted and DisabledSchemes works together |
| 2147 // with URLblacklisting and URLwhitelisting. | 2142 // with URLblacklisting and URLwhitelisting. |
| 2148 | 2143 |
| 2149 base::FilePath test_path; | 2144 base::FilePath test_path; |
| 2150 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 2145 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 2151 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; | 2146 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; |
| 2152 const std::string folder_path = base_path + "apptest/"; | 2147 const std::string folder_path = base_path + "apptest/"; |
| 2153 const std::string file_path1 = base_path + "title1.html"; | 2148 const std::string file_path1 = base_path + "title1.html"; |
| 2154 const std::string file_path2 = folder_path + "basic.html"; | 2149 const std::string file_path2 = folder_path + "basic.html"; |
| 2155 | 2150 |
| 2156 CheckCanOpenURL(browser(), file_path1.c_str()); | 2151 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), file_path1.c_str())); |
| 2157 CheckCanOpenURL(browser(), file_path2.c_str()); | 2152 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), file_path2.c_str())); |
| 2158 | 2153 |
| 2159 // Set a blacklist for all the files. | 2154 // Set a blacklist for all the files. |
| 2160 base::ListValue blacklist; | 2155 base::ListValue blacklist; |
| 2161 blacklist.Append(new base::StringValue("file://*")); | 2156 blacklist.Append(new base::StringValue("file://*")); |
| 2162 PolicyMap policies; | 2157 PolicyMap policies; |
| 2163 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2158 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
| 2164 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2159 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
| 2165 UpdateProviderPolicy(policies); | 2160 UpdateProviderPolicy(policies); |
| 2166 FlushBlacklistPolicy(); | 2161 FlushBlacklistPolicy(); |
| 2167 | 2162 |
| 2168 CheckURLIsBlocked(browser(), file_path1.c_str()); | 2163 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), file_path1.c_str())); |
| 2169 CheckURLIsBlocked(browser(), file_path2.c_str()); | 2164 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), file_path2.c_str())); |
| 2170 | 2165 |
| 2171 // Replace the URLblacklist with disabling the file scheme. | 2166 // Replace the URLblacklist with disabling the file scheme. |
| 2172 blacklist.Remove(base::StringValue("file://*"), NULL); | 2167 blacklist.Remove(base::StringValue("file://*"), NULL); |
| 2173 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2168 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
| 2174 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2169 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
| 2175 UpdateProviderPolicy(policies); | 2170 UpdateProviderPolicy(policies); |
| 2176 FlushBlacklistPolicy(); | 2171 FlushBlacklistPolicy(); |
| 2177 | 2172 |
| 2178 PrefService* prefs = browser()->profile()->GetPrefs(); | 2173 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 2179 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); | 2174 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2195 base::ListValue whitelist; | 2190 base::ListValue whitelist; |
| 2196 whitelist.Append(new base::StringValue(base_path)); | 2191 whitelist.Append(new base::StringValue(base_path)); |
| 2197 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, | 2192 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, |
| 2198 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); | 2193 POLICY_SCOPE_USER, whitelist.DeepCopy(), NULL); |
| 2199 blacklist.Append(new base::StringValue(folder_path)); | 2194 blacklist.Append(new base::StringValue(folder_path)); |
| 2200 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2195 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
| 2201 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); | 2196 POLICY_SCOPE_USER, blacklist.DeepCopy(), NULL); |
| 2202 UpdateProviderPolicy(policies); | 2197 UpdateProviderPolicy(policies); |
| 2203 FlushBlacklistPolicy(); | 2198 FlushBlacklistPolicy(); |
| 2204 | 2199 |
| 2205 CheckCanOpenURL(browser(), file_path1.c_str()); | 2200 EXPECT_NO_FATAL_FAILURE(CheckCanOpenURL(browser(), file_path1.c_str())); |
| 2206 CheckURLIsBlocked(browser(), file_path2.c_str()); | 2201 EXPECT_NO_FATAL_FAILURE(CheckURLIsBlocked(browser(), file_path2.c_str())); |
| 2207 } | 2202 } |
| 2208 | 2203 |
| 2209 #if !defined(OS_MACOSX) | 2204 #if !defined(OS_MACOSX) |
| 2210 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { | 2205 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { |
| 2211 PolicyMap policies; | 2206 PolicyMap policies; |
| 2212 policies.Set(key::kFullscreenAllowed, | 2207 policies.Set(key::kFullscreenAllowed, |
| 2213 POLICY_LEVEL_MANDATORY, | 2208 POLICY_LEVEL_MANDATORY, |
| 2214 POLICY_SCOPE_USER, | 2209 POLICY_SCOPE_USER, |
| 2215 new base::FundamentalValue(false), | 2210 new base::FundamentalValue(false), |
| 2216 NULL); | 2211 NULL); |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3232 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3227 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 3233 browser2->tab_strip_model()->GetActiveWebContents(), | 3228 browser2->tab_strip_model()->GetActiveWebContents(), |
| 3234 "domAutomationController.send(window.showModalDialog !== undefined);", | 3229 "domAutomationController.send(window.showModalDialog !== undefined);", |
| 3235 &result)); | 3230 &result)); |
| 3236 EXPECT_TRUE(result); | 3231 EXPECT_TRUE(result); |
| 3237 } | 3232 } |
| 3238 | 3233 |
| 3239 #endif // !defined(CHROME_OS) | 3234 #endif // !defined(CHROME_OS) |
| 3240 | 3235 |
| 3241 } // namespace policy | 3236 } // namespace policy |
| OLD | NEW |