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

Unified Diff: ui/events/test/cocoa_test_event_utils.mm

Issue 2101903002: MacViews: Modify cocoa_test_event_utils::SynthesizeKeyEvent to use the correct event timestamp value (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Correct header order. Created 4 years, 6 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 | « ui/events/test/cocoa_test_event_utils.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/test/cocoa_test_event_utils.mm
diff --git a/ui/events/test/cocoa_test_event_utils.mm b/ui/events/test/cocoa_test_event_utils.mm
index 9810d589419b6f6a1f2ebd1b6d01313e80cef5c5..6daae98361a396620eddcbdf91001811543ea5ae 100644
--- a/ui/events/test/cocoa_test_event_utils.mm
+++ b/ui/events/test/cocoa_test_event_utils.mm
@@ -2,44 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import <Cocoa/Cocoa.h>
-#include <mach/mach_time.h>
+#import "ui/events/test/cocoa_test_event_utils.h"
+
#include <stdint.h>
+#include "base/time/time.h"
+#include "ui/events/base_event_utils.h"
#import "ui/events/keycodes/keyboard_code_conversion_mac.h"
-#include "ui/events/test/cocoa_test_event_utils.h"
namespace cocoa_test_event_utils {
-namespace {
-
-// From
-// http://stackoverflow.com/questions/1597383/cgeventtimestamp-to-nsdate
-// Which credits Apple sample code for this routine.
-uint64_t UpTimeInNanoseconds(void) {
- uint64_t time;
- uint64_t timeNano;
- static mach_timebase_info_data_t sTimebaseInfo;
-
- time = mach_absolute_time();
-
- // Convert to nanoseconds.
-
- // If this is the first time we've run, get the timebase.
- // We can use denom == 0 to indicate that sTimebaseInfo is
- // uninitialised because it makes no sense to have a zero
- // denominator is a fraction.
- if (sTimebaseInfo.denom == 0) {
- (void) mach_timebase_info(&sTimebaseInfo);
- }
-
- // This could overflow; for testing needs we probably don't care.
- timeNano = time * sTimebaseInfo.numer / sTimebaseInfo.denom;
- return timeNano;
-}
-
-} // namespace
-
NSEvent* MouseEventAtPoint(NSPoint point, NSEventType type,
NSUInteger modifiers) {
if (type == NSOtherMouseUp) {
@@ -61,7 +33,7 @@ NSEvent* MouseEventAtPoint(NSPoint point, NSEventType type,
return [NSEvent mouseEventWithType:type
location:point
modifierFlags:modifiers
- timestamp:0
+ timestamp:TimeIntervalSinceSystemStartup()
windowNumber:0
context:nil
eventNumber:0
@@ -80,7 +52,7 @@ NSEvent* MouseEventAtPointInWindow(NSPoint point,
return [NSEvent mouseEventWithType:type
location:point
modifierFlags:0
- timestamp:0
+ timestamp:TimeIntervalSinceSystemStartup()
windowNumber:[window windowNumber]
context:nil
eventNumber:0
@@ -142,7 +114,7 @@ NSEvent* KeyEventWithKeyCode(unsigned short key_code,
return [NSEvent keyEventWithType:event_type
location:NSZeroPoint
modifierFlags:modifiers
- timestamp:0
+ timestamp:TimeIntervalSinceSystemStartup()
windowNumber:0
context:nil
characters:chars
@@ -155,7 +127,7 @@ static NSEvent* EnterExitEventWithType(NSEventType event_type) {
return [NSEvent enterExitEventWithType:event_type
location:NSZeroPoint
modifierFlags:0
- timestamp:0
+ timestamp:TimeIntervalSinceSystemStartup()
windowNumber:0
context:nil
eventNumber:0
@@ -175,7 +147,7 @@ NSEvent* OtherEventWithType(NSEventType event_type) {
return [NSEvent otherEventWithType:event_type
location:NSZeroPoint
modifierFlags:0
- timestamp:0
+ timestamp:TimeIntervalSinceSystemStartup()
windowNumber:0
context:nil
subtype:0
@@ -184,7 +156,8 @@ NSEvent* OtherEventWithType(NSEventType event_type) {
}
NSTimeInterval TimeIntervalSinceSystemStartup() {
- return UpTimeInNanoseconds() / 1000000000.0;
+ base::TimeDelta time_elapsed = ui::EventTimeForNow() - base::TimeTicks();
+ return time_elapsed.InSecondsF();
}
NSEvent* SynthesizeKeyEvent(NSWindow* window,
« no previous file with comments | « ui/events/test/cocoa_test_event_utils.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698