Index: chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc |
diff --git a/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc b/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc |
index 647ab683435de27efdd2072174c14cfb8ff06f82..8fcbae334d3288030421d7b4e54fda8e6b980e95 100644 |
--- a/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc |
+++ b/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc |
@@ -4,11 +4,13 @@ |
#include "base/metrics/histogram_samples.h" |
#include "base/prefs/pref_service.h" |
+#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/test/histogram_tester.h" |
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h" |
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
#include "chrome/test/base/testing_profile.h" |
#include "components/password_manager/core/browser/password_manager_metrics_util.h" |
#include "components/password_manager/core/common/credential_manager_types.h" |
@@ -17,6 +19,8 @@ |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "content/public/test/web_contents_tester.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/range/range.h" |
+#include "url/gurl.h" |
const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; |
@@ -309,3 +313,106 @@ TEST_F(ManagePasswordsBubbleModelTest, PopupAutoSigninAndManagedBubble) { |
password_manager::metrics_util::AUTO_SIGNIN_TOAST_CLICKED, |
1); |
} |
+ |
+TEST_F(ManagePasswordsBubbleModelTest, |
+ GetSavePasswordDialogTitleTextAndLinkRange) { |
+ const struct { |
+ const char* user_visible_url; |
palmer
2015/06/26 17:59:58
Nit: const char* const user_visible_url;
Pritam Nikam
2015/06/27 10:10:03
Done.
|
+ const char* form_origin_url; |
+ bool is_smartlock_branding_enabled; |
+ const char* expected_title_text_ends_with; |
+ size_t expected_link_range_start; |
+ size_t expected_link_range_end; |
+ } test_cases[] = {// Same domains. |
+ {"http://example.com/landing", |
+ "http://example.com/login#form?value=3", |
+ false, |
+ "this site?", |
+ 0, |
+ 0}, |
+ {"http://example.com/landing", |
+ "http://example.com/login#form?value=3", |
+ true, |
+ "this site?", |
+ 12, |
+ 29}, |
+ |
+ // Different subdomains. |
+ {"https://a.example.com/landing", |
+ "https://b.example.com/login#form?value=3", |
+ false, |
+ "this site?", |
+ 0, |
+ 0}, |
+ {"https://a.example.com/landing", |
+ "https://b.example.com/login#form?value=3", |
+ true, |
+ "this site?", |
+ 12, |
+ 29}, |
+ |
+ // Different domains. |
+ {"https://another.org", |
+ "https://example.com:/login#form?value=3", |
+ false, |
+ "https://example.com?", |
+ 0, |
+ 0}, |
+ {"https://another.org", |
+ "https://example.com/login#form?value=3", |
+ true, |
+ "https://example.com?", |
+ 12, |
+ 29}, |
+ |
+ // Different domains and password form origin url with |
+ // default port for the scheme. |
+ {"https://another.org", |
+ "https://example.com:443/login#form?value=3", |
+ false, |
+ "https://example.com?", |
+ 0, |
+ 0}, |
+ {"https://another.org", |
+ "http://example.com:80/login#form?value=3", |
+ true, |
+ "http://example.com?", |
+ 12, |
+ 29}, |
+ |
+ // Different domains and password form origin url with |
+ // non-default port for the scheme. |
+ {"https://another.org", |
+ "https://example.com:8001/login#form?value=3", |
+ false, |
+ "https://example.com:8001?", |
+ 0, |
+ 0}, |
+ {"https://another.org", |
+ "https://example.com:8001/login#form?value=3", |
+ true, |
+ "https://example.com:8001?", |
+ 12, |
+ 29}}; |
+ |
+ for (size_t i = 0; i < arraysize(test_cases); ++i) { |
+ SCOPED_TRACE(testing::Message() |
+ << "user_visible_url = " << test_cases[i].user_visible_url |
+ << ", form_origin_url = " << test_cases[i].form_origin_url); |
+ |
+ base::string16 title; |
+ gfx::Range title_link_range; |
+ GetSavePasswordDialogTitleTextAndLinkRange( |
+ GURL(test_cases[i].user_visible_url), |
+ GURL(test_cases[i].form_origin_url), |
+ test_cases[i].is_smartlock_branding_enabled, &title, &title_link_range); |
+ |
+ // Verify against expectations. |
+ EXPECT_TRUE(EndsWith( |
+ title, base::ASCIIToUTF16(test_cases[i].expected_title_text_ends_with), |
+ false)); |
+ EXPECT_EQ(test_cases[i].expected_link_range_start, |
+ title_link_range.start()); |
+ EXPECT_EQ(test_cases[i].expected_link_range_end, title_link_range.end()); |
+ } |
+} |