Chromium Code Reviews| 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/i18n/rtl.h" | |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/test/scoped_feature_list.h" | |
| 13 #include "chrome/browser/ui/cocoa/l10n_util.h" | |
| 11 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 14 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
| 12 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" | 15 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" |
| 13 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" | 16 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" |
| 14 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" | 17 #include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/omnibox/browser/omnibox_popup_model.h" | 19 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 17 #include "components/omnibox/browser/omnibox_popup_view.h" | 20 #include "components/omnibox/browser/omnibox_popup_view.h" |
| 18 #include "components/toolbar/toolbar_model_impl.h" | 21 #include "components/toolbar/toolbar_model_impl.h" |
| 19 #include "content/public/common/content_constants.h" | 22 #include "content/public/common/content_constants.h" |
| 20 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 21 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 class MockOmniboxEditModel : public OmniboxEditModel { | 30 class MockOmniboxEditModel : public OmniboxEditModel { |
| 28 public: | 31 public: |
| 29 MockOmniboxEditModel(OmniboxView* view, | 32 MockOmniboxEditModel(OmniboxView* view, |
| 30 OmniboxEditController* controller, | 33 OmniboxEditController* controller, |
| 31 Profile* profile) | 34 Profile* profile) |
| 32 : OmniboxEditModel( | 35 : OmniboxEditModel( |
| 33 view, | 36 view, |
| 34 controller, | 37 controller, |
| 35 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), | 38 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), |
| 36 up_or_down_count_(0) {} | 39 up_or_down_count_(0), |
| 40 current_text_is_url_(false) {} | |
| 37 | 41 |
| 38 void OnUpOrDownKeyPressed(int count) override { up_or_down_count_ = count; } | 42 void OnUpOrDownKeyPressed(int count) override { up_or_down_count_ = count; } |
| 39 | 43 |
| 44 bool CurrentTextIsURL() const override { return current_text_is_url_; } | |
|
Peter Kasting
2016/12/12 19:57:10
Why are you adding this override instead of simply
| |
| 45 | |
| 40 int up_or_down_count() const { return up_or_down_count_; } | 46 int up_or_down_count() const { return up_or_down_count_; } |
| 41 | 47 |
| 42 void set_up_or_down_count(int count) { | 48 void set_up_or_down_count(int count) { |
| 43 up_or_down_count_ = count; | 49 up_or_down_count_ = count; |
| 44 } | 50 } |
| 45 | 51 |
| 52 void set_current_text_is_url(bool is_url) { current_text_is_url_ = is_url; } | |
| 53 | |
| 46 private: | 54 private: |
| 47 int up_or_down_count_; | 55 int up_or_down_count_; |
| 56 bool current_text_is_url_; | |
| 48 | 57 |
| 49 DISALLOW_COPY_AND_ASSIGN(MockOmniboxEditModel); | 58 DISALLOW_COPY_AND_ASSIGN(MockOmniboxEditModel); |
| 50 }; | 59 }; |
| 51 | 60 |
| 52 class MockOmniboxPopupView : public OmniboxPopupView { | 61 class MockOmniboxPopupView : public OmniboxPopupView { |
| 53 public: | 62 public: |
| 54 MockOmniboxPopupView() : is_open_(false) {} | 63 MockOmniboxPopupView() : is_open_(false) {} |
| 55 ~MockOmniboxPopupView() override {} | 64 ~MockOmniboxPopupView() override {} |
| 56 | 65 |
| 57 // Overridden from OmniboxPopupView: | 66 // Overridden from OmniboxPopupView: |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 178 |
| 170 // With popup open verify that pressing up and down arrow works. | 179 // With popup open verify that pressing up and down arrow works. |
| 171 popup_view.set_is_open(true); | 180 popup_view.set_is_open(true); |
| 172 model->set_up_or_down_count(0); | 181 model->set_up_or_down_count(0); |
| 173 view.OnDoCommandBySelector(@selector(moveDown:)); | 182 view.OnDoCommandBySelector(@selector(moveDown:)); |
| 174 EXPECT_EQ(1, model->up_or_down_count()); | 183 EXPECT_EQ(1, model->up_or_down_count()); |
| 175 model->set_up_or_down_count(0); | 184 model->set_up_or_down_count(0); |
| 176 view.OnDoCommandBySelector(@selector(moveUp:)); | 185 view.OnDoCommandBySelector(@selector(moveUp:)); |
| 177 EXPECT_EQ(-1, model->up_or_down_count()); | 186 EXPECT_EQ(-1, model->up_or_down_count()); |
| 178 } | 187 } |
| 188 | |
| 189 TEST_F(OmniboxViewMacTest, WritingDirectionLTR) { | |
| 190 OmniboxViewMac view(NULL, profile(), NULL, NULL); | |
| 191 | |
| 192 // This is deleted by the omnibox view. | |
| 193 MockOmniboxEditModel* model = | |
| 194 new MockOmniboxEditModel(&view, NULL, profile()); | |
| 195 model->set_current_text_is_url(true); | |
| 196 SetModel(&view, model); | |
| 197 base::scoped_nsobject<NSMutableAttributedString> string( | |
| 198 [[NSMutableAttributedString alloc] initWithString:@"Foo"]); | |
| 199 view.ApplyTextStyle(string); | |
| 200 | |
| 201 NSParagraphStyle* paragraphStyle = | |
| 202 [string attribute:NSParagraphStyleAttributeName | |
| 203 atIndex:0 | |
| 204 effectiveRange:NULL]; | |
| 205 DCHECK(paragraphStyle); | |
| 206 EXPECT_EQ(paragraphStyle.alignment, NSLeftTextAlignment); | |
| 207 model->set_current_text_is_url(true); | |
| 208 EXPECT_EQ(paragraphStyle.baseWritingDirection, NSWritingDirectionLeftToRight); | |
| 209 } | |
| 210 | |
| 211 TEST_F(OmniboxViewMacTest, WritingDirectionRTL) { | |
| 212 // TODO(lgrey): Replace setup with scoper when crrev.com/2555033003 lands. | |
| 213 std::string old_locale(base::i18n::GetConfiguredLocale()); | |
| 214 base::i18n::SetICUDefaultLocale("he"); // Hebrew | |
| 215 base::test::ScopedFeatureList scoped_feature_list; | |
| 216 scoped_feature_list.InitAndEnableFeature( | |
| 217 cocoa_l10n_util::kExperimentalMacRTL); | |
| 218 NSString* const appleTextDirectionDefaultsKey = @"AppleTextDirection"; | |
| 219 NSString* const forceRTLWritingDirectionDefaultsKey = | |
| 220 @"NSForceRightToLeftWritingDirection"; | |
| 221 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | |
| 222 BOOL oldTextDirection = [defaults boolForKey:appleTextDirectionDefaultsKey]; | |
| 223 BOOL oldRTLWritingDirection = | |
| 224 [defaults boolForKey:forceRTLWritingDirectionDefaultsKey]; | |
| 225 [defaults setBool:YES forKey:appleTextDirectionDefaultsKey]; | |
| 226 [defaults setBool:YES forKey:forceRTLWritingDirectionDefaultsKey]; | |
| 227 | |
| 228 OmniboxViewMac view(NULL, profile(), NULL, NULL); | |
| 229 | |
| 230 // This is deleted by the omnibox view. | |
| 231 MockOmniboxEditModel* model = | |
| 232 new MockOmniboxEditModel(&view, NULL, profile()); | |
| 233 SetModel(&view, model); | |
| 234 model->set_current_text_is_url(true); | |
| 235 base::scoped_nsobject<NSMutableAttributedString> string( | |
| 236 [[NSMutableAttributedString alloc] initWithString:@"Foo"]); | |
| 237 view.ApplyTextStyle(string); | |
| 238 | |
| 239 NSParagraphStyle* paragraphStyle = | |
| 240 [string attribute:NSParagraphStyleAttributeName | |
| 241 atIndex:0 | |
| 242 effectiveRange:NULL]; | |
| 243 DCHECK(paragraphStyle); | |
| 244 EXPECT_EQ(paragraphStyle.alignment, NSRightTextAlignment); | |
| 245 EXPECT_EQ(paragraphStyle.baseWritingDirection, NSWritingDirectionLeftToRight); | |
| 246 | |
| 247 base::i18n::SetICUDefaultLocale(old_locale); | |
| 248 [defaults setBool:oldTextDirection forKey:appleTextDirectionDefaultsKey]; | |
| 249 [defaults setBool:oldRTLWritingDirection | |
| 250 forKey:forceRTLWritingDirectionDefaultsKey]; | |
| 251 } | |
| OLD | NEW |