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