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 "chrome/browser/extensions/extension_browsertest.h"
6 #include "chrome/browser/extensions/webstore_startup_installer.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/search/hotword_service.h"
9 #include "chrome/browser/search/hotword_service_factory.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/extension_constants.h"
12 #include "chrome/common/extensions/webstore_install_result.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
18 class MockHotwordWebstoreInstaller
19 : public HotwordService::HotwordWebstoreInstaller
{
21 MockHotwordWebstoreInstaller(Profile
* profile
, const Callback
& callback
)
22 : HotwordService::HotwordWebstoreInstaller(
23 extension_misc::kHotwordSharedModuleId
,
28 const GURL
& GetRequestorURL() const override
{
29 // This should not be valid so it hangs.
30 return GURL::EmptyGURL();
34 WebstoreStandaloneInstaller::BeginInstall();
38 ~MockHotwordWebstoreInstaller() override
{}
42 class MockHotwordService
: public HotwordService
{
44 explicit MockHotwordService(Profile
* profile
)
45 : HotwordService(profile
),
50 void InstallHotwordExtensionFromWebstore(int num_tries
) override
{
51 installer_
= new MockHotwordWebstoreInstaller(
53 base::Bind(&MockHotwordService::InstallerCallback
,
54 weak_factory_
.GetWeakPtr(),
56 installer_
->BeginInstall();
59 void InstallerCallback(int num_tries
,
61 const std::string
& error
,
62 extensions::webstore_install::Result result
) {
67 base::WeakPtrFactory
<MockHotwordService
> weak_factory_
;
70 KeyedService
* BuildMockHotwordService(content::BrowserContext
* context
) {
71 return new MockHotwordService(static_cast<Profile
*>(context
));
76 namespace extensions
{
78 class HotwordInstallerBrowserTest
: public ExtensionBrowserTest
{
80 HotwordInstallerBrowserTest() {}
81 ~HotwordInstallerBrowserTest() override
{}
84 DISALLOW_COPY_AND_ASSIGN(HotwordInstallerBrowserTest
);
87 // Test that installing to a non-existent URL (which should hang) does not
88 // crash. This test is successful if it does not crash and trigger any DCHECKS.
89 IN_PROC_BROWSER_TEST_F(HotwordInstallerBrowserTest
, AbortInstallOnShutdown
) {
90 TestingProfile test_profile
;
91 HotwordServiceFactory
* hotword_service_factory
=
92 HotwordServiceFactory::GetInstance();
93 MockHotwordService
* hotword_service
= static_cast<MockHotwordService
*>(
94 hotword_service_factory
->SetTestingFactoryAndUse(
95 &test_profile
, BuildMockHotwordService
));
96 hotword_service
->InstallHotwordExtensionFromWebstore(1);
99 } // namespace extensions