Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_uninstall_dialog_view_browsertest.cc
blob9ebd960686a3e5ddd284d4e1f8df4da59bd7b811
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"
15 namespace {
17 scoped_refptr<extensions::Extension> BuildTestExtension() {
18 return extensions::ExtensionBuilder()
19 .SetManifest(extensions::DictionaryBuilder()
20 .Set("name", "foo")
21 .Set("version", "1.0"))
22 .Build();
25 class TestExtensionUninstallDialogDelegate
26 : public extensions::ExtensionUninstallDialog::Delegate {
27 public:
28 explicit TestExtensionUninstallDialogDelegate(
29 const base::Closure& quit_closure)
30 : quit_closure_(quit_closure), canceled_(false) {}
32 ~TestExtensionUninstallDialogDelegate() override {}
34 bool canceled() { return canceled_; }
36 private:
37 void OnExtensionUninstallDialogClosed(bool did_start_uninstall,
38 const base::string16& error) override {
39 canceled_ = !did_start_uninstall;
40 quit_closure_.Run();
43 base::Closure quit_closure_;
44 bool canceled_;
46 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate);
49 } // namespace
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
58 // closed.
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(),
68 &delegate));
69 browser()->window()->Close();
70 content::RunAllPendingInMessageLoop();
72 dialog->ConfirmUninstall(extension.get(),
73 extensions::UNINSTALL_REASON_FOR_TESTING,
74 extensions::UNINSTALL_SOURCE_FOR_TESTING);
75 run_loop.Run();
76 EXPECT_TRUE(delegate.canceled());