1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" 6 7 #include "base/prefs/pref_service.h" 8 #include "base/values.h" 9 #include "chrome/browser/managed_mode/managed_user_service.h" 10 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 11 #include "chrome/browser/policy/managed_mode_policy_provider.h" 12 #include "chrome/browser/policy/profile_policy_connector.h" 13 #include "chrome/browser/policy/profile_policy_connector_factory.h" 14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/ui_test_utils.h" 18 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/web_contents.h" 20 #include "content/public/common/page_type.h" 21 #include "content/public/test/test_navigation_observer.h" 22 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h" 24 #include "policy/policy_constants.h" 25 26 using content::MessageLoopRunner; 27 using content::NavigationController; 28 using content::WebContents; 29 30 class ManagedModeResourceThrottleTest : public InProcessBrowserTest { 31 protected: 32 ManagedModeResourceThrottleTest() : managed_user_service_(NULL) {} 33 virtual ~ManagedModeResourceThrottleTest() {} 34 35 private: 36 virtual void SetUpOnMainThread() OVERRIDE; 37 38 ManagedUserService* managed_user_service_; 39 }; 40 41 void ManagedModeResourceThrottleTest::SetUpOnMainThread() { 42 managed_user_service_ = 43 ManagedUserServiceFactory::GetForProfile(browser()->profile()); 44 managed_user_service_->InitForTesting(); 45 } 46 47 // Tests that showing the blocking interstitial for a WebContents without a 48 // ManagedModeNavigationObserver doesn't crash. 49 IN_PROC_BROWSER_TEST_F(ManagedModeResourceThrottleTest, 50 NoNavigationObserverBlock) { 51 Profile* profile = browser()->profile(); 52 policy::ProfilePolicyConnector* connector = 53 policy::ProfilePolicyConnectorFactory::GetForProfile(profile); 54 policy::ManagedModePolicyProvider* policy_provider = 55 connector->managed_mode_policy_provider(); 56 policy_provider->SetLocalPolicyForTesting( 57 policy::key::kContentPackDefaultFilteringBehavior, 58 scoped_ptr<base::Value>( 59 new base::FundamentalValue(ManagedModeURLFilter::BLOCK))); 60 base::RunLoop().RunUntilIdle(); 61 62 scoped_ptr<WebContents> web_contents( 63 WebContents::Create(WebContents::CreateParams(profile))); 64 NavigationController& controller = web_contents->GetController(); 65 content::TestNavigationObserver observer(web_contents.get()); 66 controller.LoadURL(GURL("http://www.example.com"), content::Referrer(), 67 content::PAGE_TRANSITION_TYPED, std::string()); 68 observer.Wait(); 69 content::NavigationEntry* entry = controller.GetActiveEntry(); 70 ASSERT_TRUE(entry); 71 EXPECT_EQ(content::PAGE_TYPE_INTERSTITIAL, entry->GetPageType()); 72 } 73