summaryrefslogtreecommitdiffstats
path: root/net/test/android
diff options
context:
space:
mode:
authormnaganov <mnaganov@chromium.org>2015-03-04 05:42:03 -0800
committerCommit bot <commit-bot@chromium.org>2015-03-04 13:42:36 +0000
commitb2803fd408c3709889645061fad42d3371024b93 (patch)
tree7089c35a290818a10a2f52d28849142b4f911865 /net/test/android
parenta6d0c54aa3c008eb25d759bcb06422c34aa72040 (diff)
downloadchromium_src-b2803fd408c3709889645061fad42d3371024b93.zip
chromium_src-b2803fd408c3709889645061fad42d3371024b93.tar.gz
chromium_src-b2803fd408c3709889645061fad42d3371024b93.tar.bz2
[Android WebView] Synthesize a fake page loading event on page source modification (Re-land)
When a script modifies page source of a non-committed page, we need to notify clients, so they can update the URL bar to avoid confusion. New logic since the last attempt (https://codereview.chromium.org/924833003/): distinguish between a "vanilla" WebView state (basically, a newly created WebView, where no loading attempts have been made) and an "attempted to navigate" state. In the "vanilla" state, don't fire synthesized page loading events to avoid confusing clients. This is safe, as WebView is guaranteed to be on a blank page. Implementation note: we detect navigation attempts using didStartProvisionalLoadForFrame WebContentsObserver event on the Java side. As for popups AwWebContentsObserver gets re-attached from the original popup WebView to the one provided by the client, notifications issued inbetween can be missed on the Java side. To work around this, we assume that WebViews opened as popups can never be in "vanilla" state (as they are anyway opened as a result of navigation). BUG=458569,462213 TBR=davidben@chromium.org,tedchoc@chromium.org Review URL: https://codereview.chromium.org/970883002 Cr-Commit-Position: refs/heads/master@{#319061}
Diffstat (limited to 'net/test/android')
-rw-r--r--net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java b/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java
index dd40220..48c257e 100644
--- a/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java
+++ b/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java
@@ -80,11 +80,14 @@ public class TestWebServer {
final boolean mIsRedirect;
final Runnable mResponseAction;
final boolean mIsNotFound;
+ final boolean mIsNoContent;
Response(byte[] responseData, List<Pair<String, String>> responseHeaders,
- boolean isRedirect, boolean isNotFound, Runnable responseAction) {
+ boolean isRedirect, boolean isNotFound, boolean isNoContent,
+ Runnable responseAction) {
mIsRedirect = isRedirect;
mIsNotFound = isNotFound;
+ mIsNoContent = isNoContent;
mResponseData = responseData;
mResponseHeaders = responseHeaders == null
? new ArrayList<Pair<String, String>>() : responseHeaders;
@@ -208,6 +211,7 @@ public class TestWebServer {
private static final int RESPONSE_STATUS_NORMAL = 0;
private static final int RESPONSE_STATUS_MOVED_TEMPORARILY = 1;
private static final int RESPONSE_STATUS_NOT_FOUND = 2;
+ private static final int RESPONSE_STATUS_NO_CONTENT = 3;
private String setResponseInternal(
String requestPath, byte[] responseData,
@@ -215,10 +219,12 @@ public class TestWebServer {
int status) {
final boolean isRedirect = (status == RESPONSE_STATUS_MOVED_TEMPORARILY);
final boolean isNotFound = (status == RESPONSE_STATUS_NOT_FOUND);
+ final boolean isNoContent = (status == RESPONSE_STATUS_NO_CONTENT);
synchronized (mLock) {
mResponseMap.put(requestPath, new Response(
- responseData, responseHeaders, isRedirect, isNotFound, responseAction));
+ responseData, responseHeaders, isRedirect, isNotFound, isNoContent,
+ responseAction));
mResponseCountMap.put(requestPath, Integer.valueOf(0));
mLastRequestMap.put(requestPath, null);
}
@@ -251,6 +257,18 @@ public class TestWebServer {
}
/**
+ * Sets a 204 (no content) response to be returned when a particular request path is passed in.
+ *
+ * @param requestPath The path to respond to.
+ * @return The full URL including the path that should be requested to get the expected
+ * response.
+ */
+ public String setResponseWithNoContentStatus(String requestPath) {
+ return setResponseInternal(
+ requestPath, "".getBytes(), null, null, RESPONSE_STATUS_NO_CONTENT);
+ }
+
+ /**
* Sets a response to be returned when a particular request path is passed
* in (with the option to specify additional headers).
*
@@ -451,6 +469,10 @@ public class TestWebServer {
} else if (response.mIsNotFound) {
httpResponse = createResponse(HttpStatus.SC_NOT_FOUND);
servedResponseFor(path, request);
+ } else if (response.mIsNoContent) {
+ httpResponse = createResponse(HttpStatus.SC_NO_CONTENT);
+ httpResponse.setHeader("Content-Length", "0");
+ servedResponseFor(path, request);
} else if (response.mIsRedirect) {
httpResponse = createResponse(HttpStatus.SC_MOVED_TEMPORARILY);
for (Pair<String, String> header : response.mResponseHeaders) {