This source file includes following definitions.
- ReleaseBrowserProcessModule
- SetUpCommandLine
- SetUpOnMainThread
- CleanUpOnMainThread
- CheckContentSettingsSet
- CheckContentSettingsDefault
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#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"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#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 {
void ReleaseBrowserProcessModule() {
g_browser_process->ReleaseModule();
}
}
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();
profile_ = browser()->profile();
g_browser_process->AddRefModule();
}
virtual void CleanUpOnMainThread() OVERRIDE {
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();
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
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()));
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();
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
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_;
};
#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();
ReloadExtension(last_loaded_extension_id());
CheckContentSettingsSet();
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();
}
IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest,
DISABLED_GetResourceIdentifiers) {
base::FilePath::CharType kFooPath[] =
FILE_PATH_LITERAL("/plugins/foo.plugin");
base::FilePath::CharType kBarPath[] =
FILE_PATH_LITERAL("/plugins/bar.plugin");
const char* kFooName = "Foo Plugin";
const char* kBarName = "Bar Plugin";
content::PluginService::GetInstance()->RegisterInternalPlugin(
content::WebPluginInfo(base::ASCIIToUTF16(kFooName),
base::FilePath(kFooPath),
base::ASCIIToUTF16("1.2.3"),
base::ASCIIToUTF16("foo")),
false);
content::PluginService::GetInstance()->RegisterInternalPlugin(
content::WebPluginInfo(base::ASCIIToUTF16(kBarName),
base::FilePath(kBarPath),
base::ASCIIToUTF16("2.3.4"),
base::ASCIIToUTF16("bar")),
false);
EXPECT_TRUE(RunExtensionTest("content_settings/getresourceidentifiers"))
<< message_;
}
}