OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_test_message_listener.h" | 8 #include "chrome/browser/extensions/extension_test_message_listener.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 | 14 |
15 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceApi) { | 15 class ExtensionPreferenceApiTest : public ExtensionApiTest { |
16 protected: | |
17 void CheckPreferences() { | |
18 PrefService* pref_service = browser()->profile()->GetPrefs(); | |
19 const PrefService::Preference* pref = pref_service->FindPreference( | |
20 prefs::kBlockThirdPartyCookies); | |
21 ASSERT_TRUE(pref); | |
22 EXPECT_TRUE(pref->IsExtensionControlled()); | |
23 EXPECT_TRUE(pref_service->GetBoolean(prefs::kAlternateErrorPagesEnabled)); | |
24 EXPECT_TRUE(pref_service->GetBoolean(autofill::prefs::kAutofillEnabled)); | |
25 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
26 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableHyperlinkAuditing)); | |
27 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); | |
28 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableTranslate)); | |
29 EXPECT_TRUE(pref_service->GetBoolean(prefs::kNetworkPredictionEnabled)); | |
30 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | |
31 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSearchSuggestEnabled)); | |
32 } | |
33 }; | |
34 | |
35 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, Standard) { | |
16 PrefService* pref_service = browser()->profile()->GetPrefs(); | 36 PrefService* pref_service = browser()->profile()->GetPrefs(); |
17 pref_service->SetBoolean(prefs::kAlternateErrorPagesEnabled, false); | 37 pref_service->SetBoolean(prefs::kAlternateErrorPagesEnabled, false); |
18 pref_service->SetBoolean(autofill::prefs::kAutofillEnabled, false); | 38 pref_service->SetBoolean(autofill::prefs::kAutofillEnabled, false); |
19 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 39 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
20 pref_service->SetBoolean(prefs::kEnableHyperlinkAuditing, false); | 40 pref_service->SetBoolean(prefs::kEnableHyperlinkAuditing, false); |
21 pref_service->SetBoolean(prefs::kEnableReferrers, false); | 41 pref_service->SetBoolean(prefs::kEnableReferrers, false); |
22 pref_service->SetBoolean(prefs::kEnableTranslate, false); | 42 pref_service->SetBoolean(prefs::kEnableTranslate, false); |
23 pref_service->SetBoolean(prefs::kNetworkPredictionEnabled, false); | 43 pref_service->SetBoolean(prefs::kNetworkPredictionEnabled, false); |
24 pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false); | 44 pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false); |
25 pref_service->SetBoolean(prefs::kSearchSuggestEnabled, false); | 45 pref_service->SetBoolean(prefs::kSearchSuggestEnabled, false); |
26 | 46 |
27 EXPECT_TRUE(RunExtensionTest("preference/standard")) << message_; | 47 EXPECT_TRUE(RunExtensionTest("preference/standard")) << message_; |
48 CheckPreferences(); | |
28 | 49 |
29 const PrefService::Preference* pref = pref_service->FindPreference( | 50 // The settings should not be reset when the extension is reloaded. |
Jeffrey Yasskin
2013/09/06 21:31:56
Could you also check that an uninstall+reinstall d
Bernhard Bauer
2013/09/10 13:28:18
Done.
| |
30 prefs::kBlockThirdPartyCookies); | 51 ReloadExtension(last_loaded_extension_id_); |
31 ASSERT_TRUE(pref); | 52 CheckPreferences(); |
32 EXPECT_TRUE(pref->IsExtensionControlled()); | |
33 EXPECT_TRUE(pref_service->GetBoolean(prefs::kAlternateErrorPagesEnabled)); | |
34 EXPECT_TRUE(pref_service->GetBoolean(autofill::prefs::kAutofillEnabled)); | |
35 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
36 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableHyperlinkAuditing)); | |
37 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); | |
38 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableTranslate)); | |
39 EXPECT_TRUE(pref_service->GetBoolean(prefs::kNetworkPredictionEnabled)); | |
40 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | |
41 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSearchSuggestEnabled)); | |
42 } | 53 } |
43 | 54 |
44 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferencePersistentIncognito) { | 55 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, PersistentIncognito) { |
45 PrefService* prefs = browser()->profile()->GetPrefs(); | 56 PrefService* prefs = browser()->profile()->GetPrefs(); |
46 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | 57 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); |
47 | 58 |
48 EXPECT_TRUE( | 59 EXPECT_TRUE( |
49 RunExtensionTestIncognito("preference/persistent_incognito")) << | 60 RunExtensionTestIncognito("preference/persistent_incognito")) << |
50 message_; | 61 message_; |
51 | 62 |
52 // Setting an incognito preference should not create an incognito profile. | 63 // Setting an incognito preference should not create an incognito profile. |
53 EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | 64 EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); |
54 | 65 |
55 PrefService* otr_prefs = | 66 PrefService* otr_prefs = |
56 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); | 67 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); |
57 const PrefService::Preference* pref = | 68 const PrefService::Preference* pref = |
58 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); | 69 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
59 ASSERT_TRUE(pref); | 70 ASSERT_TRUE(pref); |
60 EXPECT_TRUE(pref->IsExtensionControlled()); | 71 EXPECT_TRUE(pref->IsExtensionControlled()); |
61 EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | 72 EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
62 | 73 |
63 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); | 74 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
64 ASSERT_TRUE(pref); | 75 ASSERT_TRUE(pref); |
65 EXPECT_FALSE(pref->IsExtensionControlled()); | 76 EXPECT_FALSE(pref->IsExtensionControlled()); |
66 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | 77 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
67 } | 78 } |
68 | 79 |
69 // Flakily times out: http://crbug.com/106144 | 80 // Flakily times out: http://crbug.com/106144 |
70 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_PreferenceIncognitoDisabled) { | 81 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, DISABLED_IncognitoDisabled) { |
71 EXPECT_FALSE(RunExtensionTest("preference/persistent_incognito")); | 82 EXPECT_FALSE(RunExtensionTest("preference/persistent_incognito")); |
72 } | 83 } |
73 | 84 |
74 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceSessionOnlyIncognito) { | 85 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, SessionOnlyIncognito) { |
75 PrefService* prefs = browser()->profile()->GetPrefs(); | 86 PrefService* prefs = browser()->profile()->GetPrefs(); |
76 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | 87 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); |
77 | 88 |
78 EXPECT_TRUE( | 89 EXPECT_TRUE( |
79 RunExtensionTestIncognito("preference/session_only_incognito")) << | 90 RunExtensionTestIncognito("preference/session_only_incognito")) << |
80 message_; | 91 message_; |
81 | 92 |
82 EXPECT_TRUE(browser()->profile()->HasOffTheRecordProfile()); | 93 EXPECT_TRUE(browser()->profile()->HasOffTheRecordProfile()); |
83 | 94 |
84 PrefService* otr_prefs = | 95 PrefService* otr_prefs = |
85 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); | 96 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); |
86 const PrefService::Preference* pref = | 97 const PrefService::Preference* pref = |
87 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); | 98 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
88 ASSERT_TRUE(pref); | 99 ASSERT_TRUE(pref); |
89 EXPECT_TRUE(pref->IsExtensionControlled()); | 100 EXPECT_TRUE(pref->IsExtensionControlled()); |
90 EXPECT_FALSE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | 101 EXPECT_FALSE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
91 | 102 |
92 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); | 103 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); |
93 ASSERT_TRUE(pref); | 104 ASSERT_TRUE(pref); |
94 EXPECT_FALSE(pref->IsExtensionControlled()); | 105 EXPECT_FALSE(pref->IsExtensionControlled()); |
95 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | 106 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); |
96 } | 107 } |
97 | 108 |
98 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceClear) { | 109 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, Clear) { |
99 PrefService* pref_service = browser()->profile()->GetPrefs(); | 110 PrefService* pref_service = browser()->profile()->GetPrefs(); |
100 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 111 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
101 | 112 |
102 EXPECT_TRUE(RunExtensionTest("preference/clear")) << message_; | 113 EXPECT_TRUE(RunExtensionTest("preference/clear")) << message_; |
103 | 114 |
104 const PrefService::Preference* pref = pref_service->FindPreference( | 115 const PrefService::Preference* pref = pref_service->FindPreference( |
105 prefs::kBlockThirdPartyCookies); | 116 prefs::kBlockThirdPartyCookies); |
106 ASSERT_TRUE(pref); | 117 ASSERT_TRUE(pref); |
107 EXPECT_FALSE(pref->IsExtensionControlled()); | 118 EXPECT_FALSE(pref->IsExtensionControlled()); |
108 EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | 119 EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); |
109 } | 120 } |
110 | 121 |
111 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceOnChange) { | 122 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, OnChange) { |
112 EXPECT_TRUE(RunExtensionTestIncognito("preference/onchange")) << | 123 EXPECT_TRUE(RunExtensionTestIncognito("preference/onchange")) << |
113 message_; | 124 message_; |
114 } | 125 } |
115 | 126 |
116 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceOnChangeSplit) { | 127 IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, OnChangeSplit) { |
117 ResultCatcher catcher; | 128 ResultCatcher catcher; |
118 catcher.RestrictToProfile(browser()->profile()); | 129 catcher.RestrictToProfile(browser()->profile()); |
119 ResultCatcher catcher_incognito; | 130 ResultCatcher catcher_incognito; |
120 catcher_incognito.RestrictToProfile( | 131 catcher_incognito.RestrictToProfile( |
121 browser()->profile()->GetOffTheRecordProfile()); | 132 browser()->profile()->GetOffTheRecordProfile()); |
122 | 133 |
123 // Open an incognito window. | 134 // Open an incognito window. |
124 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), | 135 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), |
125 GURL("chrome://newtab/")); | 136 GURL("chrome://newtab/")); |
126 | 137 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 | 238 |
228 // Test 6 - clearDefault | 239 // Test 6 - clearDefault |
229 EXPECT_TRUE(listener10.WaitUntilSatisfied()); // Regular ready | 240 EXPECT_TRUE(listener10.WaitUntilSatisfied()); // Regular ready |
230 EXPECT_TRUE(listener_incognito10.WaitUntilSatisfied()); // Incognito ready | 241 EXPECT_TRUE(listener_incognito10.WaitUntilSatisfied()); // Incognito ready |
231 listener10.Reply("ok"); | 242 listener10.Reply("ok"); |
232 listener_incognito10.Reply("ok"); | 243 listener_incognito10.Reply("ok"); |
233 | 244 |
234 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 245 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
235 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); | 246 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); |
236 } | 247 } |
OLD | NEW |