1 // Copyright (c) 2012 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.
5 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "base/command_line.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
13 #include "chrome/browser/chromeos/input_method/input_method_util.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/notification_service.h"
17 #include "extensions/common/switches.h"
18 #include "extensions/browser/api/test/test_api.h"
19 #include "extensions/browser/notification_types.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/base/ime/chromeos/extension_ime_util.h"
22 #include "ui/base/ime/chromeos/input_method_manager.h"
26 const char kLoginScreenUILanguage
[] = "fr";
27 const char kInitialInputMethodOnLoginScreen
[] = "xkb:us::eng";
28 const char kBackgroundReady
[] = "ready";
30 // Class that listens for the JS message.
31 class TestListener
: public content::NotificationObserver
{
35 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
,
36 content::NotificationService::AllSources());
39 ~TestListener() override
{}
41 // Implements the content::NotificationObserver interface.
42 void Observe(int type
,
43 const content::NotificationSource
& source
,
44 const content::NotificationDetails
& details
) override
{
45 const std::string
& content
= *content::Details
<std::string
>(details
).ptr();
46 if (content
== kBackgroundReady
) {
47 // Initializes IMF for testing when receives ready message from
49 chromeos::input_method::InputMethodManager
* manager
=
50 chromeos::input_method::InputMethodManager::Get();
51 manager
->GetInputMethodUtil()->InitXkbInputMethodsForTesting();
53 std::vector
<std::string
> keyboard_layouts
;
54 keyboard_layouts
.push_back(
55 chromeos::extension_ime_util::GetInputMethodIDByEngineID(
56 kInitialInputMethodOnLoginScreen
));
57 manager
->GetActiveIMEState()->EnableLoginLayouts(kLoginScreenUILanguage
,
63 content::NotificationRegistrar registrar_
;
66 class ExtensionInputMethodApiTest
: public ExtensionApiTest
{
67 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
68 ExtensionApiTest::SetUpCommandLine(command_line
);
69 command_line
->AppendSwitchASCII(
70 extensions::switches::kWhitelistedExtensionID
,
71 "ilanclmaeigfpnmdlgelmhkpkegdioip");
77 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest
, Basic
) {
78 // Listener for extension's background ready.
79 TestListener listener
;
81 ASSERT_TRUE(RunExtensionTest("input_method")) << message_
;