This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "net/base/net_util.h"
using content::NavigationController;
using content::WebContents;
using extensions::Extension;
#if defined(OS_WIN)
#define MAYBE_PluginLoadUnload DISABLED_PluginLoadUnload
#elif defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)
#define MAYBE_PluginLoadUnload DISABLED_PluginLoadUnload
#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
#define MAYBE_PluginLoadUnload DISABLED_PluginLoadUnload
#else
#define MAYBE_PluginLoadUnload PluginLoadUnload
#endif
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) {
if (!content::PluginService::GetInstance()->NPAPIPluginsSupported())
return;
browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
true);
base::FilePath extension_dir =
test_data_dir_.AppendASCII("uitest").AppendASCII("plugins");
ui_test_utils::NavigateToURL(browser(),
net::FilePathToFileURL(extension_dir.AppendASCII("test.html")));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
EXPECT_FALSE(result);
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
service->set_show_extensions_prompts(false);
const size_t size_before = service->extensions()->size();
const Extension* extension = LoadExtension(extension_dir);
ASSERT_TRUE(extension);
EXPECT_EQ(size_before + 1, service->extensions()->size());
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
#if defined(OS_CHROMEOS)
EXPECT_FALSE(result);
#else
EXPECT_TRUE(result);
#endif
EXPECT_EQ(size_before + 1, service->extensions()->size());
UnloadExtension(extension->id());
EXPECT_EQ(size_before, service->extensions()->size());
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
EXPECT_FALSE(result);
ASSERT_TRUE(LoadExtension(extension_dir));
EXPECT_EQ(size_before + 1, service->extensions()->size());
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
chrome::Reload(browser(), CURRENT_TAB);
observer.Wait();
}
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
#if defined(OS_CHROMEOS)
EXPECT_FALSE(result);
#else
EXPECT_TRUE(result);
#endif
}
#if defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)
#define MAYBE_PluginPrivate DISABLED_PluginPrivate
#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
#define MAYBE_PluginPrivate DISABLED_PluginPrivate
#elif defined(OS_WIN) && defined(ARCH_CPU_X86_64)
#define MAYBE_PluginPrivate DISABLED_PluginPrivate
#else
#define MAYBE_PluginPrivate PluginPrivate
#endif
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginPrivate) {
#if defined(OS_WIN) && defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
if (!content::PluginService::GetInstance()->NPAPIPluginsSupported())
return;
browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
true);
base::FilePath extension_dir =
test_data_dir_.AppendASCII("uitest").AppendASCII("plugins_private");
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
service->set_show_extensions_prompts(false);
const size_t size_before = service->extensions()->size();
const Extension* extension = LoadExtension(extension_dir);
ASSERT_TRUE(extension);
EXPECT_EQ(size_before + 1, service->extensions()->size());
ui_test_utils::NavigateToURL(browser(),
extension->GetResourceURL("test.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
#if defined(OS_CHROMEOS)
EXPECT_FALSE(result);
#else
EXPECT_TRUE(result);
#endif
browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
#if defined(OS_CHROMEOS)
EXPECT_FALSE(result);
#else
EXPECT_TRUE(result);
#endif
ui_test_utils::NavigateToURL(browser(),
net::FilePathToFileURL(extension_dir.AppendASCII("test.html")));
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "testPluginWorks()", &result));
EXPECT_FALSE(result);
}