OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 const char kPluginsDir[] = "plugins"; | 35 const char kPluginsDir[] = "plugins"; |
36 | 36 |
37 } | 37 } |
38 | 38 |
39 // Ignore these until 64-bit plugin build is fixed. http://crbug.com/18337 | 39 // Ignore these until 64-bit plugin build is fixed. http://crbug.com/18337 |
40 #if !defined(ARCH_CPU_64_BITS) | 40 #if !defined(ARCH_CPU_64_BITS) |
41 // Provides functionality for creating plugin tests. | 41 // Provides functionality for creating plugin tests. |
42 class PluginTest : public TestShellTest { | 42 class PluginTest : public TestShellTest { |
43 public: | 43 public: |
44 PluginTest() { | 44 PluginTest() { |
45 FilePath executable_directory; | 45 base::FilePath executable_directory; |
46 PathService::Get(base::DIR_EXE, &executable_directory); | 46 PathService::Get(base::DIR_EXE, &executable_directory); |
47 plugin_src_ = executable_directory.AppendASCII(TEST_PLUGIN_NAME); | 47 plugin_src_ = executable_directory.AppendASCII(TEST_PLUGIN_NAME); |
48 CHECK(file_util::PathExists(plugin_src_)); | 48 CHECK(file_util::PathExists(plugin_src_)); |
49 | 49 |
50 plugin_file_path_ = executable_directory.AppendASCII(kPluginsDir); | 50 plugin_file_path_ = executable_directory.AppendASCII(kPluginsDir); |
51 file_util::CreateDirectory(plugin_file_path_); | 51 file_util::CreateDirectory(plugin_file_path_); |
52 | 52 |
53 plugin_file_path_ = plugin_file_path_.AppendASCII(TEST_PLUGIN_NAME); | 53 plugin_file_path_ = plugin_file_path_.AppendASCII(TEST_PLUGIN_NAME); |
54 } | 54 } |
55 | 55 |
56 void CopyTestPlugin() { | 56 void CopyTestPlugin() { |
57 // On Linux, we need to delete before copying because if the plugin is a | 57 // On Linux, we need to delete before copying because if the plugin is a |
58 // hard link, the copy will fail. | 58 // hard link, the copy will fail. |
59 DeleteTestPlugin(); | 59 DeleteTestPlugin(); |
60 ASSERT_TRUE(file_util::CopyDirectory(plugin_src_, plugin_file_path_, true)); | 60 ASSERT_TRUE(file_util::CopyDirectory(plugin_src_, plugin_file_path_, true)); |
61 } | 61 } |
62 | 62 |
63 void DeleteTestPlugin() { | 63 void DeleteTestPlugin() { |
64 file_util::Delete(plugin_file_path_, true); | 64 file_util::Delete(plugin_file_path_, true); |
65 } | 65 } |
66 | 66 |
67 virtual void SetUp() { | 67 virtual void SetUp() { |
68 CopyTestPlugin(); | 68 CopyTestPlugin(); |
69 TestShellTest::SetUp(); | 69 TestShellTest::SetUp(); |
70 } | 70 } |
71 | 71 |
72 FilePath plugin_src_; | 72 base::FilePath plugin_src_; |
73 FilePath plugin_file_path_; | 73 base::FilePath plugin_file_path_; |
74 }; | 74 }; |
75 | 75 |
76 // Tests navigator.plugins.refresh() works. | 76 // Tests navigator.plugins.refresh() works. |
77 TEST_F(PluginTest, Refresh) { | 77 TEST_F(PluginTest, Refresh) { |
78 std::string html = "\ | 78 std::string html = "\ |
79 <div id='result'>Test running....</div>\ | 79 <div id='result'>Test running....</div>\ |
80 <script>\ | 80 <script>\ |
81 function check() {\ | 81 function check() {\ |
82 var l = navigator.plugins.length;\ | 82 var l = navigator.plugins.length;\ |
83 var result = document.getElementById('result');\ | 83 var result = document.getElementById('result');\ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 test_shell_->webView()->mainFrame()->executeScript(refresh); | 120 test_shell_->webView()->mainFrame()->executeScript(refresh); |
121 test_shell_->webView()->mainFrame()->executeScript(call_check); | 121 test_shell_->webView()->mainFrame()->executeScript(call_check); |
122 text = test_shell_->webView()->mainFrame()->contentAsText(10000).utf8(); | 122 text = test_shell_->webView()->mainFrame()->contentAsText(10000).utf8(); |
123 ASSERT_EQ(text, "DONE"); | 123 ASSERT_EQ(text, "DONE"); |
124 } | 124 } |
125 | 125 |
126 // Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we | 126 // Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we |
127 // don't crash. | 127 // don't crash. |
128 TEST_F(PluginTest, DeleteFrameDuringEvent) { | 128 TEST_F(PluginTest, DeleteFrameDuringEvent) { |
129 FilePath test_html = data_dir_; | 129 base::FilePath test_html = data_dir_; |
130 test_html = test_html.AppendASCII(kPluginsDir); | 130 test_html = test_html.AppendASCII(kPluginsDir); |
131 test_html = test_html.AppendASCII("delete_frame.html"); | 131 test_html = test_html.AppendASCII("delete_frame.html"); |
132 test_shell_->LoadFile(test_html); | 132 test_shell_->LoadFile(test_html); |
133 test_shell_->WaitTestFinished(); | 133 test_shell_->WaitTestFinished(); |
134 | 134 |
135 WebKit::WebMouseEvent input; | 135 WebKit::WebMouseEvent input; |
136 input.button = WebKit::WebMouseEvent::ButtonLeft; | 136 input.button = WebKit::WebMouseEvent::ButtonLeft; |
137 input.x = 50; | 137 input.x = 50; |
138 input.y = 50; | 138 input.y = 50; |
139 input.type = WebKit::WebInputEvent::MouseUp; | 139 input.type = WebKit::WebInputEvent::MouseUp; |
140 test_shell_->webView()->handleInputEvent(input); | 140 test_shell_->webView()->handleInputEvent(input); |
141 | 141 |
142 // No crash means we passed. | 142 // No crash means we passed. |
143 } | 143 } |
144 | 144 |
145 // Tests that a forced reload of the plugin will not crash. | 145 // Tests that a forced reload of the plugin will not crash. |
146 TEST_F(PluginTest, ForceReload) { | 146 TEST_F(PluginTest, ForceReload) { |
147 FilePath test_html = data_dir_; | 147 base::FilePath test_html = data_dir_; |
148 test_html = test_html.AppendASCII(kPluginsDir); | 148 test_html = test_html.AppendASCII(kPluginsDir); |
149 test_html = test_html.AppendASCII("force_reload.html"); | 149 test_html = test_html.AppendASCII("force_reload.html"); |
150 test_shell_->LoadFile(test_html); | 150 test_shell_->LoadFile(test_html); |
151 test_shell_->WaitTestFinished(); | 151 test_shell_->WaitTestFinished(); |
152 | 152 |
153 // No crash means we passed. | 153 // No crash means we passed. |
154 } | 154 } |
155 | 155 |
156 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
157 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { | 157 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { |
158 HWND* plugin_hwnd = reinterpret_cast<HWND*>(lparam); | 158 HWND* plugin_hwnd = reinterpret_cast<HWND*>(lparam); |
159 if (*plugin_hwnd) { | 159 if (*plugin_hwnd) { |
160 // More than one child window found, unexpected. | 160 // More than one child window found, unexpected. |
161 plugin_hwnd = NULL; | 161 plugin_hwnd = NULL; |
162 return FALSE; | 162 return FALSE; |
163 } | 163 } |
164 *plugin_hwnd = hwnd; | 164 *plugin_hwnd = hwnd; |
165 return TRUE; | 165 return TRUE; |
166 } | 166 } |
167 | 167 |
168 // Tests that hiding/showing the parent frame hides/shows the plugin. | 168 // Tests that hiding/showing the parent frame hides/shows the plugin. |
169 // Fails for WIN. http://crbug.com/111601 | 169 // Fails for WIN. http://crbug.com/111601 |
170 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
171 #define MAYBE_PluginVisibilty DISABLED_PluginVisibilty | 171 #define MAYBE_PluginVisibilty DISABLED_PluginVisibilty |
172 #else | 172 #else |
173 #define MAYBE_PluginVisibilty PluginVisibilty | 173 #define MAYBE_PluginVisibilty PluginVisibilty |
174 #endif | 174 #endif |
175 | 175 |
176 TEST_F(PluginTest, MAYBE_PluginVisibilty) { | 176 TEST_F(PluginTest, MAYBE_PluginVisibilty) { |
177 FilePath test_html = data_dir_; | 177 base::FilePath test_html = data_dir_; |
178 test_html = test_html.AppendASCII(kPluginsDir); | 178 test_html = test_html.AppendASCII(kPluginsDir); |
179 test_html = test_html.AppendASCII("plugin_visibility.html"); | 179 test_html = test_html.AppendASCII("plugin_visibility.html"); |
180 test_shell_->LoadFile(test_html); | 180 test_shell_->LoadFile(test_html); |
181 test_shell_->WaitTestFinished(); | 181 test_shell_->WaitTestFinished(); |
182 | 182 |
183 WebFrame* main_frame = test_shell_->webView()->mainFrame(); | 183 WebFrame* main_frame = test_shell_->webView()->mainFrame(); |
184 HWND frame_hwnd = test_shell_->webViewWnd(); | 184 HWND frame_hwnd = test_shell_->webViewWnd(); |
185 HWND plugin_hwnd = NULL; | 185 HWND plugin_hwnd = NULL; |
186 EnumChildWindows(frame_hwnd, EnumChildProc, | 186 EnumChildWindows(frame_hwnd, EnumChildProc, |
187 reinterpret_cast<LPARAM>(&plugin_hwnd)); | 187 reinterpret_cast<LPARAM>(&plugin_hwnd)); |
188 ASSERT_TRUE(plugin_hwnd != NULL); | 188 ASSERT_TRUE(plugin_hwnd != NULL); |
189 ASSERT_FALSE(IsWindowVisible(plugin_hwnd)); | 189 ASSERT_FALSE(IsWindowVisible(plugin_hwnd)); |
190 | 190 |
191 main_frame->executeScript(WebString::fromUTF8("showPlugin(true)")); | 191 main_frame->executeScript(WebString::fromUTF8("showPlugin(true)")); |
192 ASSERT_TRUE(IsWindowVisible(plugin_hwnd)); | 192 ASSERT_TRUE(IsWindowVisible(plugin_hwnd)); |
193 | 193 |
194 main_frame->executeScript(WebString::fromUTF8("showFrame(false)")); | 194 main_frame->executeScript(WebString::fromUTF8("showFrame(false)")); |
195 ASSERT_FALSE(IsWindowVisible(plugin_hwnd)); | 195 ASSERT_FALSE(IsWindowVisible(plugin_hwnd)); |
196 | 196 |
197 main_frame->executeScript(WebString::fromUTF8("showFrame(true)")); | 197 main_frame->executeScript(WebString::fromUTF8("showFrame(true)")); |
198 ASSERT_TRUE(IsWindowVisible(plugin_hwnd)); | 198 ASSERT_TRUE(IsWindowVisible(plugin_hwnd)); |
199 } | 199 } |
200 #endif | 200 #endif |
201 #endif //!ARCH_CPU_64_BITS | 201 #endif //!ARCH_CPU_64_BITS |
OLD | NEW |