OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/shell.h" |
| 6 #include "base/files/file_path.h" |
| 7 #include "chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.h" |
| 8 #include "chrome/browser/extensions/crx_installer.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_test_notification_observer.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "chromeos/ime/extension_ime_util.h" |
| 15 #include "chromeos/ime/input_method_manager.h" |
| 16 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/site_instance.h" |
| 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/test/browser_test_utils.h" |
| 20 #include "extensions/common/constants.h" |
| 21 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/file_util.h" |
| 23 #include "ui/aura/client/aura_constants.h" |
| 24 #include "ui/base/ime/input_method.h" |
| 25 |
| 26 namespace { |
| 27 |
| 28 const base::FilePath::CharType kExtensionName[] = "GoogleKeyboardInput-xkb.crx"; |
| 29 |
| 30 const base::FilePath::CharType kInputViewTestDir[] = |
| 31 "chromeos/virtual_keyboard/inputview/"; |
| 32 const base::FilePath::CharType kBaseKeyboardTestFramework[] = "test_base.js"; |
| 33 |
| 34 struct InputViewConfig : public VirtualKeyboardBrowserTestConfig { |
| 35 explicit InputViewConfig(std::string id) { |
| 36 base_framework_ = kBaseKeyboardTestFramework; |
| 37 extension_id_ = id; |
| 38 test_dir_ = kInputViewTestDir; |
| 39 url_ = "chrome-extension://" + id + "/inputview.html?id=us-altgr-intl"; |
| 40 } |
| 41 }; |
| 42 |
| 43 } // namespace |
| 44 |
| 45 class InputViewBrowserTest : public VirtualKeyboardBrowserTest { |
| 46 public: |
| 47 // Installs the IME Extension keyboard |kExtensionName|. |
| 48 std::string InstallIMEExtension() { |
| 49 // Loads extension. |
| 50 base::FilePath path = ui_test_utils::GetTestFilePath( |
| 51 base::FilePath(kInputViewTestDir), base::FilePath(kExtensionName)); |
| 52 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 53 scoped_refptr<extensions::CrxInstaller> installer = |
| 54 extensions::CrxInstaller::CreateSilent(service); |
| 55 |
| 56 ExtensionTestNotificationObserver observer(browser()); |
| 57 observer.Watch(chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 58 content::Source<extensions::CrxInstaller>(installer.get())); |
| 59 installer->set_allow_silent_install(true); |
| 60 installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE); |
| 61 installer->InstallCrx(path); |
| 62 // Wait for CRX to be installed. |
| 63 observer.Wait(); |
| 64 std::string extensionId = installer->extension()->id(); |
| 65 if (!service->GetExtensionById(extensionId, false)) |
| 66 return ""; |
| 67 |
| 68 // Register extension with IME. |
| 69 chromeos::input_method::InputMethodManager* ime = |
| 70 chromeos::input_method::InputMethodManager::Get(); |
| 71 std::string id = chromeos::extension_ime_util::GetComponentInputMethodID( |
| 72 extensionId, "xkb:us::eng"); |
| 73 ime->ChangeInputMethod(id); |
| 74 return extensionId; |
| 75 } |
| 76 }; |
| 77 |
| 78 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, TypingTest) { |
| 79 std::string id = InstallIMEExtension(); |
| 80 ASSERT_FALSE(id.empty()); |
| 81 RunTest(base::FilePath("typing_test.js"), InputViewConfig(id)); |
| 82 } |
OLD | NEW |