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

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

Issue 2526283002: Handle empty string in GetSavePasswordDialogTitleTextAndLinkRange gracefully (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « chrome/browser/ui/passwords/manage_passwords_view_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string16.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
13 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/range/range.h" 18 #include "ui/gfx/range/range.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 namespace { 21 namespace {
20 22
23 class EmptyDelegate : public ui::ResourceBundle::Delegate {
24 public:
25 EmptyDelegate() {}
26 ~EmptyDelegate() override {}
27
28 // ui::ResourceBundle::Delegate
29 base::FilePath GetPathForResourcePack(const base::FilePath& pack_path,
30 ui::ScaleFactor scale_factor) override {
31 return base::FilePath();
32 }
33
34 base::FilePath GetPathForLocalePack(const base::FilePath& pack_path,
35 const std::string& locale) override {
36 return base::FilePath();
37 }
38
39 gfx::Image GetImageNamed(int resource_id) override { return gfx::Image(); }
40
41 gfx::Image GetNativeImageNamed(int resource_id) override {
42 return gfx::Image();
43 }
44
45 base::RefCountedMemory* LoadDataResourceBytes(
46 int resource_id,
47 ui::ScaleFactor scale_factor) override {
48 return nullptr;
49 }
50
51 bool GetRawDataResource(int resource_id,
52 ui::ScaleFactor scale_factor,
53 base::StringPiece* value) override {
54 return false;
55 }
56
57 bool GetLocalizedString(int message_id, base::string16* value) override {
58 value->clear();
59 return true;
vasilii 2016/11/24 17:26:28 It's strange to return true in production if the r
vabr (Chromium) 2016/11/25 09:57:28 This is now removed. (I agree this was strange. In
60 }
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(EmptyDelegate);
64 };
65
21 const struct { 66 const struct {
22 const char* const user_visible_url; 67 const char* const user_visible_url;
23 const char* const form_origin_url; 68 const char* const form_origin_url;
24 bool is_smartlock_branding_enabled; 69 bool is_smartlock_branding_enabled;
25 PasswordTitleType bubble_type; 70 PasswordTitleType bubble_type;
26 const char* const expected_domain_placeholder; // "this site" or domain name 71 const char* const expected_domain_placeholder; // "this site" or domain name
27 size_t expected_link_range_start; 72 size_t expected_link_range_start;
28 size_t expected_link_range_end; 73 size_t expected_link_range_end;
29 } kDomainsTestCases[] = { 74 } kDomainsTestCases[] = {
30 // Same domains. 75 // Same domains.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 PasswordTitleType::UPDATE_PASSWORD) { 162 PasswordTitleType::UPDATE_PASSWORD) {
118 EXPECT_TRUE(title.find(base::ASCIIToUTF16("update")) != 163 EXPECT_TRUE(title.find(base::ASCIIToUTF16("update")) !=
119 base::string16::npos); 164 base::string16::npos);
120 } else { 165 } else {
121 EXPECT_TRUE(title.find(base::ASCIIToUTF16("save")) != 166 EXPECT_TRUE(title.find(base::ASCIIToUTF16("save")) !=
122 base::string16::npos); 167 base::string16::npos);
123 } 168 }
124 } 169 }
125 } 170 }
126 171
172 // Check that empty localised strings do not cause a crash.
173 TEST(ManagePasswordsViewUtilTest,
174 GetSavePasswordDialogTitleTextAndLinkRange_EmptyStrings) {
175 EmptyDelegate delegate;
176
177 ui::ResourceBundle::CleanupSharedInstance();
178 ui::ResourceBundle::InitSharedInstanceWithLocale(
vasilii 2016/11/24 17:26:28 I'm afraid that your test doesn't leave the global
vabr (Chromium) 2016/11/25 09:57:28 That's a good point. Also, I realised that the del
179 std::string(), &delegate,
180 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
181
182 base::string16 title;
183 gfx::Range title_link_range;
184 const GURL kExample = GURL("http://example.org");
vasilii 2016/11/24 17:26:28 Why not const GURL kExample("http://example.org");
vabr (Chromium) 2016/11/25 09:57:28 My oversight during copy-pasting. Fixed now.
185 GetSavePasswordDialogTitleTextAndLinkRange(kExample, kExample, true,
186 PasswordTitleType::SAVE_PASSWORD,
187 &title, &title_link_range);
188 }
189
127 TEST(ManagePasswordsViewUtilTest, GetManagePasswordsDialogTitleText) { 190 TEST(ManagePasswordsViewUtilTest, GetManagePasswordsDialogTitleText) {
128 for (size_t i = 0; i < arraysize(kDomainsTestCases); ++i) { 191 for (size_t i = 0; i < arraysize(kDomainsTestCases); ++i) {
129 SCOPED_TRACE(testing::Message() << "user_visible_url = " 192 SCOPED_TRACE(testing::Message() << "user_visible_url = "
130 << kDomainsTestCases[i].user_visible_url 193 << kDomainsTestCases[i].user_visible_url
131 << ", password_origin_url = " 194 << ", password_origin_url = "
132 << kDomainsTestCases[i].form_origin_url); 195 << kDomainsTestCases[i].form_origin_url);
133 196
134 base::string16 title; 197 base::string16 title;
135 gfx::Range title_link_range; 198 gfx::Range title_link_range;
136 GetManagePasswordsDialogTitleText( 199 GetManagePasswordsDialogTitleText(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 false /* is_smartlock_branding_enabled */, 241 false /* is_smartlock_branding_enabled */,
179 GetParam(), 242 GetParam(),
180 &title, &title_link_range); 243 &title, &title_link_range);
181 EXPECT_GE(title.find(branding, 0), title.size()); 244 EXPECT_GE(title.find(branding, 0), title.size());
182 EXPECT_EQ(0U, title_link_range.start()); 245 EXPECT_EQ(0U, title_link_range.start());
183 EXPECT_EQ(0U, title_link_range.end()); 246 EXPECT_EQ(0U, title_link_range.end());
184 } 247 }
185 248
186 INSTANTIATE_TEST_CASE_P(, AccountChooserDialogTitleTest, 249 INSTANTIATE_TEST_CASE_P(, AccountChooserDialogTitleTest,
187 ::testing::Bool()); 250 ::testing::Bool());
OLDNEW
« no previous file with comments | « chrome/browser/ui/passwords/manage_passwords_view_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698