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

Side by Side Diff: components/autofill/core/common/password_form.cc

Issue 1022823002: Make test outputs involving PasswordForms more readable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 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 <ostream> 5 #include <ostream>
6 #include <sstream>
6 7
8 #include "base/json/json_writer.h"
7 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
8 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h"
10 #include "components/autofill/core/common/password_form.h" 13 #include "components/autofill/core/common/password_form.h"
11 14
12 namespace autofill { 15 namespace autofill {
13 16
17 namespace {
18
19 // Serializes a PasswordForm to a JSON object. Used only for logging in tests.
20 void PasswordFormToJSON(const PasswordForm& form,
21 base::DictionaryValue* target) {
22 target->SetInteger("scheme", form.scheme);
23 target->SetString("signon_realm", form.signon_realm);
24 target->SetString("signon_realm", form.signon_realm);
25 target->SetString("original_signon_realm", form.original_signon_realm);
26 target->SetString("origin", form.origin.possibly_invalid_spec());
27 target->SetString("action", form.action.possibly_invalid_spec());
28 target->SetString("submit_element", form.submit_element);
29 target->SetString("username_elem", form.username_element);
30 target->SetBoolean("username_marked_by_site", form.username_marked_by_site);
31 target->SetString("username_value", form.username_value);
32 target->SetString("password_elem", form.password_element);
33 target->SetString("password_value", form.password_value);
34 target->SetString("new_password_element", form.new_password_element);
35 target->SetString("new_password_value", form.new_password_value);
36 target->SetString("other_possible_usernames",
37 JoinString(form.other_possible_usernames, '|'));
38 target->SetBoolean("autocomplete_set", form.password_autocomplete_set);
39 target->SetBoolean("blacklisted", form.blacklisted_by_user);
40 target->SetBoolean("preferred", form.preferred);
41 target->SetBoolean("ssl_valid", form.ssl_valid);
42 target->SetDouble("date_created", form.date_created.ToDoubleT());
43 target->SetDouble("date_synced", form.date_synced.ToDoubleT());
44 target->SetInteger("type", form.type);
45 target->SetInteger("times_used", form.times_used);
46 std::ostringstream form_data_string_stream;
47 form_data_string_stream << form.form_data;
48 target->SetString("form_data", form_data_string_stream.str());
49 target->SetInteger("generation_upload_status", form.generation_upload_status);
50 target->SetString("display_name", form.display_name);
51 target->SetString("avatar_url", form.avatar_url.possibly_invalid_spec());
52 target->SetString("federation_url",
53 form.federation_url.possibly_invalid_spec());
54 target->SetBoolean("skip_next_zero_click", form.skip_zero_click);
55 }
56
57 } // namespace
58
14 PasswordForm::PasswordForm() 59 PasswordForm::PasswordForm()
15 : scheme(SCHEME_HTML), 60 : scheme(SCHEME_HTML),
16 username_marked_by_site(false), 61 username_marked_by_site(false),
17 password_autocomplete_set(true), 62 password_autocomplete_set(true),
18 ssl_valid(false), 63 ssl_valid(false),
19 preferred(false), 64 preferred(false),
20 blacklisted_by_user(false), 65 blacklisted_by_user(false),
21 type(TYPE_MANUAL), 66 type(TYPE_MANUAL),
22 times_used(0), 67 times_used(0),
23 generation_upload_status(NO_SIGNAL_SENT), 68 generation_upload_status(NO_SIGNAL_SENT),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 avatar_url == form.avatar_url && 105 avatar_url == form.avatar_url &&
61 federation_url == form.federation_url && 106 federation_url == form.federation_url &&
62 skip_zero_click == form.skip_zero_click; 107 skip_zero_click == form.skip_zero_click;
63 } 108 }
64 109
65 bool PasswordForm::operator!=(const PasswordForm& form) const { 110 bool PasswordForm::operator!=(const PasswordForm& form) const {
66 return !operator==(form); 111 return !operator==(form);
67 } 112 }
68 113
69 std::ostream& operator<<(std::ostream& os, const PasswordForm& form) { 114 std::ostream& operator<<(std::ostream& os, const PasswordForm& form) {
70 return os << "scheme: " << form.scheme 115 base::DictionaryValue form_json;
71 << " signon_realm: " << form.signon_realm 116 PasswordFormToJSON(form, &form_json);
72 << " original_signon_realm: " << form.original_signon_realm 117
73 << " origin: " << form.origin 118 // Serialize the default PasswordForm, and remove values from the result that
74 << " action: " << form.action 119 // are equal to this to make the results more concise.
75 << " submit_element: " << base::UTF16ToUTF8(form.submit_element) 120 base::DictionaryValue default_form_json;
76 << " username_elem: " << base::UTF16ToUTF8(form.username_element) 121 PasswordFormToJSON(PasswordForm(), &default_form_json);
77 << " username_marked_by_site: " << form.username_marked_by_site 122 for (base::DictionaryValue::Iterator it_default_key_values(default_form_json);
78 << " username_value: " << base::UTF16ToUTF8(form.username_value) 123 !it_default_key_values.IsAtEnd(); it_default_key_values.Advance()) {
79 << " password_elem: " << base::UTF16ToUTF8(form.password_element) 124 const base::Value* actual_value;
80 << " password_value: " << base::UTF16ToUTF8(form.password_value) 125 if (form_json.Get(it_default_key_values.key(), &actual_value) &&
81 << " new_password_element: " 126 it_default_key_values.value().Equals(actual_value)) {
82 << base::UTF16ToUTF8(form.new_password_element) 127 form_json.Remove(it_default_key_values.key(), nullptr);
83 << " new_password_value: " 128 }
84 << base::UTF16ToUTF8(form.new_password_value) 129 }
85 << " other_possible_usernames: " 130
86 << JoinString(form.other_possible_usernames, '|') 131 std::string form_as_string;
87 << " autocomplete_set:" << form.password_autocomplete_set 132 base::JSONWriter::WriteWithOptions(
88 << " blacklisted: " << form.blacklisted_by_user 133 &form_json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &form_as_string);
89 << " preferred: " << form.preferred 134 base::TrimWhitespaceASCII(form_as_string, base::TRIM_ALL, &form_as_string);
90 << " ssl_valid: " << form.ssl_valid 135 return os << "PasswordForm(" << form_as_string << ")";
91 << " date_created: " << form.date_created.ToDoubleT() 136 }
92 << " date_synced: " << form.date_synced.ToDoubleT() 137
93 << " type: " << form.type 138 std::ostream& operator<<(std::ostream& os, PasswordForm* form) {
94 << " times_used: " << form.times_used 139 return os << "&" << *form;
95 << " form_data: " << form.form_data
96 << " generation_upload_status: " << form.generation_upload_status
97 << " display_name: " << base::UTF16ToUTF8(form.display_name)
98 << " avatar_url: " << form.avatar_url
99 << " federation_url: " << form.federation_url
100 << " skip_next_zero_click: " << form.skip_zero_click;
101 } 140 }
102 141
103 } // namespace autofill 142 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698