1// Copyright (c) 2012 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 "chrome/browser/ui/browser_command_controller.h"
6
7#include "chrome/app/chrome_command_ids.h"
8#include "chrome/browser/ui/browser.h"
9#include "chrome/browser/ui/browser_commands.h"
10#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
11#include "chrome/browser/ui/tabs/tab_strip_model.h"
12#include "chrome/test/base/in_process_browser_test.h"
13#include "content/public/test/test_utils.h"
14
15typedef InProcessBrowserTest BrowserCommandControllerBrowserTest;
16
17// Verify that showing a constrained window disables find.
18IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
19  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
20
21  // Showing constrained window should disable find.
22  content::WebContents* web_contents =
23      browser()->tab_strip_model()->GetActiveWebContents();
24  MockTabModalConfirmDialogDelegate* delegate =
25      new MockTabModalConfirmDialogDelegate(web_contents, NULL);
26  TabModalConfirmDialog::Create(delegate, web_contents);
27  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
28
29  // Switching to a new (unblocked) tab should reenable it.
30  AddBlankTabAndShow(browser());
31  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
32
33  // Switching back to the blocked tab should disable it again.
34  browser()->tab_strip_model()->ActivateTabAt(0, false);
35  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
36
37  // Closing the constrained window should reenable it.
38  delegate->Cancel();
39  content::RunAllPendingInMessageLoop();
40  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
41}
42