OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 MockTabStripModelObserver observer(tab_strip); | 226 MockTabStripModelObserver observer(tab_strip); |
227 base::RunLoop run_loop; | 227 base::RunLoop run_loop; |
228 EXPECT_CALL(observer, | 228 EXPECT_CALL(observer, |
229 TabClosingAt(tab_strip, tab, tab_strip->active_index())) | 229 TabClosingAt(tab_strip, tab, tab_strip->active_index())) |
230 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 230 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
231 GoBack(tab); | 231 GoBack(tab); |
232 run_loop.Run(); | 232 run_loop.Run(); |
233 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents()); | 233 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents()); |
234 } | 234 } |
235 | 235 |
236 // Navigates to a new tab, then blocks the current page (which makes the | |
Marc Treib
2017/05/02 08:24:46
nit: Maybe I'm biased, but to me "Navigates to a n
Bernhard Bauer
2017/05/02 09:02:53
Done.
| |
237 // interstitial page behave differently from the preceding test, where the | |
238 // navigation is blocked before it commits). The expected behavior is the same | |
239 // though: the tab should be closed when going back. | |
240 IN_PROC_BROWSER_TEST_F(SupervisedUserTest, BlockNewTabAfterLoading) { | |
241 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
242 WebContents* prev_tab = tab_strip->GetActiveWebContents(); | |
243 | |
244 // Open URL in a new tab. | |
245 GURL test_url("http://www.example.com/simple.html"); | |
246 ui_test_utils::NavigateToURLWithDisposition( | |
247 browser(), test_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
248 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
249 | |
250 // Check that there is no interstitial. | |
251 WebContents* tab = tab_strip->GetActiveWebContents(); | |
252 ASSERT_FALSE(ShownPageIsInterstitial(tab)); | |
253 | |
254 { | |
255 // Block the current URL. | |
256 base::RunLoop run_loop; | |
257 InterstitialPageObserver interstitial_observer(tab, run_loop.QuitClosure()); | |
258 | |
259 SupervisedUserSettingsService* supervised_user_settings_service = | |
260 SupervisedUserSettingsServiceFactory::GetForProfile( | |
261 browser()->profile()); | |
262 supervised_user_settings_service->SetLocalSetting( | |
263 supervised_users::kContentPackDefaultFilteringBehavior, | |
264 base::MakeUnique<base::Value>(SupervisedUserURLFilter::BLOCK)); | |
265 | |
266 const SupervisedUserURLFilter* filter = | |
267 supervised_user_service_->GetURLFilter(); | |
268 ASSERT_EQ(SupervisedUserURLFilter::BLOCK, | |
269 filter->GetFilteringBehaviorForURL(test_url)); | |
270 | |
271 content::RunThisRunLoop(&run_loop); | |
272 | |
273 // Check that we got the interstitial. | |
274 ASSERT_TRUE(ShownPageIsInterstitial(tab)); | |
275 } | |
276 | |
277 { | |
278 // On pressing the "back" button, the new tab should be closed, and we | |
279 // should get back to the previous active tab. | |
280 MockTabStripModelObserver observer(tab_strip); | |
281 base::RunLoop run_loop; | |
282 EXPECT_CALL(observer, | |
283 TabClosingAt(tab_strip, tab, tab_strip->active_index())) | |
284 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | |
285 GoBack(tab); | |
286 run_loop.Run(); | |
287 EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents()); | |
288 } | |
289 } | |
290 | |
291 // Tests that we don't end up canceling an interstitial (thereby closing the | |
292 // whole tab) by attempting to show a second one above it. | |
293 IN_PROC_BROWSER_TEST_F(SupervisedUserTest, DontShowInterstitialTwice) { | |
294 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
295 | |
296 // Open URL in a new tab. | |
297 GURL test_url("http://www.example.com/simple.html"); | |
298 ui_test_utils::NavigateToURLWithDisposition( | |
299 browser(), test_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
300 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
301 | |
302 // Check that there is no interstitial. | |
303 WebContents* tab = tab_strip->GetActiveWebContents(); | |
304 ASSERT_FALSE(ShownPageIsInterstitial(tab)); | |
305 | |
306 // Block the current URL. | |
307 SupervisedUserSettingsService* supervised_user_settings_service = | |
308 SupervisedUserSettingsServiceFactory::GetForProfile(browser()->profile()); | |
309 base::RunLoop run_loop; | |
310 InterstitialPageObserver interstitial_observer(tab, run_loop.QuitClosure()); | |
311 supervised_user_settings_service->SetLocalSetting( | |
312 supervised_users::kContentPackDefaultFilteringBehavior, | |
313 base::MakeUnique<base::Value>(SupervisedUserURLFilter::BLOCK)); | |
314 | |
315 const SupervisedUserURLFilter* filter = | |
316 supervised_user_service_->GetURLFilter(); | |
317 ASSERT_EQ(SupervisedUserURLFilter::BLOCK, | |
318 filter->GetFilteringBehaviorForURL(test_url)); | |
319 | |
320 content::RunThisRunLoop(&run_loop); | |
321 | |
322 // Check that we got the interstitial. | |
323 ASSERT_TRUE(ShownPageIsInterstitial(tab)); | |
324 | |
325 // Trigger a no-op change to the site lists, which will notify observers of | |
326 // the URL filter. | |
327 Profile* profile = browser()->profile(); | |
328 SupervisedUserService* supervised_user_service = | |
329 SupervisedUserServiceFactory::GetForProfile(profile); | |
330 supervised_user_service->OnSiteListUpdated(); | |
331 | |
332 content::RunAllPendingInMessageLoop(); | |
333 EXPECT_EQ(tab, tab_strip->GetActiveWebContents()); | |
334 } | |
335 | |
236 // Tests whether a visit attempt adds a special history entry. | 336 // Tests whether a visit attempt adds a special history entry. |
237 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, | 337 IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, |
238 HistoryVisitRecorded) { | 338 HistoryVisitRecorded) { |
239 GURL allowed_url("http://www.example.com/simple.html"); | 339 GURL allowed_url("http://www.example.com/simple.html"); |
240 | 340 |
241 const SupervisedUserURLFilter* filter = | 341 const SupervisedUserURLFilter* filter = |
242 supervised_user_service_->GetURLFilter(); | 342 supervised_user_service_->GetURLFilter(); |
243 | 343 |
244 // Set the host as allowed. | 344 // Set the host as allowed. |
245 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 345 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 QueryHistory(history_service, "", options, &results); | 386 QueryHistory(history_service, "", options, &results); |
287 | 387 |
288 // Check that the entries have the correct blocked_visit value. | 388 // Check that the entries have the correct blocked_visit value. |
289 ASSERT_EQ(2u, results.size()); | 389 ASSERT_EQ(2u, results.size()); |
290 EXPECT_EQ(blocked_url.spec(), results[0].url().spec()); | 390 EXPECT_EQ(blocked_url.spec(), results[0].url().spec()); |
291 EXPECT_TRUE(results[0].blocked_visit()); | 391 EXPECT_TRUE(results[0].blocked_visit()); |
292 EXPECT_EQ(allowed_url.spec(), results[1].url().spec()); | 392 EXPECT_EQ(allowed_url.spec(), results[1].url().spec()); |
293 EXPECT_FALSE(results[1].blocked_visit()); | 393 EXPECT_FALSE(results[1].blocked_visit()); |
294 } | 394 } |
295 | 395 |
296 IN_PROC_BROWSER_TEST_F(SupervisedUserTest, ImmediatelyProceed) { | |
297 GURL test_url("http://www.example.com/simple.html"); | |
298 ui_test_utils::NavigateToURL(browser(), test_url); | |
299 | |
300 WebContents* web_contents = | |
301 browser()->tab_strip_model()->GetActiveWebContents(); | |
302 ASSERT_FALSE(ShownPageIsInterstitial(web_contents)); | |
303 | |
304 // Manually show an interstitial page for a URL that is allowed. This | |
305 // simulates the case where a network request was blocked on the IO thread | |
306 // because a change to the URL filter hadn't been propagated yet. | |
307 bool proceed = false; | |
308 SupervisedUserInterstitial::Show( | |
309 web_contents, test_url, supervised_user_error_page::MANUAL, | |
310 /* initial_page_load = */ true, | |
311 base::Bind( | |
312 [](bool* result_holder, bool result) { | |
313 *result_holder = result; | |
314 }, | |
315 &proceed)); | |
316 | |
317 // The interstitial should not appear, and the callback should have been | |
318 // called immediately. | |
319 EXPECT_FALSE(ShownPageIsInterstitial(web_contents)); | |
320 EXPECT_TRUE(proceed); | |
321 } | |
322 | |
323 IN_PROC_BROWSER_TEST_F(SupervisedUserTest, GoBackOnDontProceed) { | 396 IN_PROC_BROWSER_TEST_F(SupervisedUserTest, GoBackOnDontProceed) { |
324 // We start out at the initial navigation. | 397 // We start out at the initial navigation. |
325 WebContents* web_contents = | 398 WebContents* web_contents = |
326 browser()->tab_strip_model()->GetActiveWebContents(); | 399 browser()->tab_strip_model()->GetActiveWebContents(); |
327 ASSERT_EQ(0, web_contents->GetController().GetCurrentEntryIndex()); | 400 ASSERT_EQ(0, web_contents->GetController().GetCurrentEntryIndex()); |
328 | 401 |
329 GURL test_url("http://www.example.com/simple.html"); | 402 GURL test_url("http://www.example.com/simple.html"); |
330 ui_test_utils::NavigateToURL(browser(), test_url); | 403 ui_test_utils::NavigateToURL(browser(), test_url); |
331 | 404 |
332 ASSERT_FALSE(ShownPageIsInterstitial(web_contents)); | 405 ASSERT_FALSE(ShownPageIsInterstitial(web_contents)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 browser()->tab_strip_model()->GetActiveWebContents(); | 444 browser()->tab_strip_model()->GetActiveWebContents(); |
372 | 445 |
373 ASSERT_FALSE(ShownPageIsInterstitial(web_contents)); | 446 ASSERT_FALSE(ShownPageIsInterstitial(web_contents)); |
374 | 447 |
375 // Set the host as blocked and wait for the interstitial to appear. | 448 // Set the host as blocked and wait for the interstitial to appear. |
376 auto dict = base::MakeUnique<base::DictionaryValue>(); | 449 auto dict = base::MakeUnique<base::DictionaryValue>(); |
377 dict->SetBooleanWithoutPathExpansion(test_url.host(), false); | 450 dict->SetBooleanWithoutPathExpansion(test_url.host(), false); |
378 SupervisedUserSettingsService* supervised_user_settings_service = | 451 SupervisedUserSettingsService* supervised_user_settings_service = |
379 SupervisedUserSettingsServiceFactory::GetForProfile( | 452 SupervisedUserSettingsServiceFactory::GetForProfile( |
380 browser()->profile()); | 453 browser()->profile()); |
381 auto message_loop_runner = make_scoped_refptr(new content::MessageLoopRunner); | 454 base::RunLoop run_loop; |
382 InterstitialPageObserver observer(web_contents, | 455 InterstitialPageObserver observer(web_contents, run_loop.QuitClosure()); |
383 message_loop_runner->QuitClosure()); | |
384 supervised_user_settings_service->SetLocalSetting( | 456 supervised_user_settings_service->SetLocalSetting( |
385 supervised_users::kContentPackManualBehaviorHosts, std::move(dict)); | 457 supervised_users::kContentPackManualBehaviorHosts, std::move(dict)); |
386 | 458 |
387 const SupervisedUserURLFilter* filter = | 459 const SupervisedUserURLFilter* filter = |
388 supervised_user_service_->GetURLFilter(); | 460 supervised_user_service_->GetURLFilter(); |
389 ASSERT_EQ(SupervisedUserURLFilter::BLOCK, | 461 ASSERT_EQ(SupervisedUserURLFilter::BLOCK, |
390 filter->GetFilteringBehaviorForURL(test_url)); | 462 filter->GetFilteringBehaviorForURL(test_url)); |
391 | 463 |
392 message_loop_runner->Run(); | 464 content::RunThisRunLoop(&run_loop); |
393 ASSERT_TRUE(ShownPageIsInterstitial(web_contents)); | 465 ASSERT_TRUE(ShownPageIsInterstitial(web_contents)); |
394 | 466 |
395 dict = base::MakeUnique<base::DictionaryValue>(); | 467 dict = base::MakeUnique<base::DictionaryValue>(); |
396 dict->SetBooleanWithoutPathExpansion(test_url.host(), true); | 468 dict->SetBooleanWithoutPathExpansion(test_url.host(), true); |
397 supervised_user_settings_service->SetLocalSetting( | 469 supervised_user_settings_service->SetLocalSetting( |
398 supervised_users::kContentPackManualBehaviorHosts, std::move(dict)); | 470 supervised_users::kContentPackManualBehaviorHosts, std::move(dict)); |
399 ASSERT_EQ(SupervisedUserURLFilter::ALLOW, | 471 ASSERT_EQ(SupervisedUserURLFilter::ALLOW, |
400 filter->GetFilteringBehaviorForURL(test_url)); | 472 filter->GetFilteringBehaviorForURL(test_url)); |
401 | 473 |
402 ASSERT_EQ(test_url, web_contents->GetURL()); | 474 ASSERT_EQ(test_url, web_contents->GetURL()); |
(...skipping 26 matching lines...) Expand all Loading... | |
429 const SupervisedUserURLFilter* filter = | 501 const SupervisedUserURLFilter* filter = |
430 supervised_user_service_->GetURLFilter(); | 502 supervised_user_service_->GetURLFilter(); |
431 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, | 503 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, |
432 filter->GetFilteringBehaviorForURL(test_url.GetWithEmptyPath())); | 504 filter->GetFilteringBehaviorForURL(test_url.GetWithEmptyPath())); |
433 | 505 |
434 observer.Wait(); | 506 observer.Wait(); |
435 EXPECT_EQ(test_url, web_contents->GetURL()); | 507 EXPECT_EQ(test_url, web_contents->GetURL()); |
436 } | 508 } |
437 | 509 |
438 } // namespace | 510 } // namespace |
OLD | NEW |