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.
Keep virtual keyboard visibility the same after enable an IME in a di…
…fferent extension BUG=404340 Review URL: https://codereview.chromium.org/487253003 Cr-Commit-Position: refs/heads/master@{#291678}
- Loading branch information
bshe
authored and
Commit bot
committed
Aug 25, 2014
1 parent
7f720e5
commit f1e3346
Showing
5 changed files
with
139 additions
and
8 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
chrome/browser/ui/ash/keyboard_controller_browsertest.cc
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,109 @@ | ||
// Copyright 2014 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. | ||
|
||
#include "base/command_line.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/base/ime/dummy_text_input_client.h" | ||
#include "ui/base/ime/input_method.h" | ||
#include "ui/base/ime/input_method_factory.h" | ||
#include "ui/keyboard/keyboard_constants.h" | ||
#include "ui/keyboard/keyboard_controller.h" | ||
#include "ui/keyboard/keyboard_controller_proxy.h" | ||
#include "ui/keyboard/keyboard_switches.h" | ||
#include "ui/keyboard/keyboard_util.h" | ||
|
||
namespace { | ||
const int kKeyboardHeightForTest = 100; | ||
} // namespace | ||
|
||
class VirtualKeyboardWebContentTest : public InProcessBrowserTest { | ||
public: | ||
VirtualKeyboardWebContentTest() {}; | ||
virtual ~VirtualKeyboardWebContentTest() {}; | ||
|
||
virtual void SetUp() OVERRIDE { | ||
ui::SetUpInputMethodFactoryForTesting(); | ||
InProcessBrowserTest::SetUp(); | ||
} | ||
|
||
// Ensure that the virtual keyboard is enabled. | ||
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | ||
command_line->AppendSwitch( | ||
keyboard::switches::kEnableVirtualKeyboard); | ||
} | ||
|
||
keyboard::KeyboardControllerProxy* proxy() { | ||
return keyboard::KeyboardController::GetInstance()->proxy(); | ||
} | ||
|
||
protected: | ||
void FocusEditableNodeAndShowKeyboard() { | ||
client.reset(new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | ||
ui::InputMethod* input_method = proxy()->GetInputMethod(); | ||
input_method->SetFocusedTextInputClient(client.get()); | ||
input_method->ShowImeIfNeeded(); | ||
ResizeKeyboardWindow(); | ||
} | ||
|
||
void FocusNonEditableNode() { | ||
client.reset(new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_NONE)); | ||
ui::InputMethod* input_method = proxy()->GetInputMethod(); | ||
input_method->SetFocusedTextInputClient(client.get()); | ||
} | ||
|
||
void MockEnableIMEInDifferentExtension(const std::string& url) { | ||
keyboard::SetOverrideContentUrl(GURL(url)); | ||
keyboard::KeyboardController::GetInstance()->Reload(); | ||
ResizeKeyboardWindow(); | ||
} | ||
|
||
bool IsKeyboardVisible() const { | ||
return keyboard::KeyboardController::GetInstance()->keyboard_visible(); | ||
} | ||
|
||
private: | ||
// Mock window.resizeTo that is expected to be called after navigate to a new | ||
// virtual keyboard. | ||
void ResizeKeyboardWindow() { | ||
gfx::Rect bounds = proxy()->GetKeyboardWindow()->bounds(); | ||
proxy()->GetKeyboardWindow()->SetBounds(gfx::Rect( | ||
bounds.x(), | ||
bounds.bottom() - kKeyboardHeightForTest, | ||
bounds.width(), | ||
kKeyboardHeightForTest)); | ||
} | ||
|
||
scoped_ptr<ui::DummyTextInputClient> client; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardWebContentTest); | ||
}; | ||
|
||
// Test for crbug.com/404340. After enabling an IME in a different extension, | ||
// its virtual keyboard should not become visible if previous one is not. | ||
IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest, | ||
EnableIMEInDifferentExtension) { | ||
FocusEditableNodeAndShowKeyboard(); | ||
EXPECT_TRUE(IsKeyboardVisible()); | ||
FocusNonEditableNode(); | ||
EXPECT_FALSE(IsKeyboardVisible()); | ||
|
||
MockEnableIMEInDifferentExtension("chrome-extension://domain-1"); | ||
// Keyboard should not become visible if previous keyboard is not. | ||
EXPECT_FALSE(IsKeyboardVisible()); | ||
|
||
FocusEditableNodeAndShowKeyboard(); | ||
// Keyboard should become visible after focus on an editable node. | ||
EXPECT_TRUE(IsKeyboardVisible()); | ||
|
||
// Simulate hide keyboard by pressing hide key on the virtual keyboard. | ||
keyboard::KeyboardController::GetInstance()->HideKeyboard( | ||
keyboard::KeyboardController::HIDE_REASON_MANUAL); | ||
EXPECT_FALSE(IsKeyboardVisible()); | ||
|
||
MockEnableIMEInDifferentExtension("chrome-extension://domain-2"); | ||
// Keyboard should not become visible if previous keyboard is not, even if it | ||
// is currently focused on an editable node. | ||
EXPECT_FALSE(IsKeyboardVisible()); | ||
} |
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