This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Added offline query parameter (#14857)
- Loading branch information
Julian Rex
authored
Jun 11, 2019
1 parent
ec0fa4c
commit edd04d3
Showing
4 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#import <Mapbox/Mapbox.h> | ||
#import <XCTest/XCTest.h> | ||
#import <mbgl/storage/resource.hpp> | ||
|
||
namespace mbgl { | ||
extern NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountType); | ||
} | ||
|
||
@interface MGLResourceTests : XCTestCase | ||
@end | ||
|
||
@implementation MGLResourceTests | ||
|
||
- (void)testOfflineQueryParameterIsAddedForOfflineResource { | ||
|
||
using namespace mbgl; | ||
|
||
std::string testURL = "test://mapbox.com/testing_offline_query?a=one&b=two"; | ||
|
||
// Is our test URL "correct" for subsequent checks? | ||
{ | ||
NSURL *url = [NSURL URLWithString:@(testURL.c_str())]; | ||
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; | ||
NSArray<NSURLQueryItem *> *items = components.queryItems; | ||
XCTAssert(items.count == 2 ); | ||
} | ||
|
||
Resource resource(Resource::Kind::Unknown, testURL); | ||
|
||
// By default, resource are NOT offline | ||
{ | ||
NSURL *url = resourceURLWithAccountType(resource, 0); | ||
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; | ||
for (NSURLQueryItem *item in components.queryItems) { | ||
XCTAssertFalse([item.name isEqualToString:@"offline"]); | ||
} | ||
} | ||
|
||
// Now check offline | ||
resource.setUsage(Resource::Usage::Offline); | ||
|
||
{ | ||
NSURL *url = resourceURLWithAccountType(resource, 0); | ||
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; | ||
|
||
// For offline, we expect a single offline param and a sku param | ||
NSInteger foundCount = 0; | ||
|
||
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR | ||
for (NSURLQueryItem *item in components.queryItems) { | ||
if (([item.name isEqualToString:@"offline"] && [item.value isEqualToString:@"true"]) || | ||
([item.name isEqualToString:@"a"] && [item.value isEqualToString:@"one"]) || | ||
([item.name isEqualToString:@"b"] && [item.value isEqualToString:@"two"]) || | ||
([item.name isEqualToString:@"sku"])) { | ||
foundCount++; | ||
} | ||
} | ||
|
||
XCTAssert(foundCount == 4); | ||
#else | ||
// NOTE: Currently the macOS SDK does not supply the sku or offline query parameters | ||
for (NSURLQueryItem *item in components.queryItems) { | ||
if (([item.name isEqualToString:@"a"] && [item.value isEqualToString:@"one"]) || | ||
([item.name isEqualToString:@"b"] && [item.value isEqualToString:@"two"])) { | ||
foundCount++; | ||
} | ||
} | ||
|
||
XCTAssert(foundCount == 2); | ||
#endif | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters