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