Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 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/extensions/extension_apitest.h"
      6 #include "chrome/browser/prefs/pref_service.h"
      7 #include "chrome/browser/profiles/profile.h"
      8 #include "chrome/browser/ui/browser.h"
      9 #include "chrome/common/chrome_switches.h"
     10 #include "chrome/common/pref_names.h"
     11 
     12 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) {
     13   CommandLine::ForCurrentProcess()->AppendSwitch(
     14       switches::kEnableExperimentalExtensionApis);
     15 
     16   PrefService* pref_service = browser()->profile()->GetPrefs();
     17   pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true);
     18   pref_service->SetBoolean(prefs::kEnableReferrers, false);
     19 
     20   EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_;
     21 
     22   const PrefService::Preference* pref = pref_service->FindPreference(
     23       prefs::kBlockThirdPartyCookies);
     24   ASSERT_TRUE(pref);
     25   EXPECT_TRUE(pref->IsExtensionControlled());
     26   EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies));
     27   EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers));
     28 }
     29 
     30 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoContentSettings) {
     31   CommandLine::ForCurrentProcess()->AppendSwitch(
     32       switches::kEnableExperimentalExtensionApis);
     33 
     34   PrefService* prefs = browser()->profile()->GetPrefs();
     35   prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
     36 
     37   EXPECT_TRUE(RunExtensionTestIncognito("content_settings/incognito")) <<
     38       message_;
     39 
     40   // Setting an incognito preference should not create an incognito profile.
     41   EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile());
     42 
     43   PrefService* otr_prefs =
     44       browser()->profile()->GetOffTheRecordProfile()->GetPrefs();
     45   const PrefService::Preference* pref =
     46       otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies);
     47   ASSERT_TRUE(pref);
     48   EXPECT_TRUE(pref->IsExtensionControlled());
     49   EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
     50 
     51   pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies);
     52   ASSERT_TRUE(pref);
     53   EXPECT_FALSE(pref->IsExtensionControlled());
     54   EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
     55 }
     56 
     57 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledContentSettings) {
     58   CommandLine::ForCurrentProcess()->AppendSwitch(
     59       switches::kEnableExperimentalExtensionApis);
     60 
     61   EXPECT_FALSE(RunExtensionTest("content_settings/incognito"));
     62 }
     63 
     64 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsClear) {
     65   CommandLine::ForCurrentProcess()->AppendSwitch(
     66       switches::kEnableExperimentalExtensionApis);
     67 
     68   PrefService* pref_service = browser()->profile()->GetPrefs();
     69   pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true);
     70 
     71   EXPECT_TRUE(RunExtensionTest("content_settings/clear")) << message_;
     72 
     73   const PrefService::Preference* pref = pref_service->FindPreference(
     74       prefs::kBlockThirdPartyCookies);
     75   ASSERT_TRUE(pref);
     76   EXPECT_FALSE(pref->IsExtensionControlled());
     77   EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies));
     78 }
     79 
     80 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsOnChange) {
     81   CommandLine::ForCurrentProcess()->AppendSwitch(
     82       switches::kEnableExperimentalExtensionApis);
     83 
     84   PrefService* prefs = browser()->profile()->GetPrefs();
     85   prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
     86 
     87   EXPECT_TRUE(RunExtensionTestIncognito("content_settings/onchange")) <<
     88       message_;
     89 }
     90