OLD | NEW |
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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
7 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" | 7 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/search/hotword_client.h" | 12 #include "chrome/browser/search/hotword_client.h" |
13 #include "chrome/browser/search/hotword_service.h" | 13 #include "chrome/browser/search/hotword_service.h" |
14 #include "chrome/browser/search/hotword_service_factory.h" | 14 #include "chrome/browser/search/hotword_service_factory.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "extensions/common/switches.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
| 21 const char kHotwordTestExtensionId[] = "cpfhkdbjfdgdebcjlifoldbijinjfifp"; |
| 22 |
20 class MockHotwordService : public HotwordService { | 23 class MockHotwordService : public HotwordService { |
21 public: | 24 public: |
22 explicit MockHotwordService(Profile* profile) | 25 explicit MockHotwordService(Profile* profile) |
23 : HotwordService(profile), service_available_(true) {}; | 26 : HotwordService(profile), service_available_(true) {}; |
24 virtual ~MockHotwordService() {} | 27 virtual ~MockHotwordService() {} |
25 | 28 |
26 virtual bool IsServiceAvailable() OVERRIDE { | 29 virtual bool IsServiceAvailable() OVERRIDE { |
27 return service_available_; | 30 return service_available_; |
28 } | 31 } |
29 | 32 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 int recognized_count_; | 73 int recognized_count_; |
71 | 74 |
72 DISALLOW_COPY_AND_ASSIGN(MockHotwordClient); | 75 DISALLOW_COPY_AND_ASSIGN(MockHotwordClient); |
73 }; | 76 }; |
74 | 77 |
75 class HotwordPrivateApiTest : public ExtensionApiTest { | 78 class HotwordPrivateApiTest : public ExtensionApiTest { |
76 public: | 79 public: |
77 HotwordPrivateApiTest() {} | 80 HotwordPrivateApiTest() {} |
78 virtual ~HotwordPrivateApiTest() {} | 81 virtual ~HotwordPrivateApiTest() {} |
79 | 82 |
| 83 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { |
| 84 ExtensionApiTest::SetUpCommandLine(command_line); |
| 85 |
| 86 // Whitelist the test extensions (which all share a common ID) to use |
| 87 // private APIs. |
| 88 command_line->AppendSwitchASCII( |
| 89 extensions::switches::kWhitelistedExtensionID, kHotwordTestExtensionId); |
| 90 } |
| 91 |
80 virtual void SetUpOnMainThread() OVERRIDE { | 92 virtual void SetUpOnMainThread() OVERRIDE { |
81 ExtensionApiTest::SetUpOnMainThread(); | 93 ExtensionApiTest::SetUpOnMainThread(); |
82 | 94 |
83 test_data_dir_ = test_data_dir_.AppendASCII("hotword_private"); | 95 test_data_dir_ = test_data_dir_.AppendASCII("hotword_private"); |
84 | 96 |
85 service_ = static_cast<MockHotwordService*>( | 97 service_ = static_cast<MockHotwordService*>( |
86 HotwordServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 98 HotwordServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
87 profile(), MockHotwordService::Build)); | 99 profile(), MockHotwordService::Build)); |
88 } | 100 } |
89 | 101 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 MockHotwordClient client; | 210 MockHotwordClient client; |
199 service()->RequestHotwordSession(&client); | 211 service()->RequestHotwordSession(&client); |
200 EXPECT_TRUE(listenerStopReady.WaitUntilSatisfied()); | 212 EXPECT_TRUE(listenerStopReady.WaitUntilSatisfied()); |
201 service()->StopHotwordSession(&client); | 213 service()->StopHotwordSession(&client); |
202 EXPECT_TRUE(listenerStopped.WaitUntilSatisfied()); | 214 EXPECT_TRUE(listenerStopped.WaitUntilSatisfied()); |
203 | 215 |
204 EXPECT_TRUE(client.last_enabled()); | 216 EXPECT_TRUE(client.last_enabled()); |
205 EXPECT_EQ(1, client.state_changed_count()); | 217 EXPECT_EQ(1, client.state_changed_count()); |
206 EXPECT_EQ(1, client.recognized_count()); | 218 EXPECT_EQ(1, client.recognized_count()); |
207 } | 219 } |
OLD | NEW |