mobile/android/tests/background/junit3/src/sync/TestSendTabData.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/tests/background/junit3/src/sync/TestSendTabData.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +package org.mozilla.gecko.background.sync;
     1.8 +
     1.9 +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
    1.10 +import org.mozilla.gecko.sync.setup.activities.SendTabData;
    1.11 +
    1.12 +import android.content.Intent;
    1.13 +
    1.14 +/**
    1.15 + * These tests are on device because the Intent, Pattern, and Matcher APIs are
    1.16 + * stubs on desktop.
    1.17 + */
    1.18 +public class TestSendTabData extends AndroidSyncTestCase {
    1.19 +  protected static Intent makeShareIntent(String text, String subject, String title) {
    1.20 +    Intent intent = new Intent();
    1.21 +
    1.22 +    intent.putExtra(Intent.EXTRA_TEXT, text);
    1.23 +    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    1.24 +    intent.putExtra(Intent.EXTRA_TITLE, title);
    1.25 +
    1.26 +    return intent;
    1.27 +  }
    1.28 +
    1.29 +  //  From Fennec:
    1.30 +  //
    1.31 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: Send was clicked.
    1.32 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://www.reddit.com/
    1.33 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> reddit: the front page of the internet
    1.34 +  public void testFennecBrowser() {
    1.35 +    Intent shareIntent = makeShareIntent("http://www.reddit.com/",
    1.36 +        "reddit: the front page of the internet",
    1.37 +        null);
    1.38 +    SendTabData fromIntent = SendTabData.fromIntent(shareIntent);
    1.39 +
    1.40 +    assertEquals("reddit: the front page of the internet", fromIntent.title);
    1.41 +    assertEquals("http://www.reddit.com/", fromIntent.uri);
    1.42 +  }
    1.43 +
    1.44 +  //  From Android Browser:
    1.45 +  //
    1.46 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: Send was clicked.
    1.47 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://bl176w.blu176.mail.live.com/m/messages.m/?mid=m95277577-e5a5-11e1-bfeb-00237de49bb0&mts=2012-08-14T00%3a18%3a44.390Z&fid=00000000-0000-0000-0000-000000000001&iru=%2fm%2ffolders.m%2f&pmid=m173216c1-e5ea-11e1-bac7-002264c17c66&pmts=2012-08-14T08%3a29%3a01.057Z&nmid=m0e0a4a3a-e511-11e1-bfe5-00237de3362a&nmts=2012-08-13T06%3a44%3a51.910Z
    1.48 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Hotmail: ONLY SIX PERFORMANCES LEFT! SPECIAL SECOND SHOW OFFER - GET $
    1.49 +  public void testAndroidBrowser() {
    1.50 +    Intent shareIntent = makeShareIntent("http://www.reddit.com/",
    1.51 +        "reddit: the front page of the internet",
    1.52 +        null);
    1.53 +    SendTabData fromIntent = SendTabData.fromIntent(shareIntent);
    1.54 +
    1.55 +    assertEquals("reddit: the front page of the internet", fromIntent.title);
    1.56 +    assertEquals("http://www.reddit.com/", fromIntent.uri);
    1.57 +  }
    1.58 +
    1.59 +  //  From Pocket:
    1.60 +  //
    1.61 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: Send was clicked.
    1.62 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://t.co/bfsbM2oV
    1.63 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Launching the Canadian OGP Civil Society Discussion Group
    1.64 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.TITLE -> Launching the Canadian OGP Civil Society Discussion Group
    1.65 +  public void testPocket() {
    1.66 +    Intent shareIntent = makeShareIntent("http://t.co/bfsbM2oV",
    1.67 +        "Launching the Canadian OGP Civil Society Discussion Group",
    1.68 +        "Launching the Canadian OGP Civil Society Discussion Group");
    1.69 +    SendTabData fromIntent = SendTabData.fromIntent(shareIntent);
    1.70 +
    1.71 +    assertEquals("Launching the Canadian OGP Civil Society Discussion Group", fromIntent.title);
    1.72 +    assertEquals("http://t.co/bfsbM2oV", fromIntent.uri);
    1.73 +  }
    1.74 +
    1.75 +  //  A couple of examples from Twitter App:
    1.76 +  //
    1.77 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: Send was clicked.
    1.78 +  //  I/FxSync  (17610): fennec :: SendTabActivity :: android.intent.extra.TEXT = Cory Doctorow (@doctorow) tweeted at 11:21 AM on Sat, Jan 12, 2013:
    1.79 +  //  I/FxSync  (17610): Pls RT: @lessig on the DoJ's vindictive prosecution of Aaron Swartz http://t.co/qNalE70n #aaronsw
    1.80 +  //  I/FxSync  (17610): (https://twitter.com/doctorow/status/290176681065451520)
    1.81 +  //  I/FxSync  (17610):
    1.82 +  //  I/FxSync  (17610): Get the official Twitter app at https://twitter.com/download
    1.83 +  //  I/FxSync  (17610): fennec :: SendTabActivity :: android.intent.extra.SUBJECT = Tweet from Cory Doctorow (@doctorow)
    1.84 +  //
    1.85 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: Send was clicked.
    1.86 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> David Eaves (@daeaves) tweeted at 0:08 PM on Fri, Jan 11, 2013:
    1.87 +  //  I/FxSync  ( 7420): New on eaves.ca: Launching the Canadian OGP Civil Society Discussion Group http://t.co/bfsbM2oV
    1.88 +  //  I/FxSync  ( 7420): (https://twitter.com/daeaves/status/289826143723466752)
    1.89 +  //  I/FxSync  ( 7420):
    1.90 +  //  I/FxSync  ( 7420): Get the official Twitter app at https://twitter.com/download
    1.91 +  //  I/FxSync  ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Tweet from David Eaves (@daeaves)
    1.92 +  public void testTwitter() {
    1.93 +    Intent shareIntent1 = makeShareIntent("Cory Doctorow (@doctorow) tweeted at 11:21 AM on Sat, Jan 12, 2013:\n" +
    1.94 +        "Pls RT: @lessig on the DoJ's vindictive prosecution of Aaron Swartz http://t.co/qNalE70n #aaronsw\n" +
    1.95 +        "(https://twitter.com/doctorow/status/290176681065451520)\n" +
    1.96 +        "\n" +
    1.97 +        "Get the official Twitter app at https://twitter.com/download",
    1.98 +        "Tweet from Cory Doctorow (@doctorow)",
    1.99 +        null);
   1.100 +    SendTabData fromIntent1 = SendTabData.fromIntent(shareIntent1);
   1.101 +
   1.102 +    assertEquals("Tweet from Cory Doctorow (@doctorow)", fromIntent1.title);
   1.103 +    assertEquals("http://t.co/qNalE70n", fromIntent1.uri);
   1.104 +
   1.105 +    Intent shareIntent2 = makeShareIntent("David Eaves (@daeaves) tweeted at 0:08 PM on Fri, Jan 11, 2013:\n" +
   1.106 +        "New on eaves.ca: Launching the Canadian OGP Civil Society Discussion Group http://t.co/bfsbM2oV\n" +
   1.107 +        "(https://twitter.com/daeaves/status/289826143723466752)\n" +
   1.108 +        "\n" +
   1.109 +        "Get the official Twitter app at https://twitter.com/download",
   1.110 +        "Tweet from David Eaves (@daeaves)",
   1.111 +        null);
   1.112 +    SendTabData fromIntent2 = SendTabData.fromIntent(shareIntent2);
   1.113 +
   1.114 +    assertEquals("Tweet from David Eaves (@daeaves)", fromIntent2.title);
   1.115 +    assertEquals("http://t.co/bfsbM2oV", fromIntent2.uri);
   1.116 +  }
   1.117 +}

mercurial