Componentize ShortcutsBackend
[chromium-blink-merge.git] / chrome / browser / supervised_user / supervised_user_resource_throttle_browsertest.cc
blob30eae7c0d9329d6c155c4f270674c5a232f297d4
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
3 // found in the LICENSE file.
5 #include "chrome/browser/supervised_user/supervised_user_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/profiles/profile.h"
11 #include "chrome/browser/supervised_user/supervised_user_constants.h"
12 #include "chrome/browser/supervised_user/supervised_user_service.h"
13 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
14 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
15 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.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 "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/page_type.h"
22 #include "content/public/test/test_navigation_observer.h"
23 #include "content/public/test/test_utils.h"
25 using content::MessageLoopRunner;
26 using content::NavigationController;
27 using content::WebContents;
29 class SupervisedUserResourceThrottleTest : public InProcessBrowserTest {
30 protected:
31 SupervisedUserResourceThrottleTest() : supervised_user_service_(NULL) {}
32 ~SupervisedUserResourceThrottleTest() override {}
34 private:
35 void SetUpOnMainThread() override;
36 void SetUpCommandLine(base::CommandLine* command_line) override;
38 SupervisedUserService* supervised_user_service_;
41 void SupervisedUserResourceThrottleTest::SetUpOnMainThread() {
42 supervised_user_service_ =
43 SupervisedUserServiceFactory::GetForProfile(browser()->profile());
46 void SupervisedUserResourceThrottleTest::SetUpCommandLine(
47 base::CommandLine* command_line) {
48 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
51 // Tests that showing the blocking interstitial for a WebContents without a
52 // SupervisedUserNavigationObserver doesn't crash.
53 IN_PROC_BROWSER_TEST_F(SupervisedUserResourceThrottleTest,
54 NoNavigationObserverBlock) {
55 Profile* profile = browser()->profile();
56 SupervisedUserSettingsService* supervised_user_settings_service =
57 SupervisedUserSettingsServiceFactory::GetForProfile(profile);
58 supervised_user_settings_service->SetLocalSetting(
59 supervised_users::kContentPackDefaultFilteringBehavior,
60 scoped_ptr<base::Value>(
61 new base::FundamentalValue(SupervisedUserURLFilter::BLOCK)));
63 scoped_ptr<WebContents> web_contents(
64 WebContents::Create(WebContents::CreateParams(profile)));
65 NavigationController& controller = web_contents->GetController();
66 content::TestNavigationObserver observer(web_contents.get());
67 controller.LoadURL(GURL("http://www.example.com"), content::Referrer(),
68 ui::PAGE_TRANSITION_TYPED, std::string());
69 observer.Wait();
70 content::NavigationEntry* entry = controller.GetActiveEntry();
71 ASSERT_TRUE(entry);
72 EXPECT_EQ(content::PAGE_TYPE_INTERSTITIAL, entry->GetPageType());