@@ -32,7 +32,7 @@ final class ShareManagerTests: XCTestCase {
3232
3333 // MARK: - Test sharing a file
3434
35- func testGetActivityItems_forFileURL_withNoShareText ( ) throws {
35+ func testGetActivityItems_forFileURL_withNoRemoteURL_withNoShareText ( ) throws {
3636 let testShareActivityType = UIActivity . ActivityType. message
3737
3838 let activityItems = ShareManager . getActivityItems (
@@ -57,6 +57,57 @@ final class ShareManagerTests: XCTestCase {
5757 XCTAssertTrue ( itemForShareActivity is NSNull )
5858 }
5959
60+ func testGetActivityItems_forFileURL_withRemoteURL_withNoShareText( ) throws {
61+ let testShareActivityType = UIActivity . ActivityType. message
62+
63+ // Should be no difference with or without remoteURL
64+ let activityItems = ShareManager . getActivityItems (
65+ forShareType: . file( url: testFileURL, remoteURL: testWebURL) ,
66+ withExplicitShareMessage: nil
67+ )
68+
69+ let urlActivityItemProvider = try XCTUnwrap ( activityItems [ safe: 0 ] as? URLActivityItemProvider )
70+ let itemForURLActivity = urlActivityItemProvider. activityViewController (
71+ createStubActivityViewController ( ) ,
72+ itemForActivityType: testShareActivityType
73+ )
74+
75+ let telemetryActivityItemProvider = try XCTUnwrap ( activityItems [ safe: 1 ] as? ShareTelemetryActivityItemProvider )
76+ let itemForShareActivity = telemetryActivityItemProvider. activityViewController (
77+ createStubActivityViewController ( ) ,
78+ itemForActivityType: testShareActivityType
79+ )
80+
81+ XCTAssertEqual ( activityItems. count, 2 )
82+ XCTAssertEqual ( itemForURLActivity as? URL , testFileURL)
83+ XCTAssertTrue ( itemForShareActivity is NSNull )
84+ }
85+
86+ func testGetActivityItems_forFileURL_withRemoteURL_withNoShareText( ) throws {
87+ let testShareActivityType = UIActivity . ActivityType. message
88+
89+ let activityItems = ShareManager . getActivityItems (
90+ forShareType: . file( url: testFileURL, remoteURL: testWebURL) ,
91+ withExplicitShareMessage: nil
92+ )
93+
94+ let urlActivityItemProvider = try XCTUnwrap ( activityItems [ safe: 0 ] as? URLActivityItemProvider )
95+ let itemForURLActivity = urlActivityItemProvider. activityViewController (
96+ createStubActivityViewController ( ) ,
97+ itemForActivityType: testShareActivityType
98+ )
99+
100+ let telemetryActivityItemProvider = try XCTUnwrap ( activityItems [ safe: 1 ] as? ShareTelemetryActivityItemProvider )
101+ let itemForShareActivity = telemetryActivityItemProvider. activityViewController (
102+ createStubActivityViewController ( ) ,
103+ itemForActivityType: testShareActivityType
104+ )
105+
106+ XCTAssertEqual ( activityItems. count, 2 )
107+ XCTAssertEqual ( itemForURLActivity as? URL , testFileURL)
108+ XCTAssertTrue ( itemForShareActivity is NSNull )
109+ }
110+
60111 func testGetActivityItems_forFileURL_withShareText( ) throws {
61112 let testShareActivityType = UIActivity . ActivityType. mail
62113 let testMessage = " Test message "
@@ -312,6 +363,59 @@ final class ShareManagerTests: XCTestCase {
312363 XCTAssertTrue ( itemForShareActivity is NSNull )
313364 }
314365
366+ // MARK: - Custom SendToDeviceActivity
367+
368+ func testCustomApplicationActivities_forSiteShare( ) throws {
369+ let testShareActivityType = UIActivity . ActivityType ( " org.mozilla.ios.Fennec.sendToDevice " )
370+ let testActivityTitle = " Send Link to Device "
371+
372+ let testShareType = ShareType . site ( url: testWebURL)
373+
374+ let activityItems = ShareManager . getApplicationActivities ( forShareType: testShareType)
375+
376+ let customActivityType = try XCTUnwrap ( activityItems [ safe: 0 ] as? SendToDeviceActivity )
377+ XCTAssertEqual ( activityItems. count, 1 )
378+ XCTAssertEqual ( customActivityType. activityTitle, testActivityTitle)
379+ XCTAssertEqual ( customActivityType. activityType, testShareActivityType)
380+ }
381+
382+ func testCustomApplicationActivities_forTabShare( ) throws {
383+ let testShareActivityType = UIActivity . ActivityType ( " org.mozilla.ios.Fennec.sendToDevice " )
384+ let testActivityTitle = " Send Link to Device "
385+
386+ let testShareType = ShareType . tab ( url: testWebURL, tab: testTab)
387+
388+ let activityItems = ShareManager . getApplicationActivities ( forShareType: testShareType)
389+
390+ let customActivityType = try XCTUnwrap ( activityItems [ safe: 0 ] as? SendToDeviceActivity )
391+ XCTAssertEqual ( activityItems. count, 1 )
392+ XCTAssertEqual ( customActivityType. activityTitle, testActivityTitle)
393+ XCTAssertEqual ( customActivityType. activityType, testShareActivityType)
394+ }
395+
396+ func testCustomApplicationActivities_forFileShareWithRemoteURL_AddsSendToDevice( ) throws {
397+ let testShareActivityType = UIActivity . ActivityType ( " org.mozilla.ios.Fennec.sendToDevice " )
398+ let testActivityTitle = " Send Link to Device "
399+
400+ let testShareType = ShareType . file ( url: testFileURL, remoteURL: testWebURL)
401+
402+ let activityItems = ShareManager . getApplicationActivities ( forShareType: testShareType)
403+
404+ let customActivityType = try XCTUnwrap ( activityItems [ safe: 0 ] as? SendToDeviceActivity )
405+ XCTAssertEqual ( activityItems. count, 1 )
406+ XCTAssertEqual ( customActivityType. activityTitle, testActivityTitle)
407+ XCTAssertEqual ( customActivityType. activityType, testShareActivityType)
408+ }
409+
410+ func testCustomApplicationActivities_forFileShareWithNoRemoteURL_DoesNotAddSendToDevice( ) throws {
411+ // Simulate file share for downloaded files
412+ let testShareType = ShareType . file ( url: testFileURL, remoteURL: nil )
413+
414+ let activityItems = ShareManager . getApplicationActivities ( forShareType: testShareType)
415+
416+ XCTAssertEqual ( activityItems. count, 0 )
417+ }
418+
315419 // MARK: - Helpers
316420
317421 private func createStubActivityViewController( ) -> UIActivityViewController {
0 commit comments