blob: 249386fa768f3d7597469b6c7c996a95c4d17f45 [file] [log] [blame]
[email protected]35abc332012-02-24 23:48:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]32b7c492010-09-01 04:15:002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avia2f4804a2015-12-24 23:11:135#include <stddef.h>
6
[email protected]7c6ef352013-09-26 07:23:147#include "base/path_service.h"
[email protected]46acbf12013-06-10 18:43:428#include "base/strings/stringprintf.h"
alexmos1c3da4f2016-11-03 06:06:119#include "base/test/histogram_tester.h"
avia2f4804a2015-12-24 23:11:1310#include "build/build_config.h"
[email protected]32b7c492010-09-01 04:15:0011#include "chrome/browser/extensions/extension_apitest.h"
[email protected]01996a592013-09-13 06:55:0412#include "chrome/browser/profiles/profile.h"
[email protected]2ad4a902010-11-17 06:05:1313#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4314#include "chrome/browser/ui/browser_finder.h"
scottmg8abbff832016-01-28 22:57:3715#include "chrome/browser/ui/browser_list.h"
[email protected]e0448872013-01-11 19:35:0216#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]7c6ef352013-09-26 07:23:1417#include "chrome/common/chrome_paths.h"
alexmoscf5145bb2016-11-09 23:19:4518#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3219#include "chrome/test/base/ui_test_utils.h"
alexmos1c3da4f2016-11-03 06:06:1120#include "content/public/browser/notification_service.h"
21#include "content/public/browser/notification_types.h"
22#include "content/public/browser/render_frame_host.h"
[email protected]1dd66b72012-09-19 20:41:4823#include "content/public/browser/render_process_host.h"
[email protected]fad73672012-06-15 23:26:0624#include "content/public/browser/web_contents.h"
[email protected]1dd66b72012-09-19 20:41:4825#include "content/public/common/result_codes.h"
[email protected]99bee642014-05-31 22:36:4326#include "content/public/common/url_constants.h"
[email protected]7d478cb2012-07-24 17:19:4227#include "content/public/test/browser_test_utils.h"
alexmoscf5145bb2016-11-09 23:19:4528#include "content/public/test/test_navigation_observer.h"
[email protected]22401dc2014-03-21 01:38:5729#include "extensions/browser/extension_host.h"
[email protected]98b6d942013-11-10 00:34:0730#include "extensions/browser/process_manager.h"
[email protected]99bee642014-05-31 22:36:4331#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4132#include "extensions/common/extension.h"
lfg910f2f92014-09-19 05:31:0933#include "extensions/test/extension_test_message_listener.h"
yoze8dc2f12014-09-09 23:16:3234#include "extensions/test/result_catcher.h"
[email protected]f2cb3cf2013-03-21 01:40:5335#include "net/dns/mock_host_resolver.h"
[email protected]7c6ef352013-09-26 07:23:1436#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]bc44f4142013-02-12 06:15:5637#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0038
[email protected]f1c102b2013-02-15 07:44:1239#if defined(USE_ASH)
hashimotoad3c6872014-08-29 09:46:5740#include "extensions/browser/app_window/app_window_registry.h"
[email protected]f1c102b2013-02-15 07:44:1241#endif
42
[email protected]e5d549d2011-12-28 01:29:2043using content::OpenURLParams;
44using content::Referrer;
[email protected]fad73672012-06-15 23:26:0645using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2046
jam1a5b5582017-05-01 16:50:1047class WindowOpenApiTest : public ExtensionApiTest {
48 void SetUpOnMainThread() override {
49 ExtensionApiTest::SetUpOnMainThread();
50 host_resolver()->AddRule("*", "127.0.0.1");
51 }
52};
53
robf8cd8ce2015-02-21 12:18:0454// The test uses the chrome.browserAction.openPopup API, which requires that the
55// window can automatically be activated.
56// See comments at BrowserActionInteractiveTest::ShouldRunPopupTest
johnme7e30b512015-04-16 14:57:3557// Fails flakily on all platforms. https://crbug.com/477691
jam1a5b5582017-05-01 16:50:1058IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, DISABLED_WindowOpen) {
yoze8dc2f12014-09-09 23:16:3259 extensions::ResultCatcher catcher;
[email protected]32b7c492010-09-01 04:15:0060 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
61 .AppendASCII("window_open").AppendASCII("spanning")));
62 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
63}
[email protected]4026ce1e2010-09-14 19:35:0464
[email protected]f1c102b2013-02-15 07:44:1265bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4566 int num_tabs,
dimich566d3642016-08-23 16:39:0667 int num_popups) {
[email protected]58b349b2011-11-23 02:07:1568 SCOPED_TRACE(
dimich566d3642016-08-23 16:39:0669 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d",
70 num_tabs, num_popups));
[email protected]4026ce1e2010-09-14 19:35:0471 // We start with one tab and one browser already open.
72 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0873 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0474
[email protected]f1c102b2013-02-15 07:44:1275 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4976 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
77 while (base::TimeTicks::Now() < end_time) {
scottmg34c5dd882016-02-03 05:21:5478 if (chrome::GetBrowserCount(browser->profile()) == num_browsers &&
dimich566d3642016-08-23 16:39:0679 browser->tab_strip_model()->count() == num_tabs)
[email protected]0a5bdc6522011-06-08 19:04:4980 break;
81
[email protected]b8deecd2012-07-30 21:09:4482 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4983 }
84
scottmg34c5dd882016-02-03 05:21:5485 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile()));
[email protected]e0448872013-01-11 19:35:0286 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]0a5bdc6522011-06-08 19:04:4987
[email protected]f9e82d92011-10-29 00:50:4588 int num_popups_seen = 0;
scottmg8abbff832016-01-28 22:57:3789 for (auto* b : *BrowserList::GetInstance()) {
90 if (b == browser)
[email protected]4026ce1e2010-09-14 19:35:0491 continue;
[email protected]4026ce1e2010-09-14 19:35:0492
scottmg8abbff832016-01-28 22:57:3793 EXPECT_TRUE(b->is_type_popup());
[email protected]f6ffa7d2012-08-17 17:27:0894 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:0495 }
[email protected]f9e82d92011-10-29 00:50:4596 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:1297
scottmg34c5dd882016-02-03 05:21:5498 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) &&
[email protected]f1c102b2013-02-15 07:44:1299 (num_tabs == browser->tab_strip_model()->count()) &&
[email protected]f1c102b2013-02-15 07:44:12100 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04101}
102
jam1a5b5582017-05-01 16:50:10103IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, BrowserIsApp) {
[email protected]c1dffe82013-06-26 20:59:05104 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52105 ASSERT_TRUE(LoadExtension(
106 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
107
dimich566d3642016-08-23 16:39:06108 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2));
[email protected]f112b0f2011-05-26 01:53:52109
scottmg8abbff832016-01-28 22:57:37110 for (auto* b : *BrowserList::GetInstance()) {
111 if (b == browser())
112 ASSERT_FALSE(b->is_app());
[email protected]f112b0f2011-05-26 01:53:52113 else
scottmg8abbff832016-01-28 22:57:37114 ASSERT_TRUE(b->is_app());
[email protected]f112b0f2011-05-26 01:53:52115 }
116}
117
jam1a5b5582017-05-01 16:50:10118IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05119 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49120 ASSERT_TRUE(LoadExtension(
121 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
122
123 const int num_tabs = 1;
124 const int num_popups = 0;
dimich566d3642016-08-23 16:39:06125 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]0a5bdc6522011-06-08 19:04:49126}
127
jam1a5b5582017-05-01 16:50:10128IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupIframe) {
[email protected]7c6ef352013-09-26 07:23:14129 base::FilePath test_data_dir;
130 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
131 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
martijnf9b885b72016-11-22 22:03:47132 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]7c6ef352013-09-26 07:23:14133 ASSERT_TRUE(LoadExtension(
134 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe")));
135
jochenc5cfa642014-09-02 15:30:03136 const int num_tabs = 1;
137 const int num_popups = 0;
dimich566d3642016-08-23 16:39:06138 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]7c6ef352013-09-26 07:23:14139}
140
jam1a5b5582017-05-01 16:50:10141IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05142 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49143 ASSERT_TRUE(LoadExtension(
144 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
145
[email protected]0a5bdc6522011-06-08 19:04:49146 // On other systems this should open a new popup window.
147 const int num_tabs = 0;
148 const int num_popups = 1;
dimich566d3642016-08-23 16:39:06149 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]0a5bdc6522011-06-08 19:04:49150}
151
jam1a5b5582017-05-01 16:50:10152IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05153 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49154 ASSERT_TRUE(LoadExtension(
155 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
156
157 // On ChromeOS this should open a new panel (acts like a new popup window).
158 // On other systems this should open a new popup window.
159 const int num_tabs = 0;
160 const int num_popups = 1;
dimich566d3642016-08-23 16:39:06161 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]0a5bdc6522011-06-08 19:04:49162}
163
[email protected]73fa1fce2013-02-21 20:10:05164// Disabled on Windows. Often times out or fails: crbug.com/177530
165#if defined(OS_WIN)
166#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
167#else
168#define MAYBE_PopupBlockingExtension PopupBlockingExtension
169#endif
jam1a5b5582017-05-01 16:50:10170IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, MAYBE_PopupBlockingExtension) {
[email protected]c1dffe82013-06-26 20:59:05171 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04172
173 ASSERT_TRUE(LoadExtension(
174 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
175 .AppendASCII("extension")));
176
dimich566d3642016-08-23 16:39:06177 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3));
[email protected]4026ce1e2010-09-14 19:35:04178}
179
jam1a5b5582017-05-01 16:50:10180IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, PopupBlockingHostedApp) {
svaldeza01f7d92015-11-18 17:47:56181 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]4026ce1e2010-09-14 19:35:04182
183 ASSERT_TRUE(LoadExtension(
184 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
185 .AppendASCII("hosted_app")));
186
[email protected]fe3048872010-10-18 14:58:59187 // The app being tested owns the domain a.com . The test URLs we navigate
188 // to below must be within that domain, so that they fall within the app's
189 // web extent.
190 GURL::Replacements replace_host;
mgiuca77752c32015-02-05 07:31:18191 replace_host.SetHostStr("a.com");
[email protected]fe3048872010-10-18 14:58:59192
193 const std::string popup_app_contents_path(
svaldeza01f7d92015-11-18 17:47:56194 "/extensions/api_test/window_open/popup_blocking/hosted_app/");
[email protected]fe3048872010-10-18 14:58:59195
svaldeza01f7d92015-11-18 17:47:56196 GURL open_tab = embedded_test_server()
197 ->GetURL(popup_app_contents_path + "open_tab.html")
198 .ReplaceComponents(replace_host);
199 GURL open_popup = embedded_test_server()
200 ->GetURL(popup_app_contents_path + "open_popup.html")
201 .ReplaceComponents(replace_host);
[email protected]fe3048872010-10-18 14:58:59202
nick3b04f322016-08-31 19:29:19203 browser()->OpenURL(OpenURLParams(open_tab, Referrer(),
204 WindowOpenDisposition::NEW_FOREGROUND_TAB,
205 ui::PAGE_TRANSITION_TYPED, false));
206 browser()->OpenURL(OpenURLParams(open_popup, Referrer(),
207 WindowOpenDisposition::NEW_FOREGROUND_TAB,
208 ui::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04209
dimich566d3642016-08-23 16:39:06210 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1));
[email protected]4026ce1e2010-09-14 19:35:04211}
[email protected]d4db6c702011-03-28 21:49:14212
jam1a5b5582017-05-01 16:50:10213IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowArgumentsOverflow) {
[email protected]e7f90562011-05-23 21:38:24214 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
215}
216
jam1a5b5582017-05-01 16:50:10217IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38218 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
219}
[email protected]fad73672012-06-15 23:26:06220
[email protected]fa7c1602013-04-03 23:00:20221#if defined(OS_MACOSX)
222// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
223#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
224#else
225#define MAYBE_WindowOpenSized WindowOpenSized
226#endif
227// Ensure that the width and height properties of a window opened with
228// chrome.windows.create match the creation parameters. See crbug.com/173831.
jam1a5b5582017-05-01 16:50:10229IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, MAYBE_WindowOpenSized) {
[email protected]fa7c1602013-04-03 23:00:20230 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
dimich566d3642016-08-23 16:39:06231 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1));
[email protected]fa7c1602013-04-03 23:00:20232}
233
[email protected]fad73672012-06-15 23:26:06234// Tests that an extension page can call window.open to an extension URL and
235// the new window has extension privileges.
236IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
237 ASSERT_TRUE(LoadExtension(
238 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
239
[email protected]99bee642014-05-31 22:36:43240 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24241 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43242 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06243 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16244 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02245 ASSERT_NO_FATAL_FAILURE(
246 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
247 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06248
249 bool result = false;
[email protected]b6987e02013-01-04 18:30:43250 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
251 &result));
[email protected]fad73672012-06-15 23:26:06252 EXPECT_TRUE(result);
253}
254
255// Tests that if an extension page calls window.open to an invalid extension
256// URL, the browser doesn't crash.
257IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
258 ASSERT_TRUE(LoadExtension(
259 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
260
[email protected]99bee642014-05-31 22:36:43261 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24262 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43263 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06264 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02265 ASSERT_NO_FATAL_FAILURE(
266 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06267 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
268 false, NULL));
269
270 // If we got to this point, we didn't crash, so we're good.
271}
272
273// Tests that calling window.open from the newtab page to an extension URL
274// gives the new window extension privileges - even though the opening page
275// does not have extension privileges, we break the script connection, so
276// there is no privilege leak.
277IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
278 ASSERT_TRUE(LoadExtension(
279 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
280
281 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16282 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02283 ASSERT_NO_FATAL_FAILURE(
284 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]99bee642014-05-31 22:36:43285 GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24286 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43287 last_loaded_extension_id() + "/newtab.html"),
288 false,
289 &newtab));
[email protected]fad73672012-06-15 23:26:06290
291 // Extension API should succeed.
292 bool result = false;
[email protected]b6987e02013-01-04 18:30:43293 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
294 &result));
[email protected]fad73672012-06-15 23:26:06295 EXPECT_TRUE(result);
296}
alexmos1c3da4f2016-11-03 06:06:11297
298// Tests that calling window.open for an extension URL from a non-HTTP or HTTPS
299// URL on a new tab cannot access non-web-accessible resources.
300IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
301 WindowOpenInaccessibleResourceFromDataURL) {
302 base::HistogramTester uma;
alexmoscf5145bb2016-11-09 23:19:45303 const extensions::Extension* extension = LoadExtension(
304 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
305 ASSERT_TRUE(extension);
alexmos1c3da4f2016-11-03 06:06:11306
307 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,foo"));
308
309 // test.html is not web-accessible and should not be loaded.
alexmoscf5145bb2016-11-09 23:19:45310 GURL extension_url(extension->GetResourceURL("test.html"));
alexmos1c3da4f2016-11-03 06:06:11311 content::WindowedNotificationObserver windowed_observer(
312 content::NOTIFICATION_LOAD_STOP,
313 content::NotificationService::AllSources());
314 ASSERT_TRUE(content::ExecuteScript(
315 browser()->tab_strip_model()->GetActiveWebContents(),
316 "window.open('" + extension_url.spec() + "');"));
317 windowed_observer.Wait();
318 content::NavigationController* controller =
319 content::Source<content::NavigationController>(windowed_observer.source())
320 .ptr();
321 content::WebContents* newtab = controller->GetWebContents();
322 ASSERT_TRUE(newtab);
323
324 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL());
325 EXPECT_FALSE(newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().SchemeIs(
326 extensions::kExtensionScheme));
327
328 // Verify that the blocking was recorded correctly in UMA.
329 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
330 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */
331 1);
alexmos7f7bae62017-04-05 21:15:04332 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure.Scheme",
333 6 /* SCHEME_DATA */, 1);
alexmos1c3da4f2016-11-03 06:06:11334}
alexmoscf5145bb2016-11-09 23:19:45335
336// Test that navigating to an extension URL is allowed on chrome:// and
337// chrome-search:// pages, even for URLs that are not web-accessible.
338// See https://crbug.com/662602.
339IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
340 NavigateToInaccessibleResourceFromChromeURL) {
341 // Mint an extension URL which is not web-accessible.
342 const extensions::Extension* extension = LoadExtension(
343 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
344 ASSERT_TRUE(extension);
345 GURL extension_url(extension->GetResourceURL("test.html"));
346
347 content::WebContents* tab =
348 browser()->tab_strip_model()->GetActiveWebContents();
349
350 // Navigate to the non-web-accessible URL from chrome:// and
351 // chrome-search:// pages. Verify that the page loads correctly.
352 GURL history_url(chrome::kChromeUIHistoryURL);
353 GURL ntp_url(chrome::kChromeSearchLocalNtpUrl);
354 ASSERT_TRUE(history_url.SchemeIs(content::kChromeUIScheme));
355 ASSERT_TRUE(ntp_url.SchemeIs(chrome::kChromeSearchScheme));
356 GURL start_urls[] = {history_url, ntp_url};
357 for (size_t i = 0; i < arraysize(start_urls); i++) {
358 ui_test_utils::NavigateToURL(browser(), start_urls[i]);
359 EXPECT_EQ(start_urls[i], tab->GetMainFrame()->GetLastCommittedURL());
360
361 content::TestNavigationObserver observer(tab);
362 ASSERT_TRUE(content::ExecuteScript(
363 tab, "location.href = '" + extension_url.spec() + "';"));
364 observer.Wait();
365 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL());
366 std::string result;
367 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
368 tab, "domAutomationController.send(document.body.innerText)", &result));
369 EXPECT_EQ("HOWDIE!!!", result);
370 }
371}