OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/test/plugin/plugin_geturl_test.h" | 5 #include "content/test/plugin/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 11 matching lines...) Expand all Loading... |
22 // The identifier for the fetched url stream. | 22 // The identifier for the fetched url stream. |
23 #define FETCHED_URL_STREAM_ID 2 | 23 #define FETCHED_URL_STREAM_ID 2 |
24 | 24 |
25 // url for testing GetURL with a bogus URL. | 25 // url for testing GetURL with a bogus URL. |
26 #define BOGUS_URL "bogoproto:///x:/asdf.xysdhffieasdf.asdhj/" | 26 #define BOGUS_URL "bogoproto:///x:/asdf.xysdhffieasdf.asdhj/" |
27 | 27 |
28 // url for testing redirect notifications sent to plugins. | 28 // url for testing redirect notifications sent to plugins. |
29 #define REDIRECT_SRC_URL \ | 29 #define REDIRECT_SRC_URL \ |
30 "http://mock.http/npapi/plugin_read_page_redirect_src.html" | 30 "http://mock.http/npapi/plugin_read_page_redirect_src.html" |
31 | 31 |
32 // The notification id for the redirect notification url. | 32 // The notification id for the redirect notification url that we will cancel. |
33 #define REDIRECT_SRC_URL_NOTIFICATION_ID 4 | 33 #define REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID 4 |
| 34 |
| 35 // The notification id for the redirect notification url that we will accept. |
| 36 #define REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID 5 |
34 | 37 |
35 // The identifier for the bogus url stream. | 38 // The identifier for the bogus url stream. |
36 #define BOGUS_URL_STREAM_ID 3 | 39 #define BOGUS_URL_STREAM_ID 3 |
37 | 40 |
38 // The maximum chunk size of stream data. | 41 // The maximum chunk size of stream data. |
39 #define STREAM_CHUNK 197 | 42 #define STREAM_CHUNK 197 |
40 | 43 |
41 namespace NPAPIClient { | 44 namespace NPAPIClient { |
42 | 45 |
43 PluginGetURLTest::PluginGetURLTest(NPP id, NPNetscapeFuncs *host_functions) | 46 PluginGetURLTest::PluginGetURLTest(NPP id, NPNetscapeFuncs *host_functions) |
44 : PluginTest(id, host_functions), | 47 : PluginTest(id, host_functions), |
45 tests_started_(false), | 48 tests_started_(false), |
46 tests_in_progress_(0), | 49 tests_in_progress_(0), |
47 test_file_(NULL), | 50 test_file_(NULL), |
48 expect_404_response_(false), | 51 expect_404_response_(false), |
49 npn_evaluate_context_(false), | 52 npn_evaluate_context_(false), |
50 handle_url_redirects_(false), | 53 handle_url_redirects_(false), |
51 received_url_redirect_notification_(false), | 54 received_url_redirect_cancel_notification_(false), |
| 55 received_url_redirect_allow_notification_(false), |
52 check_cookies_(false) { | 56 check_cookies_(false) { |
53 } | 57 } |
54 | 58 |
55 PluginGetURLTest::~PluginGetURLTest() {} | 59 PluginGetURLTest::~PluginGetURLTest() {} |
56 | 60 |
57 NPError PluginGetURLTest::New(uint16 mode, int16 argc, const char* argn[], | 61 NPError PluginGetURLTest::New(uint16 mode, int16 argc, const char* argn[], |
58 const char* argv[], NPSavedData* saved) { | 62 const char* argv[], NPSavedData* saved) { |
59 const char* page_not_found_url = GetArgValue("page_not_found_url", argc, | 63 const char* page_not_found_url = GetArgValue("page_not_found_url", argc, |
60 argn, argv); | 64 argn, argv); |
61 if (page_not_found_url) { | 65 if (page_not_found_url) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 HostFunctions()->geturl(id(), fail_write_url_.c_str(), NULL); | 111 HostFunctions()->geturl(id(), fail_write_url_.c_str(), NULL); |
108 return NPERR_NO_ERROR; | 112 return NPERR_NO_ERROR; |
109 } else if (!referrer_target_url_.empty()) { | 113 } else if (!referrer_target_url_.empty()) { |
110 HostFunctions()->pushpopupsenabledstate(id(), true); | 114 HostFunctions()->pushpopupsenabledstate(id(), true); |
111 HostFunctions()->geturl(id(), referrer_target_url_.c_str(), "_blank"); | 115 HostFunctions()->geturl(id(), referrer_target_url_.c_str(), "_blank"); |
112 HostFunctions()->poppopupsenabledstate(id()); | 116 HostFunctions()->poppopupsenabledstate(id()); |
113 return NPERR_NO_ERROR; | 117 return NPERR_NO_ERROR; |
114 } else if (handle_url_redirects_) { | 118 } else if (handle_url_redirects_) { |
115 HostFunctions()->geturlnotify( | 119 HostFunctions()->geturlnotify( |
116 id(), REDIRECT_SRC_URL, NULL, | 120 id(), REDIRECT_SRC_URL, NULL, |
117 reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ID)); | 121 reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID)); |
118 return NPERR_NO_ERROR; | 122 return NPERR_NO_ERROR; |
119 } else if (check_cookies_) { | 123 } else if (check_cookies_) { |
120 HostFunctions()->geturlnotify( | 124 HostFunctions()->geturlnotify( |
121 id(), | 125 id(), |
122 "plugin_ref_target_page.html", | 126 "plugin_ref_target_page.html", |
123 NULL, | 127 NULL, |
124 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); | 128 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); |
125 return NPERR_NO_ERROR; | 129 return NPERR_NO_ERROR; |
126 } | 130 } |
127 | 131 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 214 |
211 test_file_ = file_util::OpenFile(path, "r"); | 215 test_file_ = file_util::OpenFile(path, "r"); |
212 if (!test_file_) { | 216 if (!test_file_) { |
213 SetError("Could not open source file"); | 217 SetError("Could not open source file"); |
214 } | 218 } |
215 } | 219 } |
216 break; | 220 break; |
217 case BOGUS_URL_STREAM_ID: | 221 case BOGUS_URL_STREAM_ID: |
218 SetError("Unexpected NewStream for BOGUS_URL"); | 222 SetError("Unexpected NewStream for BOGUS_URL"); |
219 break; | 223 break; |
220 case REDIRECT_SRC_URL_NOTIFICATION_ID: | 224 case REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID: |
221 SetError("Should not redirect to URL when plugin denied it."); | 225 SetError("Should not redirect to URL when plugin denied it."); |
222 break; | 226 break; |
| 227 case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: |
| 228 break; |
223 default: | 229 default: |
224 SetError("Unexpected NewStream callback"); | 230 SetError("Unexpected NewStream callback"); |
225 break; | 231 break; |
226 } | 232 } |
227 return NPERR_NO_ERROR; | 233 return NPERR_NO_ERROR; |
228 } | 234 } |
229 | 235 |
230 int32 PluginGetURLTest::WriteReady(NPStream *stream) { | 236 int32 PluginGetURLTest::WriteReady(NPStream *stream) { |
231 if (test_completed()) { | 237 if (test_completed()) { |
232 return PluginTest::WriteReady(stream); | 238 return PluginTest::WriteReady(stream); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // bytes. But this is not likely. | 293 // bytes. But this is not likely. |
288 if (bytes != len) | 294 if (bytes != len) |
289 SetError("Did not read correct bytelength from source file"); | 295 SetError("Did not read correct bytelength from source file"); |
290 if (memcmp(read_buffer, buffer, len)) | 296 if (memcmp(read_buffer, buffer, len)) |
291 SetError("Content mismatch between data and source!"); | 297 SetError("Content mismatch between data and source!"); |
292 } | 298 } |
293 break; | 299 break; |
294 case BOGUS_URL_STREAM_ID: | 300 case BOGUS_URL_STREAM_ID: |
295 SetError("Unexpected write callback for BOGUS_URL"); | 301 SetError("Unexpected write callback for BOGUS_URL"); |
296 break; | 302 break; |
| 303 case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: |
| 304 break; |
297 default: | 305 default: |
298 SetError("Unexpected write callback"); | 306 SetError("Unexpected write callback"); |
299 break; | 307 break; |
300 } | 308 } |
301 // Pretend that we took all the data. | 309 // Pretend that we took all the data. |
302 return len; | 310 return len; |
303 } | 311 } |
304 | 312 |
305 | 313 |
306 NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) { | 314 NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) { |
(...skipping 26 matching lines...) Expand all Loading... |
333 SignalTestCompleted(); | 341 SignalTestCompleted(); |
334 return NPERR_NO_ERROR; | 342 return NPERR_NO_ERROR; |
335 } | 343 } |
336 | 344 |
337 unsigned long stream_id = | 345 unsigned long stream_id = |
338 reinterpret_cast<unsigned long>(stream->notifyData); | 346 reinterpret_cast<unsigned long>(stream->notifyData); |
339 switch (stream_id) { | 347 switch (stream_id) { |
340 case SELF_URL_STREAM_ID: | 348 case SELF_URL_STREAM_ID: |
341 // don't care | 349 // don't care |
342 break; | 350 break; |
| 351 case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: |
| 352 break; |
343 case FETCHED_URL_STREAM_ID: | 353 case FETCHED_URL_STREAM_ID: |
344 { | 354 { |
345 char read_buffer[STREAM_CHUNK]; | 355 char read_buffer[STREAM_CHUNK]; |
346 size_t bytes = fread(read_buffer, 1, sizeof(read_buffer), test_file_); | 356 size_t bytes = fread(read_buffer, 1, sizeof(read_buffer), test_file_); |
347 if (bytes != 0) | 357 if (bytes != 0) |
348 SetError("Data and source mismatch on length"); | 358 SetError("Data and source mismatch on length"); |
349 file_util::CloseFile(test_file_); | 359 file_util::CloseFile(test_file_); |
350 } | 360 } |
351 break; | 361 break; |
352 default: | 362 default: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 tests_in_progress_--; | 417 tests_in_progress_--; |
408 break; | 418 break; |
409 case BOGUS_URL_STREAM_ID: | 419 case BOGUS_URL_STREAM_ID: |
410 if (reason != NPRES_NETWORK_ERR) { | 420 if (reason != NPRES_NETWORK_ERR) { |
411 std::string err = "BOGUS_URL received unexpected URLNotify status: "; | 421 std::string err = "BOGUS_URL received unexpected URLNotify status: "; |
412 err.append(base::IntToString(reason)); | 422 err.append(base::IntToString(reason)); |
413 SetError(err); | 423 SetError(err); |
414 } | 424 } |
415 tests_in_progress_--; | 425 tests_in_progress_--; |
416 break; | 426 break; |
417 case REDIRECT_SRC_URL_NOTIFICATION_ID: { | 427 case REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID: { |
418 if (!received_url_redirect_notification_) { | 428 if (!received_url_redirect_cancel_notification_) { |
419 SetError("Failed to receive URLRedirect notification"); | 429 SetError("Failed to receive URLRedirect notification for cancel"); |
| 430 } |
| 431 if (reason != NPRES_NETWORK_ERR) { |
| 432 SetError("Redirected URL didn't get canceled"); |
| 433 } |
| 434 break; |
| 435 } |
| 436 case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: { |
| 437 if (!received_url_redirect_allow_notification_) { |
| 438 SetError("Failed to receive URLRedirect notification for allow"); |
| 439 } |
| 440 if (reason != NPRES_DONE) { |
| 441 SetError("Redirected URL didn't complete successfully"); |
420 } | 442 } |
421 tests_in_progress_--; | 443 tests_in_progress_--; |
422 break; | 444 break; |
423 } | 445 } |
424 default: | 446 default: |
425 SetError("Unexpected NewStream callback"); | 447 SetError("Unexpected NewStream callback"); |
426 break; | 448 break; |
427 } | 449 } |
428 | 450 |
429 if (tests_in_progress_ == 0) | 451 if (tests_in_progress_ == 0) |
430 SignalTestCompleted(); | 452 SignalTestCompleted(); |
431 } | 453 } |
432 | 454 |
433 void PluginGetURLTest::URLRedirectNotify(const char* url, | 455 void PluginGetURLTest::URLRedirectNotify(const char* url, |
434 int32_t status, | 456 int32_t status, |
435 void* notify_data) { | 457 void* notify_data) { |
436 if (!base::strcasecmp(url, "http://mock.http/npapi/plugin_read_page.html")) { | 458 unsigned long stream_id = reinterpret_cast<unsigned long>(notify_data); |
437 received_url_redirect_notification_ = true; | 459 if (stream_id == REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID) { |
438 // Disallow redirect notification. | 460 if (!base::strcasecmp(url, |
439 HostFunctions()->urlredirectresponse(id(), notify_data, false); | 461 "http://mock.http/npapi/plugin_read_page.html")) { |
| 462 received_url_redirect_cancel_notification_ = true; |
| 463 // Disallow redirect notification. |
| 464 HostFunctions()->urlredirectresponse(id(), notify_data, false); |
| 465 |
| 466 // Now start a request that we will allow to redirect. |
| 467 HostFunctions()->geturlnotify( |
| 468 id(), REDIRECT_SRC_URL, NULL, |
| 469 reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID)); |
| 470 } |
| 471 } else if (stream_id == REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID) { |
| 472 received_url_redirect_allow_notification_ = true; |
| 473 HostFunctions()->urlredirectresponse(id(), notify_data, true); |
440 } | 474 } |
441 } | 475 } |
442 | 476 |
443 } // namespace NPAPIClient | 477 } // namespace NPAPIClient |
OLD | NEW |