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