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

Side by Side Diff: chrome/browser/search/hotword_service_unittest.cc

Issue 800523002: [Hotword] Sync Audio History pref every 24 hours, when opening chrome://settings and . . . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another compile error Created 6 years 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
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/test/test_simple_task_runner.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_service_test_base.h" 11 #include "chrome/browser/extensions/extension_service_test_base.h"
11 #include "chrome/browser/extensions/test_extension_service.h" 12 #include "chrome/browser/extensions/test_extension_service.h"
13 #include "chrome/browser/history/web_history_service.h"
14 #include "chrome/browser/search/hotword_audio_history_handler.h"
12 #include "chrome/browser/search/hotword_service.h" 15 #include "chrome/browser/search/hotword_service.h"
13 #include "chrome/browser/search/hotword_service_factory.h" 16 #include "chrome/browser/search/hotword_service_factory.h"
14 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_builder.h" 24 #include "extensions/common/extension_builder.h"
22 #include "extensions/common/manifest.h" 25 #include "extensions/common/manifest.h"
23 #include "extensions/common/one_shot_event.h" 26 #include "extensions/common/one_shot_event.h"
24 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
25 28
26 namespace { 29 namespace {
27 30
31 class MockAudioHistoryHandler : public HotwordAudioHistoryHandler {
32 public:
33 MockAudioHistoryHandler(
34 content::BrowserContext* context,
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
36 history::WebHistoryService* web_history)
37 : HotwordAudioHistoryHandler(context, task_runner),
38 get_audio_history_calls_(0),
39 web_history_(web_history) {
40 }
41 ~MockAudioHistoryHandler() override {}
42
43 void GetAudioHistoryEnabled(
44 const HotwordAudioHistoryCallback& callback) override {
45 get_audio_history_calls_++;
46 callback.Run(true, true);
47 }
48
49 history::WebHistoryService* GetWebHistory() override {
50 return web_history_.get();
51 }
52
53 int GetAudioHistoryCalls() {
54 return get_audio_history_calls_;
55 }
56
57 private:
58 int get_audio_history_calls_;
59 scoped_ptr<history::WebHistoryService> web_history_;
60 };
61
28 class MockHotwordService : public HotwordService { 62 class MockHotwordService : public HotwordService {
29 public: 63 public:
30 explicit MockHotwordService(Profile* profile) 64 explicit MockHotwordService(Profile* profile)
31 : HotwordService(profile), 65 : HotwordService(profile),
32 uninstall_count_(0) { 66 uninstall_count_(0) {
33 } 67 }
34 68
35 bool UninstallHotwordExtension(ExtensionService* extension_service) override { 69 bool UninstallHotwordExtension(ExtensionService* extension_service) override {
36 uninstall_count_++; 70 uninstall_count_++;
37 return HotwordService::UninstallHotwordExtension(extension_service); 71 return HotwordService::UninstallHotwordExtension(extension_service);
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 527
494 // Set pref. 528 // Set pref.
495 profile()->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, true); 529 profile()->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, true);
496 EXPECT_FALSE(hotword_service->IsSometimesOnEnabled()); 530 EXPECT_FALSE(hotword_service->IsSometimesOnEnabled());
497 531
498 // Disable always-on. 532 // Disable always-on.
499 profile()->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, 533 profile()->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled,
500 false); 534 false);
501 EXPECT_FALSE(hotword_service->IsSometimesOnEnabled()); 535 EXPECT_FALSE(hotword_service->IsSometimesOnEnabled());
502 } 536 }
537
538 TEST_P(HotwordServiceTest, AudioHistorySyncOccurs) {
539 // Set the field trial to a valid one.
540 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
541 hotword_internal::kHotwordFieldTrialName, "Install"));
542
543 InitializeEmptyExtensionService();
544 service_->Init();
545
546 HotwordServiceFactory* hotword_service_factory =
547 HotwordServiceFactory::GetInstance();
548
549 MockHotwordService* hotword_service = static_cast<MockHotwordService*>(
550 hotword_service_factory->SetTestingFactoryAndUse(
551 profile(), BuildMockHotwordService));
552 EXPECT_TRUE(hotword_service != NULL);
553 hotword_service->SetExtensionService(service());
554 hotword_service->SetExtensionId(extension_id_);
555
556 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner(
557 new base::TestSimpleTaskRunner());
558 MockAudioHistoryHandler* audio_history_handler =
559 new MockAudioHistoryHandler(profile(), test_task_runner, nullptr);
560 hotword_service->SetAudioHistoryHandler(audio_history_handler);
561 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls());
562 // We expect the next check for audio history to be in the queue.
563 EXPECT_EQ(base::TimeDelta::FromDays(1),
564 test_task_runner->NextPendingTaskDelay());
565 EXPECT_TRUE(test_task_runner->HasPendingTask());
566 test_task_runner->RunPendingTasks();
567 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls());
568 EXPECT_TRUE(test_task_runner->HasPendingTask());
569 test_task_runner->ClearPendingTasks();
570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698