Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / components / password_manager / core / browser / psl_matching_helper_unittest.cc
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
11 TEST(PSLMatchingUtilsTest, IsPublicSuffixDomainMatch) {
12   struct TestPair {
13     const char* url1;
14     const char* url2;
15     bool should_match;
16   };
17
18   TestPair pairs[] = {
19     { "http://facebook.com", "http://m.facebook.com", true },
20     { "http://www.facebook.com", "http://m.facebook.com", true },
21     { "http://www.example.com", "http://wwwexample.com", false },
22     { "http://www.example.com", "https://www.example.com", false },
23     { "http://www.example.com:123", "http://www.example.com", false },
24     { "http://www.example.org", "http://www.example.com", false },
25   };
26
27   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(pairs); ++i) {
28     autofill::PasswordForm form1;
29     form1.signon_realm = pairs[i].url1;
30     autofill::PasswordForm form2;
31     form2.signon_realm = pairs[i].url2;
32     EXPECT_EQ(pairs[i].should_match,
33               PSLMatchingHelper::IsPublicSuffixDomainMatch(form1.signon_realm,
34                                                            form2.signon_realm))
35         << "First URL = " << pairs[i].url1
36         << ", second URL = " << pairs[i].url2;
37   }
38 }