OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/web/mailto_handler.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "testing/gtest_mac.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 TEST(MailtoHandlerTest, TestConstructor) { |
| 12 MailtoHandler* handler = |
| 13 [[MailtoHandler alloc] initWithName:@"Some App" appStoreID:@"12345"]; |
| 14 EXPECT_NSEQ(@"Some App", [handler appName]); |
| 15 EXPECT_NSEQ(@"12345", [handler appStoreID]); |
| 16 EXPECT_NSEQ(@"mailtohandler:/co?", [handler beginningScheme]); |
| 17 EXPECT_GT([[handler supportedHeaders] count], 0U); |
| 18 } |
| 19 |
| 20 TEST(MailtoHandlerTest, TestRewriteGood) { |
| 21 MailtoHandler* handler = [[MailtoHandler alloc] init]; |
| 22 // Tests mailto URL without a subject. |
| 23 NSString* result = [handler rewriteMailtoURL:GURL("mailto:user@domain.com")]; |
| 24 EXPECT_NSEQ(@"mailtohandler:/co?to=user@domain.com", result); |
| 25 // Tests mailto URL with a subject. |
| 26 result = |
| 27 [handler rewriteMailtoURL:GURL("mailto:user@domain.com?subject=hello")]; |
| 28 EXPECT_NSEQ(@"mailtohandler:/co?to=user@domain.com&subject=hello", result); |
| 29 // Tests mailto URL with unrecognized query parameters. |
| 30 result = [handler |
| 31 rewriteMailtoURL: |
| 32 GURL("mailto:someone@there.com?garbage=in&garbageOut&subject=trash")]; |
| 33 EXPECT_NSEQ(@"mailtohandler:/co?to=someone@there.com&subject=trash", result); |
| 34 } |
| 35 |
| 36 TEST(MailtoHandlerTest, TestRewriteBad) { |
| 37 MailtoHandler* handler = [[MailtoHandler alloc] init]; |
| 38 NSString* result = [handler rewriteMailtoURL:GURL("http://www.google.com")]; |
| 39 EXPECT_FALSE(result); |
| 40 result = [handler |
| 41 rewriteMailtoURL: |
| 42 GURL("mailto:user@domain.com?foo=bar&cc=someone@somewhere.com")]; |
| 43 EXPECT_NSEQ(@"mailtohandler:/co?to=user@domain.com&cc=someone@somewhere.com", |
| 44 result); |
| 45 } |
OLD | NEW |