1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/webstore_startup_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/search/hotword_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/webstore_install_result.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class MockHotwordWebstoreInstaller
: public HotwordService::HotwordWebstoreInstaller {
public:
MockHotwordWebstoreInstaller(Profile* profile, const Callback& callback)
: HotwordService::HotwordWebstoreInstaller(
extension_misc::kHotwordSharedModuleId,
profile,
callback) {
}
const GURL& GetRequestorURL() const override {
// This should not be valid so it hangs.
return GURL::EmptyGURL();
}
void BeginInstall() {
WebstoreStandaloneInstaller::BeginInstall();
}
private:
~MockHotwordWebstoreInstaller() override {}
};
class MockHotwordService : public HotwordService {
public:
explicit MockHotwordService(Profile* profile)
: HotwordService(profile),
profile_(profile),
weak_factory_(this) {
}
void InstallHotwordExtensionFromWebstore(int num_tries) override {
installer_ = new MockHotwordWebstoreInstaller(
profile_,
base::Bind(&MockHotwordService::InstallerCallback,
weak_factory_.GetWeakPtr(),
num_tries - 1));
installer_->BeginInstall();
}
void InstallerCallback(int num_tries,
bool success,
const std::string& error,
extensions::webstore_install::Result result) {
}
private:
Profile* profile_;
base::WeakPtrFactory<MockHotwordService> weak_factory_;
};
KeyedService* BuildMockHotwordService(content::BrowserContext* context) {
return new MockHotwordService(static_cast<Profile*>(context));
}
} // namespace
namespace extensions {
class HotwordInstallerBrowserTest : public ExtensionBrowserTest {
public:
HotwordInstallerBrowserTest() {}
~HotwordInstallerBrowserTest() override {}
private:
DISALLOW_COPY_AND_ASSIGN(HotwordInstallerBrowserTest);
};
// Test that installing to a non-existent URL (which should hang) does not
// crash. This test is successful if it does not crash and trigger any DCHECKS.
IN_PROC_BROWSER_TEST_F(HotwordInstallerBrowserTest, AbortInstallOnShutdown) {
TestingProfile test_profile;
HotwordServiceFactory* hotword_service_factory =
HotwordServiceFactory::GetInstance();
MockHotwordService* hotword_service = static_cast<MockHotwordService*>(
hotword_service_factory->SetTestingFactoryAndUse(
&test_profile, BuildMockHotwordService));
hotword_service->InstallHotwordExtensionFromWebstore(1);
}
} // namespace extensions
|