// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "content/renderer/android/phone_number_detector.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" namespace content { class PhoneNumberDetectorTest : public testing::Test { public: static std::string FindNumber(const std::string& content, const std::string& region) { base::string16 content_16 = base::UTF8ToUTF16(content); base::string16 result_16; size_t start, end; PhoneNumberDetector detector(region); std::string content_text; if (detector.FindContent(content_16.begin(), content_16.end(), &start, &end, &content_text)) result_16 = content_16.substr(start, end - start); return base::UTF16ToUTF8(result_16); } static std::string FindAndFormatNumber(const std::string& content, const std::string& region) { base::string16 content_16 = base::UTF8ToUTF16(content); base::string16 result_16; size_t start, end; PhoneNumberDetector detector(region); std::string content_text; detector.FindContent(content_16.begin(), content_16.end(), &start, &end, &content_text); return content_text; } }; TEST_F(PhoneNumberDetectorTest, FindNumber) { // Tests cases with valid home numbers. EXPECT_EQ("617-426-3000", FindNumber("hello 617-426-3000 blah", "us")); EXPECT_EQ("", FindNumber("hello 617-426-3000 blah", "gb")); EXPECT_EQ("020-7617-4426", FindNumber("