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; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 protected void createAwBrowserContext() { | 97 protected void createAwBrowserContext() { |
98 if (mBrowserContext != null) { | 98 if (mBrowserContext != null) { |
99 throw new AndroidRuntimeException("There should only be one browser context."); | 99 throw new AndroidRuntimeException("There should only be one browser context."); |
100 } | 100 } |
101 getActivity(); // The Activity must be launched in order to load native code | 101 getActivity(); // The Activity must be launched in order to load native code |
102 final InMemorySharedPreferences prefs = new InMemorySharedPreferences(); | 102 final InMemorySharedPreferences prefs = new InMemorySharedPreferences(); |
103 final Context appContext = getInstrumentation().getTargetContext().getAp plicationContext(); | 103 final Context appContext = getInstrumentation().getTargetContext().getAp plicationContext(); |
104 getInstrumentation().runOnMainSync(new Runnable() { | 104 getInstrumentation().runOnMainSync(new Runnable() { |
105 @Override | 105 @Override |
106 public void run() { | 106 public void run() { |
107 mBrowserContext = new AwBrowserContext(prefs, appContext); | 107 mBrowserContext = createAwBrowserContextOnUiThread(prefs, appCon text); |
108 } | 108 } |
109 }); | 109 }); |
110 } | 110 } |
111 | 111 |
112 protected AwBrowserContext createAwBrowserContextOnUiThread( | |
113 InMemorySharedPreferences prefs, Context appContext) { | |
114 return new AwBrowserContext(prefs, appContext); | |
115 } | |
116 | |
112 protected void startBrowserProcess() throws Exception { | 117 protected void startBrowserProcess() throws Exception { |
113 // The Activity must be launched in order for proper webview statics to be setup. | 118 // The Activity must be launched in order for proper webview statics to be setup. |
114 getActivity(); | 119 getActivity(); |
115 getInstrumentation().runOnMainSync(new Runnable() { | 120 getInstrumentation().runOnMainSync(new Runnable() { |
116 @Override | 121 @Override |
117 public void run() { | 122 public void run() { |
118 AwBrowserProcess.start(); | 123 AwBrowserProcess.start(); |
119 } | 124 } |
120 }); | 125 }); |
121 } | 126 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 public void onComplete(long id) { | 364 public void onComplete(long id) { |
360 assertEquals(requestId, id); | 365 assertEquals(requestId, id); |
361 ch.notifyCalled(); | 366 ch.notifyCalled(); |
362 } | 367 } |
363 }); | 368 }); |
364 } | 369 } |
365 }); | 370 }); |
366 ch.waitForCallback(chCount); | 371 ch.waitForCallback(chCount); |
367 } | 372 } |
368 | 373 |
374 // Gets the pixel color at the center of AwContents. | |
375 public int getPixelColorAtCenterOfView( | |
boliu
2017/02/21 21:37:47
I think this can just be static, in which case jus
Nate Fischer
2017/02/21 21:56:06
Done
| |
376 final AwContents awContents, final AwTestContainerView testContainer View) { | |
377 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Integer >() { | |
378 @Override | |
379 public Integer call() { | |
380 Bitmap bitmap = GraphicsTestUtils.drawAwContents(awContents, 2, 2, | |
381 -(float) testContainerView.getWidth() / 2, | |
382 -(float) testContainerView.getHeight() / 2); | |
383 return bitmap.getPixel(0, 0); | |
384 } | |
385 }); | |
386 } | |
387 | |
369 // Waits for the pixel at the center of AwContents to color up into expected Color. | 388 // 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, | 389 // 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. | 390 // as visual state callback only indicates that *something* has appeared in WebView. |
372 public void waitForPixelColorAtCenterOfView(final AwContents awContents, | 391 public void waitForPixelColorAtCenterOfView(final AwContents awContents, |
373 final AwTestContainerView testContainerView, final int expectedColor ) throws Exception { | 392 final AwTestContainerView testContainerView, final int expectedColor ) throws Exception { |
374 pollUiThread(new Callable<Boolean>() { | 393 pollUiThread(new Callable<Boolean>() { |
375 @Override | 394 @Override |
376 public Boolean call() throws Exception { | 395 public Boolean call() throws Exception { |
377 Bitmap bitmap = GraphicsTestUtils.drawAwContents(awContents, 2, 2, | 396 return getPixelColorAtCenterOfView(awContents, testContainerView ) == expectedColor; |
378 -(float) testContainerView.getWidth() / 2, | |
379 -(float) testContainerView.getHeight() / 2); | |
380 return bitmap.getPixel(0, 0) == expectedColor; | |
381 } | 397 } |
382 }); | 398 }); |
383 } | 399 } |
384 | 400 |
385 /** | 401 /** |
386 * Checks the current test has |clazz| annotation. Note this swallows NoSuch MethodException | 402 * Checks the current test has |clazz| annotation. Note this swallows NoSuch MethodException |
387 * and returns false in that case. | 403 * and returns false in that case. |
388 */ | 404 */ |
389 private boolean testMethodHasAnnotation(Class<? extends Annotation> clazz) { | 405 private boolean testMethodHasAnnotation(Class<? extends Annotation> clazz) { |
390 String testName = getName(); | 406 String testName = getName(); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 int titleCallCount = onReceivedTitleHelper.getCallCount(); | 720 int titleCallCount = onReceivedTitleHelper.getCallCount(); |
705 | 721 |
706 onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS , | 722 onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS , |
707 TimeUnit.MILLISECONDS); | 723 TimeUnit.MILLISECONDS); |
708 onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS , | 724 onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS , |
709 TimeUnit.MILLISECONDS); | 725 TimeUnit.MILLISECONDS); |
710 | 726 |
711 return new PopupInfo(popupContentsClient, popupContainerView, popupConte nts); | 727 return new PopupInfo(popupContentsClient, popupContainerView, popupConte nts); |
712 } | 728 } |
713 } | 729 } |
OLD | NEW |