Skip to content

Commit

Permalink
Add FXIOS-10816 [Sent from Firefox] Add more URLActivityItemProvider …
Browse files Browse the repository at this point in the history
…unit tests (#23729)

* Add more thorough URLActivityItemProviderTests.

* Fix tests for improved TitleActivityItemProvider testability on item.
  • Loading branch information
ih-codes authored Dec 14, 2024
1 parent eae4d29 commit f49b921
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down Expand Up @@ -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."
)
Expand Down Expand Up @@ -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."
)
}

Expand Down Expand Up @@ -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."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit f49b921

Please sign in to comment.