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

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

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

Powered by Google App Engine
This is Rietveld 408576698