1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/file_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "net/base/cookie_monster.h"
#include "net/base/net_util.h"
#include "net/http/http_cache.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_unittest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/test_shell.h"
#include "webkit/tools/test_shell/test_shell_test.h"
static const char kTestCompleteCookie[] = "status";
static const char kTestCompleteSuccess[] = "OK";
// Provides functionality for creating plugin tests.
class PluginTest : public TestShellTest {
// A basic URLRequestContext that only provides an in-memory cookie store.
class RequestContext : public TestURLRequestContext {
public:
RequestContext() {
cookie_store_.reset(new net::CookieMonster());
}
};
public:
PluginTest() {}
~PluginTest() {}
void NavigateToURL(const std::wstring& test_url) {
ASSERT_TRUE(file_util::PathExists(test_url));
test_url_ = net::FilePathToFileURL(test_url);
test_shell_->LoadURL(test_url.c_str());
}
// Waits for the test case to finish.
// ASSERTS if there are test failures.
void WaitForFinish(const std::string &name, const std::string &id) {
test_shell_->WaitTestFinished();
std::string cookies =
request_context_->cookie_store()->GetCookies(test_url_);
EXPECT_FALSE(cookies.empty());
std::string cookieName = name;
cookieName.append(".");
cookieName.append(id);
cookieName.append(".");
cookieName.append(kTestCompleteCookie);
cookieName.append("=");
std::string::size_type idx = cookies.find(cookieName);
std::string cookie;
if (idx != std::string::npos) {
cookies.erase(0, idx + cookieName.length());
cookie = cookies.substr(0, cookies.find(";"));
}
EXPECT_EQ(kTestCompleteSuccess, cookie);
}
protected:
virtual void SetUp() {
// We need to copy our test-plugin into the plugins directory so that
// the test can load it.
std::wstring current_directory;
PathService::Get(base::DIR_EXE, ¤t_directory);
std::wstring plugin_src = current_directory + L"\\npapi_test_plugin.dll";
ASSERT_TRUE(file_util::PathExists(plugin_src));
plugin_dll_path_ = current_directory + L"\\plugins";
::CreateDirectory(plugin_dll_path_.c_str(), NULL);
plugin_dll_path_ += L"\\npapi_test_plugin.dll";
ASSERT_TRUE(CopyFile(plugin_src.c_str(), plugin_dll_path_.c_str(), FALSE));
// The plugin list has to be refreshed to ensure that the npapi_test_plugin
// is loaded by webkit.
std::vector<WebPluginInfo> plugin_list;
bool refresh = true;
NPAPI::PluginList::Singleton()->GetPlugins(refresh, &plugin_list);
TestShellTest::SetUp();
plugin_data_dir_ = data_dir_;
file_util::AppendToPath(&plugin_data_dir_, L"plugin_tests");
ASSERT_TRUE(file_util::PathExists(plugin_data_dir_));
}
virtual void TearDown() {
TestShellTest::TearDown();
// TODO(iyengar) The DeleteFile call fails in some cases as the plugin is
// still in use. Needs more investigation.
::DeleteFile(plugin_dll_path_.c_str());
}
std::wstring plugin_data_dir_;
std::wstring plugin_dll_path_;
RequestContext* request_context_;
GURL test_url_;
};
TEST_F(PluginTest, DISABLED_VerifyPluginWindowRect) {
std::wstring test_url = GetTestURL(plugin_data_dir_,
L"verify_plugin_window_rect.html");
NavigateToURL(test_url);
WaitForFinish("checkwindowrect", "1");
}
|