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