Bug 1391421 - Part 10 - Add a basic Robocop test for IDN domain support. r?gbrown draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 15 Sep 2017 23:29:01 +0200
changeset 665946 a6a4e7c5debcf25638a2fcfbd2f2bfad86dee6c7
parent 665944 204e8544b1f33ccbd993b736b0398925924c8047
child 665947 f0aef4d92bcf4e51ff872d63b9622c02e51eae2b
push id80227
push usermozilla@buttercookie.de
push dateSat, 16 Sep 2017 15:01:54 +0000
reviewersgbrown
bugs1391421
milestone57.0a1
Bug 1391421 - Part 10 - Add a basic Robocop test for IDN domain support. r?gbrown MozReview-Commit-ID: HAT9Imh9YVf
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/ToolbarComponent.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testIdnSupport.java
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -37,16 +37,17 @@ skip-if = android_version == "18"
 [src/org/mozilla/gecko/tests/testFlingCorrectness.java]
 skip-if = true # Bug 1390059
 [src/org/mozilla/gecko/tests/testFormHistory.java]
 [src/org/mozilla/gecko/tests/testGetUserMedia.java]
 # failures across the board, bug 1092202 & bug 1144926
 skip-if = true
 # [src/org/mozilla/gecko/tests/testHistory.java] # see bug 915350
 [src/org/mozilla/gecko/tests/testHomeBanner.java]
+[src/org/mozilla/gecko/tests/testIdnSupport.java]
 [src/org/mozilla/gecko/tests/testInputUrlBar.java]
 [src/org/mozilla/gecko/tests/testJarReader.java]
 [src/org/mozilla/gecko/tests/testLinkContextMenu.java]
 # [src/org/mozilla/gecko/tests/testHomeListsProvider.java] # see bug 952310
 [src/org/mozilla/gecko/tests/testLoad.java]
 skip-if = true # Bug 1390059
 [src/org/mozilla/gecko/tests/testMailToContextMenu.java]
 [src/org/mozilla/gecko/tests/testNewTab.java]
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/ToolbarComponent.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/components/ToolbarComponent.java
@@ -12,25 +12,28 @@ import static org.mozilla.gecko.tests.he
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.tests.UITestContext;
 import org.mozilla.gecko.tests.helpers.DeviceHelper;
 import org.mozilla.gecko.tests.helpers.NavigationHelper;
 import org.mozilla.gecko.tests.helpers.WaitHelper;
 import org.mozilla.gecko.toolbar.PageActionLayout;
 import org.mozilla.gecko.toolbar.TabCounter;
 
+import android.net.Uri;
 import android.view.View;
 import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.TextSwitcher;
 import android.widget.TextView;
 
 import com.robotium.solo.Condition;
 import com.robotium.solo.Solo;
 
+import java.net.IDN;
+
 /**
  * A class representing any interactions that take place on the Toolbar.
  */
 public class ToolbarComponent extends BaseComponent {
     public static final String URL_HTTP_PREFIX = "http://";
 
     // We are waiting up to 30 seconds instead of the default waiting time because reader mode
     // parsing can take quite some time on slower devices (Bug 1142699)
@@ -251,18 +254,21 @@ public class ToolbarComponent extends Ba
         fAssertNotNull("url is not null", url);
 
         assertIsEditing();
 
         final EditText urlEditText = getUrlEditText();
         fAssertTrue("The UrlEditText is the input method target",
                 urlEditText.isInputMethodTarget());
 
+        // Solo doesn't handle typing text with Unicode characters, so if the input looks like a
+        // genuine URL, we work around this by converting it to Punycode beforehand.
+        final String textToType = url.contains("://") ? convertUrlToPunycode(url) : url;
         mSolo.clearEditText(urlEditText);
-        mSolo.typeText(urlEditText, url);
+        mSolo.typeText(urlEditText, textToType);
 
         return this;
     }
 
     public ToolbarComponent pressBackButton() {
         final ImageButton backButton = getBackButton();
         return pressButton(backButton, "back");
     }
@@ -334,9 +340,16 @@ public class ToolbarComponent extends Ba
 
     private boolean isUrlEditTextSelected() {
         return getUrlEditText().isSelected();
     }
 
     private boolean isBackButtonEnabled() {
         return getBackButton().isEnabled();
     }
+
+    private String convertUrlToPunycode(final String url) {
+        final Uri uri = Uri.parse(url);
+        final Uri.Builder uriBuilder = uri.buildUpon();
+        uriBuilder.authority(IDN.toASCII(uri.getAuthority()));
+        return uriBuilder.toString();
+    }
 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testIdnSupport.java
@@ -0,0 +1,25 @@
+package org.mozilla.gecko.tests;
+
+import org.mozilla.gecko.tests.helpers.GeckoHelper;
+import org.mozilla.gecko.tests.helpers.NavigationHelper;
+
+public class testIdnSupport extends UITest {
+    public void testToolbarIdnSupport() {
+        GeckoHelper.blockForReady();
+
+        mBaseHostnameUrl = "http://exämple.test/tests";
+        String url = mStringHelper.ROBOCOP_BLANK_PAGE_01_URL;
+        NavigationHelper.enterAndLoadUrl(url);
+        mToolbar.assertTitle(url);
+
+        mBaseHostnameUrl = "http://παράδειγμα.δοκιμή/tests";
+        url = mStringHelper.ROBOCOP_BLANK_PAGE_02_URL;
+        NavigationHelper.enterAndLoadUrl(url);
+        mToolbar.assertTitle(url);
+
+        mBaseHostnameUrl = "http://天気の良い日.w3c-test.org/tests";
+        url = mStringHelper.ROBOCOP_BLANK_PAGE_03_URL;
+        NavigationHelper.enterAndLoadUrl(url);
+        mToolbar.assertTitle(url);
+    }
+}