| 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 typedef PlatformTest HardwareKeyboardWatcherTest; | 27 class HardwareKeyboardWatcherTest : public PlatformTest { |
| 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 }; |
| 28 | 38 |
| 29 TEST_F(HardwareKeyboardWatcherTest, AccessoryViewNotInHierarchy_NoHistogram) { | 39 TEST_F(HardwareKeyboardWatcherTest, AccessoryViewNotInHierarchy_NoHistogram) { |
| 30 base::HistogramTester histogram_tester; | 40 base::HistogramTester histogram_tester; |
| 31 id mockView = [OCMockObject niceMockForClass:[UIView class]]; | 41 id mockView = [OCMockObject niceMockForClass:[UIView class]]; |
| 32 [[mockView stub] andReturn:nil]; | 42 [[mockView stub] andReturn:nil]; |
| 33 base::scoped_nsobject<HardwareKeyboardWatcher> watcher( | 43 base::scoped_nsobject<HardwareKeyboardWatcher> watcher( |
| 34 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); | 44 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); |
| 35 | 45 |
| 36 PostKeyboardWillChangeNotification(CGRectZero, CGRectZero); | 46 PostKeyboardWillChangeNotification(CGRectZero, CGRectZero); |
| 37 PostKeyboardWillChangeNotification(CGRectInfinite, CGRectInfinite); | 47 PostKeyboardWillChangeNotification(CGRectInfinite, CGRectInfinite); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); | 119 [[HardwareKeyboardWatcher alloc] initWithAccessoryView:mockView]); |
| 110 | 120 |
| 111 PostKeyboardWillChangeNotification(CGRectMake(0, -50, 100, 100), | 121 PostKeyboardWillChangeNotification(CGRectMake(0, -50, 100, 100), |
| 112 CGRectMake(0, 0, 100, 100)); | 122 CGRectMake(0, 0, 100, 100)); |
| 113 | 123 |
| 114 histogram_tester.ExpectUniqueSample("Omnibox.HardwareKeyboardModeEnabled", | 124 histogram_tester.ExpectUniqueSample("Omnibox.HardwareKeyboardModeEnabled", |
| 115 true, 1); | 125 true, 1); |
| 116 } | 126 } |
| 117 | 127 |
| 118 } // namespace | 128 } // namespace |
| OLD | NEW |