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

Unified Diff: ios/chrome/browser/web/mailto_url_rewriter_unittest.mm

Issue 2859743002: Adds MailtoURLRewriterObserver to MailtoURLRewriter (Closed)
Patch Set: make observer weak, and test it. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/web/mailto_url_rewriter.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/mailto_url_rewriter_unittest.mm
diff --git a/ios/chrome/browser/web/mailto_url_rewriter_unittest.mm b/ios/chrome/browser/web/mailto_url_rewriter_unittest.mm
index 8edead2b7f832e499b5a881045e498d81bbab1f5..796f53c47b6f35cf8673b313871e18cf0b5739a1 100644
--- a/ios/chrome/browser/web/mailto_url_rewriter_unittest.mm
+++ b/ios/chrome/browser/web/mailto_url_rewriter_unittest.mm
@@ -50,6 +50,19 @@ NSString* const kGmailAppStoreID = @"422689480";
}
@end
+#pragma mark - Test Observer object
+
+@interface RewriterObserver : NSObject<MailtoURLRewriterObserver>
+@property(nonatomic, readonly) int changeCount;
+@end
+
+@implementation RewriterObserver
+@synthesize changeCount = _changeCount;
+- (void)rewriterDidChange:(MailtoURLRewriter*)rewriter {
+ ++_changeCount;
+}
+@end
+
#pragma mark - MailtoURLRewriter private interfaces for testing.
@interface MailtoURLRewriter ()
@@ -69,6 +82,7 @@ TEST_F(MailtoURLRewriterTest, TestStandardInstance) {
MailtoURLRewriter* rewriter =
[[MailtoURLRewriter alloc] initWithStandardHandlers];
EXPECT_TRUE(rewriter);
+ EXPECT_GT([[rewriter defaultHandlerName] length], 0U);
// ID for system Mail client app must not be an empty string.
EXPECT_GT([[MailtoURLRewriter systemMailApp] length], 0U);
@@ -115,6 +129,42 @@ TEST_F(MailtoURLRewriterTest, TestUserPreferencePersistence) {
EXPECT_NSEQ(otherHandlerID, [rewriter2 defaultHandlerID]);
}
+TEST_F(MailtoURLRewriterTest, TestChangeObserver) {
+ RewriterObserver* observer = [[RewriterObserver alloc] init];
+ ASSERT_EQ(0, [observer changeCount]);
+
+ // Sets up a MailtoURLRewriter object. The default handler is Gmail app
+ // because |fakeGmailHandler| reports that it is "installed".
+ MailtoURLRewriter* rewriter = [[MailtoURLRewriter alloc] init];
+ MailtoHandler* systemMailHandler = [[MailtoHandlerSystemMail alloc] init];
+ MailtoHandler* fakeGmailHandler =
+ [[FakeMailtoHandlerGmailInstalled alloc] init];
+ [rewriter addMailtoApps:@[ systemMailHandler, fakeGmailHandler ]];
+ EXPECT_NSEQ([fakeGmailHandler appStoreID], [rewriter defaultHandlerID]);
+ [rewriter setObserver:observer];
+
+ // Setting system Mail app as handler while current handler is Gmail should
+ // trigger the observer callback, incrementing count from 0 to 1.
+ [rewriter setDefaultHandlerID:[systemMailHandler appStoreID]];
+ EXPECT_EQ(1, [observer changeCount]);
+
+ // Setting system Mail app as handler while current handler is already
+ // system Mail app should not trigger the observer callback. Count remains
+ // at 1.
+ [rewriter setDefaultHandlerID:[systemMailHandler appStoreID]];
+ EXPECT_EQ(1, [observer changeCount]);
+
+ // Setting Gmail app as the default handler when current handler is system
+ // Mail app should trigger the observer callback. Count increases from 1 to 2.
+ [rewriter setDefaultHandlerID:[fakeGmailHandler appStoreID]];
+ EXPECT_EQ(2, [observer changeCount]);
+
+ // Deallocates the observer to test that there are no ill side-effects (e.g.
+ // crashes) when observer's lifetime is shorter than the rewriter.
+ observer = nil;
+ [rewriter setDefaultHandlerID:[systemMailHandler appStoreID]];
+}
+
// Tests that a new user without Gmail app installed launches system Mail app.
TEST_F(MailtoURLRewriterTest, TestNewUserNoGmail) {
// Sets pre-condition for a user who did not have Chrome installed.
« 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