psl_matching_helper_unittest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright 2013 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 "components/password_manager/core/browser/psl_matching_helper.h" 6 7#include "base/basictypes.h" 8#include "components/autofill/core/common/password_form.h" 9#include "testing/gtest/include/gtest/gtest.h" 10 11namespace password_manager { 12 13namespace { 14 15TEST(PSLMatchingUtilsTest, IsPublicSuffixDomainMatch) { 16 struct TestPair { 17 const char* url1; 18 const char* url2; 19 bool should_match; 20 }; 21 22 TestPair pairs[] = { 23 {"http://facebook.com", "http://facebook.com", true}, 24 {"http://facebook.com/path", "http://facebook.com/path", true}, 25 {"http://facebook.com/path1", "http://facebook.com/path2", true}, 26 {"http://facebook.com", "http://m.facebook.com", true}, 27 {"http://www.facebook.com", "http://m.facebook.com", true}, 28 {"http://facebook.com/path", "http://m.facebook.com/path", true}, 29 {"http://facebook.com/path1", "http://m.facebook.com/path2", true}, 30 {"http://example.com/has space", "http://example.com/has space", true}, 31 {"http://www.example.com", "http://wwwexample.com", false}, 32 {"http://www.example.com", "https://www.example.com", false}, 33 {"http://www.example.com:123", "http://www.example.com", false}, 34 {"http://www.example.org", "http://www.example.com", false}, 35 // Invalid urls should not match anything. 36 {"http://", "http://", false}, 37 {"", "", false}, 38 {"bad url", "bad url", false}, 39 {"http://www.example.com", "http://", false}, 40 {"", "http://www.example.com", false}, 41 {"http://www.example.com", "bad url", false}, 42 {"http://www.example.com/%00", "http://www.example.com/%00", false}, 43 }; 44 45 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(pairs); ++i) { 46 autofill::PasswordForm form1; 47 form1.signon_realm = pairs[i].url1; 48 autofill::PasswordForm form2; 49 form2.signon_realm = pairs[i].url2; 50 EXPECT_EQ(pairs[i].should_match, 51 PSLMatchingHelper::IsPublicSuffixDomainMatch(form1.signon_realm, 52 form2.signon_realm)) 53 << "First URL = " << pairs[i].url1 54 << ", second URL = " << pairs[i].url2; 55 } 56} 57 58} // namespace 59 60} // namespace password_manager 61