Skip to content

Commit

Permalink
(iOS) Test deletion request ping in the sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Nov 25, 2019
1 parent db3dbab commit 6804da7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/ios/app/Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "httpswift/swifter" ~> 1.4.7
github "mozilla/glean" "master"
git "/Users/jrediger/mozilla/src/glean.rs" "deletion-request"
4 changes: 4 additions & 0 deletions samples/ios/app/glean-sample-app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
BFDA7ACE2371C9B800575C7B /* BrowserEngagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDA7AC92371C9B800575C7B /* BrowserEngagement.swift */; };
BFDA7AD02371CE4900575C7B /* ViewControllerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDA7ACF2371CE4900575C7B /* ViewControllerTest.swift */; };
BFDA7AD22371D2BA00575C7B /* MockServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDA7AD12371D2BA00575C7B /* MockServer.swift */; };
BFED6B2C238C1638006E2BC4 /* DeletionRequestPingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFED6B2B238C1638006E2BC4 /* DeletionRequestPingTest.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -72,6 +73,7 @@
BFDA7ACF2371CE4900575C7B /* ViewControllerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerTest.swift; sourceTree = "<group>"; };
BFDA7AD12371D2BA00575C7B /* MockServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockServer.swift; sourceTree = "<group>"; };
BFE1E7D523435A600067A12A /* sdk_generator.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = sdk_generator.sh; sourceTree = "<group>"; };
BFED6B2B238C1638006E2BC4 /* DeletionRequestPingTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeletionRequestPingTest.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -167,6 +169,7 @@
isa = PBXGroup;
children = (
BFD3AB4D224D475E00AD9255 /* BaselinePingTest.swift */,
BFED6B2B238C1638006E2BC4 /* DeletionRequestPingTest.swift */,
BFDA7ACF2371CE4900575C7B /* ViewControllerTest.swift */,
BFD3AB4F224D475E00AD9255 /* Info.plist */,
BFDA7AD12371D2BA00575C7B /* MockServer.swift */,
Expand Down Expand Up @@ -412,6 +415,7 @@
BFDA7AD22371D2BA00575C7B /* MockServer.swift in Sources */,
BFDA7AD02371CE4900575C7B /* ViewControllerTest.swift in Sources */,
BFD3AB4E224D475E00AD9255 /* BaselinePingTest.swift in Sources */,
BFED6B2C238C1638006E2BC4 /* DeletionRequestPingTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Glean
import Swifter
import XCTest

// swiftlint:disable force_cast
// REASON: Used in below test cases to cause errors if data is missing
class DeletionRequestPingTest: XCTestCase {
var app: XCUIApplication!
var expectation: XCTestExpectation?
var lastPingJson: [String: Any]?

override func setUp() {
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// UI tests must launch the application that they test.
// Doing this in setup will make sure it happens for each test method.
app = XCUIApplication()
}

func setupServer(expectPingType: String) -> HttpServer {
return mockServer(expectPingType: expectPingType) { json in
self.lastPingJson = json
// Fulfill test's expectation once we parsed the incoming data.
self.expectation?.fulfill()
}
}

func testDeletionRequestPing() {
var server = setupServer(expectPingType: "deletion_request")
expectation = expectation(description: "Completed upload")

app.launchArguments = ["USE_MOCK_SERVER"]
app.launch()

app.switches.firstMatch.tap()

waitForExpectations(timeout: 5.0) { error in
XCTAssertNil(error, "Test timed out waiting for upload: \(error!)")
}

var pingInfo = lastPingJson!["ping_info"] as! [String: Any]
XCTAssertEqual(pingInfo["ping_type"] as! String, "deletion_request")

var clientInfo = lastPingJson!["client_info"] as! [String: Any]
let clientId = clientInfo["client_id"] as! String
XCTAssertNotEqual(clientId, "c0ffeec0-ffee-c0ff-eec0-ffeec0ffeec0")

server.stop()

// Try re-enabling and waiting for next baseline ping
server = setupServer(expectPingType: "baseline")
expectation = expectation(description: "Completed upload")

app.switches.firstMatch.tap()

// Trigger baseline ping by putting app into the background
XCUIDevice.shared.press(XCUIDevice.Button.home)

waitForExpectations(timeout: 5.0) { error in
XCTAssertNil(error, "Test timed out waiting for upload: \(error!)")
}

pingInfo = lastPingJson!["ping_info"] as! [String: Any]
XCTAssertEqual(pingInfo["ping_type"] as! String, "baseline")

clientInfo = lastPingJson!["client_info"] as! [String: Any]
let newClientId = clientInfo["client_id"] as! String
XCTAssertNotEqual(newClientId, clientId)
XCTAssertNotEqual(newClientId, "c0ffeec0-ffee-c0ff-eec0-ffeec0ffeec0")

server.stop()
}
}

0 comments on commit 6804da7

Please sign in to comment.