| 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/history/web_history_service.h" | 10 #include "chrome/browser/history/web_history_service.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 bool expected_success_; | 58 bool expected_success_; |
| 59 bool expected_value_; | 59 bool expected_value_; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 // Make a mock audio history handler so that the method for getting the web | 62 // Make a mock audio history handler so that the method for getting the web |
| 63 // history can be overridden. | 63 // history can be overridden. |
| 64 class MockAudioHistoryHandler : public HotwordAudioHistoryHandler { | 64 class MockAudioHistoryHandler : public HotwordAudioHistoryHandler { |
| 65 public: | 65 public: |
| 66 MockAudioHistoryHandler(content::BrowserContext* context, | 66 MockAudioHistoryHandler(content::BrowserContext* context, |
| 67 history::WebHistoryService* web_history) | 67 history::WebHistoryService* web_history) |
| 68 : HotwordAudioHistoryHandler(context), | 68 : HotwordAudioHistoryHandler(context, |
| 69 base::MessageLoop::current()->task_runner()), |
| 69 web_history_(web_history) {} | 70 web_history_(web_history) {} |
| 70 ~MockAudioHistoryHandler() override {} | 71 ~MockAudioHistoryHandler() override {} |
| 71 | 72 |
| 72 history::WebHistoryService* GetWebHistory() override { | 73 history::WebHistoryService* GetWebHistory() override { |
| 73 return web_history_.get(); | 74 return web_history_.get(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 private: | 77 private: |
| 77 scoped_ptr<history::WebHistoryService> web_history_; | 78 scoped_ptr<history::WebHistoryService> web_history_; |
| 78 }; | 79 }; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 EXPECT_TRUE(setListenerT2.WaitUntilSatisfied()); | 436 EXPECT_TRUE(setListenerT2.WaitUntilSatisfied()); |
| 436 EXPECT_TRUE(setListenerF2.WaitUntilSatisfied()); | 437 EXPECT_TRUE(setListenerF2.WaitUntilSatisfied()); |
| 437 EXPECT_TRUE(getListener2.WaitUntilSatisfied()); | 438 EXPECT_TRUE(getListener2.WaitUntilSatisfied()); |
| 438 } | 439 } |
| 439 | 440 |
| 440 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, AudioHistoryNoWebHistory) { | 441 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, AudioHistoryNoWebHistory) { |
| 441 MockAudioHistoryHandler* handler = | 442 MockAudioHistoryHandler* handler = |
| 442 new MockAudioHistoryHandler(profile(), nullptr); | 443 new MockAudioHistoryHandler(profile(), nullptr); |
| 443 service()->SetAudioHistoryHandler(handler); | 444 service()->SetAudioHistoryHandler(handler); |
| 444 | 445 |
| 445 ExtensionTestMessageListener setListenerT("set AH: false failure", false); | 446 // Set an initial value for the audio logging pref. |
| 446 ExtensionTestMessageListener setListenerF("set AH: false failure", false); | 447 PrefService* prefs = profile()->GetPrefs(); |
| 447 ExtensionTestMessageListener getListener("get AH: false failure", false); | 448 prefs->SetBoolean(prefs::kHotwordAudioLoggingEnabled, true); |
| 449 |
| 450 ExtensionTestMessageListener setListenerT("set AH: true failure", false); |
| 451 ExtensionTestMessageListener setListenerF("set AH: true failure", false); |
| 452 ExtensionTestMessageListener getListener("get AH: true failure", false); |
| 448 | 453 |
| 449 ASSERT_TRUE(RunComponentExtensionTest("audioHistory")) << message_; | 454 ASSERT_TRUE(RunComponentExtensionTest("audioHistory")) << message_; |
| 450 | 455 |
| 451 EXPECT_TRUE(setListenerT.WaitUntilSatisfied()); | 456 EXPECT_TRUE(setListenerT.WaitUntilSatisfied()); |
| 452 EXPECT_TRUE(setListenerF.WaitUntilSatisfied()); | 457 EXPECT_TRUE(setListenerF.WaitUntilSatisfied()); |
| 453 EXPECT_TRUE(getListener.WaitUntilSatisfied()); | 458 EXPECT_TRUE(getListener.WaitUntilSatisfied()); |
| 454 } | 459 } |
| 455 | 460 |
| 456 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, AudioHistoryWebHistoryFailure) { | 461 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, AudioHistoryWebHistoryFailure) { |
| 457 MockWebHistoryService* web_history = new MockWebHistoryService(profile()); | 462 MockWebHistoryService* web_history = new MockWebHistoryService(profile()); |
| 458 MockAudioHistoryHandler* handler = | 463 MockAudioHistoryHandler* handler = |
| 459 new MockAudioHistoryHandler(profile(), web_history); | 464 new MockAudioHistoryHandler(profile(), web_history); |
| 460 service()->SetAudioHistoryHandler(handler); | 465 service()->SetAudioHistoryHandler(handler); |
| 461 web_history->SetFailureState(); | 466 web_history->SetFailureState(); |
| 462 // It shouldn't matter if this is set to true. GetAduioHistoryEnabled should | 467 // It shouldn't matter if this is set to true. GetAduioHistoryEnabled should |
| 463 // still return false. | 468 // still return false. |
| 464 web_history->SetExpectedValue(true); | 469 web_history->SetExpectedValue(true); |
| 465 | 470 |
| 466 ExtensionTestMessageListener setListenerT("set AH: false failure", false); | 471 ExtensionTestMessageListener setListenerT("set AH: false failure", false); |
| 467 ExtensionTestMessageListener setListenerF("set AH: false failure", false); | 472 ExtensionTestMessageListener setListenerF("set AH: false failure", false); |
| 468 ExtensionTestMessageListener getListener("get AH: false failure", false); | 473 ExtensionTestMessageListener getListener("get AH: false failure", false); |
| 469 | 474 |
| 470 ASSERT_TRUE(RunComponentExtensionTest("audioHistory")) << message_; | 475 ASSERT_TRUE(RunComponentExtensionTest("audioHistory")) << message_; |
| 471 | 476 |
| 472 EXPECT_TRUE(setListenerT.WaitUntilSatisfied()); | 477 EXPECT_TRUE(setListenerT.WaitUntilSatisfied()); |
| 473 EXPECT_TRUE(setListenerF.WaitUntilSatisfied()); | 478 EXPECT_TRUE(setListenerF.WaitUntilSatisfied()); |
| 474 EXPECT_TRUE(getListener.WaitUntilSatisfied()); | 479 EXPECT_TRUE(getListener.WaitUntilSatisfied()); |
| 475 } | 480 } |
| OLD | NEW |