diff options
-rw-r--r-- | chrome/test/data/npapi/plugin_url_request_404.html | 26 | ||||
-rw-r--r-- | chrome/test/interactive_ui/npapi_interactive_test.cc | 21 | ||||
-rw-r--r-- | webkit/glue/plugins/test/plugin_client.cc | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/test/plugin_geturl_test.cc | 70 | ||||
-rw-r--r-- | webkit/glue/plugins/test/plugin_geturl_test.h | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/test/plugin_test.cc | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/test/plugin_test.h | 7 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.cc | 23 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.h | 1 |
9 files changed, 145 insertions, 13 deletions
diff --git a/chrome/test/data/npapi/plugin_url_request_404.html b/chrome/test/data/npapi/plugin_url_request_404.html new file mode 100644 index 0000000..deb200e --- /dev/null +++ b/chrome/test/data/npapi/plugin_url_request_404.html @@ -0,0 +1,26 @@ +<html> + +<head> +<script src="npapi.js"></script> +</head> + + +<body> +<div id="statusPanel" style="border: 1px solid red; width: 100%"> +Test running.... +</div> + + +GetURL 404 Response Test<p> +This test fetches a URL which results in the server sending back a 404 +response in the header. The plugin should expect a valid response followed +by a failure. + +<embed type="application/vnd.npapi-test" + page_not_found_url="http://mock.http/page404.html" + name="geturl_404_response" + id="1" + mode="np_embed" +> +</body> +</html> diff --git a/chrome/test/interactive_ui/npapi_interactive_test.cc b/chrome/test/interactive_ui/npapi_interactive_test.cc index 24aa5d1..49271a6 100644 --- a/chrome/test/interactive_ui/npapi_interactive_test.cc +++ b/chrome/test/interactive_ui/npapi_interactive_test.cc @@ -32,8 +32,10 @@ // #include "base/file_util.h" +#include "chrome/browser/net/url_request_mock_http_job.h" #include "chrome/common/chrome_paths.h" #include "chrome/test/automation/tab_proxy.h" +#include "chrome/test/automation/window_proxy.h" #include "chrome/test/ui/npapi_test_helper.h" #include "net/base/net_util.h" @@ -76,3 +78,22 @@ TEST_F(NPAPIVisiblePluginTester, SelfDeletePluginInvokeInSynchronousMouseMove) { kShortWaitTimeout); } } + +TEST_F(NPAPIVisiblePluginTester, GetURLRequest404Response) { + if (UITest::in_process_renderer()) + return; + + GURL url(URLRequestMockHTTPJob::GetMockUrl( + L"npapi/plugin_url_request_404.html")); + + NavigateToURL(url); + + // Wait for the alert dialog and then close it. + automation()->WaitForAppModalDialog(action_max_timeout_ms()); + scoped_refptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get()); + ASSERT_TRUE(window->SimulateOSKeyPress(VK_ESCAPE, 0)); + + WaitForFinish("geturl_404_response", "1", url, kTestCompleteCookie, + kTestCompleteSuccess, kShortWaitTimeout); +} diff --git a/webkit/glue/plugins/test/plugin_client.cc b/webkit/glue/plugins/test/plugin_client.cc index bcad2a8..2361805 100644 --- a/webkit/glue/plugins/test/plugin_client.cc +++ b/webkit/glue/plugins/test/plugin_client.cc @@ -99,7 +99,7 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, if (test_name == "arguments") { new_test = new NPAPIClient::PluginArgumentsTest(instance, NPAPIClient::PluginClient::HostFunctions()); - } else if (test_name == "geturl") { + } else if (test_name == "geturl" || test_name == "geturl_404_response") { new_test = new NPAPIClient::PluginGetURLTest(instance, NPAPIClient::PluginClient::HostFunctions()); } else if (test_name == "npobject_proxy") { diff --git a/webkit/glue/plugins/test/plugin_geturl_test.cc b/webkit/glue/plugins/test/plugin_geturl_test.cc index d584ae3..1a9e440 100644 --- a/webkit/glue/plugins/test/plugin_geturl_test.cc +++ b/webkit/glue/plugins/test/plugin_geturl_test.cc @@ -34,7 +34,21 @@ PluginGetURLTest::PluginGetURLTest(NPP id, NPNetscapeFuncs *host_functions) : PluginTest(id, host_functions), tests_started_(false), tests_in_progress_(0), - test_file_(NULL) { + test_file_(NULL), + expect_404_response_(false), + npn_evaluate_context_(false) { +} + +NPError PluginGetURLTest::New(uint16 mode, int16 argc, const char* argn[], + const char* argv[], NPSavedData* saved) { + const char* page_not_found_url = GetArgValue("page_not_found_url", argc, + argn, argv); + if (page_not_found_url) { + page_not_found_url_ = page_not_found_url; + expect_404_response_ = true; + } + + return PluginTest::New(mode, argc, argn, argv, saved); } NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) { @@ -43,6 +57,11 @@ NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) { tests_in_progress_++; + if (expect_404_response_) { + HostFunctions()->geturl(id(), page_not_found_url_.c_str(), NULL); + return NPERR_NO_ERROR; + } + std::string url = SELF_URL; HostFunctions()->geturlnotify(id(), url.c_str(), NULL, reinterpret_cast<void*>(SELF_URL_STREAM_ID)); @@ -60,10 +79,37 @@ NPError PluginGetURLTest::NewStream(NPMIMEType type, NPStream* stream, if (stream == NULL) SetError("NewStream got null stream"); + if (test_completed()) { + return PluginTest::NewStream(type, stream, seekable, stype); + } + COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), cast_validity_check); + + if (expect_404_response_) { + NPObject *window_obj = NULL; + HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); + if (!window_obj) { + SetError("Failed to get NPObject for plugin instance2"); + SignalTestCompleted(); + return NPERR_NO_ERROR; + } + + std::string script = "javascript:alert('Hi there from plugin');"; + NPString script_string; + script_string.UTF8Characters = script.c_str(); + script_string.UTF8Length = static_cast<unsigned int>(script.length()); + NPVariant result_var; + + npn_evaluate_context_ = true; + HostFunctions()->evaluate(id(), window_obj, &script_string, &result_var); + npn_evaluate_context_ = false; + return NPERR_NO_ERROR; + } + unsigned long stream_id = reinterpret_cast<unsigned long>( stream->notifyData); + switch (stream_id) { case SELF_URL_STREAM_ID: break; @@ -94,6 +140,10 @@ NPError PluginGetURLTest::NewStream(NPMIMEType type, NPStream* stream, } int32 PluginGetURLTest::WriteReady(NPStream *stream) { + if (test_completed()) { + return PluginTest::WriteReady(stream); + } + COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), cast_validity_check); unsigned long stream_id = reinterpret_cast<unsigned long>( @@ -106,6 +156,10 @@ int32 PluginGetURLTest::WriteReady(NPStream *stream) { int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, void *buffer) { + if (test_completed()) { + return PluginTest::Write(stream, offset, len, buffer); + } + if (stream == NULL) SetError("Write got null stream"); if (len < 0 || len > STREAM_CHUNK) @@ -144,11 +198,25 @@ int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) { + if (test_completed()) { + return PluginTest::DestroyStream(stream, reason); + } + if (stream == NULL) SetError("NewStream got null stream"); COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), cast_validity_check); + + if (expect_404_response_) { + if (npn_evaluate_context_) { + SetError("Received destroyStream in the context of NPN_Evaluate."); + } + + SignalTestCompleted(); + return NPERR_NO_ERROR; + } + unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData); switch (stream_id) { diff --git a/webkit/glue/plugins/test/plugin_geturl_test.h b/webkit/glue/plugins/test/plugin_geturl_test.h index 7aaa3b8..1ff443b 100644 --- a/webkit/glue/plugins/test/plugin_geturl_test.h +++ b/webkit/glue/plugins/test/plugin_geturl_test.h @@ -25,6 +25,8 @@ class PluginGetURLTest : public PluginTest { // // NPAPI functions // + virtual NPError New(uint16 mode, int16 argc, const char* argn[], + const char* argv[], NPSavedData* saved); virtual NPError SetWindow(NPWindow* pNPWindow); virtual NPError NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); @@ -40,6 +42,10 @@ class PluginGetURLTest : public PluginTest { int tests_in_progress_; std::string self_url_; FILE* test_file_; + bool expect_404_response_; + // This flag is set to true in the context of the NPN_Evaluate call. + bool npn_evaluate_context_; + std::string page_not_found_url_; }; } // namespace NPAPIClient diff --git a/webkit/glue/plugins/test/plugin_test.cc b/webkit/glue/plugins/test/plugin_test.cc index bd3d552..c838094 100644 --- a/webkit/glue/plugins/test/plugin_test.cc +++ b/webkit/glue/plugins/test/plugin_test.cc @@ -13,6 +13,7 @@ PluginTest::PluginTest(NPP id, NPNetscapeFuncs *host_functions) { id_ = id; id_->pdata = this; host_functions_ = host_functions; + test_completed_ = false; } NPError PluginTest::New(uint16 mode, int16 argc, const char* argn[], @@ -59,6 +60,7 @@ std::string URLEncode(const std::string &sIn) { } void PluginTest::SignalTestCompleted() { + test_completed_ = true; // To signal test completion, we expect a couple of // javascript functions to be defined in the webpage // which hosts this plugin: diff --git a/webkit/glue/plugins/test/plugin_test.h b/webkit/glue/plugins/test/plugin_test.h index 5914fef..ff0c2cf 100644 --- a/webkit/glue/plugins/test/plugin_test.h +++ b/webkit/glue/plugins/test/plugin_test.h @@ -110,15 +110,16 @@ class PluginTest { // The NPP Identifier for this plugin instance. NPP id() { return id_; } - std::string test_id() { return test_id_; } - std::string test_name() { return test_name_; } - + std::string test_id() const { return test_id_; } + std::string test_name() const { return test_name_; } + bool test_completed() const { return test_completed_; } private: NPP id_; NPNetscapeFuncs * host_functions_; std::string test_name_; std::string test_id_; std::string test_status_; + bool test_completed_; }; } // namespace NPAPIClient diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index d10cf6c..ce7e234 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -769,11 +769,9 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, // The plugin instance could be in the process of deletion here. // Verify if the WebPluginResourceClient instance still exists before // use. - WebPluginResourceClient* resource_client = GetClientFromLoader(loader); - if (resource_client) { - loader->cancel(); - resource_client->DidFail(); - RemoveClient(loader); + ClientInfo* client_info = GetClientInfoFromLoader(loader); + if (client_info) { + client_info->pending_failure_notification = true; } } } @@ -942,6 +940,7 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id, info.request.setRequestorProcessID(delegate_->GetProcessId()); info.request.setTargetType(WebURLRequest::TargetIsObject); info.request.setHTTPMethod(WebString::fromUTF8(method)); + info.pending_failure_notification = false; if (range_info) { info.request.addHTTPHeaderField(WebString::fromUTF8("Range"), @@ -1002,6 +1001,17 @@ void WebPluginImpl::SetDeferResourceLoading(int resource_id, bool defer) { if (client_info.id == resource_id) { client_info.loader->setDefersLoading(defer); + + // If we determined that the request had failed via the HTTP headers + // in the response then we send out a failure notification to the + // plugin process, as certain plugins don't handle HTTP failure codes + // correctly. + if (!defer && client_info.client && + client_info.pending_failure_notification) { + client_info.loader->cancel(); + client_info.client->DidFail(); + clients_.erase(client_index++); + } break; } client_index++; @@ -1129,10 +1139,7 @@ void WebPluginImpl::TearDownPluginInstance( if (client_info.loader.get()) client_info.loader->cancel(); - WebPluginResourceClient* resource_client = client_info.client; client_index = clients_.erase(client_index); - if (resource_client) - resource_client->DidFail(); } // This needs to be called now and not in the destructor since the diff --git a/webkit/glue/webplugin_impl.h b/webkit/glue/webplugin_impl.h index ce8ab56..b8cace4 100644 --- a/webkit/glue/webplugin_impl.h +++ b/webkit/glue/webplugin_impl.h @@ -238,6 +238,7 @@ class WebPluginImpl : public WebPlugin, int id; WebPluginResourceClient* client; WebKit::WebURLRequest request; + bool pending_failure_notification; linked_ptr<WebKit::WebURLLoader> loader; }; |