| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Foundation/Foundation.h> |
| 6 |
| 7 #import "ios/chrome/browser/itunes_links/itunes_links_observer.h" |
| 8 |
| 9 #import "base/mac/scoped_nsobject.h" |
| 10 #import "ios/web/public/test/test_web_state.h" |
| 11 #import "ios/chrome/browser/storekit_launcher.h" |
| 12 #include "testing/gtest_mac.h" |
| 13 #include "testing/platform_test.h" |
| 14 #import "third_party/ocmock/gtest_support.h" |
| 15 #import "third_party/ocmock/OCMock/OCMock.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 class ITunesLinksObserverTest : public PlatformTest { |
| 21 protected: |
| 22 void SetUp() override { |
| 23 mocked_store_kit_launcher_.reset( |
| 24 [[OCMockObject mockForProtocol:@protocol(StoreKitLauncher)] retain]); |
| 25 link_observer_.reset( |
| 26 [[ITunesLinksObserver alloc] initWithWebState:&web_state_]); |
| 27 [link_observer_ setStoreKitLauncher:mocked_store_kit_launcher_]; |
| 28 } |
| 29 void VerifyOpeningOfAppStore(NSString* expected_product_id, |
| 30 std::string const& url_string) { |
| 31 if (expected_product_id) |
| 32 [[mocked_store_kit_launcher_.get() expect] |
| 33 openAppStore:expected_product_id]; |
| 34 web_state_.SetCurrentURL(GURL(url_string)); |
| 35 [link_observer_ webStateDidLoadPage:&web_state_]; |
| 36 EXPECT_OCMOCK_VERIFY(mocked_store_kit_launcher_.get()); |
| 37 } |
| 38 web::TestWebState web_state_; |
| 39 base::scoped_nsobject<id> mocked_store_kit_launcher_; |
| 40 // |link_observer_| must be destroyed before web_state_. |
| 41 base::scoped_nsobject<ITunesLinksObserver> link_observer_; |
| 42 }; |
| 43 |
| 44 // Verifies that navigating to URLs not concerning a product hosted on the |
| 45 // iTunes AppStore does not trigger the opening of the AppStore. |
| 46 TEST_F(ITunesLinksObserverTest, NonMatchingUrls) { |
| 47 VerifyOpeningOfAppStore(nil, ""); |
| 48 VerifyOpeningOfAppStore(nil, "foobar"); |
| 49 VerifyOpeningOfAppStore(nil, "foo://bar"); |
| 50 VerifyOpeningOfAppStore(nil, "http://foo"); |
| 51 VerifyOpeningOfAppStore(nil, "http://foo?bar#qux"); |
| 52 VerifyOpeningOfAppStore(nil, "http://foo.bar/qux"); |
| 53 VerifyOpeningOfAppStore(nil, "http://itunes.apple.com"); |
| 54 VerifyOpeningOfAppStore(nil, "http://itunes.apple.com/id"); |
| 55 VerifyOpeningOfAppStore(nil, "http://itunes.apple.com/12345"); |
| 56 VerifyOpeningOfAppStore(nil, "ftp://itunes.apple.com/id123"); |
| 57 } |
| 58 |
| 59 // Verifies that navigating to URLs concerning a product hosted on iTunes |
| 60 // AppStore triggers the opening of the AppStore. |
| 61 TEST_F(ITunesLinksObserverTest, MatchingUrls) { |
| 62 VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/id123"); |
| 63 VerifyOpeningOfAppStore(@"123", "https://itunes.apple.com/id123"); |
| 64 VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/bar/id123"); |
| 65 VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/bar/id123?qux"); |
| 66 VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/bar/id123?qux&baz"); |
| 67 VerifyOpeningOfAppStore(@"123", |
| 68 "http://itunes.apple.com/bar/id123?qux&baz#foo"); |
| 69 VerifyOpeningOfAppStore(@"123", |
| 70 "http://foo.itunes.apple.com/bar/id123?qux&baz#foo"); |
| 71 } |
| 72 |
| 73 } // namespace |
| OLD | NEW |