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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search/hotword_client.h" | 11 #include "chrome/browser/search/hotword_client.h" |
12 #include "chrome/browser/search/hotword_service.h" | 12 #include "chrome/browser/search/hotword_service.h" |
13 #include "chrome/browser/search/hotword_service_factory.h" | 13 #include "chrome/browser/search/hotword_service_factory.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "extensions/common/switches.h" | 16 #include "extensions/common/switches.h" |
17 #include "extensions/test/extension_test_message_listener.h" | 17 #include "extensions/test/extension_test_message_listener.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kHotwordTestExtensionId[] = "cpfhkdbjfdgdebcjlifoldbijinjfifp"; | 21 const char kHotwordTestExtensionId[] = "cpfhkdbjfdgdebcjlifoldbijinjfifp"; |
22 | 22 |
23 class MockHotwordService : public HotwordService { | 23 class MockHotwordService : public HotwordService { |
24 public: | 24 public: |
25 explicit MockHotwordService(Profile* profile) | 25 explicit MockHotwordService(Profile* profile) |
26 : HotwordService(profile), service_available_(true) {}; | 26 : HotwordService(profile), service_available_(true) {}; |
27 virtual ~MockHotwordService() {} | 27 virtual ~MockHotwordService() {} |
28 | 28 |
29 virtual bool IsServiceAvailable() OVERRIDE { | 29 virtual bool IsServiceAvailable() override { |
30 return service_available_; | 30 return service_available_; |
31 } | 31 } |
32 | 32 |
33 void setServiceAvailable(bool available) { | 33 void setServiceAvailable(bool available) { |
34 service_available_ = available; | 34 service_available_ = available; |
35 } | 35 } |
36 | 36 |
37 static KeyedService* Build(content::BrowserContext* profile) { | 37 static KeyedService* Build(content::BrowserContext* profile) { |
38 return new MockHotwordService(static_cast<Profile*>(profile)); | 38 return new MockHotwordService(static_cast<Profile*>(profile)); |
39 } | 39 } |
40 | 40 |
41 virtual LaunchMode GetHotwordAudioVerificationLaunchMode() OVERRIDE { | 41 virtual LaunchMode GetHotwordAudioVerificationLaunchMode() override { |
42 return launch_mode_; | 42 return launch_mode_; |
43 } | 43 } |
44 | 44 |
45 void SetHotwordAudioVerificationLaunchMode(const LaunchMode& launch_mode) { | 45 void SetHotwordAudioVerificationLaunchMode(const LaunchMode& launch_mode) { |
46 launch_mode_ = launch_mode; | 46 launch_mode_ = launch_mode; |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 bool service_available_; | 50 bool service_available_; |
51 LaunchMode launch_mode_; | 51 LaunchMode launch_mode_; |
52 | 52 |
53 DISALLOW_COPY_AND_ASSIGN(MockHotwordService); | 53 DISALLOW_COPY_AND_ASSIGN(MockHotwordService); |
54 }; | 54 }; |
55 | 55 |
56 class MockHotwordClient : public HotwordClient { | 56 class MockHotwordClient : public HotwordClient { |
57 public: | 57 public: |
58 MockHotwordClient() | 58 MockHotwordClient() |
59 : last_enabled_(false), | 59 : last_enabled_(false), |
60 state_changed_count_(0), | 60 state_changed_count_(0), |
61 recognized_count_(0) { | 61 recognized_count_(0) { |
62 } | 62 } |
63 | 63 |
64 virtual ~MockHotwordClient() {} | 64 virtual ~MockHotwordClient() {} |
65 | 65 |
66 virtual void OnHotwordStateChanged(bool enabled) OVERRIDE { | 66 virtual void OnHotwordStateChanged(bool enabled) override { |
67 last_enabled_ = enabled; | 67 last_enabled_ = enabled; |
68 state_changed_count_++; | 68 state_changed_count_++; |
69 } | 69 } |
70 | 70 |
71 virtual void OnHotwordRecognized() OVERRIDE { | 71 virtual void OnHotwordRecognized() override { |
72 recognized_count_++; | 72 recognized_count_++; |
73 } | 73 } |
74 | 74 |
75 bool last_enabled() const { return last_enabled_; } | 75 bool last_enabled() const { return last_enabled_; } |
76 int state_changed_count() const { return state_changed_count_; } | 76 int state_changed_count() const { return state_changed_count_; } |
77 int recognized_count() const { return recognized_count_; } | 77 int recognized_count() const { return recognized_count_; } |
78 | 78 |
79 private: | 79 private: |
80 bool last_enabled_; | 80 bool last_enabled_; |
81 int state_changed_count_; | 81 int state_changed_count_; |
82 int recognized_count_; | 82 int recognized_count_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(MockHotwordClient); | 84 DISALLOW_COPY_AND_ASSIGN(MockHotwordClient); |
85 }; | 85 }; |
86 | 86 |
87 class HotwordPrivateApiTest : public ExtensionApiTest { | 87 class HotwordPrivateApiTest : public ExtensionApiTest { |
88 public: | 88 public: |
89 HotwordPrivateApiTest() {} | 89 HotwordPrivateApiTest() {} |
90 virtual ~HotwordPrivateApiTest() {} | 90 virtual ~HotwordPrivateApiTest() {} |
91 | 91 |
92 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { | 92 virtual void SetUpCommandLine(base::CommandLine* command_line) override { |
93 ExtensionApiTest::SetUpCommandLine(command_line); | 93 ExtensionApiTest::SetUpCommandLine(command_line); |
94 | 94 |
95 // Whitelist the test extensions (which all share a common ID) to use | 95 // Whitelist the test extensions (which all share a common ID) to use |
96 // private APIs. | 96 // private APIs. |
97 command_line->AppendSwitchASCII( | 97 command_line->AppendSwitchASCII( |
98 extensions::switches::kWhitelistedExtensionID, kHotwordTestExtensionId); | 98 extensions::switches::kWhitelistedExtensionID, kHotwordTestExtensionId); |
99 } | 99 } |
100 | 100 |
101 virtual void SetUpOnMainThread() OVERRIDE { | 101 virtual void SetUpOnMainThread() override { |
102 ExtensionApiTest::SetUpOnMainThread(); | 102 ExtensionApiTest::SetUpOnMainThread(); |
103 | 103 |
104 test_data_dir_ = test_data_dir_.AppendASCII("hotword_private"); | 104 test_data_dir_ = test_data_dir_.AppendASCII("hotword_private"); |
105 | 105 |
106 service_ = static_cast<MockHotwordService*>( | 106 service_ = static_cast<MockHotwordService*>( |
107 HotwordServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 107 HotwordServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
108 profile(), MockHotwordService::Build)); | 108 profile(), MockHotwordService::Build)); |
109 } | 109 } |
110 | 110 |
111 MockHotwordService* service() { | 111 MockHotwordService* service() { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 | 280 |
281 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, | 281 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, |
282 GetLaunchStateHotwordAudioHistory) { | 282 GetLaunchStateHotwordAudioHistory) { |
283 service()->SetHotwordAudioVerificationLaunchMode( | 283 service()->SetHotwordAudioVerificationLaunchMode( |
284 HotwordService::HOTWORD_AND_AUDIO_HISTORY); | 284 HotwordService::HOTWORD_AND_AUDIO_HISTORY); |
285 ExtensionTestMessageListener listener("launchMode: 2", false); | 285 ExtensionTestMessageListener listener("launchMode: 2", false); |
286 ASSERT_TRUE(RunComponentExtensionTest("getLaunchState")) << message_; | 286 ASSERT_TRUE(RunComponentExtensionTest("getLaunchState")) << message_; |
287 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 287 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
288 } | 288 } |
OLD | NEW |