blob: 0ce310d02bb8c1406645c1b23fd06e531b0c4619 [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
robf8cd8ce2015-02-21 12:18:0447// The test uses the chrome.browserAction.openPopup API, which requires that the
48// window can automatically be activated.
49// See comments at BrowserActionInteractiveTest::ShouldRunPopupTest
johnme7e30b512015-04-16 14:57:3550// Fails flakily on all platforms. https://crbug.com/477691
51IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
yoze8dc2f12014-09-09 23:16:3252 extensions::ResultCatcher catcher;
[email protected]32b7c492010-09-01 04:15:0053 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
54 .AppendASCII("window_open").AppendASCII("spanning")));
55 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
56}
[email protected]4026ce1e2010-09-14 19:35:0457
[email protected]f1c102b2013-02-15 07:44:1258bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4559 int num_tabs,
dimich566d3642016-08-23 16:39:0660 int num_popups) {
[email protected]58b349b2011-11-23 02:07:1561 SCOPED_TRACE(
dimich566d3642016-08-23 16:39:0662 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d",
63 num_tabs, num_popups));
[email protected]4026ce1e2010-09-14 19:35:0464 // We start with one tab and one browser already open.
65 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0866 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0467
[email protected]f1c102b2013-02-15 07:44:1268 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4969 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
70 while (base::TimeTicks::Now() < end_time) {
scottmg34c5dd882016-02-03 05:21:5471 if (chrome::GetBrowserCount(browser->profile()) == num_browsers &&
dimich566d3642016-08-23 16:39:0672 browser->tab_strip_model()->count() == num_tabs)
[email protected]0a5bdc6522011-06-08 19:04:4973 break;
74
[email protected]b8deecd2012-07-30 21:09:4475 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4976 }
77
scottmg34c5dd882016-02-03 05:21:5478 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile()));
[email protected]e0448872013-01-11 19:35:0279 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]0a5bdc6522011-06-08 19:04:4980
[email protected]f9e82d92011-10-29 00:50:4581 int num_popups_seen = 0;
scottmg8abbff832016-01-28 22:57:3782 for (auto* b : *BrowserList::GetInstance()) {
83 if (b == browser)
[email protected]4026ce1e2010-09-14 19:35:0484 continue;
[email protected]4026ce1e2010-09-14 19:35:0485
scottmg8abbff832016-01-28 22:57:3786 EXPECT_TRUE(b->is_type_popup());
[email protected]f6ffa7d2012-08-17 17:27:0887 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:0488 }
[email protected]f9e82d92011-10-29 00:50:4589 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:1290
scottmg34c5dd882016-02-03 05:21:5491 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) &&
[email protected]f1c102b2013-02-15 07:44:1292 (num_tabs == browser->tab_strip_model()->count()) &&
[email protected]f1c102b2013-02-15 07:44:1293 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:0494}
95
[email protected]f112b0f2011-05-26 01:53:5296IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
97 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:0598 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:5299 ASSERT_TRUE(LoadExtension(
100 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
101
dimich566d3642016-08-23 16:39:06102 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2));
[email protected]f112b0f2011-05-26 01:53:52103
scottmg8abbff832016-01-28 22:57:37104 for (auto* b : *BrowserList::GetInstance()) {
105 if (b == browser())
106 ASSERT_FALSE(b->is_app());
[email protected]f112b0f2011-05-26 01:53:52107 else
scottmg8abbff832016-01-28 22:57:37108 ASSERT_TRUE(b->is_app());
[email protected]f112b0f2011-05-26 01:53:52109 }
110}
111
[email protected]0a5bdc6522011-06-08 19:04:49112IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05113 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49114 ASSERT_TRUE(LoadExtension(
115 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
116
117 const int num_tabs = 1;
118 const int num_popups = 0;
dimich566d3642016-08-23 16:39:06119 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]0a5bdc6522011-06-08 19:04:49120}
121
[email protected]7c6ef352013-09-26 07:23:14122IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) {
123 ASSERT_TRUE(StartEmbeddedTestServer());
124 base::FilePath test_data_dir;
125 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
126 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
127 ASSERT_TRUE(LoadExtension(
128 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe")));
129
jochenc5cfa642014-09-02 15:30:03130 const int num_tabs = 1;
131 const int num_popups = 0;
dimich566d3642016-08-23 16:39:06132 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]7c6ef352013-09-26 07:23:14133}
134
[email protected]0a5bdc6522011-06-08 19:04:49135IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05136 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49137 ASSERT_TRUE(LoadExtension(
138 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
139
[email protected]0a5bdc6522011-06-08 19:04:49140 // On other systems this should open a new popup window.
141 const int num_tabs = 0;
142 const int num_popups = 1;
dimich566d3642016-08-23 16:39:06143 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]0a5bdc6522011-06-08 19:04:49144}
145
146IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05147 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49148 ASSERT_TRUE(LoadExtension(
149 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
150
151 // On ChromeOS this should open a new panel (acts like a new popup window).
152 // On other systems this should open a new popup window.
153 const int num_tabs = 0;
154 const int num_popups = 1;
dimich566d3642016-08-23 16:39:06155 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
[email protected]0a5bdc6522011-06-08 19:04:49156}
157
[email protected]73fa1fce2013-02-21 20:10:05158// Disabled on Windows. Often times out or fails: crbug.com/177530
159#if defined(OS_WIN)
160#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
161#else
162#define MAYBE_PopupBlockingExtension PopupBlockingExtension
163#endif
164IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04165 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05166 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04167
168 ASSERT_TRUE(LoadExtension(
169 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
170 .AppendASCII("extension")));
171
dimich566d3642016-08-23 16:39:06172 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3));
[email protected]4026ce1e2010-09-14 19:35:04173}
174
175IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
176 host_resolver()->AddRule("*", "127.0.0.1");
svaldeza01f7d92015-11-18 17:47:56177 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]4026ce1e2010-09-14 19:35:04178
179 ASSERT_TRUE(LoadExtension(
180 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
181 .AppendASCII("hosted_app")));
182
[email protected]fe3048872010-10-18 14:58:59183 // The app being tested owns the domain a.com . The test URLs we navigate
184 // to below must be within that domain, so that they fall within the app's
185 // web extent.
186 GURL::Replacements replace_host;
mgiuca77752c32015-02-05 07:31:18187 replace_host.SetHostStr("a.com");
[email protected]fe3048872010-10-18 14:58:59188
189 const std::string popup_app_contents_path(
svaldeza01f7d92015-11-18 17:47:56190 "/extensions/api_test/window_open/popup_blocking/hosted_app/");
[email protected]fe3048872010-10-18 14:58:59191
svaldeza01f7d92015-11-18 17:47:56192 GURL open_tab = embedded_test_server()
193 ->GetURL(popup_app_contents_path + "open_tab.html")
194 .ReplaceComponents(replace_host);
195 GURL open_popup = embedded_test_server()
196 ->GetURL(popup_app_contents_path + "open_popup.html")
197 .ReplaceComponents(replace_host);
[email protected]fe3048872010-10-18 14:58:59198
nick3b04f322016-08-31 19:29:19199 browser()->OpenURL(OpenURLParams(open_tab, Referrer(),
200 WindowOpenDisposition::NEW_FOREGROUND_TAB,
201 ui::PAGE_TRANSITION_TYPED, false));
202 browser()->OpenURL(OpenURLParams(open_popup, Referrer(),
203 WindowOpenDisposition::NEW_FOREGROUND_TAB,
204 ui::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04205
dimich566d3642016-08-23 16:39:06206 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1));
[email protected]4026ce1e2010-09-14 19:35:04207}
[email protected]d4db6c702011-03-28 21:49:14208
[email protected]e7f90562011-05-23 21:38:24209IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
210 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
211}
212
[email protected]24c6bcfc2012-02-29 21:06:36213IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38214 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
215}
[email protected]fad73672012-06-15 23:26:06216
[email protected]fa7c1602013-04-03 23:00:20217#if defined(OS_MACOSX)
218// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
219#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
220#else
221#define MAYBE_WindowOpenSized WindowOpenSized
222#endif
223// Ensure that the width and height properties of a window opened with
224// chrome.windows.create match the creation parameters. See crbug.com/173831.
225IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
226 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
dimich566d3642016-08-23 16:39:06227 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1));
[email protected]fa7c1602013-04-03 23:00:20228}
229
[email protected]fad73672012-06-15 23:26:06230// Tests that an extension page can call window.open to an extension URL and
231// the new window has extension privileges.
232IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
233 ASSERT_TRUE(LoadExtension(
234 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
235
[email protected]99bee642014-05-31 22:36:43236 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24237 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43238 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06239 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16240 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02241 ASSERT_NO_FATAL_FAILURE(
242 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
243 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06244
245 bool result = false;
[email protected]b6987e02013-01-04 18:30:43246 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
247 &result));
[email protected]fad73672012-06-15 23:26:06248 EXPECT_TRUE(result);
249}
250
251// Tests that if an extension page calls window.open to an invalid extension
252// URL, the browser doesn't crash.
253IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
254 ASSERT_TRUE(LoadExtension(
255 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
256
[email protected]99bee642014-05-31 22:36:43257 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24258 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43259 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06260 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02261 ASSERT_NO_FATAL_FAILURE(
262 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06263 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
264 false, NULL));
265
266 // If we got to this point, we didn't crash, so we're good.
267}
268
269// Tests that calling window.open from the newtab page to an extension URL
270// gives the new window extension privileges - even though the opening page
271// does not have extension privileges, we break the script connection, so
272// there is no privilege leak.
273IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
274 ASSERT_TRUE(LoadExtension(
275 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
276
277 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16278 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02279 ASSERT_NO_FATAL_FAILURE(
280 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]99bee642014-05-31 22:36:43281 GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24282 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43283 last_loaded_extension_id() + "/newtab.html"),
284 false,
285 &newtab));
[email protected]fad73672012-06-15 23:26:06286
287 // Extension API should succeed.
288 bool result = false;
[email protected]b6987e02013-01-04 18:30:43289 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
290 &result));
[email protected]fad73672012-06-15 23:26:06291 EXPECT_TRUE(result);
292}
alexmos1c3da4f2016-11-03 06:06:11293
294// Tests that calling window.open for an extension URL from a non-HTTP or HTTPS
295// URL on a new tab cannot access non-web-accessible resources.
296IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
297 WindowOpenInaccessibleResourceFromDataURL) {
298 base::HistogramTester uma;
alexmoscf5145bb2016-11-09 23:19:45299 const extensions::Extension* extension = LoadExtension(
300 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
301 ASSERT_TRUE(extension);
alexmos1c3da4f2016-11-03 06:06:11302
303 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,foo"));
304
305 // test.html is not web-accessible and should not be loaded.
alexmoscf5145bb2016-11-09 23:19:45306 GURL extension_url(extension->GetResourceURL("test.html"));
alexmos1c3da4f2016-11-03 06:06:11307 content::WindowedNotificationObserver windowed_observer(
308 content::NOTIFICATION_LOAD_STOP,
309 content::NotificationService::AllSources());
310 ASSERT_TRUE(content::ExecuteScript(
311 browser()->tab_strip_model()->GetActiveWebContents(),
312 "window.open('" + extension_url.spec() + "');"));
313 windowed_observer.Wait();
314 content::NavigationController* controller =
315 content::Source<content::NavigationController>(windowed_observer.source())
316 .ptr();
317 content::WebContents* newtab = controller->GetWebContents();
318 ASSERT_TRUE(newtab);
319
320 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL());
321 EXPECT_FALSE(newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().SchemeIs(
322 extensions::kExtensionScheme));
323
324 // Verify that the blocking was recorded correctly in UMA.
325 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
326 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */
327 1);
328}
alexmoscf5145bb2016-11-09 23:19:45329
330// Test that navigating to an extension URL is allowed on chrome:// and
331// chrome-search:// pages, even for URLs that are not web-accessible.
332// See https://crbug.com/662602.
333IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
334 NavigateToInaccessibleResourceFromChromeURL) {
335 // Mint an extension URL which is not web-accessible.
336 const extensions::Extension* extension = LoadExtension(
337 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
338 ASSERT_TRUE(extension);
339 GURL extension_url(extension->GetResourceURL("test.html"));
340
341 content::WebContents* tab =
342 browser()->tab_strip_model()->GetActiveWebContents();
343
344 // Navigate to the non-web-accessible URL from chrome:// and
345 // chrome-search:// pages. Verify that the page loads correctly.
346 GURL history_url(chrome::kChromeUIHistoryURL);
347 GURL ntp_url(chrome::kChromeSearchLocalNtpUrl);
348 ASSERT_TRUE(history_url.SchemeIs(content::kChromeUIScheme));
349 ASSERT_TRUE(ntp_url.SchemeIs(chrome::kChromeSearchScheme));
350 GURL start_urls[] = {history_url, ntp_url};
351 for (size_t i = 0; i < arraysize(start_urls); i++) {
352 ui_test_utils::NavigateToURL(browser(), start_urls[i]);
353 EXPECT_EQ(start_urls[i], tab->GetMainFrame()->GetLastCommittedURL());
354
355 content::TestNavigationObserver observer(tab);
356 ASSERT_TRUE(content::ExecuteScript(
357 tab, "location.href = '" + extension_url.spec() + "';"));
358 observer.Wait();
359 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL());
360 std::string result;
361 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
362 tab, "domAutomationController.send(document.body.innerText)", &result));
363 EXPECT_EQ("HOWDIE!!!", result);
364 }
365}