extension_content_settings_apitest.cc revision dc0f95d653279beabeb9817299e2902918ba123e
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 12IN_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 19 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; 20 21 const PrefService::Preference* pref = pref_service->FindPreference( 22 prefs::kBlockThirdPartyCookies); 23 ASSERT_TRUE(pref); 24 EXPECT_TRUE(pref->IsExtensionControlled()); 25 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); 26} 27 28IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoContentSettings) { 29 CommandLine::ForCurrentProcess()->AppendSwitch( 30 switches::kEnableExperimentalExtensionApis); 31 32 PrefService* prefs = browser()->profile()->GetPrefs(); 33 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); 34 35 EXPECT_TRUE(RunExtensionTest("content_settings/incognito")) << message_; 36 37 // Setting an incognito preference should not create an incognito profile. 38 EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); 39 40 PrefService* otr_prefs = 41 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); 42 const PrefService::Preference* pref = 43 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); 44 ASSERT_TRUE(pref); 45 EXPECT_TRUE(pref->IsExtensionControlled()); 46 EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); 47 48 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); 49 ASSERT_TRUE(pref); 50 EXPECT_FALSE(pref->IsExtensionControlled()); 51 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); 52} 53 54IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsClear) { 55 CommandLine::ForCurrentProcess()->AppendSwitch( 56 switches::kEnableExperimentalExtensionApis); 57 58 PrefService* pref_service = browser()->profile()->GetPrefs(); 59 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); 60 61 EXPECT_TRUE(RunExtensionTest("content_settings/clear")) << message_; 62 63 const PrefService::Preference* pref = pref_service->FindPreference( 64 prefs::kBlockThirdPartyCookies); 65 ASSERT_TRUE(pref); 66 EXPECT_FALSE(pref->IsExtensionControlled()); 67 EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); 68} 69