| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 11 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
| 12 #include "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h" |
| 12 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" | 13 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" |
| 13 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" | 14 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" |
| 14 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" | 15 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/omnibox/browser/omnibox_popup_model.h" | 17 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 17 #include "components/omnibox/browser/omnibox_popup_view.h" | 18 #include "components/omnibox/browser/omnibox_popup_view.h" |
| 18 #include "components/toolbar/toolbar_model_impl.h" | 19 #include "components/toolbar/toolbar_model_impl.h" |
| 19 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
| 20 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| 21 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 170 |
| 170 // With popup open verify that pressing up and down arrow works. | 171 // With popup open verify that pressing up and down arrow works. |
| 171 popup_view.set_is_open(true); | 172 popup_view.set_is_open(true); |
| 172 model->set_up_or_down_count(0); | 173 model->set_up_or_down_count(0); |
| 173 view.OnDoCommandBySelector(@selector(moveDown:)); | 174 view.OnDoCommandBySelector(@selector(moveDown:)); |
| 174 EXPECT_EQ(1, model->up_or_down_count()); | 175 EXPECT_EQ(1, model->up_or_down_count()); |
| 175 model->set_up_or_down_count(0); | 176 model->set_up_or_down_count(0); |
| 176 view.OnDoCommandBySelector(@selector(moveUp:)); | 177 view.OnDoCommandBySelector(@selector(moveUp:)); |
| 177 EXPECT_EQ(-1, model->up_or_down_count()); | 178 EXPECT_EQ(-1, model->up_or_down_count()); |
| 178 } | 179 } |
| 180 |
| 181 TEST_F(OmniboxViewMacTest, WritingDirectionLTR) { |
| 182 TestingToolbarModelDelegate delegate; |
| 183 ToolbarModelImpl toolbar_model(&delegate, 32 * 1024); |
| 184 TestingOmniboxEditController edit_controller(&toolbar_model); |
| 185 OmniboxViewMac view(&edit_controller, profile(), NULL, NULL); |
| 186 |
| 187 // This is deleted by the omnibox view. |
| 188 MockOmniboxEditModel* model = |
| 189 new MockOmniboxEditModel(&view, &edit_controller, profile()); |
| 190 MockOmniboxPopupView popup_view; |
| 191 OmniboxPopupModel popup_model(&popup_view, model); |
| 192 |
| 193 model->OnSetFocus(true); |
| 194 SetModel(&view, model); |
| 195 view.SetUserText(base::ASCIIToUTF16("foo.com")); |
| 196 model->OnChanged(); |
| 197 |
| 198 base::scoped_nsobject<NSMutableAttributedString> string( |
| 199 [[NSMutableAttributedString alloc] initWithString:@"foo.com"]); |
| 200 view.ApplyTextStyle(string); |
| 201 |
| 202 NSParagraphStyle* paragraphStyle = |
| 203 [string attribute:NSParagraphStyleAttributeName |
| 204 atIndex:0 |
| 205 effectiveRange:NULL]; |
| 206 DCHECK(paragraphStyle); |
| 207 EXPECT_EQ(paragraphStyle.alignment, NSLeftTextAlignment); |
| 208 EXPECT_EQ(paragraphStyle.baseWritingDirection, NSWritingDirectionLeftToRight); |
| 209 } |
| 210 |
| 211 TEST_F(OmniboxViewMacTest, WritingDirectionRTL) { |
| 212 cocoa_l10n_util::ScopedForceRTLMac rtl; |
| 213 |
| 214 TestingToolbarModelDelegate delegate; |
| 215 ToolbarModelImpl toolbar_model(&delegate, 32 * 1024); |
| 216 TestingOmniboxEditController edit_controller(&toolbar_model); |
| 217 OmniboxViewMac view(&edit_controller, profile(), NULL, NULL); |
| 218 |
| 219 // This is deleted by the omnibox view. |
| 220 MockOmniboxEditModel* model = |
| 221 new MockOmniboxEditModel(&view, &edit_controller, profile()); |
| 222 MockOmniboxPopupView popup_view; |
| 223 OmniboxPopupModel popup_model(&popup_view, model); |
| 224 |
| 225 model->OnSetFocus(true); |
| 226 SetModel(&view, model); |
| 227 view.SetUserText(base::ASCIIToUTF16("foo.com")); |
| 228 model->OnChanged(); |
| 229 |
| 230 base::scoped_nsobject<NSMutableAttributedString> string( |
| 231 [[NSMutableAttributedString alloc] initWithString:@"foo.com"]); |
| 232 view.ApplyTextStyle(string); |
| 233 |
| 234 NSParagraphStyle* paragraphStyle = |
| 235 [string attribute:NSParagraphStyleAttributeName |
| 236 atIndex:0 |
| 237 effectiveRange:NULL]; |
| 238 DCHECK(paragraphStyle); |
| 239 EXPECT_EQ(paragraphStyle.alignment, NSRightTextAlignment); |
| 240 EXPECT_EQ(paragraphStyle.baseWritingDirection, NSWritingDirectionLeftToRight); |
| 241 } |
| OLD | NEW |