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/run_loop.h"
6 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "content/public/test/test_utils.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_builder.h"
13 #include "extensions/common/value_builder.h"
17 scoped_refptr<extensions::Extension> BuildTestExtension() {
18 return extensions::ExtensionBuilder()
19 .SetManifest(extensions::DictionaryBuilder()
21 .Set("version", "1.0"))
25 class TestExtensionUninstallDialogDelegate
26 : public extensions::ExtensionUninstallDialog::Delegate {
28 explicit TestExtensionUninstallDialogDelegate(
29 const base::Closure& quit_closure)
30 : quit_closure_(quit_closure), canceled_(false) {}
32 ~TestExtensionUninstallDialogDelegate() override {}
34 bool canceled() { return canceled_; }
37 void ExtensionUninstallAccepted() override { quit_closure_.Run(); }
39 void ExtensionUninstallCanceled() override {
44 base::Closure quit_closure_;
47 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate);
52 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest;
54 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window
55 // which is passed to ExtensionUninstallDialog::Create() is destroyed.
56 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
57 TrackParentWindowDestruction) {
58 // Create a second browser to prevent the app from exiting when the browser is
60 CreateBrowser(browser()->profile());
62 scoped_refptr<extensions::Extension> extension(BuildTestExtension());
64 base::RunLoop run_loop;
65 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
66 scoped_ptr<extensions::ExtensionUninstallDialog> dialog(
67 extensions::ExtensionUninstallDialog::Create(
68 browser()->profile(), browser()->window()->GetNativeWindow(),
70 browser()->window()->Close();
71 content::RunAllPendingInMessageLoop();
73 dialog->ConfirmUninstall(extension.get());
75 EXPECT_TRUE(delegate.canceled());