| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 14 #include "webkit/glue/webframe.h" | 15 #include "webkit/glue/webframe.h" |
| 15 #include "webkit/glue/webview.h" | 16 #include "webkit/glue/webview.h" |
| 16 #include "webkit/tools/test_shell/test_shell.h" | 17 #include "webkit/tools/test_shell/test_shell.h" |
| 17 #include "webkit/tools/test_shell/test_shell_test.h" | 18 #include "webkit/tools/test_shell/test_shell_test.h" |
| 18 | 19 |
| 19 using WebKit::WebScriptSource; | 20 using WebKit::WebScriptSource; |
| 20 using WebKit::WebString; | 21 using WebKit::WebString; |
| 21 | 22 |
| 23 #if defined(OS_WIN) |
| 24 #define TEST_PLUGIN_NAME "npapi_test_plugin.dll" |
| 25 #elif defined(OS_MACOSX) |
| 26 #define TEST_PLUGIN_NAME "npapi_test_plugin.bundle" |
| 27 #elif defined(OS_LINUX) |
| 28 #define TEST_PLUGIN_NAME "npapi_test_plugin.so" |
| 29 #endif |
| 30 |
| 22 // Provides functionality for creating plugin tests. | 31 // Provides functionality for creating plugin tests. |
| 23 class PluginTest : public TestShellTest { | 32 class PluginTest : public TestShellTest { |
| 24 public: | 33 public: |
| 25 PluginTest() { | 34 PluginTest() { |
| 26 std::wstring current_directory; | 35 FilePath executable_directory; |
| 27 PathService::Get(base::DIR_EXE, ¤t_directory); | 36 PathService::Get(base::DIR_EXE, &executable_directory); |
| 28 plugin_src_ = current_directory + L"\\npapi_test_plugin.dll"; | 37 plugin_src_ = executable_directory.AppendASCII(TEST_PLUGIN_NAME); |
| 29 CHECK(file_util::PathExists(plugin_src_)); | 38 CHECK(file_util::PathExists(plugin_src_)); |
| 30 | 39 |
| 31 plugin_file_path_ = current_directory + L"\\plugins"; | 40 plugin_file_path_ = executable_directory.AppendASCII("plugins"); |
| 32 ::CreateDirectory(plugin_file_path_.c_str(), NULL); | 41 file_util::CreateDirectory(plugin_file_path_); |
| 33 | 42 |
| 34 plugin_file_path_ += L"\\npapi_test_plugin.dll"; | 43 plugin_file_path_ = plugin_file_path_.AppendASCII(TEST_PLUGIN_NAME); |
| 35 } | 44 } |
| 36 | 45 |
| 37 void CopyTestPlugin() { | 46 void CopyTestPlugin() { |
| 38 ASSERT_TRUE(CopyFile(plugin_src_.c_str(), plugin_file_path_.c_str(), FALSE))
; | 47 ASSERT_TRUE(file_util::CopyDirectory(plugin_src_, plugin_file_path_, true)); |
| 39 } | 48 } |
| 40 | 49 |
| 41 void DeleteTestPlugin() { | 50 void DeleteTestPlugin() { |
| 42 ::DeleteFile(plugin_file_path_.c_str()); | 51 file_util::Delete(plugin_file_path_, true); |
| 43 } | 52 } |
| 44 | 53 |
| 45 std::wstring plugin_src_; | 54 FilePath plugin_src_; |
| 46 std::wstring plugin_file_path_; | 55 FilePath plugin_file_path_; |
| 47 }; | 56 }; |
| 48 | 57 |
| 49 // Tests navigator.plugins.refresh() works. | 58 // Tests navigator.plugins.refresh() works. |
| 50 TEST_F(PluginTest, Refresh) { | 59 TEST_F(PluginTest, Refresh) { |
| 51 std::string html = "\ | 60 std::string html = "\ |
| 52 <div id='result'>Test running....</div>\ | 61 <div id='result'>Test running....</div>\ |
| 53 <script>\ | 62 <script>\ |
| 54 function check() {\ | 63 function check() {\ |
| 55 var l = navigator.plugins.length;\ | 64 var l = navigator.plugins.length;\ |
| 56 var result = document.getElementById('result');\ | 65 var result = document.getElementById('result');\ |
| 57 for(var i = 0; i < l; i++) {\ | 66 for(var i = 0; i < l; i++) {\ |
| 58 if (navigator.plugins[i].filename == 'npapi_test_plugin.dll') {\ | 67 if (navigator.plugins[i].filename == '" TEST_PLUGIN_NAME "') {\ |
| 59 result.innerHTML = 'DONE';\ | 68 result.innerHTML = 'DONE';\ |
| 60 break;\ | 69 break;\ |
| 61 }\ | 70 }\ |
| 62 }\ | 71 }\ |
| 63 \ | 72 \ |
| 64 if (result.innerHTML != 'DONE')\ | 73 if (result.innerHTML != 'DONE')\ |
| 65 result.innerHTML = 'FAIL';\ | 74 result.innerHTML = 'FAIL';\ |
| 66 }\ | 75 }\ |
| 67 </script>\ | 76 </script>\ |
| 68 "; | 77 "; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 CopyTestPlugin(); | 100 CopyTestPlugin(); |
| 92 | 101 |
| 93 test_shell_->webView()->GetMainFrame()->ExecuteScript(refresh); | 102 test_shell_->webView()->GetMainFrame()->ExecuteScript(refresh); |
| 94 test_shell_->webView()->GetMainFrame()->ExecuteScript(call_check); | 103 test_shell_->webView()->GetMainFrame()->ExecuteScript(call_check); |
| 95 test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text); | 104 test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text); |
| 96 ASSERT_EQ(text, L"DONE"); | 105 ASSERT_EQ(text, L"DONE"); |
| 97 | 106 |
| 98 DeleteTestPlugin(); | 107 DeleteTestPlugin(); |
| 99 } | 108 } |
| 100 | 109 |
| 110 #if defined(OS_WIN) |
| 111 // TODO(port): Reenable on mac and linux once they have working default plugins. |
| 101 TEST_F(PluginTest, DefaultPluginLoadTest) { | 112 TEST_F(PluginTest, DefaultPluginLoadTest) { |
| 102 std::string html = "\ | 113 std::string html = "\ |
| 103 <div id='result'>Test running....</div>\ | 114 <div id='result'>Test running....</div>\ |
| 104 <script>\ | 115 <script>\ |
| 105 function onSuccess() {\ | 116 function onSuccess() {\ |
| 106 var result = document.getElementById('result');\ | 117 var result = document.getElementById('result');\ |
| 107 result.innerHTML = 'DONE';\ | 118 result.innerHTML = 'DONE';\ |
| 108 }\ | 119 }\ |
| 109 </script>\ | 120 </script>\ |
| 110 <DIV ID=PluginDiv>\ | 121 <DIV ID=PluginDiv>\ |
| 111 <object classid=\"clsid:9E8BC6CE-AF35-400c-ABF6-A3F746A1871D\">\ | 122 <object classid=\"clsid:9E8BC6CE-AF35-400c-ABF6-A3F746A1871D\">\ |
| 112 <embed type=\"application/chromium-test-default-plugin\"\ | 123 <embed type=\"application/chromium-test-default-plugin\"\ |
| 113 mode=\"np_embed\"\ | 124 mode=\"np_embed\"\ |
| 114 ></embed>\ | 125 ></embed>\ |
| 115 </object>\ | 126 </object>\ |
| 116 </DIV>\ | 127 </DIV>\ |
| 117 "; | 128 "; |
| 118 | 129 |
| 119 test_shell_->webView()->GetMainFrame()->LoadHTMLString( | 130 test_shell_->webView()->GetMainFrame()->LoadHTMLString( |
| 120 html, GURL("about:blank")); | 131 html, GURL("about:blank")); |
| 121 test_shell_->WaitTestFinished(); | 132 test_shell_->WaitTestFinished(); |
| 122 | 133 |
| 123 std::wstring text; | 134 std::wstring text; |
| 124 test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text); | 135 test_shell_->webView()->GetMainFrame()->GetContentAsPlainText(10000, &text); |
| 125 | 136 |
| 126 ASSERT_EQ(true, StartsWith(text, L"DONE", true)); | 137 ASSERT_EQ(true, StartsWith(text, L"DONE", true)); |
| 127 } | 138 } |
| 139 #endif |
| 128 | 140 |
| 129 // Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we | 141 // Tests that if a frame is deleted as a result of calling NPP_HandleEvent, we |
| 130 // don't crash. | 142 // don't crash. |
| 131 TEST_F(PluginTest, DeleteFrameDuringEvent) { | 143 TEST_F(PluginTest, DeleteFrameDuringEvent) { |
| 132 FilePath test_html = data_dir_; | 144 FilePath test_html = data_dir_; |
| 133 test_html = test_html.AppendASCII("plugins"); | 145 test_html = test_html.AppendASCII("plugins"); |
| 134 test_html = test_html.AppendASCII("delete_frame.html"); | 146 test_html = test_html.AppendASCII("delete_frame.html"); |
| 135 test_shell_->LoadURL(test_html.ToWStringHack().c_str()); | 147 test_shell_->LoadURL(test_html.ToWStringHack().c_str()); |
| 136 test_shell_->WaitTestFinished(); | 148 test_shell_->WaitTestFinished(); |
| 137 | 149 |
| 138 WebKit::WebMouseEvent input; | 150 WebKit::WebMouseEvent input; |
| 139 input.button = WebKit::WebMouseEvent::ButtonLeft; | 151 input.button = WebKit::WebMouseEvent::ButtonLeft; |
| 140 input.x = 50; | 152 input.x = 50; |
| 141 input.y = 50; | 153 input.y = 50; |
| 142 input.type = WebKit::WebInputEvent::MouseUp; | 154 input.type = WebKit::WebInputEvent::MouseUp; |
| 143 test_shell_->webView()->HandleInputEvent(&input); | 155 test_shell_->webView()->HandleInputEvent(&input); |
| 144 | 156 |
| 145 // No crash means we passed. | 157 // No crash means we passed. |
| 146 } | 158 } |
| OLD | NEW |