OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 12 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
13 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 13 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 14 #include "chrome/common/pref_names.h" |
| 15 #include "chromeos/chromeos_switches.h" |
| 16 #include "components/prefs/pref_service.h" |
14 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
17 #include "extensions/common/switches.h" | 20 #include "extensions/common/switches.h" |
18 #include "extensions/browser/api/test/test_api.h" | 21 #include "extensions/browser/api/test/test_api.h" |
19 #include "extensions/browser/notification_types.h" | 22 #include "extensions/browser/notification_types.h" |
| 23 #include "extensions/test/extension_test_message_listener.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/base/ime/chromeos/extension_ime_util.h" | 25 #include "ui/base/ime/chromeos/extension_ime_util.h" |
22 #include "ui/base/ime/chromeos/input_method_manager.h" | 26 #include "ui/base/ime/chromeos/input_method_manager.h" |
23 #include "ui/base/ime/chromeos/input_method_whitelist.h" | 27 #include "ui/base/ime/chromeos/input_method_whitelist.h" |
24 | 28 |
25 using namespace chromeos::input_method; | 29 using namespace chromeos::input_method; |
26 | 30 |
27 namespace { | 31 namespace { |
28 | 32 |
29 const char kLoginScreenUILanguage[] = "fr"; | 33 const char kLoginScreenUILanguage[] = "fr"; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 private: | 69 private: |
66 content::NotificationRegistrar registrar_; | 70 content::NotificationRegistrar registrar_; |
67 }; | 71 }; |
68 | 72 |
69 class ExtensionInputMethodApiTest : public ExtensionApiTest { | 73 class ExtensionInputMethodApiTest : public ExtensionApiTest { |
70 void SetUpCommandLine(base::CommandLine* command_line) override { | 74 void SetUpCommandLine(base::CommandLine* command_line) override { |
71 ExtensionApiTest::SetUpCommandLine(command_line); | 75 ExtensionApiTest::SetUpCommandLine(command_line); |
72 command_line->AppendSwitchASCII( | 76 command_line->AppendSwitchASCII( |
73 extensions::switches::kWhitelistedExtensionID, | 77 extensions::switches::kWhitelistedExtensionID, |
74 "ilanclmaeigfpnmdlgelmhkpkegdioip"); | 78 "ilanclmaeigfpnmdlgelmhkpkegdioip"); |
| 79 command_line->AppendSwitch(chromeos::switches::kEnableImeMenu); |
75 } | 80 } |
76 }; | 81 }; |
77 | 82 |
78 } // namespace | 83 } // namespace |
79 | 84 |
80 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest, Basic) { | 85 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest, Basic) { |
81 // Listener for extension's background ready. | 86 // Listener for extension's background ready. |
82 TestListener listener; | 87 TestListener listener; |
83 | 88 |
84 ASSERT_TRUE(RunExtensionTest("input_method")) << message_; | 89 ASSERT_TRUE(RunExtensionTest("input_method/basic")) << message_; |
85 } | 90 } |
| 91 |
| 92 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest, ImeMenuActivation) { |
| 93 // Listener for IME menu initial state ready. |
| 94 ExtensionTestMessageListener config_listener("config_ready", false); |
| 95 // Listener for IME menu event ready. |
| 96 ExtensionTestMessageListener event_listener("event_ready", false); |
| 97 |
| 98 browser()->profile()->GetPrefs()->SetBoolean(prefs::kLanguageImeMenuActivated, |
| 99 true); |
| 100 |
| 101 // Test the initial state and add listener for IME menu activation change. |
| 102 ASSERT_TRUE( |
| 103 LoadExtension(test_data_dir_.AppendASCII("input_method/ime_menu"))); |
| 104 ASSERT_TRUE(config_listener.WaitUntilSatisfied()) << message_; |
| 105 |
| 106 // Trigger chrome.inputMethodPrivate.onImeMenuActivationChanged() event. |
| 107 browser()->profile()->GetPrefs()->SetBoolean(prefs::kLanguageImeMenuActivated, |
| 108 false); |
| 109 // Test that the extension gets the IME activation change event properly. |
| 110 ASSERT_TRUE(event_listener.WaitUntilSatisfied()) << message_; |
| 111 } |
OLD | NEW |