Rename vector icon header files.
[chromium-blink-merge.git] / chrome / browser / search / hotword_installer_browsertest.cc
blob3293bf2f4a7ad056795bac4b06a42c8ee5978f7f
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/extensions/webstore_startup_installer.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search/hotword_service.h"
10 #include "chrome/browser/search/hotword_service_factory.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension_constants.h"
13 #include "chrome/common/extensions/webstore_install_result.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/test/test_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace {
19 class MockHotwordWebstoreInstaller
20 : public HotwordService::HotwordWebstoreInstaller {
21 public:
22 MockHotwordWebstoreInstaller(Profile* profile, const Callback& callback)
23 : HotwordService::HotwordWebstoreInstaller(
24 extension_misc::kHotwordSharedModuleId,
25 profile,
26 callback) {
29 const GURL& GetRequestorURL() const override {
30 // This should not be valid so it hangs.
31 return GURL::EmptyGURL();
34 void BeginInstall() {
35 WebstoreStandaloneInstaller::BeginInstall();
38 private:
39 ~MockHotwordWebstoreInstaller() override {}
43 class MockHotwordService : public HotwordService {
44 public:
45 explicit MockHotwordService(Profile* profile)
46 : HotwordService(profile),
47 profile_(profile),
48 weak_factory_(this) {
51 void InstallHotwordExtensionFromWebstore(int num_tries) override {
52 installer_ = new MockHotwordWebstoreInstaller(
53 profile_,
54 base::Bind(&MockHotwordService::InstallerCallback,
55 weak_factory_.GetWeakPtr(),
56 num_tries - 1));
57 installer_->BeginInstall();
60 void InstallerCallback(int num_tries,
61 bool success,
62 const std::string& error,
63 extensions::webstore_install::Result result) {
66 private:
67 Profile* profile_;
68 base::WeakPtrFactory<MockHotwordService> weak_factory_;
71 scoped_ptr<KeyedService> BuildMockHotwordService(
72 content::BrowserContext* context) {
73 return make_scoped_ptr(
74 new MockHotwordService(static_cast<Profile*>(context)));
77 } // namespace
79 namespace extensions {
81 class HotwordInstallerBrowserTest : public ExtensionBrowserTest {
82 public:
83 HotwordInstallerBrowserTest() {}
84 ~HotwordInstallerBrowserTest() override {}
86 private:
87 DISALLOW_COPY_AND_ASSIGN(HotwordInstallerBrowserTest);
90 // Test that installing to a non-existent URL (which should hang) does not
91 // crash. This test is successful if it does not crash and trigger any DCHECKS.
92 IN_PROC_BROWSER_TEST_F(HotwordInstallerBrowserTest, AbortInstallOnShutdown) {
93 TestingProfile test_profile;
94 HotwordServiceFactory* hotword_service_factory =
95 HotwordServiceFactory::GetInstance();
96 MockHotwordService* hotword_service = static_cast<MockHotwordService*>(
97 hotword_service_factory->SetTestingFactoryAndUse(
98 &test_profile, BuildMockHotwordService));
99 hotword_service->InstallHotwordExtensionFromWebstore(1);
102 } // namespace extensions