[email protected] | 35abc33 | 2012-02-24 23:48:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 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" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 6 | #include "base/memory/scoped_vector.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 7 | #include "base/strings/stringprintf.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_host.h" |
| 10 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
[email protected] | 01996a59 | 2013-09-13 06:55:04 | [diff] [blame^] | 13 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 16 | #include "chrome/browser/ui/browser_iterator.h" |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 17 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 18 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 19 | #include "chrome/common/chrome_switches.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 20 | #include "chrome/common/extensions/extension.h" |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 21 | #include "chrome/test/base/test_switches.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 22 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 23 | #include "content/public/browser/render_process_host.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 24 | #include "content/public/browser/web_contents.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 25 | #include "content/public/common/result_codes.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 26 | #include "content/public/test/browser_test_utils.h" |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 27 | #include "extensions/common/switches.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 28 | #include "net/dns/mock_host_resolver.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 29 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 30 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 31 | #if defined(USE_ASH) |
[email protected] | f6d9b28 | 2013-08-09 11:03:20 | [diff] [blame] | 32 | #include "apps/shell_window_registry.h" |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | #if defined(USE_ASH) && !defined(OS_WIN) |
| 36 | // TODO(stevenjb): Figure out the correct behavior for Ash + Win |
| 37 | #define USE_ASH_PANELS |
| 38 | #endif |
| 39 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 40 | using content::OpenURLParams; |
| 41 | using content::Referrer; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 42 | using content::WebContents; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 43 | |
[email protected] | e78eb29 | 2010-12-22 08:35:39 | [diff] [blame] | 44 | // Disabled, http://crbug.com/64899. |
| 45 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 46 | CommandLine::ForCurrentProcess()->AppendSwitch( |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 47 | extensions::switches::kEnableExperimentalExtensionApis); |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 48 | |
| 49 | ResultCatcher catcher; |
| 50 | ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 51 | .AppendASCII("window_open").AppendASCII("spanning"))); |
| 52 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 53 | } |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 54 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 55 | int GetPanelCount(Browser* browser) { |
| 56 | #if defined(USE_ASH_PANELS) |
[email protected] | f6d9b28 | 2013-08-09 11:03:20 | [diff] [blame] | 57 | return static_cast<int>(apps::ShellWindowRegistry::Get( |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 58 | browser->profile())->shell_windows().size()); |
| 59 | #else |
| 60 | return PanelManager::GetInstance()->num_panels(); |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | bool WaitForTabsAndPopups(Browser* browser, |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 65 | int num_tabs, |
| 66 | int num_popups, |
| 67 | int num_panels) { |
[email protected] | 58b349b | 2011-11-23 02:07:15 | [diff] [blame] | 68 | SCOPED_TRACE( |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 69 | base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d", |
| 70 | num_tabs, num_popups, num_panels)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 71 | // We start with one tab and one browser already open. |
| 72 | ++num_tabs; |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 73 | size_t num_browsers = static_cast<size_t>(num_popups) + 1; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 74 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 75 | const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 76 | base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; |
| 77 | while (base::TimeTicks::Now() < end_time) { |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 78 | if (chrome::GetBrowserCount(browser->profile(), |
| 79 | browser->host_desktop_type()) == num_browsers && |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 80 | browser->tab_strip_model()->count() == num_tabs && |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 81 | GetPanelCount(browser) == num_panels) |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 82 | break; |
| 83 | |
[email protected] | b8deecd | 2012-07-30 21:09:44 | [diff] [blame] | 84 | content::RunAllPendingInMessageLoop(); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 87 | EXPECT_EQ(num_browsers, |
| 88 | chrome::GetBrowserCount(browser->profile(), |
| 89 | browser->host_desktop_type())); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 90 | EXPECT_EQ(num_tabs, browser->tab_strip_model()->count()); |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 91 | EXPECT_EQ(num_panels, GetPanelCount(browser)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 92 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 93 | int num_popups_seen = 0; |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 94 | for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 95 | if (*iter == browser) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 96 | continue; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 97 | |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 98 | EXPECT_TRUE((*iter)->is_type_popup()); |
| 99 | ++num_popups_seen; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 100 | } |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 101 | EXPECT_EQ(num_popups, num_popups_seen); |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 102 | |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 103 | return ((num_browsers == |
| 104 | chrome::GetBrowserCount(browser->profile(), |
| 105 | browser->host_desktop_type())) && |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 106 | (num_tabs == browser->tab_strip_model()->count()) && |
| 107 | (num_panels == GetPanelCount(browser)) && |
| 108 | (num_popups == num_popups_seen)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 111 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 112 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 113 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 114 | ASSERT_TRUE(LoadExtension( |
| 115 | test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 116 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 117 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0)); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 118 | |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 119 | for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 120 | if (*iter == browser()) |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 121 | ASSERT_FALSE(iter->is_app()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 122 | else |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 123 | ASSERT_TRUE(iter->is_app()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 127 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 128 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 129 | ASSERT_TRUE(LoadExtension( |
| 130 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 131 | |
| 132 | const int num_tabs = 1; |
| 133 | const int num_popups = 0; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 134 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 138 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 139 | ASSERT_TRUE(LoadExtension( |
| 140 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); |
| 141 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 142 | // On other systems this should open a new popup window. |
| 143 | const int num_tabs = 0; |
| 144 | const int num_popups = 1; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 145 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 149 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 150 | ASSERT_TRUE(LoadExtension( |
| 151 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); |
| 152 | |
| 153 | // On ChromeOS this should open a new panel (acts like a new popup window). |
| 154 | // On other systems this should open a new popup window. |
| 155 | const int num_tabs = 0; |
| 156 | const int num_popups = 1; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 157 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | 73fa1fce | 2013-02-21 20:10:05 | [diff] [blame] | 160 | // Disabled on Windows. Often times out or fails: crbug.com/177530 |
| 161 | #if defined(OS_WIN) |
| 162 | #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension |
| 163 | #else |
| 164 | #define MAYBE_PopupBlockingExtension PopupBlockingExtension |
| 165 | #endif |
| 166 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 167 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 168 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 169 | |
| 170 | ASSERT_TRUE(LoadExtension( |
| 171 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 172 | .AppendASCII("extension"))); |
| 173 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 174 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { |
| 178 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 179 | ASSERT_TRUE(test_server()->Start()); |
| 180 | |
| 181 | ASSERT_TRUE(LoadExtension( |
| 182 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 183 | .AppendASCII("hosted_app"))); |
| 184 | |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 185 | // The app being tested owns the domain a.com . The test URLs we navigate |
| 186 | // to below must be within that domain, so that they fall within the app's |
| 187 | // web extent. |
| 188 | GURL::Replacements replace_host; |
| 189 | std::string a_dot_com = "a.com"; |
| 190 | replace_host.SetHostStr(a_dot_com); |
| 191 | |
| 192 | const std::string popup_app_contents_path( |
| 193 | "files/extensions/api_test/window_open/popup_blocking/hosted_app/"); |
| 194 | |
| 195 | GURL open_tab = |
| 196 | test_server()->GetURL(popup_app_contents_path + "open_tab.html") |
| 197 | .ReplaceComponents(replace_host); |
| 198 | GURL open_popup = |
| 199 | test_server()->GetURL(popup_app_contents_path + "open_popup.html") |
| 200 | .ReplaceComponents(replace_host); |
| 201 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 202 | browser()->OpenURL(OpenURLParams( |
| 203 | open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, |
| 204 | false)); |
| 205 | browser()->OpenURL(OpenURLParams( |
| 206 | open_popup, Referrer(), NEW_FOREGROUND_TAB, |
| 207 | content::PAGE_TRANSITION_TYPED, false)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 208 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 209 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 210 | } |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 211 | |
[email protected] | e7f9056 | 2011-05-23 21:38:24 | [diff] [blame] | 212 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) { |
| 213 | ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; |
| 214 | } |
| 215 | |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 216 | class WindowOpenPanelDisabledTest : public ExtensionApiTest { |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 217 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 218 | ExtensionApiTest::SetUpCommandLine(command_line); |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 219 | // TODO(jennb): Re-enable when panels are enabled by default. |
| 220 | // command_line->AppendSwitch(switches::kDisablePanels); |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 221 | } |
| 222 | }; |
| 223 | |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 224 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest, |
| 225 | DISABLED_WindowOpenPanelNotEnabled) { |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 226 | ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_; |
| 227 | } |
| 228 | |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 229 | class WindowOpenPanelTest : public ExtensionApiTest { |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 230 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 231 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 232 | command_line->AppendSwitch(switches::kEnablePanels); |
| 233 | } |
| 234 | }; |
| 235 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 236 | #if defined(USE_ASH_PANELS) |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 237 | // On Ash, this currently fails because we're currently opening new panel |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 238 | // windows as popup windows instead. |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 239 | #define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 240 | #else |
| 241 | #define MAYBE_WindowOpenPanel WindowOpenPanel |
| 242 | #endif |
| 243 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) { |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 244 | ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_; |
| 245 | } |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 246 | |
[email protected] | cb1849e | 2013-07-08 21:12:53 | [diff] [blame] | 247 | #if defined(USE_ASH_PANELS) |
[email protected] | ca29ed1 | 2012-09-06 09:10:50 | [diff] [blame] | 248 | // On Ash, this currently fails because we're currently opening new panel |
| 249 | // windows as popup windows instead. |
[email protected] | cb1849e | 2013-07-08 21:12:53 | [diff] [blame] | 250 | #define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached |
| 251 | #else |
| 252 | #define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached |
| 253 | #endif |
| 254 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) { |
[email protected] | ca29ed1 | 2012-09-06 09:10:50 | [diff] [blame] | 255 | ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_; |
| 256 | } |
| 257 | |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 258 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 259 | CloseNonExtensionPanelsOnUninstall) { |
[email protected] | 45c6f672 | 2013-07-23 03:02:19 | [diff] [blame] | 260 | #if defined(OS_WIN) && defined(USE_ASH) |
| 261 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 262 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
[email protected] | 45c6f672 | 2013-07-23 03:02:19 | [diff] [blame] | 263 | return; |
| 264 | #endif |
| 265 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 266 | #if defined(USE_ASH_PANELS) |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 267 | // On Ash, new panel windows open as popup windows instead. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 268 | int num_popups, num_panels; |
| 269 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) { |
| 270 | num_popups = 2; |
| 271 | num_panels = 2; |
| 272 | } else { |
| 273 | num_popups = 4; |
| 274 | num_panels = 0; |
| 275 | } |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 276 | #else |
| 277 | int num_popups = 2; |
| 278 | int num_panels = 2; |
| 279 | #endif |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 280 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 281 | |
| 282 | // Setup listeners to wait on strings we expect the extension pages to send. |
| 283 | std::vector<std::string> test_strings; |
| 284 | test_strings.push_back("content_tab"); |
| 285 | if (num_panels) |
| 286 | test_strings.push_back("content_panel"); |
| 287 | test_strings.push_back("content_popup"); |
| 288 | |
| 289 | ScopedVector<ExtensionTestMessageListener> listeners; |
| 290 | for (size_t i = 0; i < test_strings.size(); ++i) { |
| 291 | listeners.push_back( |
| 292 | new ExtensionTestMessageListener(test_strings[i], false)); |
| 293 | } |
| 294 | |
| 295 | const extensions::Extension* extension = LoadExtension( |
| 296 | test_data_dir_.AppendASCII("window_open").AppendASCII( |
| 297 | "close_panels_on_uninstall")); |
| 298 | ASSERT_TRUE(extension); |
| 299 | |
| 300 | // Two tabs. One in extension domain and one in non-extension domain. |
| 301 | // Two popups - one in extension domain and one in non-extension domain. |
| 302 | // Two panels - one in extension domain and one in non-extension domain. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 303 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels)); |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 304 | |
| 305 | // Wait on test messages to make sure the pages loaded. |
| 306 | for (size_t i = 0; i < listeners.size(); ++i) |
| 307 | ASSERT_TRUE(listeners[i]->WaitUntilSatisfied()); |
| 308 | |
| 309 | UninstallExtension(extension->id()); |
| 310 | |
| 311 | // Wait for the tabs and popups in non-extension domain to stay open. |
| 312 | // Expect everything else, including panels, to close. |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 313 | num_popups -= 1; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 314 | #if defined(USE_ASH_PANELS) |
| 315 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) { |
| 316 | // On Ash, new panel windows open as popup windows instead, so there are 2 |
| 317 | // extension domain popups that will close (instead of 1 popup on non-Ash). |
| 318 | num_popups -= 1; |
| 319 | } |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 320 | #endif |
[email protected] | 9111fff | 2013-06-12 18:01:55 | [diff] [blame] | 321 | #if defined(USE_ASH) |
| 322 | #if !defined(OS_WIN) |
| 323 | // On linux ash we close all popup applications when closing its extension. |
| 324 | num_popups = 0; |
| 325 | #endif |
| 326 | #endif |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 327 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0)); |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | 4ad85f4 | 2013-07-24 02:31:57 | [diff] [blame] | 330 | // This test isn't applicable on Chrome OS, which automatically reloads |
| 331 | // crashed pages. |
| 332 | #if !defined(OS_CHROMEOS) |
| 333 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) { |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 334 | #if defined(USE_ASH_PANELS) |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 335 | // On Ash, new panel windows open as popup windows instead. |
| 336 | int num_popups = 4; |
| 337 | int num_panels = 0; |
| 338 | #else |
| 339 | int num_popups = 2; |
| 340 | int num_panels = 2; |
| 341 | #endif |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 342 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 343 | |
| 344 | // Setup listeners to wait on strings we expect the extension pages to send. |
| 345 | std::vector<std::string> test_strings; |
| 346 | test_strings.push_back("content_tab"); |
| 347 | if (num_panels) |
| 348 | test_strings.push_back("content_panel"); |
| 349 | test_strings.push_back("content_popup"); |
| 350 | |
| 351 | ScopedVector<ExtensionTestMessageListener> listeners; |
| 352 | for (size_t i = 0; i < test_strings.size(); ++i) { |
| 353 | listeners.push_back( |
| 354 | new ExtensionTestMessageListener(test_strings[i], false)); |
| 355 | } |
| 356 | |
| 357 | const extensions::Extension* extension = LoadExtension( |
| 358 | test_data_dir_.AppendASCII("window_open").AppendASCII( |
| 359 | "close_panels_on_uninstall")); |
| 360 | ASSERT_TRUE(extension); |
| 361 | |
| 362 | // Two tabs. One in extension domain and one in non-extension domain. |
| 363 | // Two popups - one in extension domain and one in non-extension domain. |
| 364 | // Two panels - one in extension domain and one in non-extension domain. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 365 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels)); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 366 | |
| 367 | // Wait on test messages to make sure the pages loaded. |
| 368 | for (size_t i = 0; i < listeners.size(); ++i) |
| 369 | ASSERT_TRUE(listeners[i]->WaitUntilSatisfied()); |
| 370 | |
| 371 | // Crash the extension. |
| 372 | extensions::ExtensionHost* extension_host = |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 373 | extensions::ExtensionSystem::Get(browser()->profile())-> |
| 374 | process_manager()->GetBackgroundHostForExtension(extension->id()); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 375 | ASSERT_TRUE(extension_host); |
| 376 | base::KillProcess(extension_host->render_process_host()->GetHandle(), |
| 377 | content::RESULT_CODE_KILLED, false); |
| 378 | WaitForExtensionCrash(extension->id()); |
| 379 | |
| 380 | // Only expect panels to close. The rest stay open to show a sad-tab. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 381 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0)); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 382 | } |
[email protected] | 4ad85f4 | 2013-07-24 02:31:57 | [diff] [blame] | 383 | #endif // !defined(OS_CHROMEOS) |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 384 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 385 | #if defined(USE_ASH_PANELS) |
| 386 | // This test is not applicable on Ash. The modified window.open behavior only |
| 387 | // applies to non-Ash panel windows. |
[email protected] | 99f4fdb9 | 2012-08-30 23:13:51 | [diff] [blame] | 388 | #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel |
| 389 | #else |
| 390 | #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel |
| 391 | #endif |
| 392 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 393 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 6798c33 | 2012-08-29 02:16:51 | [diff] [blame] | 394 | |
[email protected] | 99f4fdb9 | 2012-08-30 23:13:51 | [diff] [blame] | 395 | // Load the extension that will open a panel which then calls window.open. |
[email protected] | 6798c33 | 2012-08-29 02:16:51 | [diff] [blame] | 396 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open"). |
| 397 | AppendASCII("panel_window_open"))); |
[email protected] | 99f4fdb9 | 2012-08-30 23:13:51 | [diff] [blame] | 398 | |
| 399 | // Expect one panel (opened by extension) and one tab (from the panel calling |
| 400 | // window.open). Panels modify the WindowOpenDisposition in window.open |
| 401 | // to always open in a tab. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 402 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1)); |
[email protected] | 6798c33 | 2012-08-29 02:16:51 | [diff] [blame] | 403 | } |
| 404 | |
[email protected] | 24c6bcfc | 2012-02-29 21:06:36 | [diff] [blame] | 405 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) { |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 406 | ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; |
| 407 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 408 | |
[email protected] | fa7c160 | 2013-04-03 23:00:20 | [diff] [blame] | 409 | #if defined(OS_MACOSX) |
| 410 | // Extension popup windows are incorrectly sized on OSX, crbug.com/225601 |
| 411 | #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized |
| 412 | #else |
| 413 | #define MAYBE_WindowOpenSized WindowOpenSized |
| 414 | #endif |
| 415 | // Ensure that the width and height properties of a window opened with |
| 416 | // chrome.windows.create match the creation parameters. See crbug.com/173831. |
| 417 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) { |
| 418 | ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_; |
| 419 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0)); |
| 420 | } |
| 421 | |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 422 | // Tests that an extension page can call window.open to an extension URL and |
| 423 | // the new window has extension privileges. |
| 424 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 425 | ASSERT_TRUE(LoadExtension( |
| 426 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 427 | |
| 428 | GURL start_url(std::string("chrome-extension://") + |
| 429 | last_loaded_extension_id_ + "/test.html"); |
| 430 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | f3e73f6 | 2012-10-20 05:35:16 | [diff] [blame] | 431 | WebContents* newtab = NULL; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 432 | ASSERT_NO_FATAL_FAILURE( |
| 433 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 434 | start_url.Resolve("newtab.html"), true, &newtab)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 435 | |
| 436 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 437 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 438 | &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 439 | EXPECT_TRUE(result); |
| 440 | } |
| 441 | |
| 442 | // Tests that if an extension page calls window.open to an invalid extension |
| 443 | // URL, the browser doesn't crash. |
| 444 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 445 | ASSERT_TRUE(LoadExtension( |
| 446 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 447 | |
| 448 | GURL start_url(std::string("chrome-extension://") + |
| 449 | last_loaded_extension_id_ + "/test.html"); |
| 450 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 451 | ASSERT_NO_FATAL_FAILURE( |
| 452 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 453 | GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 454 | false, NULL)); |
| 455 | |
| 456 | // If we got to this point, we didn't crash, so we're good. |
| 457 | } |
| 458 | |
| 459 | // Tests that calling window.open from the newtab page to an extension URL |
| 460 | // gives the new window extension privileges - even though the opening page |
| 461 | // does not have extension privileges, we break the script connection, so |
| 462 | // there is no privilege leak. |
| 463 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 464 | ASSERT_TRUE(LoadExtension( |
| 465 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 466 | |
| 467 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
[email protected] | f3e73f6 | 2012-10-20 05:35:16 | [diff] [blame] | 468 | WebContents* newtab = NULL; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 469 | ASSERT_NO_FATAL_FAILURE( |
| 470 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 471 | GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 472 | "/newtab.html"), false, &newtab)); |
| 473 | |
| 474 | // Extension API should succeed. |
| 475 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 476 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 477 | &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 478 | EXPECT_TRUE(result); |
| 479 | } |