OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 #include "base/scoped_nsobject.h" | 6 #include "base/scoped_nsobject.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #import "chrome/browser/cocoa/page_info_window_mac.h" | 11 #import "chrome/browser/cocoa/page_info_window_mac.h" |
12 #import "chrome/browser/cocoa/page_info_window_controller.h" | 12 #import "chrome/browser/cocoa/page_info_window_controller.h" |
13 #include "chrome/browser/cocoa/browser_test_helper.h" | 13 #include "chrome/browser/cocoa/browser_test_helper.h" |
14 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 14 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
15 #include "chrome/browser/page_info_model.h" | 15 #include "chrome/browser/page_info_model.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class FakeModel : public PageInfoModel { | 20 class FakeModel : public PageInfoModel { |
21 public: | 21 public: |
22 void AddSection(SectionInfoState state, | 22 FakeModel() : PageInfoModel() {} |
| 23 |
| 24 void AddSection(SectionStateIcon icon_id, |
23 const string16& title, | 25 const string16& title, |
24 const string16& description, | 26 const string16& description, |
25 SectionInfoType type) { | 27 SectionInfoType type) { |
26 sections_.push_back(SectionInfo( | 28 sections_.push_back(SectionInfo( |
27 state, | 29 icon_id, |
28 title, | 30 title, |
29 string16(), | 31 string16(), |
30 description, | 32 description, |
31 type)); | 33 type)); |
32 } | 34 } |
33 }; | 35 }; |
34 | 36 |
35 class PageInfoWindowMacTest : public CocoaTest { | 37 class PageInfoWindowMacTest : public CocoaTest { |
36 public: | 38 public: |
37 virtual void SetUp() { | 39 virtual void SetUp() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 84 } |
83 | 85 |
84 // Makes sure the box has a valid image and a string. | 86 // Makes sure the box has a valid image and a string. |
85 void CheckBox(NSBox* box) { | 87 void CheckBox(NSBox* box) { |
86 EXPECT_TRUE([box title]); | 88 EXPECT_TRUE([box title]); |
87 NSArray* subviews = [[box contentView] subviews]; | 89 NSArray* subviews = [[box contentView] subviews]; |
88 EXPECT_EQ(2U, [subviews count]); | 90 EXPECT_EQ(2U, [subviews count]); |
89 for (NSView* view in subviews) { | 91 for (NSView* view in subviews) { |
90 if ([view isKindOfClass:[NSImageView class]]) { | 92 if ([view isKindOfClass:[NSImageView class]]) { |
91 NSImageView* image_view = static_cast<NSImageView*>(view); | 93 NSImageView* image_view = static_cast<NSImageView*>(view); |
92 EXPECT_TRUE([image_view image] == bridge_->good_image_.get() || | 94 EXPECT_TRUE([image_view image]); |
93 [image_view image] == bridge_->bad_image_.get()); | |
94 } else if ([view isKindOfClass:[NSTextField class]]) { | 95 } else if ([view isKindOfClass:[NSTextField class]]) { |
95 NSTextField* text_field = static_cast<NSTextField*>(view); | 96 NSTextField* text_field = static_cast<NSTextField*>(view); |
96 EXPECT_LT(0U, [[text_field stringValue] length]); | 97 EXPECT_LT(0U, [[text_field stringValue] length]); |
97 } else { | 98 } else { |
98 EXPECT_TRUE(false) << "Unknown box subview"; | 99 EXPECT_TRUE(false) << "Unknown box subview"; |
99 } | 100 } |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
103 BrowserTestHelper helper_; | 104 BrowserTestHelper helper_; |
104 | 105 |
105 PageInfoWindowController* controller_; // Weak, owns self. | 106 PageInfoWindowController* controller_; // Weak, owns self. |
106 PageInfoWindowMac* bridge_; // Weak, owned by controller. | 107 PageInfoWindowMac* bridge_; // Weak, owned by controller. |
107 FakeModel* model_; // Weak, owned by bridge. | 108 FakeModel* model_; // Weak, owned by bridge. |
108 | 109 |
109 NSWindow* window_; // Weak, owned by controller. | 110 NSWindow* window_; // Weak, owned by controller. |
110 }; | 111 }; |
111 | 112 |
112 | 113 |
113 TEST_F(PageInfoWindowMacTest, NoHistoryNoSecurity) { | 114 TEST_F(PageInfoWindowMacTest, NoHistoryNoSecurity) { |
114 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 115 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
115 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 116 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
116 l10n_util::GetStringFUTF16( | 117 l10n_util::GetStringFUTF16( |
117 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, | 118 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, |
118 ASCIIToUTF16("google.com")), | 119 ASCIIToUTF16("google.com")), |
119 PageInfoModel::SECTION_INFO_IDENTITY); | 120 PageInfoModel::SECTION_INFO_IDENTITY); |
120 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 121 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
121 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 122 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
122 l10n_util::GetStringFUTF16( | 123 l10n_util::GetStringFUTF16( |
123 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, | 124 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
124 ASCIIToUTF16("google.com")), | 125 ASCIIToUTF16("google.com")), |
125 PageInfoModel::SECTION_INFO_CONNECTION); | 126 PageInfoModel::SECTION_INFO_CONNECTION); |
126 | 127 |
127 bridge_->ModelChanged(); | 128 bridge_->ModelChanged(); |
128 | 129 |
129 CheckWindow(1, 2); | 130 CheckWindow(1, 2); |
130 } | 131 } |
131 | 132 |
132 | 133 |
133 TEST_F(PageInfoWindowMacTest, HistoryNoSecurity) { | 134 TEST_F(PageInfoWindowMacTest, HistoryNoSecurity) { |
134 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 135 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
135 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 136 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
136 l10n_util::GetStringFUTF16( | 137 l10n_util::GetStringFUTF16( |
137 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, | 138 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, |
138 ASCIIToUTF16("google.com")), | 139 ASCIIToUTF16("google.com")), |
139 PageInfoModel::SECTION_INFO_IDENTITY); | 140 PageInfoModel::SECTION_INFO_IDENTITY); |
140 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 141 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
141 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 142 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
142 l10n_util::GetStringFUTF16( | 143 l10n_util::GetStringFUTF16( |
143 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, | 144 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
144 ASCIIToUTF16("google.com")), | 145 ASCIIToUTF16("google.com")), |
145 PageInfoModel::SECTION_INFO_CONNECTION); | 146 PageInfoModel::SECTION_INFO_CONNECTION); |
146 | 147 |
147 // In practice, the history information comes later because it's queried | 148 // In practice, the history information comes later because it's queried |
148 // asynchronously, so replicate the double-build here. | 149 // asynchronously, so replicate the double-build here. |
149 bridge_->ModelChanged(); | 150 bridge_->ModelChanged(); |
150 | 151 |
151 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 152 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
152 l10n_util::GetStringUTF16( | 153 l10n_util::GetStringUTF16( |
153 IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), | 154 IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), |
154 l10n_util::GetStringUTF16( | 155 l10n_util::GetStringUTF16( |
155 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY), | 156 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY), |
156 PageInfoModel::SECTION_INFO_FIRST_VISIT); | 157 PageInfoModel::SECTION_INFO_FIRST_VISIT); |
157 | 158 |
158 bridge_->ModelChanged(); | 159 bridge_->ModelChanged(); |
159 | 160 |
160 CheckWindow(1, 3); | 161 CheckWindow(1, 3); |
161 } | 162 } |
162 | 163 |
163 | 164 |
164 TEST_F(PageInfoWindowMacTest, NoHistoryMixedSecurity) { | 165 TEST_F(PageInfoWindowMacTest, NoHistoryMixedSecurity) { |
165 model_->AddSection(PageInfoModel::SECTION_STATE_OK, | 166 model_->AddSection(PageInfoModel::ICON_STATE_OK, |
166 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 167 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
167 l10n_util::GetStringFUTF16( | 168 l10n_util::GetStringFUTF16( |
168 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, | 169 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, |
169 ASCIIToUTF16("Goat Security Systems")), | 170 ASCIIToUTF16("Goat Security Systems")), |
170 PageInfoModel::SECTION_INFO_IDENTITY); | 171 PageInfoModel::SECTION_INFO_IDENTITY); |
171 | 172 |
172 // This string is super long and the text should overflow the default clip | 173 // This string is super long and the text should overflow the default clip |
173 // region (kImageSize). | 174 // region (kImageSize). |
174 string16 title = | 175 string16 title = |
175 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE); | 176 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE); |
176 model_->AddSection(PageInfoModel::SECTION_STATE_OK, | 177 model_->AddSection(PageInfoModel::ICON_STATE_OK, |
177 title, | 178 title, |
178 l10n_util::GetStringFUTF16( | 179 l10n_util::GetStringFUTF16( |
179 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, | 180 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, |
180 l10n_util::GetStringFUTF16( | 181 l10n_util::GetStringFUTF16( |
181 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, | 182 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, |
182 ASCIIToUTF16("chrome.google.com"), | 183 ASCIIToUTF16("chrome.google.com"), |
183 base::IntToString16(1024)), | 184 base::IntToString16(1024)), |
184 l10n_util::GetStringUTF16( | 185 l10n_util::GetStringUTF16( |
185 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)), | 186 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)), |
186 PageInfoModel::SECTION_INFO_CONNECTION); | 187 PageInfoModel::SECTION_INFO_CONNECTION); |
(...skipping 10 matching lines...) Expand all Loading... |
197 NSBox* box = static_cast<NSBox*>(subview); | 198 NSBox* box = static_cast<NSBox*>(subview); |
198 if ([[box title] isEqualToString:targetTitle]) { | 199 if ([[box title] isEqualToString:targetTitle]) { |
199 // Typical box frame is ~55px, make sure this is extra large. | 200 // Typical box frame is ~55px, make sure this is extra large. |
200 EXPECT_LT(75, NSHeight([box frame])); | 201 EXPECT_LT(75, NSHeight([box frame])); |
201 } | 202 } |
202 } | 203 } |
203 } | 204 } |
204 } | 205 } |
205 | 206 |
206 } // namespace | 207 } // namespace |
OLD | NEW |