Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / search / hotword_installer_browsertest.cc
blob44d818c00d1501cccbfb4ea0f652289e9497b0ef
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"
17 namespace {
18 class MockHotwordWebstoreInstaller
19 : public HotwordService::HotwordWebstoreInstaller {
20 public:
21 MockHotwordWebstoreInstaller(Profile* profile, const Callback& callback)
22 : HotwordService::HotwordWebstoreInstaller(
23 extension_misc::kHotwordSharedModuleId,
24 profile,
25 callback) {
28 const GURL& GetRequestorURL() const override {
29 // This should not be valid so it hangs.
30 return GURL::EmptyGURL();
33 void BeginInstall() {
34 WebstoreStandaloneInstaller::BeginInstall();
37 private:
38 ~MockHotwordWebstoreInstaller() override {}
42 class MockHotwordService : public HotwordService {
43 public:
44 explicit MockHotwordService(Profile* profile)
45 : HotwordService(profile),
46 profile_(profile),
47 weak_factory_(this) {
50 void InstallHotwordExtensionFromWebstore(int num_tries) override {
51 installer_ = new MockHotwordWebstoreInstaller(
52 profile_,
53 base::Bind(&MockHotwordService::InstallerCallback,
54 weak_factory_.GetWeakPtr(),
55 num_tries - 1));
56 installer_->BeginInstall();
59 void InstallerCallback(int num_tries,
60 bool success,
61 const std::string& error,
62 extensions::webstore_install::Result result) {
65 private:
66 Profile* profile_;
67 base::WeakPtrFactory<MockHotwordService> weak_factory_;
70 KeyedService* BuildMockHotwordService(content::BrowserContext* context) {
71 return new MockHotwordService(static_cast<Profile*>(context));
74 } // namespace
76 namespace extensions {
78 class HotwordInstallerBrowserTest : public ExtensionBrowserTest {
79 public:
80 HotwordInstallerBrowserTest() {}
81 ~HotwordInstallerBrowserTest() override {}
83 private:
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