| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ios/chrome/browser/web/mailto_url_rewriter.h" | 5 #import "ios/chrome/browser/web/mailto_url_rewriter.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/web/fake_mailto_handler_helpers.h" | 7 #import "ios/chrome/browser/web/fake_mailto_handler_helpers.h" |
| 8 #import "ios/chrome/browser/web/mailto_handler_system_mail.h" | 8 #import "ios/chrome/browser/web/mailto_handler_system_mail.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/gtest_mac.h" | 10 #include "testing/gtest_mac.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 EXPECT_TRUE(rewriter); | 48 EXPECT_TRUE(rewriter); |
| 49 EXPECT_GT([[rewriter defaultHandlerName] length], 0U); | 49 EXPECT_GT([[rewriter defaultHandlerName] length], 0U); |
| 50 // ID for system Mail client app must not be an empty string. | 50 // ID for system Mail client app must not be an empty string. |
| 51 EXPECT_GT([[MailtoURLRewriter systemMailApp] length], 0U); | 51 EXPECT_GT([[MailtoURLRewriter systemMailApp] length], 0U); |
| 52 | 52 |
| 53 NSArray<MailtoHandler*>* handlers = [rewriter defaultHandlers]; | 53 NSArray<MailtoHandler*>* handlers = [rewriter defaultHandlers]; |
| 54 EXPECT_GE([handlers count], 1U); | 54 EXPECT_GE([handlers count], 1U); |
| 55 for (MailtoHandler* handler in handlers) { | 55 for (MailtoHandler* handler in handlers) { |
| 56 ASSERT_TRUE(handler); | 56 ASSERT_TRUE(handler); |
| 57 NSString* appStoreID = [handler appStoreID]; | 57 NSString* appStoreID = [handler appStoreID]; |
| 58 NSString* expectedDefaultAppID = |
| 59 [handler isAvailable] ? appStoreID : [MailtoURLRewriter systemMailApp]; |
| 58 [rewriter setDefaultHandlerID:appStoreID]; | 60 [rewriter setDefaultHandlerID:appStoreID]; |
| 59 EXPECT_NSEQ(appStoreID, [rewriter defaultHandlerID]); | 61 EXPECT_NSEQ(expectedDefaultAppID, [rewriter defaultHandlerID]); |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 65 TEST_F(MailtoURLRewriterTest, TestDefaultsInvalidToSystemMail) { |
| 66 // Sets up a MailtoURLRewriter with 2 MailtoHandler objects: |
| 67 // - system-provided Mail client app |
| 68 // - Gmail app, but it is not installed |
| 69 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; |
| 70 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; |
| 71 MailtoHandler* fakeGmailHandler = |
| 72 [[FakeMailtoHandlerGmailNotInstalled alloc] init]; |
| 73 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; |
| 74 // Sets the default handler to Gmail (which is not installed). This simulates |
| 75 // the situation when Gmail was installed and set as the default handler. |
| 76 // Then Gmail app is deleted from the device. |
| 77 [rewriter setDefaultHandlerID:[fakeGmailHandler appStoreID]]; |
| 78 // Verifies that the system-provided Mail app automatically assumes the |
| 79 // default handler. |
| 80 EXPECT_NSEQ([MailtoURLRewriter systemMailApp], [rewriter defaultHandlerID]); |
| 81 } |
| 82 |
| 63 TEST_F(MailtoURLRewriterTest, TestUserPreferencePersistence) { | 83 TEST_F(MailtoURLRewriterTest, TestUserPreferencePersistence) { |
| 64 // Sets up a first MailtoURLRewriter with at least 2 MailtoHandler objects. | 84 // Sets up a first MailtoURLRewriter with at least 2 MailtoHandler objects. |
| 65 // A faked Gmail handler that is installed must be used or -addMailtoApp: | 85 // A faked Gmail handler that is installed must be used or -addMailtoApp: |
| 66 // will just skip it. | 86 // will just skip it. |
| 67 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; | 87 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; |
| 68 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; | 88 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; |
| 69 MailtoHandler* fakeGmailHandler = | 89 MailtoHandler* fakeGmailHandler = |
| 70 [[FakeMailtoHandlerGmailInstalled alloc] init]; | 90 [[FakeMailtoHandlerGmailInstalled alloc] init]; |
| 71 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; | 91 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; |
| 72 | 92 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 [[FakeMailtoHandlerGmailInstalled alloc] init]; | 240 [[FakeMailtoHandlerGmailInstalled alloc] init]; |
| 221 | 241 |
| 222 // Sets up a MailtoURLRewriter for testing. | 242 // Sets up a MailtoURLRewriter for testing. |
| 223 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; | 243 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; |
| 224 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; | 244 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; |
| 225 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; | 245 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; |
| 226 | 246 |
| 227 // Verify that MailtoURLRewriter will use Gmail app. | 247 // Verify that MailtoURLRewriter will use Gmail app. |
| 228 EXPECT_NSEQ(kGmailAppStoreID, [rewriter defaultHandlerID]); | 248 EXPECT_NSEQ(kGmailAppStoreID, [rewriter defaultHandlerID]); |
| 229 } | 249 } |
| OLD | NEW |