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