| 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/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 149 } |
| 150 | 150 |
| 151 if (test_completed()) { | 151 if (test_completed()) { |
| 152 return PluginTest::NewStream(type, stream, seekable, stype); | 152 return PluginTest::NewStream(type, stream, seekable, stype); |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (!referrer_target_url_.empty()) { | 155 if (!referrer_target_url_.empty()) { |
| 156 return NPERR_NO_ERROR; | 156 return NPERR_NO_ERROR; |
| 157 } | 157 } |
| 158 | 158 |
| 159 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 159 static_assert(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 160 cast_validity_check); | 160 "cast validity check"); |
| 161 | 161 |
| 162 if (expect_404_response_) { | 162 if (expect_404_response_) { |
| 163 NPObject *window_obj = NULL; | 163 NPObject *window_obj = NULL; |
| 164 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); | 164 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); |
| 165 if (!window_obj) { | 165 if (!window_obj) { |
| 166 SetError("Failed to get NPObject for plugin instance2"); | 166 SetError("Failed to get NPObject for plugin instance2"); |
| 167 SignalTestCompleted(); | 167 SignalTestCompleted(); |
| 168 return NPERR_NO_ERROR; | 168 return NPERR_NO_ERROR; |
| 169 } | 169 } |
| 170 | 170 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 int32 PluginGetURLTest::WriteReady(NPStream *stream) { | 236 int32 PluginGetURLTest::WriteReady(NPStream *stream) { |
| 237 if (test_completed()) { | 237 if (test_completed()) { |
| 238 return PluginTest::WriteReady(stream); | 238 return PluginTest::WriteReady(stream); |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (!referrer_target_url_.empty() || check_cookies_) { | 241 if (!referrer_target_url_.empty() || check_cookies_) { |
| 242 return STREAM_CHUNK; | 242 return STREAM_CHUNK; |
| 243 } | 243 } |
| 244 | 244 |
| 245 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 245 static_assert(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 246 cast_validity_check); | 246 "cast validity check"); |
| 247 unsigned long stream_id = reinterpret_cast<unsigned long>( | 247 unsigned long stream_id = reinterpret_cast<unsigned long>( |
| 248 stream->notifyData); | 248 stream->notifyData); |
| 249 if (stream_id == BOGUS_URL_STREAM_ID) | 249 if (stream_id == BOGUS_URL_STREAM_ID) |
| 250 SetError("Received WriteReady for BOGUS_URL"); | 250 SetError("Received WriteReady for BOGUS_URL"); |
| 251 | 251 |
| 252 return STREAM_CHUNK; | 252 return STREAM_CHUNK; |
| 253 } | 253 } |
| 254 | 254 |
| 255 int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, | 255 int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, |
| 256 void *buffer) { | 256 void *buffer) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 269 | 269 |
| 270 if (stream == NULL) { | 270 if (stream == NULL) { |
| 271 SetError("Write got null stream"); | 271 SetError("Write got null stream"); |
| 272 return -1; | 272 return -1; |
| 273 } | 273 } |
| 274 if (len < 0 || len > STREAM_CHUNK) { | 274 if (len < 0 || len > STREAM_CHUNK) { |
| 275 SetError("Write got bogus stream chunk size"); | 275 SetError("Write got bogus stream chunk size"); |
| 276 return -1; | 276 return -1; |
| 277 } | 277 } |
| 278 | 278 |
| 279 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 279 static_assert(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 280 cast_validity_check); | 280 "cast validity check"); |
| 281 unsigned long stream_id = reinterpret_cast<unsigned long>( | 281 unsigned long stream_id = reinterpret_cast<unsigned long>( |
| 282 stream->notifyData); | 282 stream->notifyData); |
| 283 switch (stream_id) { | 283 switch (stream_id) { |
| 284 case SELF_URL_STREAM_ID: | 284 case SELF_URL_STREAM_ID: |
| 285 self_url_.append(static_cast<char*>(buffer), len); | 285 self_url_.append(static_cast<char*>(buffer), len); |
| 286 break; | 286 break; |
| 287 case FETCHED_URL_STREAM_ID: | 287 case FETCHED_URL_STREAM_ID: |
| 288 { | 288 { |
| 289 char read_buffer[STREAM_CHUNK]; | 289 char read_buffer[STREAM_CHUNK]; |
| 290 int32 bytes = | 290 int32 bytes = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 314 NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) { | 314 NPError PluginGetURLTest::DestroyStream(NPStream *stream, NPError reason) { |
| 315 if (test_completed()) { | 315 if (test_completed()) { |
| 316 return PluginTest::DestroyStream(stream, reason); | 316 return PluginTest::DestroyStream(stream, reason); |
| 317 } | 317 } |
| 318 | 318 |
| 319 if (stream == NULL) { | 319 if (stream == NULL) { |
| 320 SetError("NewStream got null stream"); | 320 SetError("NewStream got null stream"); |
| 321 return NPERR_INVALID_PARAM; | 321 return NPERR_INVALID_PARAM; |
| 322 } | 322 } |
| 323 | 323 |
| 324 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 324 static_assert(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 325 cast_validity_check); | 325 "cast validity check"); |
| 326 | 326 |
| 327 if (expect_404_response_) { | 327 if (expect_404_response_) { |
| 328 if (npn_evaluate_context_) { | 328 if (npn_evaluate_context_) { |
| 329 SetError("Received destroyStream in the context of NPN_Evaluate."); | 329 SetError("Received destroyStream in the context of NPN_Evaluate."); |
| 330 } | 330 } |
| 331 | 331 |
| 332 SignalTestCompleted(); | 332 SignalTestCompleted(); |
| 333 return NPERR_NO_ERROR; | 333 return NPERR_NO_ERROR; |
| 334 } | 334 } |
| 335 | 335 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 365 } | 365 } |
| 366 return NPERR_NO_ERROR; | 366 return NPERR_NO_ERROR; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void PluginGetURLTest::StreamAsFile(NPStream* stream, const char* fname) { | 369 void PluginGetURLTest::StreamAsFile(NPStream* stream, const char* fname) { |
| 370 if (stream == NULL) { | 370 if (stream == NULL) { |
| 371 SetError("NewStream got null stream"); | 371 SetError("NewStream got null stream"); |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 | 374 |
| 375 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 375 static_assert(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 376 cast_validity_check); | 376 "cast validity check"); |
| 377 unsigned long stream_id = | 377 unsigned long stream_id = |
| 378 reinterpret_cast<unsigned long>(stream->notifyData); | 378 reinterpret_cast<unsigned long>(stream->notifyData); |
| 379 switch (stream_id) { | 379 switch (stream_id) { |
| 380 case SELF_URL_STREAM_ID: | 380 case SELF_URL_STREAM_ID: |
| 381 // don't care | 381 // don't care |
| 382 break; | 382 break; |
| 383 default: | 383 default: |
| 384 SetError("Unexpected NewStream callback"); | 384 SetError("Unexpected NewStream callback"); |
| 385 break; | 385 break; |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 | 388 |
| 389 void PluginGetURLTest::URLNotify(const char* url, NPReason reason, void* data) { | 389 void PluginGetURLTest::URLNotify(const char* url, NPReason reason, void* data) { |
| 390 if (!tests_in_progress_) { | 390 if (!tests_in_progress_) { |
| 391 SetError("URLNotify received after tests completed"); | 391 SetError("URLNotify received after tests completed"); |
| 392 return; | 392 return; |
| 393 } | 393 } |
| 394 | 394 |
| 395 if (!url) { | 395 if (!url) { |
| 396 SetError("URLNotify received NULL url"); | 396 SetError("URLNotify received NULL url"); |
| 397 return; | 397 return; |
| 398 } | 398 } |
| 399 | 399 |
| 400 if (check_cookies_) | 400 if (check_cookies_) |
| 401 return; | 401 return; |
| 402 | 402 |
| 403 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data), cast_validity_check); | 403 static_assert(sizeof(unsigned long) <= sizeof(data), "cast validity check"); |
| 404 unsigned long stream_id = reinterpret_cast<unsigned long>(data); | 404 unsigned long stream_id = reinterpret_cast<unsigned long>(data); |
| 405 switch (stream_id) { | 405 switch (stream_id) { |
| 406 case SELF_URL_STREAM_ID: | 406 case SELF_URL_STREAM_ID: |
| 407 if (strcmp(url, SELF_URL) != 0) | 407 if (strcmp(url, SELF_URL) != 0) |
| 408 SetError("URLNotify reported incorrect url for SELF_URL"); | 408 SetError("URLNotify reported incorrect url for SELF_URL"); |
| 409 | 409 |
| 410 // We have our stream url. Go fetch it. | 410 // We have our stream url. Go fetch it. |
| 411 HostFunctions()->geturlnotify(id(), self_url_.c_str(), NULL, | 411 HostFunctions()->geturlnotify(id(), self_url_.c_str(), NULL, |
| 412 reinterpret_cast<void*>(FETCHED_URL_STREAM_ID)); | 412 reinterpret_cast<void*>(FETCHED_URL_STREAM_ID)); |
| 413 break; | 413 break; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 id(), REDIRECT_SRC_URL, NULL, | 468 id(), REDIRECT_SRC_URL, NULL, |
| 469 reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID)); | 469 reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID)); |
| 470 } | 470 } |
| 471 } else if (stream_id == REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID) { | 471 } else if (stream_id == REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID) { |
| 472 received_url_redirect_allow_notification_ = true; | 472 received_url_redirect_allow_notification_ = true; |
| 473 HostFunctions()->urlredirectresponse(id(), notify_data, true); | 473 HostFunctions()->urlredirectresponse(id(), notify_data, true); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 } // namespace NPAPIClient | 477 } // namespace NPAPIClient |
| OLD | NEW |