diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/ShareManagerTests.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/ShareManagerTests.swift index 305520c924ea..59b17b8582d3 100644 --- a/firefox-ios/firefox-ios-tests/Tests/ClientTests/ShareManagerTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/ShareManagerTests.swift @@ -291,8 +291,12 @@ final class ShareManagerTests: XCTestCase { _ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView) let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider) + let itemForTitleActivity = titleActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: whatsAppActivity + ) XCTAssertEqual( - titleActivityItemProvider.item as? String, + itemForTitleActivity as? String, testWebpageDisplayTitle, "When no explicit share message is set, we expect to see the webpage's title." ) @@ -332,8 +336,12 @@ final class ShareManagerTests: XCTestCase { _ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView) let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider) + let itemForTitleActivity = titleActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: whatsAppActivity + ) XCTAssertEqual( - titleActivityItemProvider.item as? String, + itemForTitleActivity as? String, testWebpageDisplayTitle, "When no explicit share message is set, we expect to see the webpage's title." ) @@ -371,10 +379,13 @@ final class ShareManagerTests: XCTestCase { _ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView) let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider) - XCTAssertEqual( - titleActivityItemProvider.item as? String, - testWebpageDisplayTitle, - "When no explicit share message is set, we expect to see the webpage's title." + let itemForTitleActivity = titleActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: mailActivity + ) + XCTAssertTrue( + itemForTitleActivity is NSNull, + "When no explicit share message, TitleActivityItemProvider item should not be shared to excluded activity Mail." ) } @@ -411,8 +422,12 @@ final class ShareManagerTests: XCTestCase { _ = try XCTUnwrap(activityItems[safe: 2] as? TabWebView) let titleActivityItemProvider = try XCTUnwrap(activityItems[safe: 3] as? TitleActivityItemProvider) + let itemForTitleActivity = titleActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: whatsAppActivity + ) XCTAssertEqual( - titleActivityItemProvider.item as? String, + itemForTitleActivity as? String, testWebpageDisplayTitle, "When no explicit share message is set, we expect to see the webpage's title." ) diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/URLActivityItemProviderTests.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/URLActivityItemProviderTests.swift index a62bcde62c66..412495515894 100644 --- a/firefox-ios/firefox-ios-tests/Tests/ClientTests/URLActivityItemProviderTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/URLActivityItemProviderTests.swift @@ -6,8 +6,8 @@ import UniformTypeIdentifiers import XCTest @testable import Client -// TODO: FXIOS-10816 Flesh out these unit tests final class URLActivityItemProviderTests: XCTestCase { + let testFileURL = URL(string: "file://some/file/url")! let testWebURL = URL(string: "https://mozilla.org")! override func setUp() { @@ -16,9 +16,111 @@ final class URLActivityItemProviderTests: XCTestCase { LegacyFeatureFlagsManager.shared.initializeDeveloperFeatures(with: MockProfile()) } + func testWebURL_forMailActivity() { + let testActivityType = UIActivity.ActivityType.mail + + let urlActivityItemProvider = URLActivityItemProvider(url: testWebURL, allowSentFromFirefoxTreatment: false) + let urlDataIdentifier = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + dataTypeIdentifierForActivityType: testActivityType + ) + let itemForActivity = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: testActivityType + ) + + XCTAssertEqual(urlDataIdentifier, UTType.url.identifier) + XCTAssertEqual(itemForActivity as? URL, testWebURL) + } + + func testWebURL_forMessagesActivity() { + let testActivityType = UIActivity.ActivityType.message + + let urlActivityItemProvider = URLActivityItemProvider(url: testWebURL, allowSentFromFirefoxTreatment: false) + let urlDataIdentifier = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + dataTypeIdentifierForActivityType: testActivityType + ) + let itemForActivity = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: testActivityType + ) + + XCTAssertEqual(urlDataIdentifier, UTType.url.identifier) + XCTAssertEqual(itemForActivity as? URL, testWebURL) + } + + func testFileURL_forMailActivity() { + let testActivityType = UIActivity.ActivityType.mail + + let urlActivityItemProvider = URLActivityItemProvider(url: testFileURL, allowSentFromFirefoxTreatment: false) + let urlDataIdentifier = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + dataTypeIdentifierForActivityType: testActivityType + ) + let itemForActivity = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: testActivityType + ) + + XCTAssertEqual(urlDataIdentifier, UTType.fileURL.identifier) + XCTAssertEqual(itemForActivity as? URL, testFileURL) + } + + func testFileURL_forMessagesActivity() { + let testActivityType = UIActivity.ActivityType.message + + let urlActivityItemProvider = URLActivityItemProvider(url: testFileURL, allowSentFromFirefoxTreatment: false) + let urlDataIdentifier = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + dataTypeIdentifierForActivityType: testActivityType + ) + let itemForActivity = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: testActivityType + ) + + XCTAssertEqual(urlDataIdentifier, UTType.fileURL.identifier) + XCTAssertEqual(itemForActivity as? URL, testFileURL) + } + + func testWebURL_forExcludedActivity() { + let testActivityType = UIActivity.ActivityType.addToReadingList + + let urlActivityItemProvider = URLActivityItemProvider(url: testWebURL, allowSentFromFirefoxTreatment: false) + let urlDataIdentifier = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + dataTypeIdentifierForActivityType: testActivityType + ) + let itemForActivity = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: testActivityType + ) + + XCTAssertEqual(urlDataIdentifier, UTType.url.identifier) + XCTAssertTrue(itemForActivity is NSNull) + } + + func testFileURL_forExcludedActivity() { + let testActivityType = UIActivity.ActivityType.addToReadingList + + let urlActivityItemProvider = URLActivityItemProvider(url: testFileURL, allowSentFromFirefoxTreatment: false) + let urlDataIdentifier = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + dataTypeIdentifierForActivityType: testActivityType + ) + let itemForActivity = urlActivityItemProvider.activityViewController( + createStubActivityViewController(), + itemForActivityType: testActivityType + ) + + XCTAssertEqual(urlDataIdentifier, UTType.fileURL.identifier) + XCTAssertTrue(itemForActivity is NSNull) + } + // MARK: - Sent from Firefox experiment WhatsApp tab share override - func testOveridesWhatsAppShareItem_forTreatmentA() throws { + func testOveridesWhatsAppShareItem_forTreatmentA() { setupNimbusSentFromFirefoxTesting(isEnabled: true, isTreatmentA: true) let expectedShareContentA = "https://mozilla.org Sent from Firefox 🦊 Try the mobile browser: https://mzl.la/4fOWPpd" @@ -33,7 +135,7 @@ final class URLActivityItemProviderTests: XCTestCase { XCTAssertEqual(itemForActivity as? String, expectedShareContentA) } - func testOveridesWhatsAppShareItem_forTreatmentB() throws { + func testOveridesWhatsAppShareItem_forTreatmentB() { setupNimbusSentFromFirefoxTesting(isEnabled: true, isTreatmentA: false) let expectedShareContentB = "https://mozilla.org Sent from Firefox 🦊 https://mzl.la/3YSUOl8"