Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: ui/base/test/scoped_fake_full_keyboard_access.mm

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Address review comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/test/scoped_fake_full_keyboard_access.mm
diff --git a/ui/base/test/scoped_fake_full_keyboard_access.mm b/ui/base/test/scoped_fake_full_keyboard_access.mm
new file mode 100644
index 0000000000000000000000000000000000000000..dffccdb057006b95af1fe7be1006efe86485460e
--- /dev/null
+++ b/ui/base/test/scoped_fake_full_keyboard_access.mm
@@ -0,0 +1,60 @@
+// 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.
+
+#import "ui/base/test/scoped_fake_full_keyboard_access.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/logging.h"
+#import "base/mac/scoped_objc_class_swizzler.h"
+
+namespace {
+
+ui::test::ScopedFakeFullKeyboardAccess* g_instance = nullptr;
+bool g_full_keyboard_access_mode = true;
tapted 2016/05/03 08:08:25 this can be stored as a data member on ScopedFakeF
karandeepb 2016/05/04 01:56:38 Done.
+
+} // namespace
+
+// Donates a testing implementation of [NSApp isFullKeyboardAccessEnabled].
+@interface FakeNSAppKeyboardAccessDonor : NSObject
+@end
+
+@implementation FakeNSAppKeyboardAccessDonor
+
+- (BOOL)isFullKeyboardAccessEnabled {
+ return g_full_keyboard_access_mode;
+}
+
+@end
+
+namespace ui {
+namespace test {
+
+ScopedFakeFullKeyboardAccess::ScopedFakeFullKeyboardAccess()
+ : swizzler_(new base::mac::ScopedObjCClassSwizzler(
+ [NSApplication class],
+ [FakeNSAppKeyboardAccessDonor class],
+ @selector(isFullKeyboardAccessEnabled))) {
+ DCHECK(!g_instance)
+ << "Cannot initialize ScopedFakeFullKeyboardAccess twice\n";
+ g_instance = this;
+ g_full_keyboard_access_mode = true;
+}
+
+ScopedFakeFullKeyboardAccess::~ScopedFakeFullKeyboardAccess() {
+ DCHECK_EQ(g_instance, this);
+ g_instance = nullptr;
+}
+
+// static
+ScopedFakeFullKeyboardAccess* ScopedFakeFullKeyboardAccess::GetInstance() {
+ return g_instance;
+}
+
+void ScopedFakeFullKeyboardAccess::SetFullKeyboardAccessState(bool new_state) {
+ g_full_keyboard_access_mode = new_state;
+}
+
+} // namespace test
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698