Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.sync; |
michael@0 | 5 | |
michael@0 | 6 | import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; |
michael@0 | 7 | import org.mozilla.gecko.sync.setup.activities.SendTabData; |
michael@0 | 8 | |
michael@0 | 9 | import android.content.Intent; |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * These tests are on device because the Intent, Pattern, and Matcher APIs are |
michael@0 | 13 | * stubs on desktop. |
michael@0 | 14 | */ |
michael@0 | 15 | public class TestSendTabData extends AndroidSyncTestCase { |
michael@0 | 16 | protected static Intent makeShareIntent(String text, String subject, String title) { |
michael@0 | 17 | Intent intent = new Intent(); |
michael@0 | 18 | |
michael@0 | 19 | intent.putExtra(Intent.EXTRA_TEXT, text); |
michael@0 | 20 | intent.putExtra(Intent.EXTRA_SUBJECT, subject); |
michael@0 | 21 | intent.putExtra(Intent.EXTRA_TITLE, title); |
michael@0 | 22 | |
michael@0 | 23 | return intent; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | // From Fennec: |
michael@0 | 27 | // |
michael@0 | 28 | // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. |
michael@0 | 29 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://www.reddit.com/ |
michael@0 | 30 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> reddit: the front page of the internet |
michael@0 | 31 | public void testFennecBrowser() { |
michael@0 | 32 | Intent shareIntent = makeShareIntent("http://www.reddit.com/", |
michael@0 | 33 | "reddit: the front page of the internet", |
michael@0 | 34 | null); |
michael@0 | 35 | SendTabData fromIntent = SendTabData.fromIntent(shareIntent); |
michael@0 | 36 | |
michael@0 | 37 | assertEquals("reddit: the front page of the internet", fromIntent.title); |
michael@0 | 38 | assertEquals("http://www.reddit.com/", fromIntent.uri); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | // From Android Browser: |
michael@0 | 42 | // |
michael@0 | 43 | // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. |
michael@0 | 44 | // 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 | 45 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Hotmail: ONLY SIX PERFORMANCES LEFT! SPECIAL SECOND SHOW OFFER - GET $ |
michael@0 | 46 | public void testAndroidBrowser() { |
michael@0 | 47 | Intent shareIntent = makeShareIntent("http://www.reddit.com/", |
michael@0 | 48 | "reddit: the front page of the internet", |
michael@0 | 49 | null); |
michael@0 | 50 | SendTabData fromIntent = SendTabData.fromIntent(shareIntent); |
michael@0 | 51 | |
michael@0 | 52 | assertEquals("reddit: the front page of the internet", fromIntent.title); |
michael@0 | 53 | assertEquals("http://www.reddit.com/", fromIntent.uri); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // From Pocket: |
michael@0 | 57 | // |
michael@0 | 58 | // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. |
michael@0 | 59 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> http://t.co/bfsbM2oV |
michael@0 | 60 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Launching the Canadian OGP Civil Society Discussion Group |
michael@0 | 61 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TITLE -> Launching the Canadian OGP Civil Society Discussion Group |
michael@0 | 62 | public void testPocket() { |
michael@0 | 63 | Intent shareIntent = makeShareIntent("http://t.co/bfsbM2oV", |
michael@0 | 64 | "Launching the Canadian OGP Civil Society Discussion Group", |
michael@0 | 65 | "Launching the Canadian OGP Civil Society Discussion Group"); |
michael@0 | 66 | SendTabData fromIntent = SendTabData.fromIntent(shareIntent); |
michael@0 | 67 | |
michael@0 | 68 | assertEquals("Launching the Canadian OGP Civil Society Discussion Group", fromIntent.title); |
michael@0 | 69 | assertEquals("http://t.co/bfsbM2oV", fromIntent.uri); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | // A couple of examples from Twitter App: |
michael@0 | 73 | // |
michael@0 | 74 | // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. |
michael@0 | 75 | // I/FxSync (17610): fennec :: SendTabActivity :: android.intent.extra.TEXT = Cory Doctorow (@doctorow) tweeted at 11:21 AM on Sat, Jan 12, 2013: |
michael@0 | 76 | // I/FxSync (17610): Pls RT: @lessig on the DoJ's vindictive prosecution of Aaron Swartz http://t.co/qNalE70n #aaronsw |
michael@0 | 77 | // I/FxSync (17610): (https://twitter.com/doctorow/status/290176681065451520) |
michael@0 | 78 | // I/FxSync (17610): |
michael@0 | 79 | // I/FxSync (17610): Get the official Twitter app at https://twitter.com/download |
michael@0 | 80 | // I/FxSync (17610): fennec :: SendTabActivity :: android.intent.extra.SUBJECT = Tweet from Cory Doctorow (@doctorow) |
michael@0 | 81 | // |
michael@0 | 82 | // I/FxSync ( 7420): fennec :: SendTabActivity :: Send was clicked. |
michael@0 | 83 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.TEXT -> David Eaves (@daeaves) tweeted at 0:08 PM on Fri, Jan 11, 2013: |
michael@0 | 84 | // I/FxSync ( 7420): New on eaves.ca: Launching the Canadian OGP Civil Society Discussion Group http://t.co/bfsbM2oV |
michael@0 | 85 | // I/FxSync ( 7420): (https://twitter.com/daeaves/status/289826143723466752) |
michael@0 | 86 | // I/FxSync ( 7420): |
michael@0 | 87 | // I/FxSync ( 7420): Get the official Twitter app at https://twitter.com/download |
michael@0 | 88 | // I/FxSync ( 7420): fennec :: SendTabActivity :: android.intent.extra.SUBJECT -> Tweet from David Eaves (@daeaves) |
michael@0 | 89 | public void testTwitter() { |
michael@0 | 90 | Intent shareIntent1 = makeShareIntent("Cory Doctorow (@doctorow) tweeted at 11:21 AM on Sat, Jan 12, 2013:\n" + |
michael@0 | 91 | "Pls RT: @lessig on the DoJ's vindictive prosecution of Aaron Swartz http://t.co/qNalE70n #aaronsw\n" + |
michael@0 | 92 | "(https://twitter.com/doctorow/status/290176681065451520)\n" + |
michael@0 | 93 | "\n" + |
michael@0 | 94 | "Get the official Twitter app at https://twitter.com/download", |
michael@0 | 95 | "Tweet from Cory Doctorow (@doctorow)", |
michael@0 | 96 | null); |
michael@0 | 97 | SendTabData fromIntent1 = SendTabData.fromIntent(shareIntent1); |
michael@0 | 98 | |
michael@0 | 99 | assertEquals("Tweet from Cory Doctorow (@doctorow)", fromIntent1.title); |
michael@0 | 100 | assertEquals("http://t.co/qNalE70n", fromIntent1.uri); |
michael@0 | 101 | |
michael@0 | 102 | Intent shareIntent2 = makeShareIntent("David Eaves (@daeaves) tweeted at 0:08 PM on Fri, Jan 11, 2013:\n" + |
michael@0 | 103 | "New on eaves.ca: Launching the Canadian OGP Civil Society Discussion Group http://t.co/bfsbM2oV\n" + |
michael@0 | 104 | "(https://twitter.com/daeaves/status/289826143723466752)\n" + |
michael@0 | 105 | "\n" + |
michael@0 | 106 | "Get the official Twitter app at https://twitter.com/download", |
michael@0 | 107 | "Tweet from David Eaves (@daeaves)", |
michael@0 | 108 | null); |
michael@0 | 109 | SendTabData fromIntent2 = SendTabData.fromIntent(shareIntent2); |
michael@0 | 110 | |
michael@0 | 111 | assertEquals("Tweet from David Eaves (@daeaves)", fromIntent2.title); |
michael@0 | 112 | assertEquals("http://t.co/bfsbM2oV", fromIntent2.uri); |
michael@0 | 113 | } |
michael@0 | 114 | } |