| 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 "chrome/browser/policy/url_blacklist_manager.h" | 5 #include "chrome/browser/policy/url_blacklist_manager.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "google_apis/gaia/gaia_urls.h" | 15 #include "google_apis/gaia/gaia_urls.h" |
| 16 #include "net/base/request_priority.h" |
| 16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace policy { | 22 namespace policy { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 490 |
| 490 TEST_F(URLBlacklistManagerTest, DontBlockResources) { | 491 TEST_F(URLBlacklistManagerTest, DontBlockResources) { |
| 491 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist()); | 492 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist()); |
| 492 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 493 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
| 493 blocked->Append(new base::StringValue("google.com")); | 494 blocked->Append(new base::StringValue("google.com")); |
| 494 blacklist->Block(blocked.get()); | 495 blacklist->Block(blocked.get()); |
| 495 blacklist_manager_->SetBlacklist(blacklist.Pass()); | 496 blacklist_manager_->SetBlacklist(blacklist.Pass()); |
| 496 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); | 497 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); |
| 497 | 498 |
| 498 net::TestURLRequestContext context; | 499 net::TestURLRequestContext context; |
| 499 net::URLRequest request(GURL("http://google.com"), NULL, &context); | 500 net::URLRequest request( |
| 501 GURL("http://google.com"), net::DEFAULT_PRIORITY, NULL, &context); |
| 500 | 502 |
| 501 // Background requests aren't filtered. | 503 // Background requests aren't filtered. |
| 502 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(request)); | 504 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(request)); |
| 503 | 505 |
| 504 // Main frames are filtered. | 506 // Main frames are filtered. |
| 505 request.set_load_flags(net::LOAD_MAIN_FRAME); | 507 request.set_load_flags(net::LOAD_MAIN_FRAME); |
| 506 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(request)); | 508 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(request)); |
| 507 | 509 |
| 508 // On most platforms, sync gets a free pass due to signin flows. | 510 // On most platforms, sync gets a free pass due to signin flows. |
| 509 bool block_signin_urls = false; | 511 bool block_signin_urls = false; |
| 510 #if defined(OS_CHROMEOS) | 512 #if defined(OS_CHROMEOS) |
| 511 // There are no sync specific signin flows on Chrome OS, so no special | 513 // There are no sync specific signin flows on Chrome OS, so no special |
| 512 // treatment. | 514 // treatment. |
| 513 block_signin_urls = true; | 515 block_signin_urls = true; |
| 514 #endif | 516 #endif |
| 515 | 517 |
| 516 GURL sync_url(GaiaUrls::GetInstance()->service_login_url().Resolve( | 518 GURL sync_url(GaiaUrls::GetInstance()->service_login_url().Resolve( |
| 517 "?service=chromiumsync")); | 519 "?service=chromiumsync")); |
| 518 net::URLRequest sync_request(sync_url, NULL, &context); | 520 net::URLRequest sync_request(sync_url, net::DEFAULT_PRIORITY, NULL, &context); |
| 519 sync_request.set_load_flags(net::LOAD_MAIN_FRAME); | 521 sync_request.set_load_flags(net::LOAD_MAIN_FRAME); |
| 520 EXPECT_EQ(block_signin_urls, | 522 EXPECT_EQ(block_signin_urls, |
| 521 blacklist_manager_->IsRequestBlocked(sync_request)); | 523 blacklist_manager_->IsRequestBlocked(sync_request)); |
| 522 } | 524 } |
| 523 | 525 |
| 524 } // namespace policy | 526 } // namespace policy |
| OLD | NEW |