Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.graphics.Picture; | 7 import android.graphics.Picture; |
| 8 import android.net.http.SslError; | |
| 8 import android.webkit.ConsoleMessage; | 9 import android.webkit.ConsoleMessage; |
| 10 import android.webkit.ValueCallback; | |
| 9 | 11 |
| 10 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.content.browser.test.util.CallbackHelper; | 13 import org.chromium.content.browser.test.util.CallbackHelper; |
| 12 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval uateJavaScriptResultHelper; | 14 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval uateJavaScriptResultHelper; |
| 13 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper; | 15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper; |
| 14 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage StartedHelper; | 16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage StartedHelper; |
| 15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece ivedErrorHelper; | 17 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece ivedErrorHelper; |
| 16 | 18 |
| 17 /** | 19 /** |
| 18 * AwContentsClient subclass used for testing. | 20 * AwContentsClient subclass used for testing. |
| 19 */ | 21 */ |
| 20 public class TestAwContentsClient extends NullContentsClient { | 22 public class TestAwContentsClient extends NullContentsClient { |
| 21 private String mUpdatedTitle; | 23 private String mUpdatedTitle; |
| 24 private boolean mAllowSslError; | |
| 22 private final OnPageStartedHelper mOnPageStartedHelper; | 25 private final OnPageStartedHelper mOnPageStartedHelper; |
| 23 private final OnPageFinishedHelper mOnPageFinishedHelper; | 26 private final OnPageFinishedHelper mOnPageFinishedHelper; |
| 24 private final OnReceivedErrorHelper mOnReceivedErrorHelper; | 27 private final OnReceivedErrorHelper mOnReceivedErrorHelper; |
| 28 private final OnReceivedSslErrorHelper mOnReceivedSslErrorHelper; | |
|
sgurun-gerrit only
2014/12/12 04:23:10
CallbackHelper
hush (inactive)
2014/12/12 19:43:40
Done.
| |
| 25 private final OnDownloadStartHelper mOnDownloadStartHelper; | 29 private final OnDownloadStartHelper mOnDownloadStartHelper; |
| 26 private final OnReceivedLoginRequestHelper mOnReceivedLoginRequestHelper; | 30 private final OnReceivedLoginRequestHelper mOnReceivedLoginRequestHelper; |
| 27 private final OnEvaluateJavaScriptResultHelper mOnEvaluateJavaScriptResultHe lper; | 31 private final OnEvaluateJavaScriptResultHelper mOnEvaluateJavaScriptResultHe lper; |
| 28 private final AddMessageToConsoleHelper mAddMessageToConsoleHelper; | 32 private final AddMessageToConsoleHelper mAddMessageToConsoleHelper; |
| 29 private final OnScaleChangedHelper mOnScaleChangedHelper; | 33 private final OnScaleChangedHelper mOnScaleChangedHelper; |
| 30 private final PictureListenerHelper mPictureListenerHelper; | 34 private final PictureListenerHelper mPictureListenerHelper; |
| 31 private final ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper ; | 35 private final ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper ; |
| 32 private final DoUpdateVisitedHistoryHelper mDoUpdateVisitedHistoryHelper; | 36 private final DoUpdateVisitedHistoryHelper mDoUpdateVisitedHistoryHelper; |
| 33 private final OnCreateWindowHelper mOnCreateWindowHelper; | 37 private final OnCreateWindowHelper mOnCreateWindowHelper; |
| 34 | 38 |
| 35 public TestAwContentsClient() { | 39 public TestAwContentsClient() { |
| 36 super(ThreadUtils.getUiThreadLooper()); | 40 super(ThreadUtils.getUiThreadLooper()); |
| 37 mOnPageStartedHelper = new OnPageStartedHelper(); | 41 mOnPageStartedHelper = new OnPageStartedHelper(); |
| 38 mOnPageFinishedHelper = new OnPageFinishedHelper(); | 42 mOnPageFinishedHelper = new OnPageFinishedHelper(); |
| 39 mOnReceivedErrorHelper = new OnReceivedErrorHelper(); | 43 mOnReceivedErrorHelper = new OnReceivedErrorHelper(); |
| 44 mOnReceivedSslErrorHelper = new OnReceivedSslErrorHelper(); | |
| 40 mOnDownloadStartHelper = new OnDownloadStartHelper(); | 45 mOnDownloadStartHelper = new OnDownloadStartHelper(); |
| 41 mOnReceivedLoginRequestHelper = new OnReceivedLoginRequestHelper(); | 46 mOnReceivedLoginRequestHelper = new OnReceivedLoginRequestHelper(); |
| 42 mOnEvaluateJavaScriptResultHelper = new OnEvaluateJavaScriptResultHelper (); | 47 mOnEvaluateJavaScriptResultHelper = new OnEvaluateJavaScriptResultHelper (); |
| 43 mAddMessageToConsoleHelper = new AddMessageToConsoleHelper(); | 48 mAddMessageToConsoleHelper = new AddMessageToConsoleHelper(); |
| 44 mOnScaleChangedHelper = new OnScaleChangedHelper(); | 49 mOnScaleChangedHelper = new OnScaleChangedHelper(); |
| 45 mPictureListenerHelper = new PictureListenerHelper(); | 50 mPictureListenerHelper = new PictureListenerHelper(); |
| 46 mShouldOverrideUrlLoadingHelper = new ShouldOverrideUrlLoadingHelper(); | 51 mShouldOverrideUrlLoadingHelper = new ShouldOverrideUrlLoadingHelper(); |
| 47 mDoUpdateVisitedHistoryHelper = new DoUpdateVisitedHistoryHelper(); | 52 mDoUpdateVisitedHistoryHelper = new DoUpdateVisitedHistoryHelper(); |
| 48 mOnCreateWindowHelper = new OnCreateWindowHelper(); | 53 mOnCreateWindowHelper = new OnCreateWindowHelper(); |
| 54 mAllowSslError = true; | |
| 49 } | 55 } |
| 50 | 56 |
| 51 public OnPageStartedHelper getOnPageStartedHelper() { | 57 public OnPageStartedHelper getOnPageStartedHelper() { |
| 52 return mOnPageStartedHelper; | 58 return mOnPageStartedHelper; |
| 53 } | 59 } |
| 54 | 60 |
| 55 public OnPageFinishedHelper getOnPageFinishedHelper() { | 61 public OnPageFinishedHelper getOnPageFinishedHelper() { |
| 56 return mOnPageFinishedHelper; | 62 return mOnPageFinishedHelper; |
| 57 } | 63 } |
| 58 | 64 |
| 59 public OnReceivedErrorHelper getOnReceivedErrorHelper() { | 65 public OnReceivedErrorHelper getOnReceivedErrorHelper() { |
| 60 return mOnReceivedErrorHelper; | 66 return mOnReceivedErrorHelper; |
| 61 } | 67 } |
| 62 | 68 |
| 69 /** | |
| 70 * Callback helper for onReceivedSslError. | |
| 71 */ | |
| 72 public static class OnReceivedSslErrorHelper extends CallbackHelper {} | |
|
sgurun-gerrit only
2014/12/12 04:23:10
drop this and simply use callbackhelper.
hush (inactive)
2014/12/12 19:43:40
Done.
| |
| 73 | |
| 74 public OnReceivedSslErrorHelper getOnReceivedSslErrorHelper() { | |
| 75 return mOnReceivedSslErrorHelper; | |
| 76 } | |
| 77 | |
| 63 public OnDownloadStartHelper getOnDownloadStartHelper() { | 78 public OnDownloadStartHelper getOnDownloadStartHelper() { |
| 64 return mOnDownloadStartHelper; | 79 return mOnDownloadStartHelper; |
| 65 } | 80 } |
| 66 | 81 |
| 67 public OnReceivedLoginRequestHelper getOnReceivedLoginRequestHelper() { | 82 public OnReceivedLoginRequestHelper getOnReceivedLoginRequestHelper() { |
| 68 return mOnReceivedLoginRequestHelper; | 83 return mOnReceivedLoginRequestHelper; |
| 69 } | 84 } |
| 70 | 85 |
| 71 public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper( ) { | 86 public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper( ) { |
| 72 return mOnEvaluateJavaScriptResultHelper; | 87 return mOnEvaluateJavaScriptResultHelper; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 @Override | 154 @Override |
| 140 public void onPageFinished(String url) { | 155 public void onPageFinished(String url) { |
| 141 mOnPageFinishedHelper.notifyCalled(url); | 156 mOnPageFinishedHelper.notifyCalled(url); |
| 142 } | 157 } |
| 143 | 158 |
| 144 @Override | 159 @Override |
| 145 public void onReceivedError(int errorCode, String description, String failin gUrl) { | 160 public void onReceivedError(int errorCode, String description, String failin gUrl) { |
| 146 mOnReceivedErrorHelper.notifyCalled(errorCode, description, failingUrl); | 161 mOnReceivedErrorHelper.notifyCalled(errorCode, description, failingUrl); |
| 147 } | 162 } |
| 148 | 163 |
| 164 @Override | |
| 165 public void onReceivedSslError(ValueCallback<Boolean> callback, SslError err or) { | |
| 166 callback.onReceiveValue(mAllowSslError); | |
| 167 mOnReceivedSslErrorHelper.notifyCalled(); | |
| 168 } | |
| 169 | |
| 170 public void setAllowSslError(boolean allow) { | |
| 171 mAllowSslError = allow; | |
| 172 } | |
| 173 | |
| 149 /** | 174 /** |
| 150 * CallbackHelper for OnDownloadStart. | 175 * CallbackHelper for OnDownloadStart. |
| 151 */ | 176 */ |
| 152 public static class OnDownloadStartHelper extends CallbackHelper { | 177 public static class OnDownloadStartHelper extends CallbackHelper { |
| 153 private String mUrl; | 178 private String mUrl; |
| 154 private String mUserAgent; | 179 private String mUserAgent; |
| 155 private String mContentDisposition; | 180 private String mContentDisposition; |
| 156 private String mMimeType; | 181 private String mMimeType; |
| 157 long mContentLength; | 182 long mContentLength; |
| 158 | 183 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 300 } |
| 276 | 301 |
| 277 @Override | 302 @Override |
| 278 public boolean onConsoleMessage(ConsoleMessage consoleMessage) { | 303 public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
| 279 mAddMessageToConsoleHelper.notifyCalled(consoleMessage.messageLevel().or dinal(), | 304 mAddMessageToConsoleHelper.notifyCalled(consoleMessage.messageLevel().or dinal(), |
| 280 consoleMessage.message(), consoleMessage.lineNumber(), consoleMe ssage.sourceId()); | 305 consoleMessage.message(), consoleMessage.lineNumber(), consoleMe ssage.sourceId()); |
| 281 return false; | 306 return false; |
| 282 } | 307 } |
| 283 | 308 |
| 284 /** | 309 /** |
| 285 * Callback helper for onScaleChangedScaled. | 310 * Callback helper for AddMessageToConsole. |
| 286 */ | 311 */ |
| 287 public static class AddMessageToConsoleHelper extends CallbackHelper { | 312 public static class AddMessageToConsoleHelper extends CallbackHelper { |
| 288 private int mLevel; | 313 private int mLevel; |
| 289 private String mMessage; | 314 private String mMessage; |
| 290 private int mLineNumber; | 315 private int mLineNumber; |
| 291 private String mSourceId; | 316 private String mSourceId; |
| 292 | 317 |
| 293 public int getLevel() { | 318 public int getLevel() { |
| 294 assert getCallCount() > 0; | 319 assert getCallCount() > 0; |
| 295 return mLevel; | 320 return mLevel; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 318 notifyCalled(); | 343 notifyCalled(); |
| 319 } | 344 } |
| 320 } | 345 } |
| 321 | 346 |
| 322 @Override | 347 @Override |
| 323 public void onScaleChangedScaled(float oldScale, float newScale) { | 348 public void onScaleChangedScaled(float oldScale, float newScale) { |
| 324 mOnScaleChangedHelper.notifyCalled(oldScale, newScale); | 349 mOnScaleChangedHelper.notifyCalled(oldScale, newScale); |
| 325 } | 350 } |
| 326 | 351 |
| 327 /** | 352 /** |
| 328 * Callback helper for onScaleChangedScaled. | 353 * Callback helper for PictureListener. |
| 329 */ | 354 */ |
| 330 public static class PictureListenerHelper extends CallbackHelper { | 355 public static class PictureListenerHelper extends CallbackHelper { |
| 331 // Generally null, depending on |invalidationOnly| in enableOnNewPicture () | 356 // Generally null, depending on |invalidationOnly| in enableOnNewPicture () |
| 332 private Picture mPicture; | 357 private Picture mPicture; |
| 333 | 358 |
| 334 public Picture getPicture() { | 359 public Picture getPicture() { |
| 335 assert getCallCount() > 0; | 360 assert getCallCount() > 0; |
| 336 return mPicture; | 361 return mPicture; |
| 337 } | 362 } |
| 338 | 363 |
| 339 void notifyCalled(Picture picture) { | 364 void notifyCalled(Picture picture) { |
| 340 mPicture = picture; | 365 mPicture = picture; |
| 341 notifyCalled(); | 366 notifyCalled(); |
| 342 } | 367 } |
| 343 } | 368 } |
| 344 | 369 |
| 345 @Override | 370 @Override |
| 346 public void onNewPicture(Picture picture) { | 371 public void onNewPicture(Picture picture) { |
| 347 mPictureListenerHelper.notifyCalled(picture); | 372 mPictureListenerHelper.notifyCalled(picture); |
| 348 } | 373 } |
| 349 | 374 |
| 350 /** | 375 /** |
| 351 * Callback helper for onScaleChangedScaled. | 376 * Callback helper for ShouldOverrideUrlLoading. |
| 352 */ | 377 */ |
| 353 public static class ShouldOverrideUrlLoadingHelper extends CallbackHelper { | 378 public static class ShouldOverrideUrlLoadingHelper extends CallbackHelper { |
| 354 private String mShouldOverrideUrlLoadingUrl; | 379 private String mShouldOverrideUrlLoadingUrl; |
| 355 private String mPreviousShouldOverrideUrlLoadingUrl; | 380 private String mPreviousShouldOverrideUrlLoadingUrl; |
| 356 private boolean mShouldOverrideUrlLoadingReturnValue = false; | 381 private boolean mShouldOverrideUrlLoadingReturnValue = false; |
| 357 void setShouldOverrideUrlLoadingUrl(String url) { | 382 void setShouldOverrideUrlLoadingUrl(String url) { |
| 358 mShouldOverrideUrlLoadingUrl = url; | 383 mShouldOverrideUrlLoadingUrl = url; |
| 359 } | 384 } |
| 360 void setPreviousShouldOverrideUrlLoadingUrl(String url) { | 385 void setPreviousShouldOverrideUrlLoadingUrl(String url) { |
| 361 mPreviousShouldOverrideUrlLoadingUrl = url; | 386 mPreviousShouldOverrideUrlLoadingUrl = url; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 mIsReload = isReload; | 438 mIsReload = isReload; |
| 414 notifyCalled(); | 439 notifyCalled(); |
| 415 } | 440 } |
| 416 } | 441 } |
| 417 | 442 |
| 418 @Override | 443 @Override |
| 419 public void doUpdateVisitedHistory(String url, boolean isReload) { | 444 public void doUpdateVisitedHistory(String url, boolean isReload) { |
| 420 getDoUpdateVisitedHistoryHelper().notifyCalled(url, isReload); | 445 getDoUpdateVisitedHistoryHelper().notifyCalled(url, isReload); |
| 421 } | 446 } |
| 422 } | 447 } |
| OLD | NEW |