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

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

Issue 2442223002: Views: Give ScrollViewTest a test harness. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | ui/views/controls/scroll_view_unittest.cc » ('j') | ui/views/controls/scroll_view_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/test/scoped_preferred_scroller_style_mac.mm
diff --git a/ui/base/test/scoped_preferred_scroller_style_mac.mm b/ui/base/test/scoped_preferred_scroller_style_mac.mm
index 1a73819bd122591ef9f27ec219f103fa89e0b5d9..84eb27503000301b226272f9d9f2257708f2db6d 100644
--- a/ui/base/test/scoped_preferred_scroller_style_mac.mm
+++ b/ui/base/test/scoped_preferred_scroller_style_mac.mm
@@ -6,12 +6,17 @@
#import <AppKit/AppKit.h>
+#include "base/logging.h"
#import "base/mac/scoped_objc_class_swizzler.h"
using base::mac::ScopedObjCClassSwizzler;
namespace {
+// Swizzling can be stacked, but not interleaved without creating unexpected
+// states. Require that there is only one swizzler rather than tracking a stack.
+bool g_swizzling = false;
+
void NotifyStyleChanged() {
[[NSNotificationCenter defaultCenter]
postNotificationName:NSPreferredScrollerStyleDidChangeNotification
@@ -60,6 +65,8 @@ ScopedPreferredScrollerStyle::ScopedPreferredScrollerStyle(bool overlay)
? [FakeNSScrollerPreferredStyleOverlayDonor class]
: [FakeNSScrollerPreferredStyleLegacyDonor class];
+ DCHECK(!g_swizzling);
+ g_swizzling = true;
swizzler_.reset(new ScopedObjCClassSwizzler(
[NSScroller class], style_class, @selector(preferredScrollerStyle)));
@@ -69,6 +76,8 @@ ScopedPreferredScrollerStyle::ScopedPreferredScrollerStyle(bool overlay)
ScopedPreferredScrollerStyle::~ScopedPreferredScrollerStyle() {
swizzler_.reset();
+ DCHECK(g_swizzling);
+ g_swizzling = false;
if ([NSScroller preferredScrollerStyle] != GetScrollerStyle(overlay_))
NotifyStyleChanged();
« no previous file with comments | « no previous file | ui/views/controls/scroll_view_unittest.cc » ('j') | ui/views/controls/scroll_view_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698