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 OnExtensionUninstallDialogClosed(bool did_start_uninstall
,
38 const base::string16
& error
) override
{
39 canceled_
= !did_start_uninstall
;
43 base::Closure quit_closure_
;
46 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate
);
51 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest
;
53 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window
54 // which is passed to ExtensionUninstallDialog::Create() is destroyed.
55 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest
,
56 TrackParentWindowDestruction
) {
57 // Create a second browser to prevent the app from exiting when the browser is
59 CreateBrowser(browser()->profile());
61 scoped_refptr
<extensions::Extension
> extension(BuildTestExtension());
63 base::RunLoop run_loop
;
64 TestExtensionUninstallDialogDelegate
delegate(run_loop
.QuitClosure());
65 scoped_ptr
<extensions::ExtensionUninstallDialog
> dialog(
66 extensions::ExtensionUninstallDialog::Create(
67 browser()->profile(), browser()->window()->GetNativeWindow(),
69 browser()->window()->Close();
70 content::RunAllPendingInMessageLoop();
72 dialog
->ConfirmUninstall(extension
.get(),
73 extensions::UNINSTALL_REASON_FOR_TESTING
,
74 extensions::UNINSTALL_SOURCE_FOR_TESTING
);
76 EXPECT_TRUE(delegate
.canceled());