[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 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 7 | #include "base/memory/scoped_vector.h" |
[email protected] | 7c6ef35 | 2013-09-26 07:23:14 | [diff] [blame] | 8 | #include "base/path_service.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | 01996a59 | 2013-09-13 06:55:04 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser_finder.h" |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 16 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 7c6ef35 | 2013-09-26 07:23:14 | [diff] [blame] | 17 | #include "chrome/common/chrome_paths.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 18 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 19 | #include "content/public/browser/render_process_host.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 20 | #include "content/public/browser/web_contents.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 21 | #include "content/public/common/result_codes.h" |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 22 | #include "content/public/common/url_constants.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 23 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 24 | #include "extensions/browser/extension_host.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 25 | #include "extensions/browser/process_manager.h" |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 26 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 27 | #include "extensions/common/extension.h" |
lfg | 910f2f9 | 2014-09-19 05:31:09 | [diff] [blame] | 28 | #include "extensions/test/extension_test_message_listener.h" |
yoz | e8dc2f1 | 2014-09-09 23:16:32 | [diff] [blame] | 29 | #include "extensions/test/result_catcher.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 30 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 7c6ef35 | 2013-09-26 07:23:14 | [diff] [blame] | 31 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 32 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 33 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 34 | #if defined(USE_ASH) |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 35 | #include "extensions/browser/app_window/app_window_registry.h" |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 36 | #endif |
| 37 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 38 | using content::OpenURLParams; |
| 39 | using content::Referrer; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 40 | using content::WebContents; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 41 | |
rob | f8cd8ce | 2015-02-21 12:18:04 | [diff] [blame] | 42 | // The test uses the chrome.browserAction.openPopup API, which requires that the |
| 43 | // window can automatically be activated. |
| 44 | // See comments at BrowserActionInteractiveTest::ShouldRunPopupTest |
johnme | 7e30b51 | 2015-04-16 14:57:35 | [diff] [blame] | 45 | // Fails flakily on all platforms. https://crbug.com/477691 |
| 46 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { |
yoz | e8dc2f1 | 2014-09-09 23:16:32 | [diff] [blame] | 47 | extensions::ResultCatcher catcher; |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 48 | ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 49 | .AppendASCII("window_open").AppendASCII("spanning"))); |
| 50 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 51 | } |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 52 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 53 | bool WaitForTabsAndPopups(Browser* browser, |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 54 | int num_tabs, |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 55 | int num_popups) { |
[email protected] | 58b349b | 2011-11-23 02:07:15 | [diff] [blame] | 56 | SCOPED_TRACE( |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 57 | base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d", |
| 58 | num_tabs, num_popups)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 59 | // We start with one tab and one browser already open. |
| 60 | ++num_tabs; |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 61 | size_t num_browsers = static_cast<size_t>(num_popups) + 1; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 62 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 63 | const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 64 | base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; |
| 65 | while (base::TimeTicks::Now() < end_time) { |
scottmg | 34c5dd88 | 2016-02-03 05:21:54 | [diff] [blame] | 66 | if (chrome::GetBrowserCount(browser->profile()) == num_browsers && |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 67 | browser->tab_strip_model()->count() == num_tabs) |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 68 | break; |
| 69 | |
[email protected] | b8deecd | 2012-07-30 21:09:44 | [diff] [blame] | 70 | content::RunAllPendingInMessageLoop(); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 71 | } |
| 72 | |
scottmg | 34c5dd88 | 2016-02-03 05:21:54 | [diff] [blame] | 73 | EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile())); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 74 | EXPECT_EQ(num_tabs, browser->tab_strip_model()->count()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 75 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 76 | int num_popups_seen = 0; |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 77 | for (auto* b : *BrowserList::GetInstance()) { |
| 78 | if (b == browser) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 79 | continue; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 80 | |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 81 | EXPECT_TRUE(b->is_type_popup()); |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 82 | ++num_popups_seen; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 83 | } |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 84 | EXPECT_EQ(num_popups, num_popups_seen); |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 85 | |
scottmg | 34c5dd88 | 2016-02-03 05:21:54 | [diff] [blame] | 86 | return ((num_browsers == chrome::GetBrowserCount(browser->profile())) && |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 87 | (num_tabs == browser->tab_strip_model()->count()) && |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 88 | (num_popups == num_popups_seen)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 91 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 92 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 93 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 94 | ASSERT_TRUE(LoadExtension( |
| 95 | test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 96 | |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 97 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2)); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 98 | |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 99 | for (auto* b : *BrowserList::GetInstance()) { |
| 100 | if (b == browser()) |
| 101 | ASSERT_FALSE(b->is_app()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 102 | else |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 103 | ASSERT_TRUE(b->is_app()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 107 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 108 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 109 | ASSERT_TRUE(LoadExtension( |
| 110 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 111 | |
| 112 | const int num_tabs = 1; |
| 113 | const int num_popups = 0; |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 114 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 115 | } |
| 116 | |
[email protected] | 7c6ef35 | 2013-09-26 07:23:14 | [diff] [blame] | 117 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) { |
| 118 | ASSERT_TRUE(StartEmbeddedTestServer()); |
| 119 | base::FilePath test_data_dir; |
| 120 | PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 121 | embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 122 | ASSERT_TRUE(LoadExtension( |
| 123 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe"))); |
| 124 | |
jochen | c5cfa64 | 2014-09-02 15:30:03 | [diff] [blame] | 125 | const int num_tabs = 1; |
| 126 | const int num_popups = 0; |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 127 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
[email protected] | 7c6ef35 | 2013-09-26 07:23:14 | [diff] [blame] | 128 | } |
| 129 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 130 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 131 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 132 | ASSERT_TRUE(LoadExtension( |
| 133 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); |
| 134 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 135 | // On other systems this should open a new popup window. |
| 136 | const int num_tabs = 0; |
| 137 | const int num_popups = 1; |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 138 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 142 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 143 | ASSERT_TRUE(LoadExtension( |
| 144 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); |
| 145 | |
| 146 | // On ChromeOS this should open a new panel (acts like a new popup window). |
| 147 | // On other systems this should open a new popup window. |
| 148 | const int num_tabs = 0; |
| 149 | const int num_popups = 1; |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 150 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | 73fa1fce | 2013-02-21 20:10:05 | [diff] [blame] | 153 | // Disabled on Windows. Often times out or fails: crbug.com/177530 |
| 154 | #if defined(OS_WIN) |
| 155 | #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension |
| 156 | #else |
| 157 | #define MAYBE_PopupBlockingExtension PopupBlockingExtension |
| 158 | #endif |
| 159 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 160 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 161 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 162 | |
| 163 | ASSERT_TRUE(LoadExtension( |
| 164 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 165 | .AppendASCII("extension"))); |
| 166 | |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 167 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { |
| 171 | host_resolver()->AddRule("*", "127.0.0.1"); |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 172 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 173 | |
| 174 | ASSERT_TRUE(LoadExtension( |
| 175 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 176 | .AppendASCII("hosted_app"))); |
| 177 | |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 178 | // The app being tested owns the domain a.com . The test URLs we navigate |
| 179 | // to below must be within that domain, so that they fall within the app's |
| 180 | // web extent. |
| 181 | GURL::Replacements replace_host; |
mgiuca | 77752c3 | 2015-02-05 07:31:18 | [diff] [blame] | 182 | replace_host.SetHostStr("a.com"); |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 183 | |
| 184 | const std::string popup_app_contents_path( |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 185 | "/extensions/api_test/window_open/popup_blocking/hosted_app/"); |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 186 | |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 187 | GURL open_tab = embedded_test_server() |
| 188 | ->GetURL(popup_app_contents_path + "open_tab.html") |
| 189 | .ReplaceComponents(replace_host); |
| 190 | GURL open_popup = embedded_test_server() |
| 191 | ->GetURL(popup_app_contents_path + "open_popup.html") |
| 192 | .ReplaceComponents(replace_host); |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 193 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 194 | browser()->OpenURL(OpenURLParams( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 195 | open_tab, Referrer(), NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 196 | false)); |
| 197 | browser()->OpenURL(OpenURLParams( |
| 198 | open_popup, Referrer(), NEW_FOREGROUND_TAB, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 199 | ui::PAGE_TRANSITION_TYPED, false)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 200 | |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 201 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 202 | } |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 203 | |
[email protected] | e7f9056 | 2011-05-23 21:38:24 | [diff] [blame] | 204 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) { |
| 205 | ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; |
| 206 | } |
| 207 | |
[email protected] | 24c6bcfc | 2012-02-29 21:06:36 | [diff] [blame] | 208 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) { |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 209 | ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; |
| 210 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 211 | |
[email protected] | fa7c160 | 2013-04-03 23:00:20 | [diff] [blame] | 212 | #if defined(OS_MACOSX) |
| 213 | // Extension popup windows are incorrectly sized on OSX, crbug.com/225601 |
| 214 | #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized |
| 215 | #else |
| 216 | #define MAYBE_WindowOpenSized WindowOpenSized |
| 217 | #endif |
| 218 | // Ensure that the width and height properties of a window opened with |
| 219 | // chrome.windows.create match the creation parameters. See crbug.com/173831. |
| 220 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) { |
| 221 | ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_; |
dimich | 566d364 | 2016-08-23 16:39:06 | [diff] [blame^] | 222 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1)); |
[email protected] | fa7c160 | 2013-04-03 23:00:20 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 225 | // Tests that an extension page can call window.open to an extension URL and |
| 226 | // the new window has extension privileges. |
| 227 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 228 | ASSERT_TRUE(LoadExtension( |
| 229 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 230 | |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 231 | GURL start_url(std::string(extensions::kExtensionScheme) + |
[email protected] | fb4fe095 | 2014-06-05 09:44:24 | [diff] [blame] | 232 | url::kStandardSchemeSeparator + |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 233 | last_loaded_extension_id() + "/test.html"); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 234 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | f3e73f6 | 2012-10-20 05:35:16 | [diff] [blame] | 235 | WebContents* newtab = NULL; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 236 | ASSERT_NO_FATAL_FAILURE( |
| 237 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 238 | start_url.Resolve("newtab.html"), true, &newtab)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 239 | |
| 240 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 241 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 242 | &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 243 | EXPECT_TRUE(result); |
| 244 | } |
| 245 | |
| 246 | // Tests that if an extension page calls window.open to an invalid extension |
| 247 | // URL, the browser doesn't crash. |
| 248 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 249 | ASSERT_TRUE(LoadExtension( |
| 250 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 251 | |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 252 | GURL start_url(std::string(extensions::kExtensionScheme) + |
[email protected] | fb4fe095 | 2014-06-05 09:44:24 | [diff] [blame] | 253 | url::kStandardSchemeSeparator + |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 254 | last_loaded_extension_id() + "/test.html"); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 255 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 256 | ASSERT_NO_FATAL_FAILURE( |
| 257 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 258 | GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 259 | false, NULL)); |
| 260 | |
| 261 | // If we got to this point, we didn't crash, so we're good. |
| 262 | } |
| 263 | |
| 264 | // Tests that calling window.open from the newtab page to an extension URL |
| 265 | // gives the new window extension privileges - even though the opening page |
| 266 | // does not have extension privileges, we break the script connection, so |
| 267 | // there is no privilege leak. |
| 268 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 269 | ASSERT_TRUE(LoadExtension( |
| 270 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 271 | |
| 272 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
[email protected] | f3e73f6 | 2012-10-20 05:35:16 | [diff] [blame] | 273 | WebContents* newtab = NULL; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 274 | ASSERT_NO_FATAL_FAILURE( |
| 275 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 276 | GURL(std::string(extensions::kExtensionScheme) + |
[email protected] | fb4fe095 | 2014-06-05 09:44:24 | [diff] [blame] | 277 | url::kStandardSchemeSeparator + |
[email protected] | 99bee64 | 2014-05-31 22:36:43 | [diff] [blame] | 278 | last_loaded_extension_id() + "/newtab.html"), |
| 279 | false, |
| 280 | &newtab)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 281 | |
| 282 | // Extension API should succeed. |
| 283 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 284 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 285 | &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 286 | EXPECT_TRUE(result); |
| 287 | } |