OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
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" | |
14 | |
15 namespace { | |
16 | |
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(); | |
23 } | |
24 | |
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) {} | |
31 | |
32 ~TestExtensionUninstallDialogDelegate() override {} | |
33 | |
34 bool DidCancel() { return canceled_; } | |
Finnur
2014/11/02 21:38:25
nit: did_cancel() or canceled()
| |
35 | |
36 private: | |
37 void ExtensionUninstallAccepted() override { quit_closure_.Run(); } | |
38 | |
39 void ExtensionUninstallCanceled() override { | |
40 canceled_ = true; | |
41 quit_closure_.Run(); | |
42 } | |
43 | |
44 base::Closure quit_closure_; | |
45 bool canceled_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); | |
48 }; | |
49 | |
50 } // namespace | |
51 | |
52 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; | |
53 | |
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 | |
59 // closed. | |
60 CreateBrowser(browser()->profile()); | |
61 | |
62 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | |
63 | |
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(), | |
69 &delegate)); | |
70 browser()->window()->Close(); | |
71 content::RunAllPendingInMessageLoop(); | |
72 | |
73 dialog->ConfirmUninstall(extension.get()); | |
74 run_loop.Run(); | |
75 EXPECT_TRUE(delegate.DidCancel()); | |
76 } | |
OLD | NEW |