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

Side by Side Diff: content/renderer/android/email_detector_unittest.cc

Issue 2790893004: Delete Android content detectors. (Closed)
Patch Set: Rebase Created 3 years, 8 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
OLDNEW
(Empty)
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.
4
5 #include "content/renderer/android/email_detector.h"
6
7 #include <stddef.h>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace content {
13
14 class EmailDetectorTest : public testing::Test {
15 public:
16 static void FindAndCheckEmail(const std::string& content,
17 const std::string& expected) {
18 base::string16 content_16 = base::UTF8ToUTF16(content);
19 base::string16 result_16;
20 size_t start, end;
21 EmailDetector detector;
22 std::string content_text;
23 if (detector.FindContent(content_16.begin(), content_16.end(),
24 &start, &end, &content_text)) {
25 result_16 = content_16.substr(start, end - start);
26 }
27 EXPECT_EQ(expected, base::UTF16ToUTF8(result_16));
28 EXPECT_EQ(expected, content_text);
29 }
30 };
31
32 TEST_F(EmailDetectorTest, FindEmail) {
33 FindAndCheckEmail("please email test@testing.com", "test@testing.com");
34 FindAndCheckEmail("please email test@123.456.co.uk.", "test@123.456.co.uk");
35 FindAndCheckEmail("My email is 'a@b.org'.", "a@b.org");
36 FindAndCheckEmail("123@bcd.org", "123@bcd.org");
37 FindAndCheckEmail("[quitelongwelllongemailaddress@somequitelongdomain.org]",
38 "quitelongwelllongemailaddress@somequitelongdomain.org");
39 FindAndCheckEmail("Should find the first@email.org not the second@email.org",
40 "first@email.org");
41 FindAndCheckEmail("Email:HELLO@SOMETHING.COM", "HELLO@SOMETHING.COM");
42 FindAndCheckEmail("Email SOMEONE@GOOGLE.COM for details.",
43 "SOMEONE@GOOGLE.COM");
44 FindAndCheckEmail("It's \"testadd@company.fr\"", "testadd@company.fr");
45 FindAndCheckEmail("This is not an @emailaddress.com", "");
46 FindAndCheckEmail("Apples @2.50 each", "");
47 FindAndCheckEmail("Log on to google.com", "");
48 FindAndCheckEmail("Try someone@, they might know.", "");
49 FindAndCheckEmail("No, bob@com is not an email address.", "");
50 FindAndCheckEmail("@", "");
51 FindAndCheckEmail("Just bob @google.com", "");
52 FindAndCheckEmail("Why not call larry@google and ask him.", "");
53 FindAndCheckEmail("Lets test invalid invalid@email..com address", "");
54 FindAndCheckEmail("Invalid dots are bad invalid@.email.com address", "");
55 }
56
57 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/android/email_detector.cc ('k') | content/renderer/android/phone_number_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698