OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/prefs/pref_service.h" | 6 #include "chrome/browser/prefs/pref_service.h" |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 | 11 |
12 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { | 12 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { |
13 CommandLine::ForCurrentProcess()->AppendSwitch( | 13 CommandLine::ForCurrentProcess()->AppendSwitch( |
14 switches::kEnableExperimentalExtensionApis); | 14 switches::kEnableExperimentalExtensionApis); |
15 | 15 |
16 PrefService* pref_service = browser()->profile()->GetPrefs(); | 16 PrefService* pref_service = browser()->profile()->GetPrefs(); |
17 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 17 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
18 pref_service->SetBoolean(prefs::kEnableReferrers, false); | 18 pref_service->SetBoolean(prefs::kEnableReferrers, false); |
19 | 19 |
20 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; | 20 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; |
21 | 21 |
22 const PrefService::Preference* pref = pref_service->FindPreference( | 22 const PrefService::Preference* pref = pref_service->FindPreference( |
23 prefs::kBlockThirdPartyCookies); | 23 prefs::kBlockThirdPartyCookies); |
24 ASSERT_TRUE(pref); | 24 ASSERT_TRUE(pref); |
25 EXPECT_TRUE(pref->IsExtensionControlled()); | 25 EXPECT_TRUE(pref->IsExtensionControlled()); |
26 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | 26 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); |
27 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); | 27 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); |
28 } | 28 } |
29 | 29 |
30 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoContentSettings) { | 30 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PersistentIncognitoContentSettings) { |
31 CommandLine::ForCurrentProcess()->AppendSwitch( | 31 CommandLine::ForCurrentProcess()->AppendSwitch( |
32 switches::kEnableExperimentalExtensionApis); | 32 switches::kEnableExperimentalExtensionApis); |
33 | 33 |
34 PrefService* prefs = browser()->profile()->GetPrefs(); | 34 PrefService* prefs = browser()->profile()->GetPrefs(); |
35 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | 35 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); |
36 | 36 |
37 EXPECT_TRUE(RunExtensionTestIncognito("content_settings/incognito")) << | 37 EXPECT_TRUE( |
| 38 RunExtensionTestIncognito("content_settings/persistent_incognito")) << |
38 message_; | 39 message_; |
39 | 40 |
40 // Setting an incognito preference should not create an incognito profile. | 41 // Setting an incognito preference should not create an incognito profile. |
41 EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | 42 EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); |
42 | 43 |
43 PrefService* otr_prefs = | 44 PrefService* otr_prefs = |
44 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); | 45 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); |
45 const PrefService::Preference* pref = | 46 const PrefService::Preference* pref = |
46 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); | 47 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
47 ASSERT_TRUE(pref); | 48 ASSERT_TRUE(pref); |
48 EXPECT_TRUE(pref->IsExtensionControlled()); | 49 EXPECT_TRUE(pref->IsExtensionControlled()); |
49 EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | 50 EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
50 | 51 |
51 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); | 52 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
52 ASSERT_TRUE(pref); | 53 ASSERT_TRUE(pref); |
53 EXPECT_FALSE(pref->IsExtensionControlled()); | 54 EXPECT_FALSE(pref->IsExtensionControlled()); |
54 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | 55 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
55 } | 56 } |
56 | 57 |
57 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledContentSettings) { | 58 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledContentSettings) { |
58 CommandLine::ForCurrentProcess()->AppendSwitch( | 59 CommandLine::ForCurrentProcess()->AppendSwitch( |
59 switches::kEnableExperimentalExtensionApis); | 60 switches::kEnableExperimentalExtensionApis); |
60 | 61 |
61 EXPECT_FALSE(RunExtensionTest("content_settings/incognito")); | 62 EXPECT_FALSE(RunExtensionTest("content_settings/persistent_incognito")); |
| 63 } |
| 64 |
| 65 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, SessionOnlyIncognitoContentSettings) { |
| 66 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 67 switches::kEnableExperimentalExtensionApis); |
| 68 |
| 69 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 70 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); |
| 71 |
| 72 EXPECT_TRUE( |
| 73 RunExtensionTestIncognito("content_settings/session_only_incognito")) << |
| 74 message_; |
| 75 |
| 76 EXPECT_TRUE(browser()->profile()->HasOffTheRecordProfile()); |
| 77 |
| 78 PrefService* otr_prefs = |
| 79 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); |
| 80 const PrefService::Preference* pref = |
| 81 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
| 82 ASSERT_TRUE(pref); |
| 83 EXPECT_TRUE(pref->IsExtensionControlled()); |
| 84 EXPECT_FALSE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
| 85 |
| 86 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
| 87 ASSERT_TRUE(pref); |
| 88 EXPECT_FALSE(pref->IsExtensionControlled()); |
| 89 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
62 } | 90 } |
63 | 91 |
64 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsClear) { | 92 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsClear) { |
65 CommandLine::ForCurrentProcess()->AppendSwitch( | 93 CommandLine::ForCurrentProcess()->AppendSwitch( |
66 switches::kEnableExperimentalExtensionApis); | 94 switches::kEnableExperimentalExtensionApis); |
67 | 95 |
68 PrefService* pref_service = browser()->profile()->GetPrefs(); | 96 PrefService* pref_service = browser()->profile()->GetPrefs(); |
69 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 97 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
70 | 98 |
71 EXPECT_TRUE(RunExtensionTest("content_settings/clear")) << message_; | 99 EXPECT_TRUE(RunExtensionTest("content_settings/clear")) << message_; |
72 | 100 |
73 const PrefService::Preference* pref = pref_service->FindPreference( | 101 const PrefService::Preference* pref = pref_service->FindPreference( |
74 prefs::kBlockThirdPartyCookies); | 102 prefs::kBlockThirdPartyCookies); |
75 ASSERT_TRUE(pref); | 103 ASSERT_TRUE(pref); |
76 EXPECT_FALSE(pref->IsExtensionControlled()); | 104 EXPECT_FALSE(pref->IsExtensionControlled()); |
77 EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | 105 EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); |
78 } | 106 } |
79 | 107 |
80 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsOnChange) { | 108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsOnChange) { |
81 CommandLine::ForCurrentProcess()->AppendSwitch( | 109 CommandLine::ForCurrentProcess()->AppendSwitch( |
82 switches::kEnableExperimentalExtensionApis); | 110 switches::kEnableExperimentalExtensionApis); |
83 | 111 |
84 PrefService* prefs = browser()->profile()->GetPrefs(); | 112 PrefService* prefs = browser()->profile()->GetPrefs(); |
85 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | 113 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); |
86 | 114 |
87 EXPECT_TRUE(RunExtensionTestIncognito("content_settings/onchange")) << | 115 EXPECT_TRUE(RunExtensionTestIncognito("content_settings/onchange")) << |
88 message_; | 116 message_; |
89 } | 117 } |
OLD | NEW |