Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java

Issue 1907703002: Fix a nasty scroll bug for Chrome Now-on-tap feature. Also combine the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add hint back Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.content.Context; 7 import android.content.Context;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.graphics.BitmapFactory; 9 import android.graphics.BitmapFactory;
10 import android.graphics.Canvas; 10 import android.graphics.Canvas;
(...skipping 17 matching lines...) Expand all
28 import org.chromium.android_webview.test.util.CommonResources; 28 import org.chromium.android_webview.test.util.CommonResources;
29 import org.chromium.android_webview.test.util.JSUtils; 29 import org.chromium.android_webview.test.util.JSUtils;
30 import org.chromium.base.annotations.SuppressFBWarnings; 30 import org.chromium.base.annotations.SuppressFBWarnings;
31 import org.chromium.base.test.util.CommandLineFlags; 31 import org.chromium.base.test.util.CommandLineFlags;
32 import org.chromium.base.test.util.Feature; 32 import org.chromium.base.test.util.Feature;
33 import org.chromium.base.test.util.parameter.ParameterizedTest; 33 import org.chromium.base.test.util.parameter.ParameterizedTest;
34 import org.chromium.content.browser.BindingManager; 34 import org.chromium.content.browser.BindingManager;
35 import org.chromium.content.browser.ChildProcessConnection; 35 import org.chromium.content.browser.ChildProcessConnection;
36 import org.chromium.content.browser.ChildProcessLauncher; 36 import org.chromium.content.browser.ChildProcessLauncher;
37 import org.chromium.content.browser.test.util.CallbackHelper; 37 import org.chromium.content.browser.test.util.CallbackHelper;
38 import org.chromium.content_public.browser.AccessibilitySnapshotCallback;
39 import org.chromium.content_public.browser.AccessibilitySnapshotNode;
40 import org.chromium.net.test.util.TestWebServer; 38 import org.chromium.net.test.util.TestWebServer;
41 39
42 import java.io.InputStream; 40 import java.io.InputStream;
43 import java.net.URL; 41 import java.net.URL;
44 import java.util.ArrayList; 42 import java.util.ArrayList;
45 import java.util.HashMap; 43 import java.util.HashMap;
46 import java.util.List; 44 import java.util.List;
47 import java.util.Map; 45 import java.util.Map;
48 import java.util.concurrent.Callable; 46 import java.util.concurrent.Callable;
49 import java.util.concurrent.Semaphore; 47 import java.util.concurrent.Semaphore;
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 607
610 assertTrue(bindingManager.isChildProcessCreated()); 608 assertTrue(bindingManager.isChildProcessCreated());
611 609
612 // Test end-to-end interaction with the renderer. 610 // Test end-to-end interaction with the renderer.
613 AwSettings awSettings = getAwSettingsOnUiThread(awContents); 611 AwSettings awSettings = getAwSettingsOnUiThread(awContents);
614 awSettings.setJavaScriptEnabled(true); 612 awSettings.setJavaScriptEnabled(true);
615 assertEquals("42", JSUtils.executeJavaScriptAndWaitForResult(this, awCon tents, 613 assertEquals("42", JSUtils.executeJavaScriptAndWaitForResult(this, awCon tents,
616 mContentsClient.getOnEvaluateJavaScriptResultHelper(), " 21 + 21")); 614 mContentsClient.getOnEvaluateJavaScriptResultHelper(), " 21 + 21"));
617 } 615 }
618 616
619 private static class AccessibilityCallbackHelper extends CallbackHelper {
620
621 private AccessibilitySnapshotNode mRoot;
622
623 public void notifyCalled(AccessibilitySnapshotNode root) {
624 mRoot = root;
625 super.notifyCalled();
626 }
627
628 public AccessibilitySnapshotNode getValue() {
629 return mRoot;
630 }
631 }
632
633 private float mPageScale;
634
635 private AccessibilitySnapshotNode receiveAccessibilitySnapshot(String data, String js)
636 throws Throwable {
637 final AwTestContainerView testView = createAwTestContainerViewOnMainSync (mContentsClient);
638 final AwContents awContents = testView.getAwContents();
639 final CallbackHelper loadHelper = mContentsClient.getOnPageFinishedHelpe r();
640 AwSettings awSettings = getAwSettingsOnUiThread(awContents);
641 awSettings.setJavaScriptEnabled(true);
642 if (data != null) {
643 loadDataSync(awContents, loadHelper, data, "text/html", false);
644 }
645 if (js != null) {
646 executeJavaScriptAndWaitForResult(awContents, mContentsClient, js);
647 }
648
649 final AccessibilityCallbackHelper callbackHelper = new AccessibilityCall backHelper();
650 final AccessibilitySnapshotCallback callback = new AccessibilitySnapshot Callback() {
651 @Override
652 public void onAccessibilitySnapshot(AccessibilitySnapshotNode root) {
653 callbackHelper.notifyCalled(root);
654 }
655 };
656 // read the callbackcount before executing the call on UI thread, since it may
657 // synchronously complete.
658 final int callbackCount = callbackHelper.getCallCount();
659 runTestOnUiThread(new Runnable() {
660 @Override
661 public void run() {
662 awContents.requestAccessibilitySnapshot(callback);
663 mPageScale = awContents.getScale();
664 }
665 });
666 callbackHelper.waitForCallback(callbackCount);
667 return callbackHelper.getValue();
668 }
669
670 /**
671 * Verifies that AX tree is returned.
672 */
673 @Feature({"AndroidWebView"})
674 @SmallTest
675 public void testRequestAccessibilitySnapshot() throws Throwable {
676 final String data = "<button>Click</button>";
677 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
678 assertEquals(1, root.children.size());
679 assertEquals("", root.text);
680 AccessibilitySnapshotNode child = root.children.get(0);
681 assertEquals(1, child.children.size());
682 assertEquals("", child.text);
683 AccessibilitySnapshotNode grandChild = child.children.get(0);
684 assertEquals(0, grandChild.children.size());
685 assertEquals("Click", grandChild.text);
686 }
687
688 @Feature({"AndroidWebView"})
689 @SmallTest
690 public void testRequestAccessibilitySnapshotColors() throws Throwable {
691 final String data = "<p style=\"color:#123456;background:#abcdef\">color </p>";
692 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
693 assertEquals(1, root.children.size());
694 assertEquals("", root.text);
695 AccessibilitySnapshotNode child = root.children.get(0);
696 assertEquals("color", child.text);
697 assertTrue(child.hasStyle);
698 assertEquals("ff123456", Integer.toHexString(child.color));
699 assertEquals("ffabcdef", Integer.toHexString(child.bgcolor));
700 }
701
702 @Feature({"AndroidWebView"})
703 @SmallTest
704 public void testRequestAccessibilitySnapshotFontSize() throws Throwable {
705 final String data =
706 "<html><head><style> "
707 + " body { font-size:11px; }"
708 + " </style></head><body><p>foo</p></body></html>";
709 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
710 assertEquals(1, root.children.size());
711 assertEquals("", root.text);
712 AccessibilitySnapshotNode child = root.children.get(0);
713 assertTrue(child.hasStyle);
714 assertEquals("foo", child.text);
715 assertEquals(11.0 * mPageScale, child.textSize, 0.01);
716 }
717
718 @Feature({"AndroidWebView"})
719 @SmallTest
720 public void testRequestAccessibilitySnapshotStyles() throws Throwable {
721 final String data =
722 "<html><head><style> "
723 + " body { font: italic bold 12px Courier; }"
724 + " </style></head><body><p>foo</p></body></html>";
725 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
726 assertEquals(1, root.children.size());
727 assertEquals("", root.text);
728 AccessibilitySnapshotNode child = root.children.get(0);
729 assertEquals("foo", child.text);
730 assertTrue(child.hasStyle);
731 assertTrue(child.bold);
732 assertTrue(child.italic);
733 assertFalse(child.lineThrough);
734 assertFalse(child.underline);
735 }
736
737 @Feature({"AndroidWebView"})
738 @SmallTest
739 public void testRequestAccessibilitySnapshotStrongStyle() throws Throwable {
740 final String data = "<html><body><p>foo</p><p><strong>bar</strong></p></ body></html>";
741 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
742 assertEquals(2, root.children.size());
743 assertEquals("", root.text);
744 AccessibilitySnapshotNode child1 = root.children.get(0);
745 assertEquals("foo", child1.text);
746 assertTrue(child1.hasStyle);
747 assertFalse(child1.bold);
748 AccessibilitySnapshotNode child2 = root.children.get(1);
749 AccessibilitySnapshotNode child2child = child2.children.get(0);
750 assertEquals("bar", child2child.text);
751 assertEquals(child1.textSize, child2child.textSize);
752 assertTrue(child2child.bold);
753 }
754
755 @Feature({"AndroidWebView"})
756 @SmallTest
757 public void testRequestAccessibilitySnapshotItalicStyle() throws Throwable {
758 final String data = "<html><body><i>foo</i></body></html>";
759 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
760 assertEquals(1, root.children.size());
761 assertEquals("", root.text);
762 AccessibilitySnapshotNode child = root.children.get(0);
763 AccessibilitySnapshotNode grandchild = child.children.get(0);
764 assertEquals("foo", grandchild.text);
765 assertTrue(grandchild.hasStyle);
766 assertTrue(grandchild.italic);
767 }
768
769 @Feature({"AndroidWebView"})
770 @SmallTest
771 public void testRequestAccessibilitySnapshotBoldStyle() throws Throwable {
772 final String data = "<html><body><b>foo</b></body></html>";
773 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
774 assertEquals(1, root.children.size());
775 assertEquals("", root.text);
776 AccessibilitySnapshotNode child = root.children.get(0);
777 AccessibilitySnapshotNode grandchild = child.children.get(0);
778 assertEquals("foo", grandchild.text);
779 assertTrue(grandchild.hasStyle);
780 assertTrue(grandchild.bold);
781 }
782
783 @Feature({"AndroidWebView"})
784 @SmallTest
785 public void testRequestAccessibilitySnapshotNoStyle() throws Throwable {
786 final String data = "<table><thead></thead></table>";
787 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
788 assertEquals(1, root.children.size());
789 assertEquals("", root.text);
790 AccessibilitySnapshotNode grandChild = root.children.get(0).children.get (0);
791 assertFalse(grandChild.hasStyle);
792 }
793
794 @Feature({"AndroidWebView"})
795 @SmallTest
796 public void testRequestAccessibilitySnapshotAboutBlank() throws Throwable {
797 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(null, null );
798 assertEquals(null, root);
799 }
800
801 private String getSelectionScript(String node1, int start, String node2, int end) {
802 return "var element1 = document.getElementById('" + node1 + "');"
803 + "var node1 = element1.childNodes.item(0);"
804 + "var range=document.createRange();"
805 + "range.setStart(node1," + start + ");"
806 + "var element2 = document.getElementById('" + node2 + "');"
807 + "var node2 = element2.childNodes.item(0);"
808 + "range.setEnd(node2," + end + ");"
809 + "var selection=window.getSelection();"
810 + "selection.removeAllRanges();"
811 + "selection.addRange(range);";
812 }
813
814 @Feature({"AndroidWebView"})
815 @SmallTest
816 public void testRequestAccessibilitySnapshotOneCharacterSelection() throws T hrowable {
817 final String data = "<html><body><b id='node'>foo</b></body></html>";
818
819 AccessibilitySnapshotNode root =
820 receiveAccessibilitySnapshot(data, getSelectionScript("node", 0, "node", 1));
821 assertEquals(1, root.children.size());
822 assertEquals("", root.text);
823 AccessibilitySnapshotNode child = root.children.get(0);
824 AccessibilitySnapshotNode grandchild = child.children.get(0);
825 assertEquals("foo", grandchild.text);
826 assertEquals(0, grandchild.startSelection);
827 assertEquals(1, grandchild.endSelection);
828 }
829
830 @Feature({"AndroidWebView"})
831 @SmallTest
832 public void testRequestAccessibilitySnapshotOneNodeSelection() throws Throwa ble {
833 final String data = "<html><body><b id='node'>foo</b></body></html>";
834
835 AccessibilitySnapshotNode root =
836 receiveAccessibilitySnapshot(data, getSelectionScript("node", 0, "node", 3));
837 assertEquals(1, root.children.size());
838 assertEquals("", root.text);
839 AccessibilitySnapshotNode child = root.children.get(0);
840 AccessibilitySnapshotNode grandchild = child.children.get(0);
841 assertEquals("foo", grandchild.text);
842 assertEquals(0, grandchild.startSelection);
843 assertEquals(3, grandchild.endSelection);
844 }
845
846 @Feature({"AndroidWebView"})
847 @SmallTest
848 public void testRequestAccessibilitySnapshotSubsequentNodeSelection() throws Throwable {
849 final String data = "<html><body><b id='node1'>foo</b><b id='node2'>bar< /b></body></html>";
850
851 AccessibilitySnapshotNode root =
852 receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1 , "node2", 1));
853 assertEquals(1, root.children.size());
854 assertEquals("", root.text);
855 AccessibilitySnapshotNode child = root.children.get(0);
856 AccessibilitySnapshotNode grandchild = child.children.get(0);
857 assertEquals("foo", grandchild.text);
858 assertEquals(1, grandchild.startSelection);
859 assertEquals(3, grandchild.endSelection);
860 grandchild = child.children.get(1);
861 assertEquals("bar", grandchild.text);
862 assertEquals(0, grandchild.startSelection);
863 assertEquals(1, grandchild.endSelection);
864 }
865
866 @Feature({"AndroidWebView"})
867 @SmallTest
868 public void testRequestAccessibilitySnapshotMultiNodeSelection() throws Thro wable {
869 final String data =
870 "<html><body><b id='node1'>foo</b><b>middle</b><b id='node2'>bar </b></body></html>";
871
872 AccessibilitySnapshotNode root =
873 receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1 , "node2", 1));
874 assertEquals(1, root.children.size());
875 assertEquals("", root.text);
876 AccessibilitySnapshotNode child = root.children.get(0);
877 AccessibilitySnapshotNode grandchild = child.children.get(0);
878 assertEquals("foo", grandchild.text);
879 assertEquals(1, grandchild.startSelection);
880 assertEquals(3, grandchild.endSelection);
881 grandchild = child.children.get(1);
882 assertEquals("middle", grandchild.text);
883 assertEquals(0, grandchild.startSelection);
884 assertEquals(6, grandchild.endSelection);
885 grandchild = child.children.get(2);
886 assertEquals("bar", grandchild.text);
887 assertEquals(0, grandchild.startSelection);
888 assertEquals(1, grandchild.endSelection);
889 }
890
891 @Feature({"AndroidWebView"})
892 @SmallTest
893 public void testRequestAccessibilitySnapshotInputSelection() throws Throwabl e {
894 final String data = "<html><body><input id='input' value='Hello, world'> </body></html>";
895 final String js = "var input = document.getElementById('input');"
896 + "input.select();"
897 + "input.selectionStart = 0;"
898 + "input.selectionEnd = 5;";
899 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, js);
900 assertEquals(1, root.children.size());
901 assertEquals("", root.text);
902 AccessibilitySnapshotNode child = root.children.get(0);
903 AccessibilitySnapshotNode grandchild = child.children.get(0);
904 assertEquals("Hello, world", grandchild.text);
905 assertEquals(0, grandchild.startSelection);
906 assertEquals(5, grandchild.endSelection);
907 }
908
909 @Feature({"AndroidWebView"})
910 @SmallTest
911 public void testRequestAccessibilitySnapshotPasswordField() throws Throwable {
912 final String data =
913 "<html><body><input id='input' type='password' value='foo'></bod y></html>";
914 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null );
915 assertEquals(1, root.children.size());
916 assertEquals("", root.text);
917 AccessibilitySnapshotNode child = root.children.get(0);
918 AccessibilitySnapshotNode grandchild = child.children.get(0);
919 assertEquals("•••", grandchild.text);
920 }
921 } 617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698