Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: webkit/glue/plugins/test/plugin_geturl_test.cc

Issue 174383: Fixes a crash caused due to a call to NPP_DestroyStream occuring in the conte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/plugins/test/plugin_geturl_test.h ('k') | webkit/glue/plugins/test/plugin_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webkit/glue/plugins/test/plugin_geturl_test.h" 5 #include "webkit/glue/plugins/test/plugin_geturl_test.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 16 matching lines...) Expand all
27 27
28 // The maximum chunk size of stream data. 28 // The maximum chunk size of stream data.
29 #define STREAM_CHUNK 197 29 #define STREAM_CHUNK 197
30 30
31 namespace NPAPIClient { 31 namespace NPAPIClient {
32 32
33 PluginGetURLTest::PluginGetURLTest(NPP id, NPNetscapeFuncs *host_functions) 33 PluginGetURLTest::PluginGetURLTest(NPP id, NPNetscapeFuncs *host_functions)
34 : PluginTest(id, host_functions), 34 : PluginTest(id, host_functions),
35 tests_started_(false), 35 tests_started_(false),
36 tests_in_progress_(0), 36 tests_in_progress_(0),
37 test_file_(NULL) { 37 test_file_(NULL),
38 expect_404_response_(false),
39 npn_evaluate_context_(false) {
40 }
41
42 NPError PluginGetURLTest::New(uint16 mode, int16 argc, const char* argn[],
43 const char* argv[], NPSavedData* saved) {
44 const char* page_not_found_url = GetArgValue("page_not_found_url", argc,
45 argn, argv);
46 if (page_not_found_url) {
47 page_not_found_url_ = page_not_found_url;
48 expect_404_response_ = true;
49 }
50
51 return PluginTest::New(mode, argc, argn, argv, saved);
38 } 52 }
39 53
40 NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) { 54 NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) {
41 if (!tests_started_) { 55 if (!tests_started_) {
42 tests_started_ = true; 56 tests_started_ = true;
43 57
44 tests_in_progress_++; 58 tests_in_progress_++;
45 59
60 if (expect_404_response_) {
61 HostFunctions()->geturl(id(), page_not_found_url_.c_str(), NULL);
62 return NPERR_NO_ERROR;
63 }
64
46 std::string url = SELF_URL; 65 std::string url = SELF_URL;
47 HostFunctions()->geturlnotify(id(), url.c_str(), NULL, 66 HostFunctions()->geturlnotify(id(), url.c_str(), NULL,
48 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); 67 reinterpret_cast<void*>(SELF_URL_STREAM_ID));
49 68
50 tests_in_progress_++; 69 tests_in_progress_++;
51 std::string bogus_url = BOGUS_URL; 70 std::string bogus_url = BOGUS_URL;
52 HostFunctions()->geturlnotify(id(), bogus_url.c_str(), NULL, 71 HostFunctions()->geturlnotify(id(), bogus_url.c_str(), NULL,
53 reinterpret_cast<void*>(BOGUS_URL_STREAM_ID)); 72 reinterpret_cast<void*>(BOGUS_URL_STREAM_ID));
54 } 73 }
55 return NPERR_NO_ERROR; 74 return NPERR_NO_ERROR;
56 } 75 }
57 76
58 NPError PluginGetURLTest::NewStream(NPMIMEType type, NPStream* stream, 77 NPError PluginGetURLTest::NewStream(NPMIMEType type, NPStream* stream,
59 NPBool seekable, uint16* stype) { 78 NPBool seekable, uint16* stype) {
60 if (stream == NULL) 79 if (stream == NULL)
61 SetError("NewStream got null stream"); 80 SetError("NewStream got null stream");
62 81
82 if (test_completed()) {
83 return PluginTest::NewStream(type, stream, seekable, stype);
84 }
85
63 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), 86 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
64 cast_validity_check); 87 cast_validity_check);
88
89 if (expect_404_response_) {
90 NPObject *window_obj = NULL;
91 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj);
92 if (!window_obj) {
93 SetError("Failed to get NPObject for plugin instance2");
94 SignalTestCompleted();
95 return NPERR_NO_ERROR;
96 }
97
98 std::string script = "javascript:alert('Hi there from plugin');";
99 NPString script_string;
100 script_string.UTF8Characters = script.c_str();
101 script_string.UTF8Length = static_cast<unsigned int>(script.length());
102 NPVariant result_var;
103
104 npn_evaluate_context_ = true;
105 HostFunctions()->evaluate(id(), window_obj, &script_string, &result_var);
106 npn_evaluate_context_ = false;
107 return NPERR_NO_ERROR;
108 }
109
65 unsigned long stream_id = reinterpret_cast<unsigned long>( 110 unsigned long stream_id = reinterpret_cast<unsigned long>(
66 stream->notifyData); 111 stream->notifyData);
112
67 switch (stream_id) { 113 switch (stream_id) {
68 case SELF_URL_STREAM_ID: 114 case SELF_URL_STREAM_ID:
69 break; 115 break;
70 case FETCHED_URL_STREAM_ID: 116 case FETCHED_URL_STREAM_ID:
71 { 117 {
72 std::string filename = self_url_; 118 std::string filename = self_url_;
73 if (filename.find("file:///", 0) != 0) { 119 if (filename.find("file:///", 0) != 0) {
74 SetError("Test expects a file-url."); 120 SetError("Test expects a file-url.");
75 break; 121 break;
76 } 122 }
(...skipping 10 matching lines...) Expand all
87 SetError("Unexpected NewStream for BOGUS_URL"); 133 SetError("Unexpected NewStream for BOGUS_URL");
88 break; 134 break;
89 default: 135 default:
90 SetError("Unexpected NewStream callback"); 136 SetError("Unexpected NewStream callback");
91 break; 137 break;
92 } 138 }
93 return NPERR_NO_ERROR; 139 return NPERR_NO_ERROR;
94 } 140 }
95 141
96 int32 PluginGetURLTest::WriteReady(NPStream *stream) { 142 int32 PluginGetURLTest::WriteReady(NPStream *stream) {
143 if (test_completed()) {
144 return PluginTest::WriteReady(stream);
145 }
146
97 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), 147 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
98 cast_validity_check); 148 cast_validity_check);
99 unsigned long stream_id = reinterpret_cast<unsigned long>( 149 unsigned long stream_id = reinterpret_cast<unsigned long>(
100 stream->notifyData); 150 stream->notifyData);
101 if (stream_id == BOGUS_URL_STREAM_ID) 151 if (stream_id == BOGUS_URL_STREAM_ID)
102 SetError("Received WriteReady for BOGUS_URL"); 152 SetError("Received WriteReady for BOGUS_URL");
103 153
104 return STREAM_CHUNK; 154 return STREAM_CHUNK;
105 } 155 }
106 156
107 int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, 157 int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len,
108 void *buffer) { 158 void *buffer) {
159 if (test_completed()) {
160 return PluginTest::Write(stream, offset, len, buffer);
161 }
162
109 if (stream == NULL) 163 if (stream == NULL)
110 SetError("Write got null stream"); 164 SetError("Write got null stream");
111 if (len < 0 || len > STREAM_CHUNK) 165 if (len < 0 || len > STREAM_CHUNK)
112 SetError("Write got bogus stream chunk size"); 166 SetError("Write got bogus stream chunk size");
113 167
114 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), 168 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
115 cast_validity_check); 169 cast_validity_check);
116 unsigned long stream_id = reinterpret_cast<unsigned long>( 170 unsigned long stream_id = reinterpret_cast<unsigned long>(
117 stream->notifyData); 171 stream->notifyData);
118 switch (stream_id) { 172 switch (stream_id) {
(...skipping 18 matching lines...) Expand all
137 default: 191 default:
138 SetError("Unexpected write callback"); 192 SetError("Unexpected write callback");
139 break; 193 break;
140 } 194 }
141 // Pretend that we took all the data. 195 // Pretend that we took all the data.
142 return len; 196 return len;
143 } 197 }
144 198
145 199
146 NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) { 200 NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) {
201 if (test_completed()) {
202 return PluginTest::DestroyStream(stream, reason);
203 }
204
147 if (stream == NULL) 205 if (stream == NULL)
148 SetError("NewStream got null stream"); 206 SetError("NewStream got null stream");
149 207
150 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), 208 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
151 cast_validity_check); 209 cast_validity_check);
210
211 if (expect_404_response_) {
212 if (npn_evaluate_context_) {
213 SetError("Received destroyStream in the context of NPN_Evaluate.");
214 }
215
216 SignalTestCompleted();
217 return NPERR_NO_ERROR;
218 }
219
152 unsigned long stream_id = 220 unsigned long stream_id =
153 reinterpret_cast<unsigned long>(stream->notifyData); 221 reinterpret_cast<unsigned long>(stream->notifyData);
154 switch (stream_id) { 222 switch (stream_id) {
155 case SELF_URL_STREAM_ID: 223 case SELF_URL_STREAM_ID:
156 // don't care 224 // don't care
157 break; 225 break;
158 case FETCHED_URL_STREAM_ID: 226 case FETCHED_URL_STREAM_ID:
159 { 227 {
160 char read_buffer[STREAM_CHUNK]; 228 char read_buffer[STREAM_CHUNK];
161 size_t bytes = fread(read_buffer, 1, sizeof(read_buffer), test_file_); 229 size_t bytes = fread(read_buffer, 1, sizeof(read_buffer), test_file_);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 default: 295 default:
228 SetError("Unexpected NewStream callback"); 296 SetError("Unexpected NewStream callback");
229 break; 297 break;
230 } 298 }
231 299
232 if (tests_in_progress_ == 0) 300 if (tests_in_progress_ == 0)
233 SignalTestCompleted(); 301 SignalTestCompleted();
234 } 302 }
235 303
236 } // namespace NPAPIClient 304 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/glue/plugins/test/plugin_geturl_test.h ('k') | webkit/glue/plugins/test/plugin_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698