This source file includes following definitions.
- SetUrlRequestMock
- SetUpCommandLine
- SetUpOnMainThread
- LoadAndWaitInWindow
- LoadAndWait
- GetURL
- NavigateAway
- TestPlugin
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- found_cookie
- WaitForPluginRequest
- OnResponseStarted
- GotCookie
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/common/shell_switches.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/url_request/url_request.h"
#include "ui/gfx/rect.h"
#if defined(OS_WIN)
#include "base/win/registry.h"
#endif
#if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
#define MAYBE(x) DISABLED_##x
#else
#define MAYBE(x) x
#endif
using base::ASCIIToUTF16;
namespace content {
namespace {
void SetUrlRequestMock(const base::FilePath& path) {
URLRequestMockHTTPJob::AddUrlHandler(path);
}
}
class PluginTest : public ContentBrowserTest {
protected:
PluginTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose_gc");
#if defined(OS_WIN)
const testing::TestInfo* const test_info =
testing::UnitTest::GetInstance()->current_test_info();
if (strcmp(test_info->name(), "MediaPlayerNew") == 0) {
base::win::RegKey regkey;
if (regkey.Open(HKEY_LOCAL_MACHINE,
L"Software\\Microsoft\\MediaPlayer\\ShimInclusionList",
KEY_WRITE) == ERROR_SUCCESS) {
regkey.CreateKey(L"BROWSER_TESTS.EXE", KEY_READ);
}
} else if (strcmp(test_info->name(), "FlashSecurity") == 0) {
command_line->AppendSwitchASCII(switches::kTestSandbox,
"security_tests.dll");
}
#elif defined(OS_MACOSX)
base::FilePath plugin_dir;
PathService::Get(base::DIR_MODULE, &plugin_dir);
plugin_dir = plugin_dir.AppendASCII("plugins");
command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
#endif
}
virtual void SetUpOnMainThread() OVERRIDE {
base::FilePath path = GetTestFilePath("", "");
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(&SetUrlRequestMock, path));
}
static void LoadAndWaitInWindow(Shell* window, const GURL& url) {
base::string16 expected_title(ASCIIToUTF16("OK"));
TitleWatcher title_watcher(window->web_contents(), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("plugin_not_found"));
NavigateToURL(window, url);
base::string16 title = title_watcher.WaitAndGetTitle();
if (title == ASCIIToUTF16("plugin_not_found")) {
const testing::TestInfo* const test_info =
testing::UnitTest::GetInstance()->current_test_info();
VLOG(0) << "PluginTest." << test_info->name()
<< " not running because plugin not installed.";
} else {
EXPECT_EQ(expected_title, title);
}
}
void LoadAndWait(const GURL& url) {
LoadAndWaitInWindow(shell(), url);
}
GURL GetURL(const char* filename) {
return GetTestUrl("npapi", filename);
}
void NavigateAway() {
GURL url = GetTestUrl("", "simple_page.html");
LoadAndWait(url);
}
void TestPlugin(const char* filename) {
base::FilePath path = GetTestFilePath("plugin", filename);
if (!base::PathExists(path)) {
const testing::TestInfo* const test_info =
testing::UnitTest::GetInstance()->current_test_info();
VLOG(0) << "PluginTest." << test_info->name()
<< " not running because test data wasn't found.";
return;
}
GURL url = GetTestUrl("plugin", filename);
LoadAndWait(url);
}
};
IN_PROC_BROWSER_TEST_F(PluginTest, UnloadNoCrash) {
LoadAndWait(GetURL("layout_test_plugin.html"));
NavigateAway();
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(SelfDeletePluginGetUrl)) {
LoadAndWait(GetURL("self_delete_plugin_geturl.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(SelfDeletePluginInvoke)) {
LoadAndWait(GetURL("self_delete_plugin_invoke.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NPObjectReleasedOnDestruction)) {
NavigateToURL(shell(), GetURL("npobject_released_on_destruction.html"));
NavigateAway();
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NPObjectSetException)) {
LoadAndWait(GetURL("npobject_set_exception.html"));
}
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PluginTest,
MAYBE(SelfDeletePluginInvokeInSynchronousMouseUp)) {
NavigateToURL(shell(), GetURL("execute_script_delete_in_mouse_up.html"));
base::string16 expected_title(ASCIIToUTF16("OK"));
TitleWatcher title_watcher(shell()->web_contents(), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
SimulateMouseClick(shell()->web_contents(), 0,
blink::WebMouseEvent::ButtonLeft);
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
}
#endif
#if defined(OS_MACOSX)
#define MAYBE_GetURLRequest404Response DISABLED_GetURLRequest404Response
#else
#define MAYBE_GetURLRequest404Response MAYBE(GetURLRequest404Response)
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE_GetURLRequest404Response) {
GURL url(URLRequestMockHTTPJob::GetMockUrl(
base::FilePath().AppendASCII("npapi").
AppendASCII("plugin_url_request_404.html")));
LoadAndWait(url);
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(SelfDeletePluginInvokeAlert)) {
shell()->LoadURL(GetURL("self_delete_plugin_invoke_alert.html"));
base::string16 expected_title(ASCIIToUTF16("OK"));
TitleWatcher title_watcher(shell()->web_contents(), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
WaitForAppModalDialog(shell());
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
}
#if !defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Arguments)) {
LoadAndWait(GetURL("arguments.html"));
}
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(ManyPlugins)) {
LoadAndWait(GetURL("many_plugins.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(GetURL)) {
LoadAndWait(GetURL("geturl.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(GetJavaScriptURL)) {
LoadAndWait(GetURL("get_javascript_url.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(GetJavaScriptURL2)) {
LoadAndWait(GetURL("get_javascript_url2.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, GetURLRedirectNotification) {
LoadAndWait(GetURL("geturl_redirect_notify.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NPObjectIdentity)) {
LoadAndWait(GetURL("npobject_identity.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NPObjectProxy)) {
LoadAndWait(GetURL("npobject_proxy.html"));
}
#if defined(OS_WIN) || defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_F(PluginTest,
MAYBE(SelfDeletePluginInvokeInSynchronousPaint)) {
LoadAndWait(GetURL("execute_script_delete_in_paint.html"));
}
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(ResizeDuringPaint)) {
LoadAndWait(GetURL("resize_during_paint.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(SelfDeletePluginInNewStream)) {
LoadAndWait(GetURL("self_delete_plugin_stream.html"));
}
#if !defined(NDEBUG)
IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_DeletePluginInDeallocate) {
LoadAndWait(GetURL("plugin_delete_in_deallocate.html"));
}
#endif
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(VerifyPluginWindowRect)) {
LoadAndWait(GetURL("verify_plugin_window_rect.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(CreateInstanceInPaint)) {
LoadAndWait(GetURL("create_instance_in_paint.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_AlertInWindowMessage) {
NavigateToURL(shell(), GetURL("alert_in_window_message.html"));
WaitForAppModalDialog(shell());
WaitForAppModalDialog(shell());
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(VerifyNPObjectLifetimeTest)) {
LoadAndWait(GetURL("npobject_lifetime_test.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NewFails)) {
LoadAndWait(GetURL("new_fails.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(SelfDeletePluginInNPNEvaluate)) {
LoadAndWait(GetURL("execute_script_delete_in_npn_evaluate.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest,
MAYBE(SelfDeleteCreatePluginInNPNEvaluate)) {
LoadAndWait(GetURL("npn_plugin_delete_create_in_evaluate.html"));
}
#endif
#if !defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(OpenPopupWindowWithPlugin)) {
LoadAndWait(GetURL("get_javascript_open_popup_with_plugin.html"));
}
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(PrivateDisabled)) {
LoadAndWait(GetURL("private.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(ScheduleTimer)) {
LoadAndWait(GetURL("schedule_timer.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(PluginThreadAsyncCall)) {
LoadAndWait(GetURL("plugin_thread_async_call.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, PluginSingleRangeRequest) {
LoadAndWait(GetURL("plugin_single_range_request.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(PrivateEnabled)) {
GURL url = GetURL("private.html");
url = GURL(url.spec() + "?private");
LoadAndWaitInWindow(CreateOffTheRecordBrowser(), url);
}
#if defined(OS_WIN) || defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(MultipleInstancesSyncCalls)) {
LoadAndWait(GetURL("multiple_instances_sync_calls.html"));
}
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(GetURLRequestFailWrite)) {
GURL url(URLRequestMockHTTPJob::GetMockUrl(
base::FilePath().AppendASCII("npapi").
AppendASCII("plugin_url_request_fail_write.html")));
LoadAndWait(url);
}
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(EnsureScriptingWorksInDestroy)) {
LoadAndWait(GetURL("ensure_scripting_works_in_destroy.html"));
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(NoHangIfInitCrashes)) {
HANDLE crash_event = CreateEvent(NULL, TRUE, FALSE, L"TestPluginCrashOnInit");
SetEvent(crash_event);
LoadAndWait(GetURL("no_hang_if_init_crashes.html"));
CloseHandle(crash_event);
}
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(PluginReferrerTest)) {
GURL url(URLRequestMockHTTPJob::GetMockUrl(
base::FilePath().AppendASCII("npapi").
AppendASCII("plugin_url_request_referrer_test.html")));
LoadAndWait(url);
}
#if defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_PluginConvertPointTest) {
gfx::Rect bounds(50, 50, 400, 400);
SetWindowBounds(shell()->window(), bounds);
NavigateToURL(shell(), GetURL("convert_point.html"));
base::string16 expected_title(ASCIIToUTF16("OK"));
TitleWatcher title_watcher(shell()->web_contents(), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
}
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Flash)) {
TestPlugin("flash.html");
}
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_FlashSecurity) {
TestPlugin("flash.html");
}
#endif
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Quicktime)) {
TestPlugin("quicktime.html");
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(MediaPlayerNew)) {
TestPlugin("wmp_new.html");
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Real)) {
TestPlugin("real.html");
}
#if (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) || \
(defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN))
#define MAYBE_FlashOctetStream DISABLED_FlashOctetStream
#else
#define MAYBE_FlashOctetStream FlashOctetStream
#endif
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE_FlashOctetStream) {
TestPlugin("flash-octet-stream.html");
}
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_FlashLayoutWhilePainting) {
#else
IN_PROC_BROWSER_TEST_F(PluginTest, FlashLayoutWhilePainting) {
#endif
TestPlugin("flash-layout-while-painting.html");
}
IN_PROC_BROWSER_TEST_F(PluginTest, DISABLED_Java) {
TestPlugin("Java.html");
}
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Silverlight)) {
TestPlugin("silverlight.html");
}
#endif
class TestResourceDispatcherHostDelegate
: public ResourceDispatcherHostDelegate {
public:
TestResourceDispatcherHostDelegate() : found_cookie_(false) {}
bool found_cookie() { return found_cookie_; }
void WaitForPluginRequest() {
if (found_cookie_)
return;
runner_ = new MessageLoopRunner;
runner_->Run();
}
private:
virtual void OnResponseStarted(
net::URLRequest* request,
ResourceContext* resource_context,
ResourceResponse* response,
IPC::Sender* sender) OVERRIDE {
if (!EndsWith(request->url().spec(),
"npapi/plugin_ref_target_page.html",
true)) {
return;
}
net::HttpRequestHeaders headers;
bool found_cookie = false;
if (request->GetFullRequestHeaders(&headers) &&
headers.ToString().find("Cookie: blah") != std::string::npos) {
found_cookie = true;
}
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&TestResourceDispatcherHostDelegate::GotCookie,
base::Unretained(this), found_cookie));
}
void GotCookie(bool found_cookie) {
found_cookie_ = found_cookie;
if (runner_)
runner_->QuitClosure().Run();
}
scoped_refptr<MessageLoopRunner> runner_;
bool found_cookie_;
DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate);
};
IN_PROC_BROWSER_TEST_F(PluginTest, MAYBE(Cookies)) {
NavigateToURL(CreateBrowser(), GURL("about:blank"));
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url(embedded_test_server()->GetURL("/npapi/cookies.html"));
TestResourceDispatcherHostDelegate test_delegate;
ResourceDispatcherHostDelegate* old_delegate =
ResourceDispatcherHostImpl::Get()->delegate();
ResourceDispatcherHostImpl::Get()->SetDelegate(&test_delegate);
LoadAndWait(url);
test_delegate.WaitForPluginRequest();
ASSERT_TRUE(test_delegate.found_cookie());
ResourceDispatcherHostImpl::Get()->SetDelegate(old_delegate);
}
}