Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/chromeos/extensions/input_method_extension_apitest.cc

Issue 8619007: Revert "Move a bunch of ChromeOS APIs out of chrome/browser/extensions." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_apitest.h"
6
7 #include "base/stringprintf.h"
8 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
9 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
10 #include "chrome/browser/extensions/extension_test_api.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_service.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 const char kNewInputMethod[] = "ru::rus";
20 const char kSetInputMethodMessage[] = "setInputMethod";
21 const char kSetInputMethodDone[] = "done";
22
23 // Class that listens for the JS message then changes input method and replies
24 // back.
25 class SetInputMethodListener : public content::NotificationObserver {
26 public:
27 // Creates listener, which should reply exactly |count_| times.
28 explicit SetInputMethodListener(int count) : count_(count) {
29 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
30 content::NotificationService::AllSources());
31 }
32
33 virtual ~SetInputMethodListener() {
34 EXPECT_EQ(0, count_);
35 }
36
37 // Implements the content::NotificationObserver interface.
38 virtual void Observe(int type,
39 const content::NotificationSource& source,
40 const content::NotificationDetails& details) {
41 const std::string& content = *content::Details<std::string>(details).ptr();
42 const std::string expected_message = StringPrintf("%s:%s",
43 kSetInputMethodMessage,
44 kNewInputMethod);
45 if (content == expected_message) {
46 chromeos::input_method::InputMethodManager::GetInstance()->
47 ChangeInputMethod(StringPrintf("xkb:%s", kNewInputMethod));
48
49 ExtensionTestSendMessageFunction* function =
50 content::Source<ExtensionTestSendMessageFunction>(source).ptr();
51 EXPECT_GT(count_--, 0);
52 function->Reply(kSetInputMethodDone);
53 }
54 }
55
56 private:
57 content::NotificationRegistrar registrar_;
58
59 int count_;
60 };
61
62 } // namespace
63
64 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, InputMethodApiBasic) {
65 // Two test, two calls. See JS code for more info.
66 SetInputMethodListener listener(2);
67
68 ASSERT_TRUE(RunExtensionTest("input_method")) << message_;
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698