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"
19 class MockHotwordWebstoreInstaller
20 : public HotwordService::HotwordWebstoreInstaller
{
22 MockHotwordWebstoreInstaller(Profile
* profile
, const Callback
& callback
)
23 : HotwordService::HotwordWebstoreInstaller(
24 extension_misc::kHotwordSharedModuleId
,
29 const GURL
& GetRequestorURL() const override
{
30 // This should not be valid so it hangs.
31 return GURL::EmptyGURL();
35 WebstoreStandaloneInstaller::BeginInstall();
39 ~MockHotwordWebstoreInstaller() override
{}
43 class MockHotwordService
: public HotwordService
{
45 explicit MockHotwordService(Profile
* profile
)
46 : HotwordService(profile
),
51 void InstallHotwordExtensionFromWebstore(int num_tries
) override
{
52 installer_
= new MockHotwordWebstoreInstaller(
54 base::Bind(&MockHotwordService::InstallerCallback
,
55 weak_factory_
.GetWeakPtr(),
57 installer_
->BeginInstall();
60 void InstallerCallback(int num_tries
,
62 const std::string
& error
,
63 extensions::webstore_install::Result result
) {
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
)));
79 namespace extensions
{
81 class HotwordInstallerBrowserTest
: public ExtensionBrowserTest
{
83 HotwordInstallerBrowserTest() {}
84 ~HotwordInstallerBrowserTest() override
{}
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