browser_command_controller_browsertest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_command_controller.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/app/chrome_command_ids.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_commands.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/test_utils.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef InProcessBrowserTest BrowserCommandControllerBrowserTest;
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Verify that showing a constrained window disables find.
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Showing constrained window should disable find.
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::WebContents* web_contents =
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      browser()->tab_strip_model()->GetActiveWebContents();
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MockTabModalConfirmDialogDelegate* delegate =
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      new MockTabModalConfirmDialogDelegate(web_contents, NULL);
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TabModalConfirmDialog::Create(delegate, web_contents);
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Switching to a new (unblocked) tab should reenable it.
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AddBlankTabAndShow(browser());
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Switching back to the blocked tab should disable it again.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser()->tab_strip_model()->ActivateTabAt(0, false);
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Closing the constrained window should reenable it.
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  delegate->Cancel();
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RunAllPendingInMessageLoop();
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
42