OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 #import "chrome/browser/ui/cocoa/extensions/windowed_install_dialog_controller.h
" |
| 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #import "chrome/browser/ui/cocoa/extensions/extension_install_prompt_test_utils.
h" |
| 10 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "extensions/common/extension.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Similar to ShowExtensionInstallDialogImpl except this allows the created |
| 18 // dialog controller to be captured and manipulated for tests. |
| 19 void TestingShowAppListInstallDialogController( |
| 20 WindowedInstallDialogController** controller, |
| 21 const ExtensionInstallPrompt::ShowParams& show_params, |
| 22 ExtensionInstallPrompt::Delegate* delegate, |
| 23 const ExtensionInstallPrompt::Prompt& prompt) { |
| 24 *controller = |
| 25 new WindowedInstallDialogController(show_params, delegate, prompt); |
| 26 } |
| 27 |
| 28 typedef InProcessBrowserTest WindowedInstallDialogControllerBrowserTest; |
| 29 |
| 30 } // namespace |
| 31 |
| 32 // Test for showing an extension install prompt with no parent WebContents. |
| 33 IN_PROC_BROWSER_TEST_F(WindowedInstallDialogControllerBrowserTest, |
| 34 ShowInstallDialog) { |
| 35 // Construct a prompt with a NULL parent window, the way ExtensionEnableFlow |
| 36 // will for the Mac app list. For testing, sets a NULL PageNavigator as well. |
| 37 scoped_ptr<ExtensionInstallPrompt> prompt( |
| 38 new ExtensionInstallPrompt(browser()->profile(), NULL, NULL)); |
| 39 |
| 40 WindowedInstallDialogController* controller = NULL; |
| 41 chrome::MockExtensionInstallPromptDelegate delegate; |
| 42 scoped_refptr<extensions::Extension> extension = |
| 43 chrome::LoadInstallPromptExtension("permissions", "many-apis.json"); |
| 44 prompt->ConfirmInstall( |
| 45 &delegate, |
| 46 extension.get(), |
| 47 base::Bind(&TestingShowAppListInstallDialogController, &controller)); |
| 48 |
| 49 // The prompt needs to load the image, which happens on the blocking pool. |
| 50 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 51 base::RunLoop().RunUntilIdle(); |
| 52 ASSERT_TRUE(controller); |
| 53 |
| 54 base::scoped_nsobject<NSWindow> window( |
| 55 [[[controller->GetViewController() view] window] retain]); |
| 56 EXPECT_TRUE([window isVisible]); |
| 57 EXPECT_TRUE([window delegate]); |
| 58 EXPECT_EQ(0, delegate.abort_count()); |
| 59 |
| 60 // Press cancel to close the window. |
| 61 [[controller->GetViewController() cancelButton] performClick:nil]; |
| 62 EXPECT_FALSE([window delegate]); |
| 63 EXPECT_EQ(1, delegate.abort_count()); |
| 64 |
| 65 // Ensure the window is closed. |
| 66 EXPECT_FALSE([window isVisible]); |
| 67 } |
OLD | NEW |