Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: ios/chrome/browser/itunes_links/itunes_links_observer_unittest.mm

Issue 2176503003: Intercept iTunes links and open iTunes controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/itunes_links/itunes_links_observer.mm ('k') | ios/chrome/browser/storekit_launcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/itunes_links/itunes_links_observer_unittest.mm
diff --git a/ios/chrome/browser/itunes_links/itunes_links_observer_unittest.mm b/ios/chrome/browser/itunes_links/itunes_links_observer_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..a72637059e2b3cd8b85fec1bdd1434382aa8a0dd
--- /dev/null
+++ b/ios/chrome/browser/itunes_links/itunes_links_observer_unittest.mm
@@ -0,0 +1,73 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Foundation/Foundation.h>
+
+#import "ios/chrome/browser/itunes_links/itunes_links_observer.h"
+
+#import "base/mac/scoped_nsobject.h"
+#import "ios/web/public/test/test_web_state.h"
+#import "ios/chrome/browser/storekit_launcher.h"
+#include "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+#import "third_party/ocmock/gtest_support.h"
+#import "third_party/ocmock/OCMock/OCMock.h"
+#include "url/gurl.h"
+
+namespace {
+
+class ITunesLinksObserverTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ mocked_store_kit_launcher_.reset(
+ [[OCMockObject mockForProtocol:@protocol(StoreKitLauncher)] retain]);
+ link_observer_.reset(
+ [[ITunesLinksObserver alloc] initWithWebState:&web_state_]);
+ [link_observer_ setStoreKitLauncher:mocked_store_kit_launcher_];
+ }
+ void VerifyOpeningOfAppStore(NSString* expected_product_id,
+ std::string const& url_string) {
+ if (expected_product_id)
+ [[mocked_store_kit_launcher_.get() expect]
+ openAppStore:expected_product_id];
+ web_state_.SetCurrentURL(GURL(url_string));
+ [link_observer_ webStateDidLoadPage:&web_state_];
+ EXPECT_OCMOCK_VERIFY(mocked_store_kit_launcher_.get());
+ }
+ web::TestWebState web_state_;
+ base::scoped_nsobject<id> mocked_store_kit_launcher_;
+ // |link_observer_| must be destroyed before web_state_.
+ base::scoped_nsobject<ITunesLinksObserver> link_observer_;
+};
+
+// Verifies that navigating to URLs not concerning a product hosted on the
+// iTunes AppStore does not trigger the opening of the AppStore.
+TEST_F(ITunesLinksObserverTest, NonMatchingUrls) {
+ VerifyOpeningOfAppStore(nil, "");
+ VerifyOpeningOfAppStore(nil, "foobar");
+ VerifyOpeningOfAppStore(nil, "foo://bar");
+ VerifyOpeningOfAppStore(nil, "http://foo");
+ VerifyOpeningOfAppStore(nil, "http://foo?bar#qux");
+ VerifyOpeningOfAppStore(nil, "http://foo.bar/qux");
+ VerifyOpeningOfAppStore(nil, "http://itunes.apple.com");
+ VerifyOpeningOfAppStore(nil, "http://itunes.apple.com/id");
+ VerifyOpeningOfAppStore(nil, "http://itunes.apple.com/12345");
+ VerifyOpeningOfAppStore(nil, "ftp://itunes.apple.com/id123");
+}
+
+// Verifies that navigating to URLs concerning a product hosted on iTunes
+// AppStore triggers the opening of the AppStore.
+TEST_F(ITunesLinksObserverTest, MatchingUrls) {
+ VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/id123");
+ VerifyOpeningOfAppStore(@"123", "https://itunes.apple.com/id123");
+ VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/bar/id123");
+ VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/bar/id123?qux");
+ VerifyOpeningOfAppStore(@"123", "http://itunes.apple.com/bar/id123?qux&baz");
+ VerifyOpeningOfAppStore(@"123",
+ "http://itunes.apple.com/bar/id123?qux&baz#foo");
+ VerifyOpeningOfAppStore(@"123",
+ "http://foo.itunes.apple.com/bar/id123?qux&baz#foo");
+}
+
+} // namespace
« no previous file with comments | « ios/chrome/browser/itunes_links/itunes_links_observer.mm ('k') | ios/chrome/browser/storekit_launcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698