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/common/url_constants.h"
20 #include "content/public/test/browser_test_utils.h"
21 #include "extensions/browser/extension_system.h"
22 #include "extensions/browser/notification_types.h"
23 #include "extensions/common/constants.h"
24 #include "extensions/common/extension.h"
25 #include "extensions/common/file_util.h"
26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/base/ime/input_method.h"
28
29 namespace {
30
31 const base::FilePath::CharType kExtensionName[] = "GoogleKeyboardInput-xkb.crx";
32
33 const base::FilePath::CharType kInputViewTestDir[] =
34 "chromeos/virtual_keyboard/inputview/";
35 const base::FilePath::CharType kBaseKeyboardTestFramework[] = "test_base.js";
36
37 const char kDefaultLayout[] = "us";
38 const char kCompactLayout[] = "us.compact.qwerty";
39
40 struct InputViewConfig : public VirtualKeyboardBrowserTestConfig {
InputViewConfig__anonab907a310111::InputViewConfig41 explicit InputViewConfig(std::string id, std::string layout) {
42 base_framework_ = kBaseKeyboardTestFramework;
43 extension_id_ = id;
44 test_dir_ = kInputViewTestDir;
45 url_ = std::string(extensions::kExtensionScheme) +
46 url::kStandardSchemeSeparator + id + "/inputview.html?id=" +
47 layout;
48 }
49 };
50
51 } // namespace
52
53 class InputViewBrowserTest : public VirtualKeyboardBrowserTest {
54 public:
55 // Installs the IME Extension keyboard |kExtensionName|.
InstallIMEExtension()56 std::string InstallIMEExtension() {
57 // Loads extension.
58 base::FilePath path = ui_test_utils::GetTestFilePath(
59 base::FilePath(kInputViewTestDir), base::FilePath(kExtensionName));
60 ExtensionService* service = extensions::ExtensionSystem::Get(
61 browser()->profile())->extension_service();
62 scoped_refptr<extensions::CrxInstaller> installer =
63 extensions::CrxInstaller::CreateSilent(service);
64
65 ExtensionTestNotificationObserver observer(browser());
66 observer.Watch(extensions::NOTIFICATION_CRX_INSTALLER_DONE,
67 content::Source<extensions::CrxInstaller>(installer.get()));
68 installer->set_allow_silent_install(true);
69 installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE);
70 installer->InstallCrx(path);
71 // Wait for CRX to be installed.
72 observer.Wait();
73 std::string extensionId = installer->extension()->id();
74 if (!service->GetExtensionById(extensionId, false))
75 return "";
76 return extensionId;
77 }
78 };
79
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,TypingTest)80 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, TypingTest) {
81 std::string id = InstallIMEExtension();
82 ASSERT_FALSE(id.empty());
83 RunTest(base::FilePath("typing_test.js"),
84 InputViewConfig(id, kDefaultLayout));
85 }
86
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,CompactTypingTest)87 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, CompactTypingTest) {
88 std::string id = InstallIMEExtension();
89 ASSERT_FALSE(id.empty());
90 RunTest(base::FilePath("typing_test.js"),
91 InputViewConfig(id, kCompactLayout));
92 }
93
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,CompactLongpressTest)94 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, CompactLongpressTest) {
95 std::string id = InstallIMEExtension();
96 ASSERT_FALSE(id.empty());
97 RunTest(base::FilePath("longpress_test.js"),
98 InputViewConfig(id, kCompactLayout));
99 }
100
101 // Disabled for leaking memory: http://crbug.com/380537
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,DISABLED_KeysetTransitionTest)102 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, DISABLED_KeysetTransitionTest) {
103 std::string id = InstallIMEExtension();
104 ASSERT_FALSE(id.empty());
105 RunTest(base::FilePath("keyset_transition_test.js"),
106 InputViewConfig(id, kDefaultLayout));
107 }
108
109 // Disabled for leaking memory: http://crbug.com/380537
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,DISABLED_CompactKeysetTransitionTest)110 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,
111 DISABLED_CompactKeysetTransitionTest) {
112 std::string id = InstallIMEExtension();
113 ASSERT_FALSE(id.empty());
114 RunTest(base::FilePath("keyset_transition_test.js"),
115 InputViewConfig(id, kCompactLayout));
116 }
117