Roll WebRTC 5699->5721.
[chromium-blink-merge.git] / chrome / browser / managed_mode / managed_mode_resource_throttle_browsertest.cc
blobd775d984bc9f7243e90467ce5d4a63f647b304cb
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.
5 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/values.h"
10 #include "chrome/browser/managed_mode/managed_user_constants.h"
11 #include "chrome/browser/managed_mode/managed_user_service.h"
12 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
13 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
14 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/page_type.h"
23 #include "content/public/test/test_navigation_observer.h"
24 #include "content/public/test/test_utils.h"
25 #include "content/public/test/test_utils.h"
27 using content::MessageLoopRunner;
28 using content::NavigationController;
29 using content::WebContents;
31 class ManagedModeResourceThrottleTest : public InProcessBrowserTest {
32 protected:
33 ManagedModeResourceThrottleTest() : managed_user_service_(NULL) {}
34 virtual ~ManagedModeResourceThrottleTest() {}
36 private:
37 virtual void SetUpOnMainThread() OVERRIDE;
38 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
40 ManagedUserService* managed_user_service_;
43 void ManagedModeResourceThrottleTest::SetUpOnMainThread() {
44 managed_user_service_ =
45 ManagedUserServiceFactory::GetForProfile(browser()->profile());
48 void ManagedModeResourceThrottleTest::SetUpCommandLine(
49 CommandLine* command_line) {
50 command_line->AppendSwitchASCII(switches::kManagedUserId, "asdf");
53 // Tests that showing the blocking interstitial for a WebContents without a
54 // ManagedModeNavigationObserver doesn't crash.
55 IN_PROC_BROWSER_TEST_F(ManagedModeResourceThrottleTest,
56 NoNavigationObserverBlock) {
57 Profile* profile = browser()->profile();
58 ManagedUserSettingsService* managed_user_settings_service =
59 ManagedUserSettingsServiceFactory::GetForProfile(profile);
60 managed_user_settings_service->SetLocalSettingForTesting(
61 managed_users::kContentPackDefaultFilteringBehavior,
62 scoped_ptr<base::Value>(
63 new base::FundamentalValue(ManagedModeURLFilter::BLOCK)));
65 scoped_ptr<WebContents> web_contents(
66 WebContents::Create(WebContents::CreateParams(profile)));
67 NavigationController& controller = web_contents->GetController();
68 content::TestNavigationObserver observer(web_contents.get());
69 controller.LoadURL(GURL("http://www.example.com"), content::Referrer(),
70 content::PAGE_TRANSITION_TYPED, std::string());
71 observer.Wait();
72 content::NavigationEntry* entry = controller.GetActiveEntry();
73 ASSERT_TRUE(entry);
74 EXPECT_EQ(content::PAGE_TYPE_INTERSTITIAL, entry->GetPageType());