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

Side by Side Diff: chrome/browser/ui/views/passwords/manage_password_item_view.cc

Issue 221853003: Password bubble: Add a test for displayed password length. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/views/passwords/manage_password_item_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
6 6
7 #include "grit/generated_resources.h" 7 #include "grit/generated_resources.h"
8 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
(...skipping 25 matching lines...) Expand all
36 layout->StartRowWithPadding( 36 layout->StartRowWithPadding(
37 0, column_set_to_build, 0, views::kRelatedControlVerticalSpacing); 37 0, column_set_to_build, 0, views::kRelatedControlVerticalSpacing);
38 38
39 // Add the username field: fills the first non-padding column of the layout. 39 // Add the username field: fills the first non-padding column of the layout.
40 label_1_ = new views::Label(password_form_.username_value); 40 label_1_ = new views::Label(password_form_.username_value);
41 label_1_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 41 label_1_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
42 layout->AddView(label_1_); 42 layout->AddView(label_1_);
43 43
44 // Add the password field: fills the second non-padding column of the layout. 44 // Add the password field: fills the second non-padding column of the layout.
45 label_2_ = 45 label_2_ =
46 new views::Link(GetPasswordDisplayString(password_form_.password_value)); 46 new views::Link(ManagePasswordsBubbleModel::GetPasswordDisplayString(
47 password_form_.password_value));
47 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 48 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
48 label_2_->set_listener(this); 49 label_2_->set_listener(this);
49 label_2_->SetFocusable(false); 50 label_2_->SetFocusable(false);
50 label_2_->SetEnabled(false); 51 label_2_->SetEnabled(false);
51 label_2_->SetUnderline(false); 52 label_2_->SetUnderline(false);
52 layout->AddView(label_2_); 53 layout->AddView(label_2_);
53 54
54 // If we're managing passwords (that is, we're not currently in the process 55 // If we're managing passwords (that is, we're not currently in the process
55 // of saving a password), construct and add the delete button: fills the 56 // of saving a password), construct and add the delete button: fills the
56 // third non-padding column of the layout. 57 // third non-padding column of the layout.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 column_set->AddColumn(views::GridLayout::TRAILING, 97 column_set->AddColumn(views::GridLayout::TRAILING,
97 views::GridLayout::FILL, 98 views::GridLayout::FILL,
98 0, 99 0,
99 views::GridLayout::USE_PREF, 100 views::GridLayout::USE_PREF,
100 0, 101 0,
101 0); 102 0);
102 } 103 }
103 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 104 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
104 } 105 }
105 106
106 // static
107 base::string16 ManagePasswordItemView::GetPasswordDisplayString(
108 const base::string16& password) {
109 const wchar_t kPasswordBullet = 0x2022;
110 const size_t kMaxPasswordChar = 22;
111 return base::string16(std::min(password.length(), kMaxPasswordChar),
112 kPasswordBullet);
113 }
114
115 ManagePasswordItemView::~ManagePasswordItemView() { 107 ManagePasswordItemView::~ManagePasswordItemView() {
116 if (delete_password_) 108 if (delete_password_)
117 manage_passwords_bubble_model_->DeleteFromBestMatches(password_form_); 109 manage_passwords_bubble_model_->DeleteFromBestMatches(password_form_);
118 } 110 }
119 111
120 void ManagePasswordItemView::Refresh() { 112 void ManagePasswordItemView::Refresh() {
121 // TODO(mkwst): We're currently swaping out values in the same view. We need 113 // TODO(mkwst): We're currently swaping out values in the same view. We need
122 // to swap out views in order to enable some future work (and to make the undo 114 // to swap out views in order to enable some future work (and to make the undo
123 // button's alignment work correctly). 115 // button's alignment work correctly).
124 116
(...skipping 16 matching lines...) Expand all
141 133
142 // Move focus to the parent in order to get the focus ring off the link 134 // Move focus to the parent in order to get the focus ring off the link
143 // that the user just clicked. 135 // that the user just clicked.
144 parent()->RequestFocus(); 136 parent()->RequestFocus();
145 137
146 // Change the username string back to the username. 138 // Change the username string back to the username.
147 label_1_->SetText(password_form_.username_value); 139 label_1_->SetText(password_form_.username_value);
148 140
149 // Set the password string to the appropriate number of bullets, and 141 // Set the password string to the appropriate number of bullets, and
150 // disable the link. 142 // disable the link.
151 label_2_->SetText(GetPasswordDisplayString(password_form_.password_value)); 143 label_2_->SetText(ManagePasswordsBubbleModel::GetPasswordDisplayString(
144 password_form_.password_value));
152 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 145 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
153 label_2_->SetEnabled(false); 146 label_2_->SetEnabled(false);
154 label_2_->SetFocusable(false); 147 label_2_->SetFocusable(false);
155 148
156 if (delete_button_) 149 if (delete_button_)
157 delete_button_->SetVisible(true); 150 delete_button_->SetVisible(true);
158 } 151 }
159 152
160 // After the view is consistent, notify the model that the password needs to 153 // After the view is consistent, notify the model that the password needs to
161 // be updated (either removed or put back into the store, as appropriate. 154 // be updated (either removed or put back into the store, as appropriate.
162 manage_passwords_bubble_model_->OnPasswordAction( 155 manage_passwords_bubble_model_->OnPasswordAction(
163 password_form_, 156 password_form_,
164 delete_password_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD 157 delete_password_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD
165 : ManagePasswordsBubbleModel::ADD_PASSWORD); 158 : ManagePasswordsBubbleModel::ADD_PASSWORD);
166 } 159 }
167 160
168 void ManagePasswordItemView::ButtonPressed(views::Button* sender, 161 void ManagePasswordItemView::ButtonPressed(views::Button* sender,
169 const ui::Event& event) { 162 const ui::Event& event) {
170 DCHECK_EQ(delete_button_, sender); 163 DCHECK_EQ(delete_button_, sender);
171 delete_password_ = true; 164 delete_password_ = true;
172 Refresh(); 165 Refresh();
173 } 166 }
174 167
175 void ManagePasswordItemView::LinkClicked(views::Link* source, 168 void ManagePasswordItemView::LinkClicked(views::Link* source,
176 int event_flags) { 169 int event_flags) {
177 DCHECK_EQ(source, label_2_); 170 DCHECK_EQ(source, label_2_);
178 delete_password_ = false; 171 delete_password_ = false;
179 Refresh(); 172 Refresh();
180 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698