OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 6 |
| 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gfx/range/range.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 // Test for GetSavePasswordDialogTitleTextAndLinkRange(). |
| 14 TEST(ManagePasswordsViewUtilTest, GetSavePasswordDialogTitleTextAndLinkRange) { |
| 15 const struct { |
| 16 const char* const user_visible_url; |
| 17 const char* const form_origin_url; |
| 18 bool is_smartlock_branding_enabled; |
| 19 const char* const expected_title_text_ends_with; |
| 20 size_t expected_link_range_start; |
| 21 size_t expected_link_range_end; |
| 22 } test_cases[] = { |
| 23 // Same domains. |
| 24 {"http://example.com/landing", "http://example.com/login#form?value=3", |
| 25 false, "this site?", 0, 0}, |
| 26 {"http://example.com/landing", "http://example.com/login#form?value=3", |
| 27 true, "this site?", 12, 29}, |
| 28 |
| 29 // Different subdomains. |
| 30 {"https://a.example.com/landing", |
| 31 "https://b.example.com/login#form?value=3", false, "this site?", 0, 0}, |
| 32 {"https://a.example.com/landing", |
| 33 "https://b.example.com/login#form?value=3", true, "this site?", 12, 29}, |
| 34 |
| 35 // Different domains. |
| 36 {"https://another.org", "https://example.com:/login#form?value=3", false, |
| 37 "https://example.com?", 0, 0}, |
| 38 {"https://another.org", "https://example.com/login#form?value=3", true, |
| 39 "https://example.com?", 12, 29}, |
| 40 |
| 41 // Different domains and password form origin url with |
| 42 // default port for the scheme. |
| 43 {"https://another.org", "https://example.com:443/login#form?value=3", |
| 44 false, "https://example.com?", 0, 0}, |
| 45 {"https://another.org", "http://example.com:80/login#form?value=3", true, |
| 46 "http://example.com?", 12, 29}, |
| 47 |
| 48 // Different domains and password form origin url with |
| 49 // non-default port for the scheme. |
| 50 {"https://another.org", "https://example.com:8001/login#form?value=3", |
| 51 false, "https://example.com:8001?", 0, 0}, |
| 52 {"https://another.org", "https://example.com:8001/login#form?value=3", |
| 53 true, "https://example.com:8001?", 12, 29}}; |
| 54 |
| 55 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 56 SCOPED_TRACE(testing::Message() |
| 57 << "user_visible_url = " << test_cases[i].user_visible_url |
| 58 << ", form_origin_url = " << test_cases[i].form_origin_url); |
| 59 |
| 60 base::string16 title; |
| 61 gfx::Range title_link_range; |
| 62 GetSavePasswordDialogTitleTextAndLinkRange( |
| 63 GURL(test_cases[i].user_visible_url), |
| 64 GURL(test_cases[i].form_origin_url), |
| 65 test_cases[i].is_smartlock_branding_enabled, &title, &title_link_range); |
| 66 |
| 67 // Verify against expectations. |
| 68 EXPECT_TRUE(base::EndsWith( |
| 69 title, base::ASCIIToUTF16(test_cases[i].expected_title_text_ends_with), |
| 70 false)); |
| 71 EXPECT_EQ(test_cases[i].expected_link_range_start, |
| 72 title_link_range.start()); |
| 73 EXPECT_EQ(test_cases[i].expected_link_range_end, title_link_range.end()); |
| 74 } |
| 75 } |
OLD | NEW |