michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.sync; michael@0: michael@0: import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; michael@0: import org.mozilla.gecko.sync.setup.activities.SendTabData; michael@0: michael@0: import android.content.Intent; michael@0: michael@0: /** michael@0: * These tests are on device because the Intent, Pattern, and Matcher APIs are michael@0: * stubs on desktop. michael@0: */ michael@0: public class TestSendTabData extends AndroidSyncTestCase { michael@0: protected static Intent makeShareIntent(String text, String subject, String title) { michael@0: Intent intent = new Intent(); michael@0: michael@0: intent.putExtra(Intent.EXTRA_TEXT, text); michael@0: intent.putExtra(Intent.EXTRA_SUBJECT, subject); michael@0: intent.putExtra(Intent.EXTRA_TITLE, title); michael@0: michael@0: return intent; michael@0: } michael@0: michael@0: // From Fennec: michael@0: // michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://www.reddit.com/ michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> reddit: the front page of the internet michael@0: public void testFennecBrowser() { michael@0: Intent shareIntent = makeShareIntent("http://www.reddit.com/", michael@0: "reddit: the front page of the internet", michael@0: null); michael@0: SendTabData fromIntent = SendTabData.fromIntent(shareIntent); michael@0: michael@0: assertEquals("reddit: the front page of the internet", fromIntent.title); michael@0: assertEquals("http://www.reddit.com/", fromIntent.uri); michael@0: } michael@0: michael@0: // From Android Browser: michael@0: // michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. michael@0: // 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 michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Hotmail: ONLY SIX PERFORMANCES LEFT! SPECIAL SECOND SHOW OFFER - GET $ michael@0: public void testAndroidBrowser() { michael@0: Intent shareIntent = makeShareIntent("http://www.reddit.com/", michael@0: "reddit: the front page of the internet", michael@0: null); michael@0: SendTabData fromIntent = SendTabData.fromIntent(shareIntent); michael@0: michael@0: assertEquals("reddit: the front page of the internet", fromIntent.title); michael@0: assertEquals("http://www.reddit.com/", fromIntent.uri); michael@0: } michael@0: michael@0: // From Pocket: michael@0: // michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://t.co/bfsbM2oV michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Launching the Canadian OGP Civil Society Discussion Group michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TITLE -> Launching the Canadian OGP Civil Society Discussion Group michael@0: public void testPocket() { michael@0: Intent shareIntent = makeShareIntent("http://t.co/bfsbM2oV", michael@0: "Launching the Canadian OGP Civil Society Discussion Group", michael@0: "Launching the Canadian OGP Civil Society Discussion Group"); michael@0: SendTabData fromIntent = SendTabData.fromIntent(shareIntent); michael@0: michael@0: assertEquals("Launching the Canadian OGP Civil Society Discussion Group", fromIntent.title); michael@0: assertEquals("http://t.co/bfsbM2oV", fromIntent.uri); michael@0: } michael@0: michael@0: // A couple of examples from Twitter App: michael@0: // michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. michael@0: // I/FxSync (17610): fennec :: SendTabActivity :: android.intent.extra.TEXT = Cory Doctorow (@doctorow) tweeted at 11:21 AM on Sat, Jan 12, 2013: michael@0: // I/FxSync (17610): Pls RT: @lessig on the DoJ's vindictive prosecution of Aaron Swartz http://t.co/qNalE70n #aaronsw michael@0: // I/FxSync (17610): (https://twitter.com/doctorow/status/290176681065451520) michael@0: // I/FxSync (17610): michael@0: // I/FxSync (17610): Get the official Twitter app at https://twitter.com/download michael@0: // I/FxSync (17610): fennec :: SendTabActivity :: android.intent.extra.SUBJECT = Tweet from Cory Doctorow (@doctorow) michael@0: // michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> David Eaves (@daeaves) tweeted at 0:08 PM on Fri, Jan 11, 2013: michael@0: // I/FxSync ( 7420): New on eaves.ca: Launching the Canadian OGP Civil Society Discussion Group http://t.co/bfsbM2oV michael@0: // I/FxSync ( 7420): (https://twitter.com/daeaves/status/289826143723466752) michael@0: // I/FxSync ( 7420): michael@0: // I/FxSync ( 7420): Get the official Twitter app at https://twitter.com/download michael@0: // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Tweet from David Eaves (@daeaves) michael@0: public void testTwitter() { michael@0: Intent shareIntent1 = makeShareIntent("Cory Doctorow (@doctorow) tweeted at 11:21 AM on Sat, Jan 12, 2013:\n" + michael@0: "Pls RT: @lessig on the DoJ's vindictive prosecution of Aaron Swartz http://t.co/qNalE70n #aaronsw\n" + michael@0: "(https://twitter.com/doctorow/status/290176681065451520)\n" + michael@0: "\n" + michael@0: "Get the official Twitter app at https://twitter.com/download", michael@0: "Tweet from Cory Doctorow (@doctorow)", michael@0: null); michael@0: SendTabData fromIntent1 = SendTabData.fromIntent(shareIntent1); michael@0: michael@0: assertEquals("Tweet from Cory Doctorow (@doctorow)", fromIntent1.title); michael@0: assertEquals("http://t.co/qNalE70n", fromIntent1.uri); michael@0: michael@0: Intent shareIntent2 = makeShareIntent("David Eaves (@daeaves) tweeted at 0:08 PM on Fri, Jan 11, 2013:\n" + michael@0: "New on eaves.ca: Launching the Canadian OGP Civil Society Discussion Group http://t.co/bfsbM2oV\n" + michael@0: "(https://twitter.com/daeaves/status/289826143723466752)\n" + michael@0: "\n" + michael@0: "Get the official Twitter app at https://twitter.com/download", michael@0: "Tweet from David Eaves (@daeaves)", michael@0: null); michael@0: SendTabData fromIntent2 = SendTabData.fromIntent(shareIntent2); michael@0: michael@0: assertEquals("Tweet from David Eaves (@daeaves)", fromIntent2.title); michael@0: assertEquals("http://t.co/bfsbM2oV", fromIntent2.uri); michael@0: } michael@0: }