Commit ec5143b6 authored by bauerb@chromium.org's avatar bauerb@chromium.org

Reland r223124: Don't clear existing extension-defined preferences and content...

Reland r223124: Don't clear existing extension-defined preferences and content settings when reloading or updating an extension.

TBR=falken@chromium.org,sky@chromium.org
BUG=284385

Original review: https://chromiumcodereview.appspot.com/23694020

Review URL: https://chromiumcodereview.appspot.com/23581015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223587 0039d316-1c4b-4281-b951-d872f2087c98
parent fc20fdd3
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/cookie_settings.h" #include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/extensions/api/content_settings/content_settings_api.h" #include "chrome/browser/extensions/api/content_settings/content_settings_api.h"
...@@ -12,97 +14,202 @@ ...@@ -12,97 +14,202 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_service.h" #include "content/public/browser/plugin_service.h"
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "content/public/test/test_utils.h"
namespace extensions { namespace {
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { void ReleaseBrowserProcessModule() {
EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; g_browser_process->ReleaseModule();
HostContentSettingsMap* map =
browser()->profile()->GetHostContentSettingsMap();
CookieSettings* cookie_settings =
CookieSettings::Factory::GetForProfile(browser()->profile()).get();
// Check default content settings by using an unknown URL.
GURL example_url("http://www.example.com");
EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
example_url, example_url));
EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
example_url, example_url));
EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(example_url));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_IMAGES,
std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_POPUPS,
std::string()));
#if 0
// TODO(bauerb): Enable once geolocation settings are integrated into the
// HostContentSettingsMap.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string()));
#endif
EXPECT_EQ(CONTENT_SETTING_ASK,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
std::string()));
// Check content settings for www.google.com
GURL url("http://www.google.com");
EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(url, url));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
#if 0
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
#endif
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
} }
class ContentSettingsGetResourceIdentifiersTest : public ExtensionApiTest { } // namespace
namespace extensions {
class ExtensionContentSettingsApiTest : public ExtensionApiTest {
public: public:
ExtensionContentSettingsApiTest() : profile_(NULL) {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line); ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kDisablePluginsDiscovery); command_line->AppendSwitch(switches::kDisablePluginsDiscovery);
} }
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionApiTest::SetUpOnMainThread();
// The browser might get closed later (and therefore be destroyed), so we
// save the profile.
profile_ = browser()->profile();
// Closing the last browser window also releases a module reference. Make
// sure it's not the last one, so the message loop doesn't quit
// unexpectedly.
g_browser_process->AddRefModule();
}
virtual void CleanUpOnMainThread() OVERRIDE {
// ReleaseBrowserProcessModule() needs to be called in a message loop, so we
// post a task to do it, then run the message loop.
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&ReleaseBrowserProcessModule));
content::RunAllPendingInMessageLoop();
ExtensionApiTest::CleanUpOnMainThread();
}
protected:
void CheckContentSettingsSet() {
HostContentSettingsMap* map =
profile_->GetHostContentSettingsMap();
CookieSettings* cookie_settings =
CookieSettings::Factory::GetForProfile(profile_).get();
// Check default content settings by using an unknown URL.
GURL example_url("http://www.example.com");
EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
example_url, example_url));
EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
example_url, example_url));
EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(example_url));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_IMAGES,
std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_POPUPS,
std::string()));
#if 0
// TODO(bauerb): Enable once geolocation settings are integrated into the
// HostContentSettingsMap.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_GEOLOCATION,
std::string()));
#endif
EXPECT_EQ(CONTENT_SETTING_ASK,
map->GetContentSetting(example_url,
example_url,
CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
std::string()));
// Check content settings for www.google.com
GURL url("http://www.google.com");
EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(url, url));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
#if 0
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
#endif
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
}
void CheckContentSettingsDefault() {
HostContentSettingsMap* map =
profile_->GetHostContentSettingsMap();
CookieSettings* cookie_settings =
CookieSettings::Factory::GetForProfile(profile_).get();
// Check content settings for www.google.com
GURL url("http://www.google.com");
EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(url, url));
EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(url, url));
EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(url));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
#if 0
// TODO(bauerb): Enable once geolocation settings are integrated into the
// HostContentSettingsMap.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
#endif
EXPECT_EQ(
CONTENT_SETTING_ASK,
map->GetContentSetting(
url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
}
private:
Profile* profile_;
}; };
// http://crbug.com/177163
#if defined(OS_WIN) && !defined(NDEBUG)
#define MAYBE_Standard DISABLED_Standard
#else
#define MAYBE_Standard Standard
#endif
IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, MAYBE_Standard) {
CheckContentSettingsDefault();
const char kExtensionPath[] = "content_settings/standard";
EXPECT_TRUE(RunExtensionSubtest(kExtensionPath, "test.html")) << message_;
CheckContentSettingsSet();
// The settings should not be reset when the extension is reloaded.
ReloadExtension(last_loaded_extension_id_);
CheckContentSettingsSet();
// Uninstalling and installing the extension (without running the test that
// calls the extension API) should clear the settings.
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::NotificationService::AllSources());
UninstallExtension(last_loaded_extension_id_);
observer.Wait();
CheckContentSettingsDefault();
LoadExtension(test_data_dir_.AppendASCII(kExtensionPath));
CheckContentSettingsDefault();
}
// Flaky on the trybots. See http://crbug.com/96725. // Flaky on the trybots. See http://crbug.com/96725.
IN_PROC_BROWSER_TEST_F(ContentSettingsGetResourceIdentifiersTest, IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest,
DISABLED_Test) { DISABLED_GetResourceIdentifiers) {
base::FilePath::CharType kFooPath[] = base::FilePath::CharType kFooPath[] =
FILE_PATH_LITERAL("/plugins/foo.plugin"); FILE_PATH_LITERAL("/plugins/foo.plugin");
base::FilePath::CharType kBarPath[] = base::FilePath::CharType kBarPath[] =
......
...@@ -123,15 +123,16 @@ void ContentSettingsStore::RegisterExtension( ...@@ -123,15 +123,16 @@ void ContentSettingsStore::RegisterExtension(
bool is_enabled) { bool is_enabled) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
ExtensionEntryMap::iterator i = FindEntry(ext_id); ExtensionEntryMap::iterator i = FindEntry(ext_id);
ExtensionEntry* entry;
if (i != entries_.end()) { if (i != entries_.end()) {
delete i->second; entry = i->second;
entries_.erase(i); } else {
entry = new ExtensionEntry;
entries_.insert(std::make_pair(install_time, entry));
} }
ExtensionEntry* entry = new ExtensionEntry;
entry->id = ext_id; entry->id = ext_id;
entry->enabled = is_enabled; entry->enabled = is_enabled;
entries_.insert(std::make_pair(install_time, entry));
} }
void ContentSettingsStore::UnregisterExtension( void ContentSettingsStore::UnregisterExtension(
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -11,38 +13,122 @@ ...@@ -11,38 +13,122 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceApi) { namespace {
PrefService* pref_service = browser()->profile()->GetPrefs();
pref_service->SetBoolean(prefs::kAlternateErrorPagesEnabled, false); void ReleaseBrowserProcessModule() {
pref_service->SetBoolean(autofill::prefs::kAutofillEnabled, false); g_browser_process->ReleaseModule();
pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); }
pref_service->SetBoolean(prefs::kEnableHyperlinkAuditing, false);
pref_service->SetBoolean(prefs::kEnableReferrers, false); } // namespace
pref_service->SetBoolean(prefs::kEnableTranslate, false);
pref_service->SetBoolean(prefs::kNetworkPredictionEnabled, false); class ExtensionPreferenceApiTest : public ExtensionApiTest {
pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false); protected:
pref_service->SetBoolean(prefs::kSearchSuggestEnabled, false); ExtensionPreferenceApiTest() : profile_(NULL) {}
EXPECT_TRUE(RunExtensionTest("preference/standard")) << message_; void CheckPreferencesSet() {
PrefService* prefs = profile_->GetPrefs();
const PrefService::Preference* pref = pref_service->FindPreference( const PrefService::Preference* pref = prefs->FindPreference(
prefs::kBlockThirdPartyCookies); prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref); ASSERT_TRUE(pref);
EXPECT_TRUE(pref->IsExtensionControlled()); EXPECT_TRUE(pref->IsExtensionControlled());
EXPECT_TRUE(pref_service->GetBoolean(prefs::kAlternateErrorPagesEnabled)); EXPECT_TRUE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
EXPECT_TRUE(pref_service->GetBoolean(autofill::prefs::kAutofillEnabled)); EXPECT_TRUE(prefs->GetBoolean(autofill::prefs::kAutofillEnabled));
EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableHyperlinkAuditing)); EXPECT_TRUE(prefs->GetBoolean(prefs::kEnableHyperlinkAuditing));
EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); EXPECT_TRUE(prefs->GetBoolean(prefs::kEnableReferrers));
EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableTranslate)); EXPECT_TRUE(prefs->GetBoolean(prefs::kEnableTranslate));
EXPECT_TRUE(pref_service->GetBoolean(prefs::kNetworkPredictionEnabled)); EXPECT_TRUE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); EXPECT_TRUE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
EXPECT_TRUE(pref_service->GetBoolean(prefs::kSearchSuggestEnabled)); EXPECT_TRUE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
}
void CheckPreferencesCleared() {
PrefService* prefs = profile_->GetPrefs();
const PrefService::Preference* pref = prefs->FindPreference(
prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsExtensionControlled());
EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
EXPECT_FALSE(prefs->GetBoolean(autofill::prefs::kAutofillEnabled));
EXPECT_TRUE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
EXPECT_FALSE(prefs->GetBoolean(prefs::kEnableHyperlinkAuditing));
EXPECT_FALSE(prefs->GetBoolean(prefs::kEnableReferrers));
EXPECT_FALSE(prefs->GetBoolean(prefs::kEnableTranslate));
EXPECT_FALSE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
}
virtual void SetUpOnMainThread() OVERRIDE {
ExtensionApiTest::SetUpOnMainThread();
// The browser might get closed later (and therefore be destroyed), so we
// save the profile.
profile_ = browser()->profile();
// Closing the last browser window also releases a module reference. Make
// sure it's not the last one, so the message loop doesn't quit
// unexpectedly.
g_browser_process->AddRefModule();
}
virtual void CleanUpOnMainThread() OVERRIDE {
// ReleaseBrowserProcessModule() needs to be called in a message loop, so we
// post a task to do it, then run the message loop.
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&ReleaseBrowserProcessModule));
content::RunAllPendingInMessageLoop();
ExtensionApiTest::CleanUpOnMainThread();
}
Profile* profile_;
};
// http://crbug.com/177163
#if defined(OS_WIN) && !defined(NDEBUG)
#define MAYBE_Standard DISABLED_Standard
#else
#define MAYBE_Standard Standard
#endif
IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, MAYBE_Standard) {
PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kAlternateErrorPagesEnabled, false);
prefs->SetBoolean(autofill::prefs::kAutofillEnabled, false);
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, true);
prefs->SetBoolean(prefs::kEnableHyperlinkAuditing, false);
prefs->SetBoolean(prefs::kEnableReferrers, false);
prefs->SetBoolean(prefs::kEnableTranslate, false);
prefs->SetBoolean(prefs::kNetworkPredictionEnabled, false);
prefs->SetBoolean(prefs::kSafeBrowsingEnabled, false);
prefs->SetBoolean(prefs::kSearchSuggestEnabled, false);
const char kExtensionPath[] = "preference/standard";
EXPECT_TRUE(RunExtensionSubtest(kExtensionPath, "test.html")) << message_;
CheckPreferencesSet();
// The settings should not be reset when the extension is reloaded.
ReloadExtension(last_loaded_extension_id_);
CheckPreferencesSet();
// Uninstalling and installing the extension (without running the test that
// calls the extension API) should clear the settings.
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::NotificationService::AllSources());
UninstallExtension(last_loaded_extension_id_);
observer.Wait();
CheckPreferencesCleared();
LoadExtension(test_data_dir_.AppendASCII(kExtensionPath));
CheckPreferencesCleared();
} }
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferencePersistentIncognito) { IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, PersistentIncognito) {
PrefService* prefs = browser()->profile()->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
EXPECT_TRUE( EXPECT_TRUE(
...@@ -50,10 +136,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferencePersistentIncognito) { ...@@ -50,10 +136,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferencePersistentIncognito) {
message_; message_;
// Setting an incognito preference should not create an incognito profile. // Setting an incognito preference should not create an incognito profile.
EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); EXPECT_FALSE(profile_->HasOffTheRecordProfile());
PrefService* otr_prefs = PrefService* otr_prefs = profile_->GetOffTheRecordProfile()->GetPrefs();
browser()->profile()->GetOffTheRecordProfile()->GetPrefs();
const PrefService::Preference* pref = const PrefService::Preference* pref =
otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref); ASSERT_TRUE(pref);
...@@ -67,22 +152,21 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferencePersistentIncognito) { ...@@ -67,22 +152,21 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferencePersistentIncognito) {
} }
// Flakily times out: http://crbug.com/106144 // Flakily times out: http://crbug.com/106144
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_PreferenceIncognitoDisabled) { IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, DISABLED_IncognitoDisabled) {
EXPECT_FALSE(RunExtensionTest("preference/persistent_incognito")); EXPECT_FALSE(RunExtensionTest("preference/persistent_incognito"));
} }
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceSessionOnlyIncognito) { IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, SessionOnlyIncognito) {
PrefService* prefs = browser()->profile()->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
EXPECT_TRUE( EXPECT_TRUE(
RunExtensionTestIncognito("preference/session_only_incognito")) << RunExtensionTestIncognito("preference/session_only_incognito")) <<
message_; message_;
EXPECT_TRUE(browser()->profile()->HasOffTheRecordProfile()); EXPECT_TRUE(profile_->HasOffTheRecordProfile());
PrefService* otr_prefs = PrefService* otr_prefs = profile_->GetOffTheRecordProfile()->GetPrefs();
browser()->profile()->GetOffTheRecordProfile()->GetPrefs();
const PrefService::Preference* pref = const PrefService::Preference* pref =
otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref); ASSERT_TRUE(pref);
...@@ -95,34 +179,32 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceSessionOnlyIncognito) { ...@@ -95,34 +179,32 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceSessionOnlyIncognito) {
EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
} }
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceClear) { IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, Clear) {
PrefService* pref_service = browser()->profile()->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); prefs->SetBoolean(prefs::kBlockThirdPartyCookies, true);
EXPECT_TRUE(RunExtensionTest("preference/clear")) << message_; EXPECT_TRUE(RunExtensionTest("preference/clear")) << message_;
const PrefService::Preference* pref = pref_service->FindPreference( const PrefService::Preference* pref = prefs->FindPreference(
prefs::kBlockThirdPartyCookies); prefs::kBlockThirdPartyCookies);
ASSERT_TRUE(pref); ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsExtensionControlled()); EXPECT_FALSE(pref->IsExtensionControlled());
EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); EXPECT_EQ(true, prefs->GetBoolean(prefs::kBlockThirdPartyCookies));
} }
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceOnChange) { IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, OnChange) {
EXPECT_TRUE(RunExtensionTestIncognito("preference/onchange")) << EXPECT_TRUE(RunExtensionTestIncognito("preference/onchange")) <<
message_; message_;
} }
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PreferenceOnChangeSplit) { IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, OnChangeSplit) {
ResultCatcher catcher; ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile()); catcher.RestrictToProfile(profile_);
ResultCatcher catcher_incognito; ResultCatcher catcher_incognito;
catcher_incognito.RestrictToProfile( catcher_incognito.RestrictToProfile(profile_->GetOffTheRecordProfile());
browser()->profile()->GetOffTheRecordProfile());
// Open an incognito window. // Open an incognito window.
ui_test_utils::OpenURLOffTheRecord(browser()->profile(), ui_test_utils::OpenURLOffTheRecord(profile_, GURL("chrome://newtab/"));
GURL("chrome://newtab/"));
// changeDefault listeners. // changeDefault listeners.
ExtensionTestMessageListener listener1("changeDefault regular ready", true); ExtensionTestMessageListener listener1("changeDefault regular ready", true);
......
...@@ -116,10 +116,13 @@ bool ExtensionPrefValueMap::DoesExtensionControlPref( ...@@ -116,10 +116,13 @@ bool ExtensionPrefValueMap::DoesExtensionControlPref(
void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id, void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id,
const base::Time& install_time, const base::Time& install_time,
bool is_enabled) { bool is_enabled) {
if (entries_.find(ext_id) != entries_.end()) if (entries_.find(ext_id) == entries_.end()) {
UnregisterExtension(ext_id); entries_[ext_id] = new ExtensionEntry;
entries_[ext_id] = new ExtensionEntry;
entries_[ext_id]->install_time = install_time; // Only update the install time if the extension is newly installed.
entries_[ext_id]->install_time = install_time;
}
entries_[ext_id]->enabled = is_enabled; entries_[ext_id]->enabled = is_enabled;
} }
......
...@@ -1835,13 +1835,26 @@ void ExtensionPrefs::FinishExtensionInfoPrefs( ...@@ -1835,13 +1835,26 @@ void ExtensionPrefs::FinishExtensionInfoPrefs(
const syncer::StringOrdinal& suggested_page_ordinal, const syncer::StringOrdinal& suggested_page_ordinal,
DictionaryValue* extension_dict) { DictionaryValue* extension_dict) {
// Reinitializes various preferences with empty dictionaries. // Reinitializes various preferences with empty dictionaries.
extension_dict->Set(pref_names::kPrefPreferences, new DictionaryValue); if (!extension_dict->HasKey(pref_names::kPrefPreferences))
extension_dict->Set(pref_names::kPrefIncognitoPreferences, extension_dict->Set(pref_names::kPrefPreferences, new DictionaryValue);
new DictionaryValue);
extension_dict->Set(pref_names::kPrefRegularOnlyPreferences, if (!extension_dict->HasKey(pref_names::kPrefIncognitoPreferences)) {
new DictionaryValue); extension_dict->Set(pref_names::kPrefIncognitoPreferences,
extension_dict->Set(pref_names::kPrefContentSettings, new ListValue); new DictionaryValue);
extension_dict->Set(pref_names::kPrefIncognitoContentSettings, new ListValue); }
if (!extension_dict->HasKey(pref_names::kPrefRegularOnlyPreferences)) {
extension_dict->Set(pref_names::kPrefRegularOnlyPreferences,
new DictionaryValue);
}
if (!extension_dict->HasKey(pref_names::kPrefContentSettings))
extension_dict->Set(pref_names::kPrefContentSettings, new ListValue);
if (!extension_dict->HasKey(pref_names::kPrefIncognitoContentSettings)) {
extension_dict->Set(pref_names::kPrefIncognitoContentSettings,
new ListValue);
}
// If this point has been reached, any pending installs should be considered // If this point has been reached, any pending installs should be considered
// out of date. // out of date.
......
...@@ -224,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, ...@@ -224,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
QueryHistory(history_service, "", options, &results); QueryHistory(history_service, "", options, &results);
// Check that the entries have the correct blocked_visit value. // Check that the entries have the correct blocked_visit value.
EXPECT_EQ(2u, results.size()); ASSERT_EQ(2u, results.size());
EXPECT_EQ(blocked_url.spec(), results[0].url().spec()); EXPECT_EQ(blocked_url.spec(), results[0].url().spec());
EXPECT_TRUE(results[0].blocked_visit()); EXPECT_TRUE(results[0].blocked_visit());
EXPECT_EQ(allowed_url.spec(), results[1].url().spec()); EXPECT_EQ(allowed_url.spec(), results[1].url().spec());
......
...@@ -3,8 +3,5 @@ ...@@ -3,8 +3,5 @@
"version" : "0.1", "version" : "0.1",
"manifest_version": 2, "manifest_version": 2,
"description" : "Content Settings API Test Extension", "description" : "Content Settings API Test Extension",
"permissions": [ "contentSettings" ], "permissions": [ "contentSettings" ]
"background": {
"page": "test.html"
}
} }
...@@ -3,8 +3,5 @@ ...@@ -3,8 +3,5 @@
"version" : "0.1", "version" : "0.1",
"manifest_version": 2, "manifest_version": 2,
"description" : "Preferences API Test Extension", "description" : "Preferences API Test Extension",
"permissions": [ "privacy" ], "permissions": [ "privacy" ]
"background": {
"page": "test.html"
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment