| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ui/keyboard/hardware_keyboard_watcher.h" | 5 #import "ios/chrome/browser/ui/keyboard/hardware_keyboard_watcher.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
| 11 #import "third_party/ocmock/OCMock/OCMock.h" | 11 #import "third_party/ocmock/OCMock/OCMock.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 void PostKeyboardWillChangeNotification(CGRect beginFrame, CGRect endFrame) { | 15 void PostKeyboardWillChangeNotification(CGRect beginFrame, CGRect endFrame) { |
| 16 [[NSNotificationCenter defaultCenter] | 16 [[NSNotificationCenter defaultCenter] |
| 17 postNotificationName:UIKeyboardWillChangeFrameNotification | 17 postNotificationName:UIKeyboardWillChangeFrameNotification |
| 18 object:nil | 18 object:nil |
| 19 userInfo:@{ | 19 userInfo:@{ |
| 20 UIKeyboardFrameBeginUserInfoKey : | 20 UIKeyboardFrameBeginUserInfoKey : |
| 21 [NSValue valueWithCGRect:beginFrame], | 21 [NSValue valueWithCGRect:beginFrame], |
| 22 UIKeyboardFrameEndUserInfoKey : | 22 UIKeyboardFrameEndUserInfoKey : |
| 23 [NSValue valueWithCGRect:endFrame], | 23 [NSValue valueWithCGRect:endFrame], |
| 24 }]; | 24 }]; |
| 25 } | 25 } |
| 26 | 26 |
| 27 class HardwareKeyboardWatcherTest : public PlatformTest { | 27 typedef PlatformTest HardwareKeyboardWatcherTest; |
| 28 public: | |
| 29 HardwareKeyboardWatcherTest() { | |
| 30 _window.reset( | |
| 31 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]); | |
| 32 [_window makeKeyAndVisible]; | |
| 33 } | |
| 34 | |
| 35 protected: | |
| 36 base::scoped_nsobject<UIWindow> _window; | |
| 37 }; | |
| 38 | 28 |
| 39 TEST_F(HardwareKeyboardWatcherTest, AccessoryViewNotInHierarchy_NoHistogram) { | 29 TEST_F(HardwareKeyboardWatcherTest, AccessoryViewNotInHierarchy_NoHistogram) { |
| 40 base::HistogramTester histogram_tester; | 30 base::HistogramTester histogram_tester; |
| 41 id mockView = [OCMockObject niceMockForClass:[UIView class]]; | 31 id mockView = [OCMockObject niceMockForClass:[UIView class]]; |
| 42 [[mockView stub] andReturn:nil]; | 32 [[mockView stub] andReturn:nil]; |
| 43 base::scoped_nsobject<HardwareKeyboardWatcher> watcher( | 33 base::scoped_nsobject<HardwareKeyboardWatcher> watcher( |
| 44 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); | 34 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); |
| 45 | 35 |
| 46 PostKeyboardWillChangeNotification(CGRectZero, CGRectZero); | 36 PostKeyboardWillChangeNotification(CGRectZero, CGRectZero); |
| 47 PostKeyboardWillChangeNotification(CGRectInfinite, CGRectInfinite); | 37 PostKeyboardWillChangeNotification(CGRectInfinite, CGRectInfinite); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); | 109 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); |
| 120 | 110 |
| 121 PostKeyboardWillChangeNotification(CGRectMake(0, -50, 100, 100), | 111 PostKeyboardWillChangeNotification(CGRectMake(0, -50, 100, 100), |
| 122 CGRectMake(0, 0, 100, 100)); | 112 CGRectMake(0, 0, 100, 100)); |
| 123 | 113 |
| 124 histogram_tester.ExpectUniqueSample("Omnibox.HardwareKeyboardModeEnabled", | 114 histogram_tester.ExpectUniqueSample("Omnibox.HardwareKeyboardModeEnabled", |
| 125 true, 1); | 115 true, 1); |
| 126 } | 116 } |
| 127 | 117 |
| 128 } // namespace | 118 } // namespace |
| OLD | NEW |