| 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_bubble_controller.h" | 11 #import "chrome/browser/cocoa/page_info_bubble_controller.h" |
| 12 #include "chrome/browser/cocoa/browser_test_helper.h" | 12 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 13 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 14 #include "chrome/browser/page_info_model.h" | 14 #include "chrome/browser/page_info_model.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class FakeModel : public PageInfoModel { | 19 class FakeModel : public PageInfoModel { |
| 20 public: | 20 public: |
| 21 void AddSection(SectionInfoState state, | 21 FakeModel() : PageInfoModel() {} |
| 22 |
| 23 void AddSection(SectionStateIcon icon_id, |
| 22 const string16& title, | 24 const string16& title, |
| 23 const string16& description, | 25 const string16& description, |
| 24 SectionInfoType type) { | 26 SectionInfoType type) { |
| 25 sections_.push_back(SectionInfo( | 27 sections_.push_back(SectionInfo( |
| 26 state, title, string16(), description, type)); | 28 icon_id, title, string16(), description, type)); |
| 27 } | 29 } |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 class FakeBridge : public PageInfoModel::PageInfoModelObserver { | 32 class FakeBridge : public PageInfoModel::PageInfoModelObserver { |
| 31 public: | 33 public: |
| 32 void ModelChanged() {} | 34 void ModelChanged() {} |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 class PageInfoBubbleControllerTest : public CocoaTest { | 37 class PageInfoBubbleControllerTest : public CocoaTest { |
| 36 public: | 38 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 92 |
| 91 BrowserTestHelper helper_; | 93 BrowserTestHelper helper_; |
| 92 | 94 |
| 93 PageInfoBubbleController* controller_; // Weak, owns self. | 95 PageInfoBubbleController* controller_; // Weak, owns self. |
| 94 FakeModel* model_; // Weak, owned by controller. | 96 FakeModel* model_; // Weak, owned by controller. |
| 95 NSWindow* window_; // Weak, owned by controller. | 97 NSWindow* window_; // Weak, owned by controller. |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 | 100 |
| 99 TEST_F(PageInfoBubbleControllerTest, NoHistoryNoSecurity) { | 101 TEST_F(PageInfoBubbleControllerTest, NoHistoryNoSecurity) { |
| 100 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 102 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
| 101 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 103 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
| 102 l10n_util::GetStringFUTF16( | 104 l10n_util::GetStringFUTF16( |
| 103 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, | 105 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, |
| 104 ASCIIToUTF16("google.com")), | 106 ASCIIToUTF16("google.com")), |
| 105 PageInfoModel::SECTION_INFO_IDENTITY); | 107 PageInfoModel::SECTION_INFO_IDENTITY); |
| 106 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 108 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
| 107 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 109 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
| 108 l10n_util::GetStringFUTF16( | 110 l10n_util::GetStringFUTF16( |
| 109 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, | 111 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 110 ASCIIToUTF16("google.com")), | 112 ASCIIToUTF16("google.com")), |
| 111 PageInfoModel::SECTION_INFO_CONNECTION); | 113 PageInfoModel::SECTION_INFO_CONNECTION); |
| 112 | 114 |
| 113 CreateBubble(); | 115 CreateBubble(); |
| 114 CheckWindow(/*text=*/4, /*image=*/2, /*spacer=*/1, /*button=*/1); | 116 CheckWindow(/*text=*/4, /*image=*/2, /*spacer=*/1, /*button=*/1); |
| 115 } | 117 } |
| 116 | 118 |
| 117 | 119 |
| 118 TEST_F(PageInfoBubbleControllerTest, HistoryNoSecurity) { | 120 TEST_F(PageInfoBubbleControllerTest, HistoryNoSecurity) { |
| 119 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 121 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
| 120 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 122 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
| 121 l10n_util::GetStringFUTF16( | 123 l10n_util::GetStringFUTF16( |
| 122 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, | 124 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY, |
| 123 ASCIIToUTF16("google.com")), | 125 ASCIIToUTF16("google.com")), |
| 124 PageInfoModel::SECTION_INFO_IDENTITY); | 126 PageInfoModel::SECTION_INFO_IDENTITY); |
| 125 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 127 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
| 126 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 128 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
| 127 l10n_util::GetStringFUTF16( | 129 l10n_util::GetStringFUTF16( |
| 128 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, | 130 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 129 ASCIIToUTF16("google.com")), | 131 ASCIIToUTF16("google.com")), |
| 130 PageInfoModel::SECTION_INFO_CONNECTION); | 132 PageInfoModel::SECTION_INFO_CONNECTION); |
| 131 | 133 |
| 132 // In practice, the history information comes later because it's queried | 134 // In practice, the history information comes later because it's queried |
| 133 // asynchronously, so replicate the double-build here. | 135 // asynchronously, so replicate the double-build here. |
| 134 CreateBubble(); | 136 CreateBubble(); |
| 135 | 137 |
| 136 model_->AddSection(PageInfoModel::SECTION_STATE_ERROR, | 138 model_->AddSection(PageInfoModel::ICON_STATE_ERROR, |
| 137 l10n_util::GetStringUTF16( | 139 l10n_util::GetStringUTF16( |
| 138 IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), | 140 IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE), |
| 139 l10n_util::GetStringUTF16( | 141 l10n_util::GetStringUTF16( |
| 140 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY), | 142 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY), |
| 141 PageInfoModel::SECTION_INFO_FIRST_VISIT); | 143 PageInfoModel::SECTION_INFO_FIRST_VISIT); |
| 142 | 144 |
| 143 [controller_ performLayout]; | 145 [controller_ performLayout]; |
| 144 | 146 |
| 145 CheckWindow(/*text=*/6, /*image=*/2, /*spacer=*/2, /*button=*/1); | 147 CheckWindow(/*text=*/6, /*image=*/3, /*spacer=*/2, /*button=*/1); |
| 146 } | 148 } |
| 147 | 149 |
| 148 | 150 |
| 149 TEST_F(PageInfoBubbleControllerTest, NoHistoryMixedSecurity) { | 151 TEST_F(PageInfoBubbleControllerTest, NoHistoryMixedSecurity) { |
| 150 model_->AddSection(PageInfoModel::SECTION_STATE_OK, | 152 model_->AddSection(PageInfoModel::ICON_STATE_OK, |
| 151 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 153 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
| 152 l10n_util::GetStringFUTF16( | 154 l10n_util::GetStringFUTF16( |
| 153 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, | 155 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, |
| 154 ASCIIToUTF16("Goat Security Systems")), | 156 ASCIIToUTF16("Goat Security Systems")), |
| 155 PageInfoModel::SECTION_INFO_IDENTITY); | 157 PageInfoModel::SECTION_INFO_IDENTITY); |
| 156 | 158 |
| 157 // This string is super long and the text should overflow the default clip | 159 // This string is super long and the text should overflow the default clip |
| 158 // region (kImageSize). | 160 // region (kImageSize). |
| 159 string16 description = l10n_util::GetStringFUTF16( | 161 string16 description = l10n_util::GetStringFUTF16( |
| 160 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, | 162 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, |
| 161 l10n_util::GetStringFUTF16( | 163 l10n_util::GetStringFUTF16( |
| 162 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, | 164 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, |
| 163 ASCIIToUTF16("chrome.google.com"), | 165 ASCIIToUTF16("chrome.google.com"), |
| 164 base::IntToString16(1024)), | 166 base::IntToString16(1024)), |
| 165 l10n_util::GetStringUTF16( | 167 l10n_util::GetStringUTF16( |
| 166 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)); | 168 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)); |
| 167 | 169 |
| 168 model_->AddSection(PageInfoModel::SECTION_STATE_OK, | 170 model_->AddSection(PageInfoModel::ICON_STATE_OK, |
| 169 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), | 171 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE), |
| 170 description, | 172 description, |
| 171 PageInfoModel::SECTION_INFO_CONNECTION); | 173 PageInfoModel::SECTION_INFO_CONNECTION); |
| 172 | 174 |
| 173 CreateBubble(); | 175 CreateBubble(); |
| 174 | 176 |
| 175 NSArray* subviews = [[window_ contentView] subviews]; | 177 NSArray* subviews = [[window_ contentView] subviews]; |
| 176 CheckWindow(/*text=*/4, /*image=*/2, /*spacer=*/1, /*button=*/1); | 178 CheckWindow(/*text=*/4, /*image=*/2, /*spacer=*/1, /*button=*/1); |
| 177 | 179 |
| 178 // Look for the over-sized box. | 180 // Look for the over-sized box. |
| 179 NSString* targetDesc = base::SysUTF16ToNSString(description); | 181 NSString* targetDesc = base::SysUTF16ToNSString(description); |
| 180 for (NSView* subview in subviews) { | 182 for (NSView* subview in subviews) { |
| 181 if ([subview isKindOfClass:[NSTextField class]]) { | 183 if ([subview isKindOfClass:[NSTextField class]]) { |
| 182 NSTextField* desc = static_cast<NSTextField*>(subview); | 184 NSTextField* desc = static_cast<NSTextField*>(subview); |
| 183 if ([[desc stringValue] isEqualToString:targetDesc]) { | 185 if ([[desc stringValue] isEqualToString:targetDesc]) { |
| 184 // Typical box frame is ~55px, make sure this is extra large. | 186 // Typical box frame is ~55px, make sure this is extra large. |
| 185 EXPECT_LT(75, NSHeight([desc frame])); | 187 EXPECT_LT(75, NSHeight([desc frame])); |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 } | 191 } |
| 190 | 192 |
| 191 } // namespace | 193 } // namespace |
| OLD | NEW |