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(bool state, | 22 void AddSection(bool state, |
23 const string16& title, | 23 const string16& title, |
24 const string16& description) { | 24 const string16& description, |
| 25 SectionInfoType type) { |
25 sections_.push_back(SectionInfo( | 26 sections_.push_back(SectionInfo( |
26 state, | 27 state, |
27 title, | 28 title, |
28 string16(), | 29 string16(), |
29 description)); | 30 description, |
| 31 type)); |
30 } | 32 } |
31 }; | 33 }; |
32 | 34 |
33 class PageInfoWindowMacTest : public CocoaTest { | 35 class PageInfoWindowMacTest : public CocoaTest { |
34 public: | 36 public: |
35 virtual void SetUp() { | 37 virtual void SetUp() { |
36 CocoaTest::SetUp(); | 38 CocoaTest::SetUp(); |
37 | 39 |
38 // The controller cleans up after itself when the window closes. | 40 // The controller cleans up after itself when the window closes. |
39 controller_ = [[PageInfoWindowController alloc] init]; | 41 controller_ = [[PageInfoWindowController alloc] init]; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 108 |
107 NSWindow* window_; // Weak, owned by controller. | 109 NSWindow* window_; // Weak, owned by controller. |
108 }; | 110 }; |
109 | 111 |
110 | 112 |
111 TEST_F(PageInfoWindowMacTest, NoHistoryNoSecurity) { | 113 TEST_F(PageInfoWindowMacTest, NoHistoryNoSecurity) { |
112 model_->AddSection(false, | 114 model_->AddSection(false, |
113 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 115 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
114 l10n_util::GetStringFUTF16( | 116 l10n_util::GetStringFUTF16( |
115 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, | 117 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, |
116 ASCIIToUTF16("google.com"))); | 118 ASCIIToUTF16("google.com")), |
| 119 PageInfoModel::SECTION_INFO_IDENTITY); |
117 model_->AddSection(false, | 120 model_->AddSection(false, |
118 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 121 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
119 l10n_util::GetStringFUTF16( | 122 l10n_util::GetStringFUTF16( |
120 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, | 123 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
121 ASCIIToUTF16("google.com"))); | 124 ASCIIToUTF16("google.com")), |
| 125 PageInfoModel::SECTION_INFO_CONNECTION); |
122 | 126 |
123 bridge_->ModelChanged(); | 127 bridge_->ModelChanged(); |
124 | 128 |
125 CheckWindow(1, 2); | 129 CheckWindow(1, 2); |
126 } | 130 } |
127 | 131 |
128 | 132 |
129 TEST_F(PageInfoWindowMacTest, HistoryNoSecurity) { | 133 TEST_F(PageInfoWindowMacTest, HistoryNoSecurity) { |
130 model_->AddSection(false, | 134 model_->AddSection(false, |
131 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 135 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
132 l10n_util::GetStringFUTF16( | 136 l10n_util::GetStringFUTF16( |
133 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, | 137 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, |
134 ASCIIToUTF16("google.com"))); | 138 ASCIIToUTF16("google.com")), |
| 139 PageInfoModel::SECTION_INFO_IDENTITY); |
135 model_->AddSection(false, | 140 model_->AddSection(false, |
136 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 141 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
137 l10n_util::GetStringFUTF16( | 142 l10n_util::GetStringFUTF16( |
138 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, | 143 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
139 ASCIIToUTF16("google.com"))); | 144 ASCIIToUTF16("google.com")), |
| 145 PageInfoModel::SECTION_INFO_CONNECTION); |
140 | 146 |
141 // In practice, the history information comes later because it's queried | 147 // In practice, the history information comes later because it's queried |
142 // asynchronously, so replicate the double-build here. | 148 // asynchronously, so replicate the double-build here. |
143 bridge_->ModelChanged(); | 149 bridge_->ModelChanged(); |
144 | 150 |
145 model_->AddSection(false, | 151 model_->AddSection(false, |
146 l10n_util::GetStringUTF16( | 152 l10n_util::GetStringUTF16( |
147 IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), | 153 IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), |
148 l10n_util::GetStringUTF16( | 154 l10n_util::GetStringUTF16( |
149 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY)); | 155 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY), |
| 156 PageInfoModel::SECTION_INFO_FIRST_VISIT); |
150 | 157 |
151 bridge_->ModelChanged(); | 158 bridge_->ModelChanged(); |
152 | 159 |
153 CheckWindow(1, 3); | 160 CheckWindow(1, 3); |
154 } | 161 } |
155 | 162 |
156 | 163 |
157 TEST_F(PageInfoWindowMacTest, NoHistoryMixedSecurity) { | 164 TEST_F(PageInfoWindowMacTest, NoHistoryMixedSecurity) { |
158 model_->AddSection(true, | 165 model_->AddSection(true, |
159 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 166 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
160 l10n_util::GetStringFUTF16( | 167 l10n_util::GetStringFUTF16( |
161 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, | 168 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, |
162 ASCIIToUTF16("Goat Security Systems"))); | 169 ASCIIToUTF16("Goat Security Systems")), |
| 170 PageInfoModel::SECTION_INFO_IDENTITY); |
163 | 171 |
164 // This string is super long and the text should overflow the default clip | 172 // This string is super long and the text should overflow the default clip |
165 // region (kImageSize). | 173 // region (kImageSize). |
166 string16 title = | 174 string16 title = |
167 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE); | 175 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE); |
168 model_->AddSection(true, | 176 model_->AddSection(true, |
169 title, | 177 title, |
170 l10n_util::GetStringFUTF16( | 178 l10n_util::GetStringFUTF16( |
171 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, | 179 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, |
172 l10n_util::GetStringFUTF16( | 180 l10n_util::GetStringFUTF16( |
173 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, | 181 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, |
174 ASCIIToUTF16("chrome.google.com"), | 182 ASCIIToUTF16("chrome.google.com"), |
175 base::IntToString16(1024)), | 183 base::IntToString16(1024)), |
176 l10n_util::GetStringUTF16( | 184 l10n_util::GetStringUTF16( |
177 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING))); | 185 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)), |
| 186 PageInfoModel::SECTION_INFO_CONNECTION); |
178 | 187 |
179 bridge_->ModelChanged(); | 188 bridge_->ModelChanged(); |
180 | 189 |
181 NSArray* subviews = [[window_ contentView] subviews]; | 190 NSArray* subviews = [[window_ contentView] subviews]; |
182 CheckWindow(1, 2); | 191 CheckWindow(1, 2); |
183 | 192 |
184 // Look for the over-sized box. | 193 // Look for the over-sized box. |
185 NSString* targetTitle = base::SysUTF16ToNSString(title); | 194 NSString* targetTitle = base::SysUTF16ToNSString(title); |
186 for (NSView* subview in subviews) { | 195 for (NSView* subview in subviews) { |
187 if ([subview isKindOfClass:[NSBox class]]) { | 196 if ([subview isKindOfClass:[NSBox class]]) { |
188 NSBox* box = static_cast<NSBox*>(subview); | 197 NSBox* box = static_cast<NSBox*>(subview); |
189 if ([[box title] isEqualToString:targetTitle]) { | 198 if ([[box title] isEqualToString:targetTitle]) { |
190 // Typical box frame is ~55px, make sure this is extra large. | 199 // Typical box frame is ~55px, make sure this is extra large. |
191 EXPECT_LT(75, NSHeight([box frame])); | 200 EXPECT_LT(75, NSHeight([box frame])); |
192 } | 201 } |
193 } | 202 } |
194 } | 203 } |
195 } | 204 } |
196 | 205 |
197 } // namespace | 206 } // namespace |
OLD | NEW |