1 // Copyright (c) 2012 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.
5 #include "content/renderer/android/email_detector.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 class EmailDetectorTest
: public testing::Test
{
14 static void FindAndCheckEmail(const std::string
& content
,
15 const std::string
& expected
) {
16 base::string16 content_16
= base::UTF8ToUTF16(content
);
17 base::string16 result_16
;
19 EmailDetector detector
;
20 std::string content_text
;
21 if (detector
.FindContent(content_16
.begin(), content_16
.end(),
22 &start
, &end
, &content_text
)) {
23 result_16
= content_16
.substr(start
, end
- start
);
25 EXPECT_EQ(expected
, base::UTF16ToUTF8(result_16
));
26 EXPECT_EQ(expected
, content_text
);
30 TEST_F(EmailDetectorTest
, FindEmail
) {
31 FindAndCheckEmail("please email test@testing.com", "test@testing.com");
32 FindAndCheckEmail("please email test@123.456.co.uk.", "test@123.456.co.uk");
33 FindAndCheckEmail("My email is 'a@b.org'.", "a@b.org");
34 FindAndCheckEmail("123@bcd.org", "123@bcd.org");
35 FindAndCheckEmail("[quitelongwelllongemailaddress@somequitelongdomain.org]",
36 "quitelongwelllongemailaddress@somequitelongdomain.org");
37 FindAndCheckEmail("Should find the first@email.org not the second@email.org",
39 FindAndCheckEmail("Email:HELLO@SOMETHING.COM", "HELLO@SOMETHING.COM");
40 FindAndCheckEmail("Email SOMEONE@GOOGLE.COM for details.",
41 "SOMEONE@GOOGLE.COM");
42 FindAndCheckEmail("It's \"testadd@company.fr\"", "testadd@company.fr");
43 FindAndCheckEmail("This is not an @emailaddress.com", "");
44 FindAndCheckEmail("Apples @2.50 each", "");
45 FindAndCheckEmail("Log on to google.com", "");
46 FindAndCheckEmail("Try someone@, they might know.", "");
47 FindAndCheckEmail("No, bob@com is not an email address.", "");
48 FindAndCheckEmail("@", "");
49 FindAndCheckEmail("Just bob @google.com", "");
50 FindAndCheckEmail("Why not call larry@google and ask him.", "");
53 } // namespace content