panel_browsertest.cc revision 4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7
1// Copyright (c) 2010 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 "base/command_line.h" 6#include "chrome/browser/browser_list.h" 7#include "chrome/browser/browser_process.h" 8#include "chrome/browser/browser_window.h" 9#include "chrome/browser/chromeos/wm_ipc.h" 10#include "chrome/browser/renderer_host/render_view_host.h" 11#include "chrome/browser/tab_contents/tab_contents.h" 12#include "chrome/browser/ui/browser.h" 13#include "chrome/common/chrome_switches.h" 14#include "chrome/test/in_process_browser_test.h" 15#include "chrome/test/ui_test_utils.h" 16#include "cros/chromeos_wm_ipc_enums.h" 17 18namespace chromeos { 19 20class PanelTest : public InProcessBrowserTest { 21 public: 22 PanelTest() { 23 EnableDOMAutomation(); 24 } 25 26 protected: 27 virtual void SetUpCommandLine(CommandLine* command_line) { 28 command_line->AppendSwitch(switches::kDisablePopupBlocking); 29 } 30 31}; 32 33// Small popups should open as a panel. 34IN_PROC_BROWSER_TEST_F(PanelTest, PanelOpenSmall) { 35 const std::string HTML = 36 "<html><head><title>PanelOpen</title></head>" 37 "<body onload='window.setTimeout(run_tests, 0)'>" 38 "<script>" 39 " function run_tests() {" 40 " window.open(null, null, 'width=100,height=100');" 41 " }" 42 "</script>" 43 "</body></html>"; 44 GURL url("data:text/html," + HTML); 45 CommandLine::ForCurrentProcess()->AppendSwitch( 46 switches::kDisablePopupBlocking); 47 48 browser()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); 49 50 // Wait for notification that window.open has been processed. 51 ui_test_utils::WaitForNotification(NotificationType::TAB_ADDED); 52 53 // Find the new browser. 54 Browser* new_browser = NULL; 55 for (BrowserList::const_iterator i = BrowserList::begin(); 56 i != BrowserList::end() && !new_browser; ++i) { 57 if (*i != browser()) 58 new_browser = *i; 59 } 60 61 ASSERT_TRUE(new_browser); 62 EXPECT_EQ(Browser::TYPE_POPUP, new_browser->type()); 63 // This window type tells the cros window manager to treat the window 64 // as a panel. 65 EXPECT_EQ( 66 WM_IPC_WINDOW_CHROME_PANEL_CONTENT, 67 WmIpc::instance()->GetWindowType( 68 GTK_WIDGET(new_browser->window()->GetNativeHandle()), NULL)); 69} 70 71// Large popups should open as new tab. 72IN_PROC_BROWSER_TEST_F(PanelTest, PanelOpenLarge) { 73 const std::string HTML = 74 "<html><head><title>PanelOpen</title></head>" 75 "<body onload='window.setTimeout(run_tests, 0)'>" 76 "<script>" 77 " function run_tests() {" 78 " window.open(null, null, 'width=1000,height=1000');" 79 " }" 80 "</script>" 81 "</body></html>"; 82 GURL url("data:text/html," + HTML); 83 CommandLine::ForCurrentProcess()->AppendSwitch( 84 switches::kDisablePopupBlocking); 85 int old_tab_count = browser()->tab_count(); 86 browser()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); 87 88 // Wait for notification that window.open has been processed. 89 ui_test_utils::WaitForNotification(NotificationType::TAB_ADDED); 90 91 // Shouldn't find a new browser. 92 Browser* new_browser = NULL; 93 for (BrowserList::const_iterator i = BrowserList::begin(); 94 i != BrowserList::end() && !new_browser; ++i) { 95 if (*i != browser()) 96 new_browser = *i; 97 } 98 EXPECT_FALSE(new_browser); 99 100 // Should find a new tab. 101 EXPECT_EQ(old_tab_count + 1, browser()->tab_count()); 102} 103 104} // namespace chromeos 105