Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: chrome/browser/extensions/api/content_settings/content_settings_apitest.cc

Issue 23581015: Reland r223124: Don't clear existing extension-defined preferences and content settings when reload… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/content_settings/content_settings_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
diff --git a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
index 10fb4127985c68c0e1648dc54df9fea158246e01..dbc714aea827ea963e1a1f427b0039e337352837 100644
--- a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
+++ b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
@@ -4,6 +4,8 @@
#include "base/prefs/pref_service.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/host_content_settings_map.h"
#include "chrome/browser/extensions/api/content_settings/content_settings_api.h"
@@ -12,97 +14,202 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/common/webplugininfo.h"
+#include "content/public/test/test_utils.h"
-namespace extensions {
+namespace {
-IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) {
- EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_;
-
- 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()));
+void ReleaseBrowserProcessModule() {
+ g_browser_process->ReleaseModule();
}
-class ContentSettingsGetResourceIdentifiersTest : public ExtensionApiTest {
+} // namespace
+
+namespace extensions {
+
+class ExtensionContentSettingsApiTest : public ExtensionApiTest {
public:
+ ExtensionContentSettingsApiTest() : profile_(NULL) {}
+
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
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.
-IN_PROC_BROWSER_TEST_F(ContentSettingsGetResourceIdentifiersTest,
- DISABLED_Test) {
+IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest,
+ DISABLED_GetResourceIdentifiers) {
base::FilePath::CharType kFooPath[] =
FILE_PATH_LITERAL("/plugins/foo.plugin");
base::FilePath::CharType kBarPath[] =
« no previous file with comments | « no previous file | chrome/browser/extensions/api/content_settings/content_settings_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698