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