| // Copyright (c) 2006-2008 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 "chrome/browser/google_url_tracker.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| |
| TEST(GoogleURLTrackerTest, CheckAndConvertURL) { |
| static const struct { |
| const char* const source_url; |
| const bool can_convert; |
| const char* const base_url; |
| } data[] = { |
| { "http://www.google.com/", true, "http://www.google.com/", }, |
| { "http://google.fr/", true, "http://google.fr/", }, |
| { "http://google.co.uk/", true, "http://google.co.uk/", }, |
| { "http://www.google.com.by/", true, "http://www.google.com.by/", }, |
| { "http://www.google.com/ig", true, "http://www.google.com/", }, |
| { "http://www.google.com/intl/xx", true, "http://www.google.com/intl/xx", }, |
| { "http://a.b.c.google.com/", true, "http://a.b.c.google.com/", }, |
| { "http://www.yahoo.com/", false, "", }, |
| { "http://google.evil.com/", false, "", }, |
| { "http://google.com.com.com/", false, "", }, |
| { "http://google/", false, "", }, |
| }; |
| |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| GURL base_url; |
| const bool can_convert = GoogleURLTracker::CheckAndConvertToGoogleBaseURL( |
| GURL(data[i].source_url), &base_url); |
| EXPECT_EQ(data[i].can_convert, can_convert); |
| EXPECT_STREQ(data[i].base_url, base_url.spec().c_str()); |
| } |
| } |
| |