Commit 0390c3aa authored by lgrey's avatar lgrey Committed by Commit bot

Add ScopedForceRTLMac class for Cocoa browser RTL testing

BUG=673362

Review-Url: https://codereview.chromium.org/2555033003
Cr-Commit-Position: refs/heads/master@{#438185}
parent b7c0b121
......@@ -3427,6 +3427,8 @@ static_library("test_support") {
"cocoa/test/cocoa_test_helper.mm",
"cocoa/test/run_loop_testing.h",
"cocoa/test/run_loop_testing.mm",
"cocoa/test/scoped_force_rtl_mac.h",
"cocoa/test/scoped_force_rtl_mac.mm",
"find_bar/find_bar_host_unittest_util.h",
"login/login_handler_test_utils.cc",
"login/login_handler_test_utils.h",
......
......@@ -5,19 +5,17 @@
#import <Cocoa/Cocoa.h>
#include <stddef.h>
#include "base/i18n/rtl.h"
#import "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_view.h"
#include "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
......@@ -584,29 +582,9 @@ TEST_F(TabControllerTest, LayoutAndVisibilityOfSubviews) {
}
TEST_F(TabControllerTest, LayoutAndVisibilityOfSubviewsRTL) {
std::string old_locale(base::i18n::GetConfiguredLocale());
base::i18n::SetICUDefaultLocale("he");
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
cocoa_l10n_util::kExperimentalMacRTL);
// TODO(lgrey): Create ScopedNSUserDefaults or similar to do
// this automatically.
NSString* const appleTextDirectionDefaultsKey = @"AppleTextDirection";
NSString* const forceRTLWritingDirectionDefaultsKey =
@"NSForceRightToLeftWritingDirection";
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
BOOL oldTextDirection = [defaults boolForKey:appleTextDirectionDefaultsKey];
BOOL oldRTLWritingDirection =
[defaults boolForKey:forceRTLWritingDirectionDefaultsKey];
[defaults setBool:YES forKey:appleTextDirectionDefaultsKey];
[defaults setBool:YES forKey:forceRTLWritingDirectionDefaultsKey];
cocoa_l10n_util::ScopedForceRTLMac scoped_rtl;
CheckLayoutAndVisibilityOfSubviewsForAllStates(true);
base::i18n::SetICUDefaultLocale(old_locale);
[defaults setBool:oldTextDirection forKey:appleTextDirectionDefaultsKey];
[defaults setBool:oldRTLWritingDirection
forKey:forceRTLWritingDirectionDefaultsKey];
}
} // namespace
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_TEST_SCOPED_FORCE_RTL_MAC_H__
#define CHROME_BROWSER_UI_COCOA_TEST_SCOPED_FORCE_RTL_MAC_H__
#include <string>
#include "base/test/scoped_feature_list.h"
namespace cocoa_l10n_util {
// Enables all flags required for
// |cocoa_l10n_util::ShouldDoExperimentalRTLLayout| to return true.
class ScopedForceRTLMac final {
public:
ScopedForceRTLMac();
~ScopedForceRTLMac();
private:
BOOL original_apple_text_direction_;
BOOL original_rtl_writing_direction_;
std::string original_locale_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(ScopedForceRTLMac);
};
} // namespace cocoa_l10n_util
#endif // CHROME_BROWSER_UI_COCOA_TEST_SCOPED_FORCE_RTL_MAC_H__
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h"
#import <Foundation/Foundation.h>
#include "base/i18n/rtl.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
namespace {
NSString* const kAppleTextDirectionDefaultsKey = @"AppleTextDirection";
NSString* const kForceRTLWritingDirectionDefaultsKey =
@"NSForceRightToLeftWritingDirection";
const char kDefaultRTLLocale[] = "he"; // Hebrew.
} // namespace
namespace cocoa_l10n_util {
ScopedForceRTLMac::ScopedForceRTLMac() {
scoped_feature_list_.InitAndEnableFeature(kExperimentalMacRTL);
NSUserDefaults* standard_defaults = [NSUserDefaults standardUserDefaults];
original_apple_text_direction_ =
[standard_defaults boolForKey:kAppleTextDirectionDefaultsKey];
original_rtl_writing_direction_ =
[standard_defaults boolForKey:kForceRTLWritingDirectionDefaultsKey];
[standard_defaults setBool:YES forKey:kAppleTextDirectionDefaultsKey];
[standard_defaults setBool:YES forKey:kForceRTLWritingDirectionDefaultsKey];
original_locale_ = base::i18n::GetConfiguredLocale();
base::i18n::SetICUDefaultLocale(kDefaultRTLLocale);
}
ScopedForceRTLMac::~ScopedForceRTLMac() {
[[NSUserDefaults standardUserDefaults]
setBool:original_apple_text_direction_
forKey:kAppleTextDirectionDefaultsKey];
[[NSUserDefaults standardUserDefaults]
setBool:original_rtl_writing_direction_
forKey:kForceRTLWritingDirectionDefaultsKey];
base::i18n::SetICUDefaultLocale(original_locale_);
}
} // namespace cocoa_l10n_util
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment