[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] | 58b349b | 2011-11-23 02:07:15 | [diff] [blame] | 7 | #include "base/stringprintf.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 10 | #include "chrome/browser/ui/browser.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 11 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 14 | #include "chrome/common/chrome_switches.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 15 | #include "chrome/common/extensions/extension.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 16 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 17 | #include "content/public/browser/web_contents.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 18 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 58b349b | 2011-11-23 02:07:15 | [diff] [blame] | 19 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 20 | #include "net/base/mock_host_resolver.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 21 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 22 | using content::OpenURLParams; |
| 23 | using content::Referrer; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 24 | using content::WebContents; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 25 | |
[email protected] | e78eb29 | 2010-12-22 08:35:39 | [diff] [blame] | 26 | // Disabled, http://crbug.com/64899. |
| 27 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 28 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 29 | switches::kEnableExperimentalExtensionApis); |
| 30 | |
| 31 | ResultCatcher catcher; |
| 32 | ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 33 | .AppendASCII("window_open").AppendASCII("spanning"))); |
| 34 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 35 | } |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 36 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 37 | void WaitForTabsAndPopups(Browser* browser, |
| 38 | int num_tabs, |
| 39 | int num_popups, |
| 40 | int num_panels) { |
[email protected] | 58b349b | 2011-11-23 02:07:15 | [diff] [blame] | 41 | SCOPED_TRACE( |
| 42 | StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d", |
| 43 | num_tabs, num_popups, num_panels)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 44 | // We start with one tab and one browser already open. |
| 45 | ++num_tabs; |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 46 | size_t num_browsers = static_cast<size_t>(num_popups + num_panels) + 1; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 47 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 48 | const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(15); |
| 49 | base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; |
| 50 | while (base::TimeTicks::Now() < end_time) { |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 51 | if (browser::GetBrowserCount(browser->profile()) == num_browsers && |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 52 | browser->tab_count() == num_tabs) |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 53 | break; |
| 54 | |
[email protected] | b8deecd | 2012-07-30 21:09:44 | [diff] [blame^] | 55 | content::RunAllPendingInMessageLoop(); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 58 | EXPECT_EQ(num_browsers, browser::GetBrowserCount(browser->profile())); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 59 | EXPECT_EQ(num_tabs, browser->tab_count()); |
| 60 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 61 | int num_popups_seen = 0; |
| 62 | int num_panels_seen = 0; |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 63 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 64 | iter != BrowserList::end(); ++iter) { |
| 65 | if (*iter == browser) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 66 | continue; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 67 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 68 | // Check for TYPE_POPUP or TYPE_PANEL. |
| 69 | EXPECT_TRUE((*iter)->is_type_popup() || (*iter)->is_type_panel()); |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 70 | if ((*iter)->is_type_popup()) |
| 71 | ++num_popups_seen; |
| 72 | else |
| 73 | ++num_panels_seen; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 74 | } |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 75 | EXPECT_EQ(num_popups, num_popups_seen); |
| 76 | EXPECT_EQ(num_panels, num_panels_seen); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 79 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 80 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 81 | ASSERT_TRUE(StartTestServer()); |
| 82 | ASSERT_TRUE(LoadExtension( |
| 83 | test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 84 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 85 | WaitForTabsAndPopups(browser(), 0, 2, 0); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 86 | |
| 87 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 88 | iter != BrowserList::end(); ++iter) { |
| 89 | if (*iter == browser()) |
| 90 | ASSERT_FALSE((*iter)->is_app()); |
| 91 | else |
| 92 | ASSERT_TRUE((*iter)->is_app()); |
| 93 | } |
| 94 | } |
| 95 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 96 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { |
| 97 | ASSERT_TRUE(StartTestServer()); |
| 98 | ASSERT_TRUE(LoadExtension( |
| 99 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 100 | |
| 101 | const int num_tabs = 1; |
| 102 | const int num_popups = 0; |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 103 | WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { |
| 107 | ASSERT_TRUE(StartTestServer()); |
| 108 | ASSERT_TRUE(LoadExtension( |
| 109 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); |
| 110 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 111 | // On other systems this should open a new popup window. |
| 112 | const int num_tabs = 0; |
| 113 | const int num_popups = 1; |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 114 | WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { |
| 118 | ASSERT_TRUE(StartTestServer()); |
| 119 | ASSERT_TRUE(LoadExtension( |
| 120 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); |
| 121 | |
| 122 | // On ChromeOS this should open a new panel (acts like a new popup window). |
| 123 | // On other systems this should open a new popup window. |
| 124 | const int num_tabs = 0; |
| 125 | const int num_popups = 1; |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 126 | WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 127 | } |
| 128 | |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 129 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) { |
| 130 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | e18a19b | 2010-10-19 20:32:30 | [diff] [blame] | 131 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 132 | |
| 133 | ASSERT_TRUE(LoadExtension( |
| 134 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 135 | .AppendASCII("extension"))); |
| 136 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 137 | WaitForTabsAndPopups(browser(), 5, 3, 0); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { |
| 141 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 142 | ASSERT_TRUE(test_server()->Start()); |
| 143 | |
| 144 | ASSERT_TRUE(LoadExtension( |
| 145 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 146 | .AppendASCII("hosted_app"))); |
| 147 | |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 148 | // The app being tested owns the domain a.com . The test URLs we navigate |
| 149 | // to below must be within that domain, so that they fall within the app's |
| 150 | // web extent. |
| 151 | GURL::Replacements replace_host; |
| 152 | std::string a_dot_com = "a.com"; |
| 153 | replace_host.SetHostStr(a_dot_com); |
| 154 | |
| 155 | const std::string popup_app_contents_path( |
| 156 | "files/extensions/api_test/window_open/popup_blocking/hosted_app/"); |
| 157 | |
| 158 | GURL open_tab = |
| 159 | test_server()->GetURL(popup_app_contents_path + "open_tab.html") |
| 160 | .ReplaceComponents(replace_host); |
| 161 | GURL open_popup = |
| 162 | test_server()->GetURL(popup_app_contents_path + "open_popup.html") |
| 163 | .ReplaceComponents(replace_host); |
| 164 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 165 | browser()->OpenURL(OpenURLParams( |
| 166 | open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, |
| 167 | false)); |
| 168 | browser()->OpenURL(OpenURLParams( |
| 169 | open_popup, Referrer(), NEW_FOREGROUND_TAB, |
| 170 | content::PAGE_TRANSITION_TYPED, false)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 171 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 172 | WaitForTabsAndPopups(browser(), 3, 1, 0); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 173 | } |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 174 | |
[email protected] | e7f9056 | 2011-05-23 21:38:24 | [diff] [blame] | 175 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) { |
| 176 | ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; |
| 177 | } |
| 178 | |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 179 | class WindowOpenPanelDisabledTest : public ExtensionApiTest { |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 180 | virtual void SetUpCommandLine(CommandLine* command_line) { |
| 181 | ExtensionApiTest::SetUpCommandLine(command_line); |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 182 | // TODO(jennb): Re-enable when panels are enabled by default. |
| 183 | // command_line->AppendSwitch(switches::kDisablePanels); |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 184 | } |
| 185 | }; |
| 186 | |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 187 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest, |
| 188 | DISABLED_WindowOpenPanelNotEnabled) { |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 189 | ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_; |
| 190 | } |
| 191 | |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 192 | class WindowOpenPanelTest : public ExtensionApiTest { |
| 193 | virtual void SetUpCommandLine(CommandLine* command_line) { |
| 194 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 195 | command_line->AppendSwitch(switches::kEnablePanels); |
| 196 | } |
| 197 | }; |
| 198 | |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 199 | #if defined(USE_ASH) |
| 200 | // On Ash, this currently fails because we're currently opening new panel |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 201 | // windows as popup windows instead. |
| 202 | #define MAYBE_WindowOpenPanel FAILS_WindowOpenPanel |
| 203 | #else |
| 204 | #define MAYBE_WindowOpenPanel WindowOpenPanel |
| 205 | #endif |
| 206 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) { |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 207 | ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_; |
| 208 | } |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 209 | |
[email protected] | 4ff65f1 | 2011-10-06 00:35:54 | [diff] [blame] | 210 | #if defined(OS_MACOSX) || defined(OS_WIN) |
| 211 | // Focus test fails if there is no window manager on Linux. |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 212 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, WindowOpenFocus) { |
[email protected] | 4ff65f1 | 2011-10-06 00:35:54 | [diff] [blame] | 213 | ASSERT_TRUE(RunExtensionTest("window_open/focus")) << message_; |
| 214 | } |
| 215 | #endif |
| 216 | |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 217 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 218 | CloseNonExtensionPanelsOnUninstall) { |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 219 | #if defined(USE_ASH) |
| 220 | int num_popups = 4; |
| 221 | int num_panels = 0; |
| 222 | #else |
| 223 | int num_popups = 2; |
| 224 | int num_panels = 2; |
| 225 | #endif |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 226 | ASSERT_TRUE(StartTestServer()); |
| 227 | |
| 228 | // Setup listeners to wait on strings we expect the extension pages to send. |
| 229 | std::vector<std::string> test_strings; |
| 230 | test_strings.push_back("content_tab"); |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 231 | if (num_panels) |
| 232 | test_strings.push_back("content_panel"); |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 233 | test_strings.push_back("content_popup"); |
| 234 | |
| 235 | ScopedVector<ExtensionTestMessageListener> listeners; |
| 236 | for (size_t i = 0; i < test_strings.size(); ++i) { |
| 237 | listeners.push_back( |
| 238 | new ExtensionTestMessageListener(test_strings[i], false)); |
| 239 | } |
| 240 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 241 | const extensions::Extension* extension = LoadExtension( |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 242 | test_data_dir_.AppendASCII("window_open").AppendASCII( |
| 243 | "close_panels_on_uninstall")); |
| 244 | ASSERT_TRUE(extension); |
| 245 | |
| 246 | // Two tabs. One in extension domain and one in non-extension domain. |
| 247 | // Two popups - one in extension domain and one in non-extension domain. |
| 248 | // Two panels - one in extension domain and one in non-extension domain. |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 249 | WaitForTabsAndPopups(browser(), 2, num_popups, num_panels); |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 250 | |
| 251 | // Wait on test messages to make sure the pages loaded. |
| 252 | for (size_t i = 0; i < listeners.size(); ++i) |
| 253 | ASSERT_TRUE(listeners[i]->WaitUntilSatisfied()); |
| 254 | |
| 255 | UninstallExtension(extension->id()); |
| 256 | |
| 257 | // Wait for one tab and one popup in non-extension domain to stay open. |
| 258 | // Expect everything else, including panels, to close. |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 259 | #if defined(USE_ASH) |
| 260 | // In Ash and additional popup remains for the "panel" non-extension domain. |
| 261 | num_popups = 2; |
| 262 | #else |
| 263 | num_popups = 1; |
| 264 | #endif |
| 265 | WaitForTabsAndPopups(browser(), 1, num_popups, 0); |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 266 | } |
| 267 | |
[email protected] | 24c6bcfc | 2012-02-29 21:06:36 | [diff] [blame] | 268 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) { |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 269 | ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; |
| 270 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 271 | |
| 272 | // Tests that an extension page can call window.open to an extension URL and |
| 273 | // the new window has extension privileges. |
| 274 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 275 | ASSERT_TRUE(LoadExtension( |
| 276 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 277 | |
| 278 | GURL start_url(std::string("chrome-extension://") + |
| 279 | last_loaded_extension_id_ + "/test.html"); |
| 280 | ui_test_utils::NavigateToURL(browser(), start_url); |
| 281 | WebContents* newtab; |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 282 | ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 283 | start_url.Resolve("newtab.html"), true, &newtab)); |
| 284 | |
| 285 | bool result = false; |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 286 | ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 287 | newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
| 288 | EXPECT_TRUE(result); |
| 289 | } |
| 290 | |
| 291 | // Tests that if an extension page calls window.open to an invalid extension |
| 292 | // URL, the browser doesn't crash. |
| 293 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 294 | ASSERT_TRUE(LoadExtension( |
| 295 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 296 | |
| 297 | GURL start_url(std::string("chrome-extension://") + |
| 298 | last_loaded_extension_id_ + "/test.html"); |
| 299 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 300 | ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 301 | GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 302 | false, NULL)); |
| 303 | |
| 304 | // If we got to this point, we didn't crash, so we're good. |
| 305 | } |
| 306 | |
| 307 | // Tests that calling window.open from the newtab page to an extension URL |
| 308 | // gives the new window extension privileges - even though the opening page |
| 309 | // does not have extension privileges, we break the script connection, so |
| 310 | // there is no privilege leak. |
| 311 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 312 | ASSERT_TRUE(LoadExtension( |
| 313 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 314 | |
| 315 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 316 | WebContents* newtab; |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 317 | ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 318 | GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 319 | "/newtab.html"), false, &newtab)); |
| 320 | |
| 321 | // Extension API should succeed. |
| 322 | bool result = false; |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 323 | ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 324 | newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
| 325 | EXPECT_TRUE(result); |
| 326 | } |