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.Bitmap; | 7 import android.graphics.Bitmap; |
8 import android.graphics.BitmapFactory; | 8 import android.graphics.BitmapFactory; |
9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
10 import android.os.Handler; | 10 import android.os.Handler; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 @SmallTest | 98 @SmallTest |
99 @Feature({"AndroidWebView"}) | 99 @Feature({"AndroidWebView"}) |
100 @UiThreadTest | 100 @UiThreadTest |
101 public void testWebViewApisFailGracefullyAfterDestruction() throws Throwable
{ | 101 public void testWebViewApisFailGracefullyAfterDestruction() throws Throwable
{ |
102 AwContents awContents = | 102 AwContents awContents = |
103 createAwTestContainerView(mContentsClient).getAwContents(); | 103 createAwTestContainerView(mContentsClient).getAwContents(); |
104 awContents.destroy(); | 104 awContents.destroy(); |
105 | 105 |
106 assertNull(awContents.getWebContents()); | |
107 assertNull(awContents.getContentViewCore()); | |
108 assertNull(awContents.getNavigationController()); | |
109 | |
110 // The documentation for WebView#destroy() reads "This method should be
called | 106 // The documentation for WebView#destroy() reads "This method should be
called |
111 // after this WebView has been removed from the view system. No other me
thods | 107 // after this WebView has been removed from the view system. No other me
thods |
112 // may be called on this WebView after destroy". | 108 // may be called on this WebView after destroy". |
113 // However, some apps do not respect that restriction so we need to ensu
re that | 109 // However, some apps do not respect that restriction so we need to ensu
re that |
114 // we fail gracefully and do not crash when APIs are invoked after destr
uction. | 110 // we fail gracefully and do not crash when APIs are invoked after destr
uction. |
115 // Due to the large number of APIs we only test a representative selecti
on here. | 111 // Due to the large number of APIs we only test a representative selecti
on here. |
116 awContents.clearHistory(); | 112 awContents.clearHistory(); |
117 awContents.loadUrl(new LoadUrlParams("http://www.google.com")); | 113 awContents.loadUrl(new LoadUrlParams("http://www.google.com")); |
118 awContents.findAllAsync("search"); | 114 awContents.findAllAsync("search"); |
119 assertNull(awContents.getUrl()); | 115 assertNull(awContents.getUrl()); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // The getFavicon will return the right icon a certain time after | 331 // The getFavicon will return the right icon a certain time after |
336 // the page load completes which makes it slightly hard to test. | 332 // the page load completes which makes it slightly hard to test. |
337 final Bitmap defaultFavicon = awContents.getFavicon(); | 333 final Bitmap defaultFavicon = awContents.getFavicon(); |
338 | 334 |
339 getAwSettingsOnUiThread(awContents).setImagesEnabled(true); | 335 getAwSettingsOnUiThread(awContents).setImagesEnabled(true); |
340 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), p
ageUrl); | 336 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), p
ageUrl); |
341 | 337 |
342 pollOnUiThread(new Callable<Boolean>() { | 338 pollOnUiThread(new Callable<Boolean>() { |
343 @Override | 339 @Override |
344 public Boolean call() { | 340 public Boolean call() { |
345 return awContents.getFavicon() != null && | 341 return awContents.getFavicon() != null |
346 !awContents.getFavicon().sameAs(defaultFavicon); | 342 && !awContents.getFavicon().sameAs(defaultFavicon); |
347 } | 343 } |
348 }); | 344 }); |
349 | 345 |
350 final Object originalFaviconSource = (new URL(faviconUrl)).getConten
t(); | 346 final Object originalFaviconSource = (new URL(faviconUrl)).getConten
t(); |
351 final Bitmap originalFavicon = | 347 final Bitmap originalFavicon = |
352 BitmapFactory.decodeStream((InputStream) originalFaviconSour
ce); | 348 BitmapFactory.decodeStream((InputStream) originalFaviconSour
ce); |
353 assertNotNull(originalFavicon); | 349 assertNotNull(originalFavicon); |
354 | 350 |
355 assertTrue(awContents.getFavicon().sameAs(originalFavicon)); | 351 assertTrue(awContents.getFavicon().sameAs(originalFavicon)); |
356 | 352 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 Header[] matchingHeaders = request.getHeaders(header); | 494 Header[] matchingHeaders = request.getHeaders(header); |
499 assertEquals("header " + header + " not found", 1, matchingHeade
rs.length); | 495 assertEquals("header " + header + " not found", 1, matchingHeade
rs.length); |
500 assertEquals(value.getValue(), matchingHeaders[0].getValue()); | 496 assertEquals(value.getValue(), matchingHeaders[0].getValue()); |
501 } | 497 } |
502 } finally { | 498 } finally { |
503 webServer.shutdown(); | 499 webServer.shutdown(); |
504 } | 500 } |
505 } | 501 } |
506 | 502 |
507 } | 503 } |
OLD | NEW |