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> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 13 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
12 #include "chrome/browser/extensions/api/test/test_api.h" | 14 #include "chrome/browser/extensions/api/test/test_api.h" |
13 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
14 #include "chromeos/ime/input_method_manager.h" | 16 #include "chromeos/ime/input_method_manager.h" |
15 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 const char kLoginScreenUILanguage[] = "fr"; | 24 const char kLoginScreenUILanguage[] = "fr"; |
23 const char kInitialInputMethodOnLoginScreen[] = "xkb:us::eng"; | 25 const char kInitialInputMethodOnLoginScreen[] = "xkb:us::eng"; |
24 const char kNewInputMethod[] = "fr::fra"; | 26 const char kNewInputMethod[] = "fr::fra"; |
25 const char kSetInputMethodMessage[] = "setInputMethod"; | 27 const char kSetInputMethodMessage[] = "setInputMethod"; |
26 const char kSetInputMethodDone[] = "done"; | 28 const char kSetInputMethodDone[] = "done"; |
27 | 29 |
28 // Class that listens for the JS message then changes input method and replies | 30 // Class that listens for the JS message then changes input method and replies |
29 // back. | 31 // back. |
30 class SetInputMethodListener : public content::NotificationObserver { | 32 class SetInputMethodListener : public content::NotificationObserver { |
31 public: | 33 public: |
32 // Creates listener, which should reply exactly |count_| times. | 34 // Creates listener, which should reply exactly |count_| times. |
33 explicit SetInputMethodListener(int count) : count_(count) { | 35 explicit SetInputMethodListener(int count) : count_(count) { |
34 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, | 36 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
35 content::NotificationService::AllSources()); | 37 content::NotificationService::AllSources()); |
| 38 std::vector<std::string> keyboard_layouts; |
| 39 keyboard_layouts.push_back(kInitialInputMethodOnLoginScreen); |
36 chromeos::input_method::InputMethodManager::Get()->EnableLoginLayouts( | 40 chromeos::input_method::InputMethodManager::Get()->EnableLoginLayouts( |
37 kLoginScreenUILanguage, kInitialInputMethodOnLoginScreen); | 41 kLoginScreenUILanguage, keyboard_layouts); |
38 } | 42 } |
39 | 43 |
40 virtual ~SetInputMethodListener() { | 44 virtual ~SetInputMethodListener() { |
41 EXPECT_EQ(0, count_); | 45 EXPECT_EQ(0, count_); |
42 } | 46 } |
43 | 47 |
44 // Implements the content::NotificationObserver interface. | 48 // Implements the content::NotificationObserver interface. |
45 virtual void Observe(int type, | 49 virtual void Observe(int type, |
46 const content::NotificationSource& source, | 50 const content::NotificationSource& source, |
47 const content::NotificationDetails& details) OVERRIDE { | 51 const content::NotificationDetails& details) OVERRIDE { |
(...skipping 27 matching lines...) Expand all Loading... |
75 }; | 79 }; |
76 | 80 |
77 } // namespace | 81 } // namespace |
78 | 82 |
79 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest, Basic) { | 83 IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest, Basic) { |
80 // Two test, two calls. See JS code for more info. | 84 // Two test, two calls. See JS code for more info. |
81 SetInputMethodListener listener(2); | 85 SetInputMethodListener listener(2); |
82 | 86 |
83 ASSERT_TRUE(RunExtensionTest("input_method")) << message_; | 87 ASSERT_TRUE(RunExtensionTest("input_method")) << message_; |
84 } | 88 } |
OLD | NEW |