forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix copy/paste shortcuts in omnibox.
Fixes Cmd+C and Cmd+V in pre-edit. Adds a unit test to prevent future regressions. Currently an EGTest is not possible, as EGTest doesn't have actions for sending keyboard events. Removes a DCHECK for OmniboxTextFieldIOS' delegate to be a more specific subclass, which seems fine as all of the methods of OTFIDelegate are optional Bug: 945024 Change-Id: I216bc8361e01e9874623e2105416e2cfa9ff03aa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547747 Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org> Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org> Reviewed-by: Robbie Gibson <rkgibson@google.com> Cr-Commit-Position: refs/heads/master@{#647751}
- Loading branch information
Stepan Khapugin
authored and
Commit Bot
committed
Apr 4, 2019
1 parent
fcfffe6
commit 1b7e6b8
Showing
5 changed files
with
149 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
ios/chrome/browser/ui/omnibox/omnibox_view_ios_unittest.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2019 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 "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h" | ||
|
||
#include "base/test/scoped_task_environment.h" | ||
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | ||
#include "testing/gtest_mac.h" | ||
#include "testing/platform_test.h" | ||
#import "third_party/ocmock/OCMock/OCMock.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
namespace { | ||
|
||
class OmniboxViewIOSTest : public PlatformTest { | ||
protected: | ||
void SetUp() override { | ||
PlatformTest::SetUp(); | ||
TestChromeBrowserState::Builder test_cbs_builder; | ||
browser_state_ = test_cbs_builder.Build(); | ||
mockOmniboxTextfield_ = OCMClassMock([OmniboxTextFieldIOS class]); | ||
view_ = std::make_unique<OmniboxViewIOS>( | ||
mockOmniboxTextfield_, /* WebOmniboxEditController*/ nullptr, | ||
/*id<OmniboxLeftImageConsumer> */ nil, browser_state_.get(), | ||
/*id<OmniboxFocuser>*/ nil); | ||
} | ||
|
||
// Test broser state. | ||
std::unique_ptr<TestChromeBrowserState> browser_state_; | ||
// The tested object. | ||
std::unique_ptr<OmniboxViewIOS> view_; | ||
// Mock for the OmniboxTextFieldIOS. | ||
id mockOmniboxTextfield_; | ||
// Message loop for the main test thread. | ||
base::test::ScopedTaskEnvironment environment_; | ||
}; | ||
|
||
TEST_F(OmniboxViewIOSTest, copyAddsTextToPasteboard) { | ||
[[UIPasteboard generalPasteboard] setString:@""]; | ||
|
||
OCMExpect([mockOmniboxTextfield_ isPreEditing]).andReturn(YES); | ||
OCMExpect([mockOmniboxTextfield_ preEditText]).andReturn(@"foobar"); | ||
|
||
view_->OnCopy(); | ||
|
||
EXPECT_TRUE( | ||
[[[UIPasteboard generalPasteboard] string] isEqualToString:@"foobar"]); | ||
[mockOmniboxTextfield_ verify]; | ||
|
||
// Clear the pasteboard state. | ||
[[UIPasteboard generalPasteboard] setString:@""]; | ||
} | ||
|
||
} // namespace |