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 "chrome/browser/spellchecker/spellcheck_factory.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/notification_service.h"
18 #include "extensions/common/switches.h"
19 #include "extensions/browser/api/test/test_api.h"
20 #include "extensions/browser/notification_types.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/ime/chromeos/extension_ime_util.h"
23 #include "ui/base/ime/chromeos/input_method_manager.h"
27 const char kLoginScreenUILanguage
[] = "fr";
28 const char kInitialInputMethodOnLoginScreen
[] = "xkb:us::eng";
29 const char kBackgroundReady
[] = "ready";
31 // Class that listens for the JS message.
32 class TestListener
: public content::NotificationObserver
{
36 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
,
37 content::NotificationService::AllSources());
40 ~TestListener() override
{}
42 // Implements the content::NotificationObserver interface.
43 void Observe(int type
,
44 const content::NotificationSource
& source
,
45 const content::NotificationDetails
& details
) override
{
46 const std::string
& content
= *content::Details
<std::string
>(details
).ptr();
47 if (content
== kBackgroundReady
) {
48 // Initializes IMF for testing when receives ready message from
50 chromeos::input_method::InputMethodManager
* manager
=
51 chromeos::input_method::InputMethodManager::Get();
52 manager
->GetInputMethodUtil()->InitXkbInputMethodsForTesting();
54 std::vector
<std::string
> keyboard_layouts
;
55 keyboard_layouts
.push_back(
56 chromeos::extension_ime_util::GetInputMethodIDByEngineID(
57 kInitialInputMethodOnLoginScreen
));
58 manager
->GetActiveIMEState()->EnableLoginLayouts(kLoginScreenUILanguage
,
64 content::NotificationRegistrar registrar_
;
67 class ExtensionInputMethodApiTest
: public ExtensionApiTest
{
68 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
69 ExtensionApiTest::SetUpCommandLine(command_line
);
70 command_line
->AppendSwitchASCII(
71 extensions::switches::kWhitelistedExtensionID
,
72 "ilanclmaeigfpnmdlgelmhkpkegdioip");
78 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest
, Basic
) {
79 // Listener for extension's background ready.
80 TestListener listener
;
82 ASSERT_TRUE(RunExtensionTest("input_method")) << message_
;