Index: content/test/plugin/plugin_geturl_test.cc |
=================================================================== |
--- content/test/plugin/plugin_geturl_test.cc (revision 234230) |
+++ content/test/plugin/plugin_geturl_test.cc (working copy) |
@@ -29,9 +29,12 @@ |
#define REDIRECT_SRC_URL \ |
"http://mock.http/npapi/plugin_read_page_redirect_src.html" |
-// The notification id for the redirect notification url. |
-#define REDIRECT_SRC_URL_NOTIFICATION_ID 4 |
+// The notification id for the redirect notification url that we will cancel. |
+#define REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID 4 |
+// The notification id for the redirect notification url that we will accept. |
+#define REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID 5 |
+ |
// The identifier for the bogus url stream. |
#define BOGUS_URL_STREAM_ID 3 |
@@ -48,7 +51,8 @@ |
expect_404_response_(false), |
npn_evaluate_context_(false), |
handle_url_redirects_(false), |
- received_url_redirect_notification_(false), |
+ received_url_redirect_cancel_notification_(false), |
+ received_url_redirect_allow_notification_(false), |
check_cookies_(false) { |
} |
@@ -114,7 +118,7 @@ |
} else if (handle_url_redirects_) { |
HostFunctions()->geturlnotify( |
id(), REDIRECT_SRC_URL, NULL, |
- reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ID)); |
+ reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID)); |
return NPERR_NO_ERROR; |
} else if (check_cookies_) { |
HostFunctions()->geturlnotify( |
@@ -217,9 +221,11 @@ |
case BOGUS_URL_STREAM_ID: |
SetError("Unexpected NewStream for BOGUS_URL"); |
break; |
- case REDIRECT_SRC_URL_NOTIFICATION_ID: |
+ case REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID: |
SetError("Should not redirect to URL when plugin denied it."); |
break; |
+ case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: |
+ break; |
default: |
SetError("Unexpected NewStream callback"); |
break; |
@@ -294,6 +300,8 @@ |
case BOGUS_URL_STREAM_ID: |
SetError("Unexpected write callback for BOGUS_URL"); |
break; |
+ case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: |
+ break; |
default: |
SetError("Unexpected write callback"); |
break; |
@@ -340,6 +348,8 @@ |
case SELF_URL_STREAM_ID: |
// don't care |
break; |
+ case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: |
+ break; |
case FETCHED_URL_STREAM_ID: |
{ |
char read_buffer[STREAM_CHUNK]; |
@@ -414,10 +424,22 @@ |
} |
tests_in_progress_--; |
break; |
- case REDIRECT_SRC_URL_NOTIFICATION_ID: { |
- if (!received_url_redirect_notification_) { |
- SetError("Failed to receive URLRedirect notification"); |
+ case REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID: { |
+ if (!received_url_redirect_cancel_notification_) { |
+ SetError("Failed to receive URLRedirect notification for cancel"); |
} |
+ if (reason != NPRES_NETWORK_ERR) { |
+ SetError("Redirected URL didn't get canceled"); |
+ } |
+ break; |
+ } |
+ case REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID: { |
+ if (!received_url_redirect_allow_notification_) { |
+ SetError("Failed to receive URLRedirect notification for allow"); |
+ } |
+ if (reason != NPRES_DONE) { |
+ SetError("Redirected URL didn't complete successfully"); |
+ } |
tests_in_progress_--; |
break; |
} |
@@ -433,10 +455,22 @@ |
void PluginGetURLTest::URLRedirectNotify(const char* url, |
int32_t status, |
void* notify_data) { |
- if (!base::strcasecmp(url, "http://mock.http/npapi/plugin_read_page.html")) { |
- received_url_redirect_notification_ = true; |
- // Disallow redirect notification. |
- HostFunctions()->urlredirectresponse(id(), notify_data, false); |
+ unsigned long stream_id = reinterpret_cast<unsigned long>(notify_data); |
+ if (stream_id == REDIRECT_SRC_URL_NOTIFICATION_CANCEL_ID) { |
+ if (!base::strcasecmp(url, |
+ "http://mock.http/npapi/plugin_read_page.html")) { |
+ received_url_redirect_cancel_notification_ = true; |
+ // Disallow redirect notification. |
+ HostFunctions()->urlredirectresponse(id(), notify_data, false); |
+ |
+ // Now start a request that we will allow to redirect. |
+ HostFunctions()->geturlnotify( |
+ id(), REDIRECT_SRC_URL, NULL, |
+ reinterpret_cast<void*>(REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID)); |
+ } |
+ } else if (stream_id == REDIRECT_SRC_URL_NOTIFICATION_ALLOW_ID) { |
+ received_url_redirect_allow_notification_ = true; |
+ HostFunctions()->urlredirectresponse(id(), notify_data, true); |
} |
} |