Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / windowed_install_dialog_controller_browsertest.mm
blob310126ee9336d7f11f469a175e4ac5d1f9b43a66
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 "content/public/test/test_utils.h"
15 #include "extensions/common/extension.h"
17 namespace {
19 // Similar to ShowExtensionInstallDialogImpl except this allows the created
20 // dialog controller to be captured and manipulated for tests.
21 void TestingShowAppListInstallDialogController(
22     WindowedInstallDialogController** controller,
23     ExtensionInstallPromptShowParams* show_params,
24     ExtensionInstallPrompt::Delegate* delegate,
25     scoped_refptr<ExtensionInstallPrompt::Prompt> prompt) {
26   *controller =
27       new WindowedInstallDialogController(show_params, delegate, prompt);
30 typedef InProcessBrowserTest WindowedInstallDialogControllerBrowserTest;
32 }  // namespace
34 // Test for showing an extension install prompt with no parent WebContents.
35 IN_PROC_BROWSER_TEST_F(WindowedInstallDialogControllerBrowserTest,
36                        ShowInstallDialog) {
37   // Construct a prompt with a NULL parent window, the way ExtensionEnableFlow
38   // will for the Mac app list. For testing, sets a NULL PageNavigator as well.
39   scoped_ptr<ExtensionInstallPrompt> prompt(
40       new ExtensionInstallPrompt(browser()->profile(), NULL));
42   WindowedInstallDialogController* controller = NULL;
43   chrome::MockExtensionInstallPromptDelegate delegate;
44   scoped_refptr<extensions::Extension> extension =
45       chrome::LoadInstallPromptExtension("permissions", "many-apis.json");
46   prompt->ConfirmInstall(
47       &delegate,
48       extension.get(),
49       base::Bind(&TestingShowAppListInstallDialogController, &controller));
51   // The prompt needs to load the image, which happens on the blocking pool.
52   content::RunAllBlockingPoolTasksUntilIdle();
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]);