OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/range/range.h" | 10 #include "ui/gfx/range/range.h" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
13 // Test for GetSavePasswordDialogTitleTextAndLinkRange(). | 13 // Test for GetSavePasswordDialogTitleTextAndLinkRange(). |
14 TEST(ManagePasswordsViewUtilTest, GetSavePasswordDialogTitleTextAndLinkRange) { | 14 TEST(ManagePasswordsViewUtilTest, GetSavePasswordDialogTitleTextAndLinkRange) { |
15 const struct { | 15 const struct { |
16 const char* const user_visible_url; | 16 const char* const user_visible_url; |
17 const char* const form_origin_url; | 17 const char* const form_origin_url; |
18 bool is_smartlock_branding_enabled; | 18 bool is_smartlock_branding_enabled; |
| 19 bool is_update_password_bubble; |
19 const char* const expected_title_text_ends_with; | 20 const char* const expected_title_text_ends_with; |
20 size_t expected_link_range_start; | 21 size_t expected_link_range_start; |
21 size_t expected_link_range_end; | 22 size_t expected_link_range_end; |
22 } test_cases[] = { | 23 } test_cases[] = { |
23 // Same domains. | 24 // Same domains. |
24 {"http://example.com/landing", "http://example.com/login#form?value=3", | 25 {"http://example.com/landing", "http://example.com/login#form?value=3", |
25 false, "this site?", 0, 0}, | 26 false, false, "this site?", 0, 0}, |
26 {"http://example.com/landing", "http://example.com/login#form?value=3", | 27 {"http://example.com/landing", "http://example.com/login#form?value=3", |
27 true, "this site?", 12, 29}, | 28 true, false, "this site?", 12, 29}, |
28 | 29 |
29 // Different subdomains. | 30 // Different subdomains. |
30 {"https://a.example.com/landing", | 31 {"https://a.example.com/landing", |
31 "https://b.example.com/login#form?value=3", false, "this site?", 0, 0}, | 32 "https://b.example.com/login#form?value=3", false, false, "this site?", |
| 33 0, 0}, |
32 {"https://a.example.com/landing", | 34 {"https://a.example.com/landing", |
33 "https://b.example.com/login#form?value=3", true, "this site?", 12, 29}, | 35 "https://b.example.com/login#form?value=3", true, false, "this site?", |
| 36 12, 29}, |
34 | 37 |
35 // Different domains. | 38 // Different domains. |
36 {"https://another.org", "https://example.com:/login#form?value=3", false, | 39 {"https://another.org", "https://example.com:/login#form?value=3", false, |
37 "https://example.com?", 0, 0}, | 40 false, "https://example.com?", 0, 0}, |
38 {"https://another.org", "https://example.com/login#form?value=3", true, | 41 {"https://another.org", "https://example.com/login#form?value=3", true, |
39 "https://example.com?", 12, 29}, | 42 false, "https://example.com?", 12, 29}, |
40 | 43 |
41 // Different domains and password form origin url with | 44 // Different domains and password form origin url with |
42 // default port for the scheme. | 45 // default port for the scheme. |
43 {"https://another.org", "https://example.com:443/login#form?value=3", | 46 {"https://another.org", "https://example.com:443/login#form?value=3", |
44 false, "https://example.com?", 0, 0}, | 47 false, false, "https://example.com?", 0, 0}, |
45 {"https://another.org", "http://example.com:80/login#form?value=3", true, | 48 {"https://another.org", "http://example.com:80/login#form?value=3", true, |
46 "http://example.com?", 12, 29}, | 49 false, "http://example.com?", 12, 29}, |
47 | 50 |
48 // Different domains and password form origin url with | 51 // Different domains and password form origin url with |
49 // non-default port for the scheme. | 52 // non-default port for the scheme. |
50 {"https://another.org", "https://example.com:8001/login#form?value=3", | 53 {"https://another.org", "https://example.com:8001/login#form?value=3", |
51 false, "https://example.com:8001?", 0, 0}, | 54 false, false, "https://example.com:8001?", 0, 0}, |
52 {"https://another.org", "https://example.com:8001/login#form?value=3", | 55 {"https://another.org", "https://example.com:8001/login#form?value=3", |
53 true, "https://example.com:8001?", 12, 29}}; | 56 true, false, "https://example.com:8001?", 12, 29}, |
| 57 |
| 58 // Update bubble. |
| 59 {"http://example.com/landing", "http://example.com/login#form?value=3", |
| 60 false, true, "this site?", 0, 0}, |
| 61 {"http://example.com/landing", "http://example.com/login#form?value=3", |
| 62 true, true, "this site?", 12, 29}}; |
54 | 63 |
55 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 64 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
56 SCOPED_TRACE(testing::Message() | 65 SCOPED_TRACE(testing::Message() |
57 << "user_visible_url = " << test_cases[i].user_visible_url | 66 << "user_visible_url = " << test_cases[i].user_visible_url |
58 << ", form_origin_url = " << test_cases[i].form_origin_url); | 67 << ", form_origin_url = " << test_cases[i].form_origin_url); |
59 | 68 |
60 base::string16 title; | 69 base::string16 title; |
61 gfx::Range title_link_range; | 70 gfx::Range title_link_range; |
62 GetSavePasswordDialogTitleTextAndLinkRange( | 71 GetSavePasswordDialogTitleTextAndLinkRange( |
63 GURL(test_cases[i].user_visible_url), | 72 GURL(test_cases[i].user_visible_url), |
64 GURL(test_cases[i].form_origin_url), | 73 GURL(test_cases[i].form_origin_url), |
65 test_cases[i].is_smartlock_branding_enabled, &title, &title_link_range); | 74 test_cases[i].is_smartlock_branding_enabled, |
| 75 test_cases[i].is_update_password_bubble, &title, &title_link_range); |
66 | 76 |
67 // Verify against expectations. | 77 // Verify against expectations. |
68 EXPECT_TRUE(base::EndsWith( | 78 EXPECT_TRUE(base::EndsWith( |
69 title, base::ASCIIToUTF16(test_cases[i].expected_title_text_ends_with), | 79 title, base::ASCIIToUTF16(test_cases[i].expected_title_text_ends_with), |
70 base::CompareCase::INSENSITIVE_ASCII)); | 80 base::CompareCase::INSENSITIVE_ASCII)); |
71 EXPECT_EQ(test_cases[i].expected_link_range_start, | 81 EXPECT_EQ(test_cases[i].expected_link_range_start, |
72 title_link_range.start()); | 82 title_link_range.start()); |
73 EXPECT_EQ(test_cases[i].expected_link_range_end, title_link_range.end()); | 83 EXPECT_EQ(test_cases[i].expected_link_range_end, title_link_range.end()); |
| 84 if (test_cases[i].is_update_password_bubble) { |
| 85 EXPECT_TRUE(title.find(base::ASCIIToUTF16("update")) != |
| 86 base::string16::npos); |
| 87 } else { |
| 88 EXPECT_TRUE(title.find(base::ASCIIToUTF16("save")) != |
| 89 base::string16::npos); |
| 90 } |
74 } | 91 } |
75 } | 92 } |
OLD | NEW |