Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc

Issue 1181623004: [Password Manager] Replace "this site" in save password prompt with password's origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Just a code rebase. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/metrics/histogram_samples.h" 5 #include "base/metrics/histogram_samples.h"
6 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
7 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h" 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
12 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
13 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 15 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
14 #include "components/password_manager/core/common/credential_manager_types.h" 16 #include "components/password_manager/core/common/credential_manager_types.h"
15 #include "components/password_manager/core/common/password_manager_pref_names.h" 17 #include "components/password_manager/core/common/password_manager_pref_names.h"
16 #include "components/password_manager/core/common/password_manager_ui.h" 18 #include "components/password_manager/core/common/password_manager_ui.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "content/public/test/web_contents_tester.h" 20 #include "content/public/test/web_contents_tester.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gfx/range/range.h"
23 #include "url/gurl.h"
20 24
21 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; 25 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason";
22 26
23 class ManagePasswordsBubbleModelTest : public testing::Test { 27 class ManagePasswordsBubbleModelTest : public testing::Test {
24 public: 28 public:
25 ManagePasswordsBubbleModelTest() 29 ManagePasswordsBubbleModelTest()
26 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 30 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
27 test_web_contents_( 31 test_web_contents_(
28 content::WebContentsTester::CreateTestWebContents(&profile_, 32 content::WebContentsTester::CreateTestWebContents(&profile_,
29 nullptr)) {} 33 nullptr)) {}
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 password_manager::metrics_util::AUTO_SIGNIN_TOAST_CLICKED); 306 password_manager::metrics_util::AUTO_SIGNIN_TOAST_CLICKED);
303 model_->OnBubbleHidden(); 307 model_->OnBubbleHidden();
304 308
305 EXPECT_TRUE(controller()->manage_accounts()); 309 EXPECT_TRUE(controller()->manage_accounts());
306 310
307 histogram_tester.ExpectUniqueSample( 311 histogram_tester.ExpectUniqueSample(
308 kUIDismissalReasonMetric, 312 kUIDismissalReasonMetric,
309 password_manager::metrics_util::AUTO_SIGNIN_TOAST_CLICKED, 313 password_manager::metrics_util::AUTO_SIGNIN_TOAST_CLICKED,
310 1); 314 1);
311 } 315 }
316
317 TEST_F(ManagePasswordsBubbleModelTest,
318 GetSavePasswordDialogTitleTextAndLinkRange) {
319 const struct {
320 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.
321 const char* form_origin_url;
322 bool is_smartlock_branding_enabled;
323 const char* expected_title_text_ends_with;
324 size_t expected_link_range_start;
325 size_t expected_link_range_end;
326 } test_cases[] = {// Same domains.
327 {"http://example.com/landing",
328 "http://example.com/login#form?value=3",
329 false,
330 "this site?",
331 0,
332 0},
333 {"http://example.com/landing",
334 "http://example.com/login#form?value=3",
335 true,
336 "this site?",
337 12,
338 29},
339
340 // Different subdomains.
341 {"https://a.example.com/landing",
342 "https://b.example.com/login#form?value=3",
343 false,
344 "this site?",
345 0,
346 0},
347 {"https://a.example.com/landing",
348 "https://b.example.com/login#form?value=3",
349 true,
350 "this site?",
351 12,
352 29},
353
354 // Different domains.
355 {"https://another.org",
356 "https://example.com:/login#form?value=3",
357 false,
358 "https://example.com?",
359 0,
360 0},
361 {"https://another.org",
362 "https://example.com/login#form?value=3",
363 true,
364 "https://example.com?",
365 12,
366 29},
367
368 // Different domains and password form origin url with
369 // default port for the scheme.
370 {"https://another.org",
371 "https://example.com:443/login#form?value=3",
372 false,
373 "https://example.com?",
374 0,
375 0},
376 {"https://another.org",
377 "http://example.com:80/login#form?value=3",
378 true,
379 "http://example.com?",
380 12,
381 29},
382
383 // Different domains and password form origin url with
384 // non-default port for the scheme.
385 {"https://another.org",
386 "https://example.com:8001/login#form?value=3",
387 false,
388 "https://example.com:8001?",
389 0,
390 0},
391 {"https://another.org",
392 "https://example.com:8001/login#form?value=3",
393 true,
394 "https://example.com:8001?",
395 12,
396 29}};
397
398 for (size_t i = 0; i < arraysize(test_cases); ++i) {
399 SCOPED_TRACE(testing::Message()
400 << "user_visible_url = " << test_cases[i].user_visible_url
401 << ", form_origin_url = " << test_cases[i].form_origin_url);
402
403 base::string16 title;
404 gfx::Range title_link_range;
405 GetSavePasswordDialogTitleTextAndLinkRange(
406 GURL(test_cases[i].user_visible_url),
407 GURL(test_cases[i].form_origin_url),
408 test_cases[i].is_smartlock_branding_enabled, &title, &title_link_range);
409
410 // Verify against expectations.
411 EXPECT_TRUE(EndsWith(
412 title, base::ASCIIToUTF16(test_cases[i].expected_title_text_ends_with),
413 false));
414 EXPECT_EQ(test_cases[i].expected_link_range_start,
415 title_link_range.start());
416 EXPECT_EQ(test_cases[i].expected_link_range_end, title_link_range.end());
417 }
418 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698