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

Side by Side Diff: ios/chrome/browser/web/mailto_url_rewriter_unittest.mm

Issue 2870783002: Adds Compose Email Settings UI for deprecating Native App Launcher (Closed)
Patch Set: replied to comments from rohitrao Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/web/mailto_url_rewriter.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/mailto_handler.h" 7 #import "ios/chrome/browser/web/fake_mailto_handler_helpers.h"
8 #import "ios/chrome/browser/web/mailto_handler_gmail.h"
9 #import "ios/chrome/browser/web/mailto_handler_system_mail.h" 8 #import "ios/chrome/browser/web/mailto_handler_system_mail.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/gtest_mac.h" 10 #include "testing/gtest_mac.h"
12 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
13 12
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 14 #error "This file requires ARC support."
16 #endif 15 #endif
17 16
18 namespace { 17 namespace {
19 18
20 // Defines the 3 valid states for ShouldAutoOpenLinks_422689480. 19 // Defines the 3 valid states for ShouldAutoOpenLinks_422689480.
21 enum { 20 enum {
22 kAutoOpenLinksNotSet = 0, 21 kAutoOpenLinksNotSet = 0,
23 kAutoOpenLinksNo = 1, 22 kAutoOpenLinksNo = 1,
24 kAutoOpenLinksYes = 2, 23 kAutoOpenLinksYes = 2,
25 }; 24 };
26 NSString* const kLegacyShouldAutoOpenKey = @"ShouldAutoOpenLinks_422689480"; 25 NSString* const kLegacyShouldAutoOpenKey = @"ShouldAutoOpenLinks_422689480";
27 NSString* const kGmailAppStoreID = @"422689480"; 26 NSString* const kGmailAppStoreID = @"422689480";
28 27
29 } // namespace 28 } // namespace
30 29
31 #pragma mark - Gmail not installed
32
33 @interface FakeMailtoHandlerGmailNotInstalled : MailtoHandlerGmail
34 @end
35
36 @implementation FakeMailtoHandlerGmailNotInstalled
37 - (BOOL)isAvailable {
38 return NO;
39 }
40 @end
41
42 #pragma mark - Gmail is installed
43
44 @interface FakeMailtoHandlerGmailInstalled : MailtoHandlerGmail
45 @end
46
47 @implementation FakeMailtoHandlerGmailInstalled
48 - (BOOL)isAvailable {
49 return YES;
50 }
51 @end
52
53 #pragma mark - Test Observer object
54
55 @interface RewriterObserver : NSObject<MailtoURLRewriterObserver>
56 @property(nonatomic, readonly) int changeCount;
57 @end
58
59 @implementation RewriterObserver
60 @synthesize changeCount = _changeCount;
61 - (void)rewriterDidChange:(MailtoURLRewriter*)rewriter {
62 ++_changeCount;
63 }
64 @end
65
66 #pragma mark - MailtoURLRewriter private interfaces for testing. 30 #pragma mark - MailtoURLRewriter private interfaces for testing.
67 31
68 @interface MailtoURLRewriter () 32 @interface MailtoURLRewriter ()
69 + (void)resetDefaultHandlerIDForTesting; 33 + (void)resetDefaultHandlerIDForTesting;
70 - (void)addMailtoApps:(NSArray<MailtoHandler*>*)handlerApps; 34 - (void)addMailtoApps:(NSArray<MailtoHandler*>*)handlerApps;
71 @end 35 @end
72 36
73 #pragma mark - Unit Test Cases 37 #pragma mark - Unit Test Cases
74 38
75 class MailtoURLRewriterTest : public PlatformTest { 39 class MailtoURLRewriterTest : public PlatformTest {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 [rewriter setDefaultHandlerID:otherHandlerID]; 87 [rewriter setDefaultHandlerID:otherHandlerID];
124 88
125 // Create a new MailtoURLRewriter object and verify that the current 89 // Create a new MailtoURLRewriter object and verify that the current
126 // default is the |otherHandlerID| set in the previous step. 90 // default is the |otherHandlerID| set in the previous step.
127 MailtoURLRewriter* rewriter2 = [[MailtoURLRewriter alloc] init]; 91 MailtoURLRewriter* rewriter2 = [[MailtoURLRewriter alloc] init];
128 [rewriter2 addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; 92 [rewriter2 addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]];
129 EXPECT_NSEQ(otherHandlerID, [rewriter2 defaultHandlerID]); 93 EXPECT_NSEQ(otherHandlerID, [rewriter2 defaultHandlerID]);
130 } 94 }
131 95
132 TEST_F(MailtoURLRewriterTest, TestChangeObserver) { 96 TEST_F(MailtoURLRewriterTest, TestChangeObserver) {
133 RewriterObserver* observer = [[RewriterObserver alloc] init]; 97 CountingMailtoURLRewriterObserver* observer =
98 [[CountingMailtoURLRewriterObserver alloc] init];
134 ASSERT_EQ(0, [observer changeCount]); 99 ASSERT_EQ(0, [observer changeCount]);
135 100
136 // Sets up a MailtoURLRewriter object. The default handler is Gmail app 101 // Sets up a MailtoURLRewriter object. The default handler is Gmail app
137 // because |fakeGmailHandler| reports that it is "installed". 102 // because |fakeGmailHandler| reports that it is "installed".
138 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; 103 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init];
139 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; 104 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init];
140 MailtoHandler* fakeGmailHandler = 105 MailtoHandler* fakeGmailHandler =
141 [[FakeMailtoHandlerGmailInstalled alloc] init]; 106 [[FakeMailtoHandlerGmailInstalled alloc] init];
142 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; 107 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]];
143 EXPECT_NSEQ([fakeGmailHandler appStoreID], [rewriter defaultHandlerID]); 108 EXPECT_NSEQ([fakeGmailHandler appStoreID], [rewriter defaultHandlerID]);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 [[FakeMailtoHandlerGmailInstalled alloc] init]; 220 [[FakeMailtoHandlerGmailInstalled alloc] init];
256 221
257 // Sets up a MailtoURLRewriter for testing. 222 // Sets up a MailtoURLRewriter for testing.
258 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init]; 223 MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init];
259 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init]; 224 MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init];
260 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]]; 225 [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]];
261 226
262 // Verify that MailtoURLRewriter will use Gmail app. 227 // Verify that MailtoURLRewriter will use Gmail app.
263 EXPECT_NSEQ(kGmailAppStoreID, [rewriter defaultHandlerID]); 228 EXPECT_NSEQ(kGmailAppStoreID, [rewriter defaultHandlerID]);
264 } 229 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/mailto_url_rewriter.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698