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 static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
8 | 8 |
9 import android.app.Instrumentation; | 9 import android.app.Instrumentation; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.graphics.Bitmap; | |
12 import android.os.Build; | 11 import android.os.Build; |
13 import android.util.AndroidRuntimeException; | 12 import android.util.AndroidRuntimeException; |
14 import android.util.Log; | 13 import android.util.Log; |
15 | 14 |
16 import org.chromium.android_webview.AwBrowserContext; | 15 import org.chromium.android_webview.AwBrowserContext; |
17 import org.chromium.android_webview.AwBrowserProcess; | 16 import org.chromium.android_webview.AwBrowserProcess; |
18 import org.chromium.android_webview.AwContents; | 17 import org.chromium.android_webview.AwContents; |
19 import org.chromium.android_webview.AwContentsClient; | 18 import org.chromium.android_webview.AwContentsClient; |
20 import org.chromium.android_webview.AwSettings; | 19 import org.chromium.android_webview.AwSettings; |
21 import org.chromium.android_webview.AwSwitches; | 20 import org.chromium.android_webview.AwSwitches; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 protected void createAwBrowserContext() { | 96 protected void createAwBrowserContext() { |
98 if (mBrowserContext != null) { | 97 if (mBrowserContext != null) { |
99 throw new AndroidRuntimeException("There should only be one browser
context."); | 98 throw new AndroidRuntimeException("There should only be one browser
context."); |
100 } | 99 } |
101 getActivity(); // The Activity must be launched in order to load native
code | 100 getActivity(); // The Activity must be launched in order to load native
code |
102 final InMemorySharedPreferences prefs = new InMemorySharedPreferences(); | 101 final InMemorySharedPreferences prefs = new InMemorySharedPreferences(); |
103 final Context appContext = getInstrumentation().getTargetContext().getAp
plicationContext(); | 102 final Context appContext = getInstrumentation().getTargetContext().getAp
plicationContext(); |
104 getInstrumentation().runOnMainSync(new Runnable() { | 103 getInstrumentation().runOnMainSync(new Runnable() { |
105 @Override | 104 @Override |
106 public void run() { | 105 public void run() { |
107 mBrowserContext = new AwBrowserContext(prefs, appContext); | 106 mBrowserContext = createAwBrowserContextOnUiThread(prefs, appCon
text); |
108 } | 107 } |
109 }); | 108 }); |
110 } | 109 } |
111 | 110 |
| 111 protected AwBrowserContext createAwBrowserContextOnUiThread( |
| 112 InMemorySharedPreferences prefs, Context appContext) { |
| 113 return new AwBrowserContext(prefs, appContext); |
| 114 } |
| 115 |
112 protected void startBrowserProcess() throws Exception { | 116 protected void startBrowserProcess() throws Exception { |
113 // The Activity must be launched in order for proper webview statics to
be setup. | 117 // The Activity must be launched in order for proper webview statics to
be setup. |
114 getActivity(); | 118 getActivity(); |
115 getInstrumentation().runOnMainSync(new Runnable() { | 119 getInstrumentation().runOnMainSync(new Runnable() { |
116 @Override | 120 @Override |
117 public void run() { | 121 public void run() { |
118 AwBrowserProcess.start(); | 122 AwBrowserProcess.start(); |
119 } | 123 } |
120 }); | 124 }); |
121 } | 125 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 371 } |
368 | 372 |
369 // Waits for the pixel at the center of AwContents to color up into expected
Color. | 373 // Waits for the pixel at the center of AwContents to color up into expected
Color. |
370 // Note that this is a stricter condition that waiting for a visual state ca
llback, | 374 // Note that this is a stricter condition that waiting for a visual state ca
llback, |
371 // as visual state callback only indicates that *something* has appeared in
WebView. | 375 // as visual state callback only indicates that *something* has appeared in
WebView. |
372 public void waitForPixelColorAtCenterOfView(final AwContents awContents, | 376 public void waitForPixelColorAtCenterOfView(final AwContents awContents, |
373 final AwTestContainerView testContainerView, final int expectedColor
) throws Exception { | 377 final AwTestContainerView testContainerView, final int expectedColor
) throws Exception { |
374 pollUiThread(new Callable<Boolean>() { | 378 pollUiThread(new Callable<Boolean>() { |
375 @Override | 379 @Override |
376 public Boolean call() throws Exception { | 380 public Boolean call() throws Exception { |
377 Bitmap bitmap = GraphicsTestUtils.drawAwContents(awContents, 2,
2, | 381 return GraphicsTestUtils.getPixelColorAtCenterOfView(awContents,
testContainerView) |
378 -(float) testContainerView.getWidth() / 2, | 382 == expectedColor; |
379 -(float) testContainerView.getHeight() / 2); | |
380 return bitmap.getPixel(0, 0) == expectedColor; | |
381 } | 383 } |
382 }); | 384 }); |
383 } | 385 } |
384 | 386 |
385 /** | 387 /** |
386 * Checks the current test has |clazz| annotation. Note this swallows NoSuch
MethodException | 388 * Checks the current test has |clazz| annotation. Note this swallows NoSuch
MethodException |
387 * and returns false in that case. | 389 * and returns false in that case. |
388 */ | 390 */ |
389 private boolean testMethodHasAnnotation(Class<? extends Annotation> clazz) { | 391 private boolean testMethodHasAnnotation(Class<? extends Annotation> clazz) { |
390 String testName = getName(); | 392 String testName = getName(); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 int titleCallCount = onReceivedTitleHelper.getCallCount(); | 706 int titleCallCount = onReceivedTitleHelper.getCallCount(); |
705 | 707 |
706 onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS
, | 708 onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS
, |
707 TimeUnit.MILLISECONDS); | 709 TimeUnit.MILLISECONDS); |
708 onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS
, | 710 onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS
, |
709 TimeUnit.MILLISECONDS); | 711 TimeUnit.MILLISECONDS); |
710 | 712 |
711 return new PopupInfo(popupContentsClient, popupContainerView, popupConte
nts); | 713 return new PopupInfo(popupContentsClient, popupContainerView, popupConte
nts); |
712 } | 714 } |
713 } | 715 } |
OLD | NEW |