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

Side by Side Diff: chrome/browser/extensions/api/hotword_private/hotword_private_apitest.cc

Issue 267653005: Adds HotwordPrivate API for integrating the hotword feature to AppLauncher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 months 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" 6 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_test_message_listener.h" 9 #include "chrome/browser/extensions/extension_test_message_listener.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search/hotword_client.h"
11 #include "chrome/browser/search/hotword_service.h" 12 #include "chrome/browser/search/hotword_service.h"
12 #include "chrome/browser/search/hotword_service_factory.h" 13 #include "chrome/browser/search/hotword_service_factory.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 15
15 namespace { 16 namespace {
16 17
17 class MockHotwordService : public HotwordService { 18 class MockHotwordService : public HotwordService {
18 public: 19 public:
19 explicit MockHotwordService(Profile* profile) 20 explicit MockHotwordService(Profile* profile)
20 : HotwordService(profile), service_available_(true) {}; 21 : HotwordService(profile), service_available_(true) {};
(...skipping 10 matching lines...) Expand all
31 static KeyedService* Build(content::BrowserContext* profile) { 32 static KeyedService* Build(content::BrowserContext* profile) {
32 return new MockHotwordService(static_cast<Profile*>(profile)); 33 return new MockHotwordService(static_cast<Profile*>(profile));
33 } 34 }
34 35
35 private: 36 private:
36 bool service_available_; 37 bool service_available_;
37 38
38 DISALLOW_COPY_AND_ASSIGN(MockHotwordService); 39 DISALLOW_COPY_AND_ASSIGN(MockHotwordService);
39 }; 40 };
40 41
42 class MockHotwordClient : public HotwordClient {
43 public:
44 MockHotwordClient()
45 : last_enabled_(false),
46 state_changed_count_(0),
47 recognized_count_(0) {
48 }
49
50 virtual ~MockHotwordClient() {}
51
52 virtual void OnHotwordStateChanged(bool enabled) OVERRIDE {
53 last_enabled_ = enabled;
54 state_changed_count_++;
55 }
56
57 virtual void OnHotwordRecognized() OVERRIDE {
58 recognized_count_++;
59 }
60
61 bool last_enabled() const { return last_enabled_; }
62 int state_changed_count() const { return state_changed_count_; }
63 int recognized_count() const { return recognized_count_; }
64
65 private:
66 bool last_enabled_;
67 int state_changed_count_;
68 int recognized_count_;
69
70 DISALLOW_COPY_AND_ASSIGN(MockHotwordClient);
71 };
72
41 class HotwordPrivateApiTest : public ExtensionApiTest { 73 class HotwordPrivateApiTest : public ExtensionApiTest {
42 public: 74 public:
43 HotwordPrivateApiTest() {} 75 HotwordPrivateApiTest() {}
44 virtual ~HotwordPrivateApiTest() {} 76 virtual ~HotwordPrivateApiTest() {}
45 77
46 virtual void SetUpOnMainThread() OVERRIDE { 78 virtual void SetUpOnMainThread() OVERRIDE {
47 ExtensionApiTest::SetUpOnMainThread(); 79 ExtensionApiTest::SetUpOnMainThread();
48 80
49 test_data_dir_ = test_data_dir_.AppendASCII("hotword_private"); 81 test_data_dir_ = test_data_dir_.AppendASCII("hotword_private");
50 82
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 extensions::HotwordPrivateEventService::GetFactoryInstance(); 156 extensions::HotwordPrivateEventService::GetFactoryInstance();
125 ExtensionTestMessageListener listener("ready", false); 157 ExtensionTestMessageListener listener("ready", false);
126 LoadExtensionAsComponent( 158 LoadExtensionAsComponent(
127 test_data_dir_.AppendASCII("onEnabledChanged")); 159 test_data_dir_.AppendASCII("onEnabledChanged"));
128 EXPECT_TRUE(listener.WaitUntilSatisfied()); 160 EXPECT_TRUE(listener.WaitUntilSatisfied());
129 161
130 ExtensionTestMessageListener listenerNotification("notification", false); 162 ExtensionTestMessageListener listenerNotification("notification", false);
131 profile()->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, true); 163 profile()->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, true);
132 EXPECT_TRUE(listenerNotification.WaitUntilSatisfied()); 164 EXPECT_TRUE(listenerNotification.WaitUntilSatisfied());
133 } 165 }
166
167 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, HotwordSession) {
168 extensions::HotwordPrivateEventService::GetFactoryInstance();
169 ExtensionTestMessageListener listener("ready", false);
170 LoadExtensionAsComponent(
171 test_data_dir_.AppendASCII("hotwordSession"));
172 EXPECT_TRUE(listener.WaitUntilSatisfied());
173
174 ExtensionTestMessageListener listenerStopReady("stopReady", false);
175 ExtensionTestMessageListener listenerStopped("stopped", false);
176 MockHotwordClient client;
177 service()->RequestHotwordSession(&client);
178 EXPECT_TRUE(listenerStopReady.WaitUntilSatisfied());
179 service()->StopHotwordSession(&client);
180 EXPECT_TRUE(listenerStopped.WaitUntilSatisfied());
181
182 EXPECT_TRUE(client.last_enabled());
183 EXPECT_EQ(1, client.state_changed_count());
184 EXPECT_EQ(1, client.recognized_count());
185 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/hotword_private/hotword_private_api.cc ('k') | chrome/browser/search/hotword_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698