1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_browser_main.h"
16 #include "chrome/browser/chrome_browser_main_extra_parts.h"
17 #include "chrome/browser/chrome_content_browser_client.h"
18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/download/download_browsertest.h"
20 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
21 #include "chrome/browser/extensions/extension_apitest.h"
22 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h"
25 #include "chrome/browser/tab_contents/render_view_context_menu.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/test/base/ui_test_utils.h"
29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/render_process_host.h"
31 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/resource_controller.h"
33 #include "content/public/browser/resource_dispatcher_host.h"
34 #include "content/public/browser/resource_throttle.h"
35 #include "content/public/browser/web_contents.h"
36 #include "content/public/common/context_menu_params.h"
37 #include "content/public/common/url_constants.h"
38 #include "content/public/test/browser_test_utils.h"
39 #include "extensions/browser/extension_system.h"
40 #include "extensions/common/switches.h"
41 #include "net/dns/mock_host_resolver.h"
42 #include "net/test/embedded_test_server/embedded_test_server.h"
43 #include "third_party/WebKit/public/web/WebContextMenuData.h"
44 #include "third_party/WebKit/public/web/WebInputEvent.h"
45 #include "webkit/common/resource_type.h"
47 using content::WebContents;
49 namespace extensions {
53 // An UI-less RenderViewContextMenu.
54 class TestRenderViewContextMenu : public RenderViewContextMenu {
56 TestRenderViewContextMenu(content::RenderFrameHost* render_frame_host,
57 const content::ContextMenuParams& params)
58 : RenderViewContextMenu(render_frame_host, params) {
60 virtual ~TestRenderViewContextMenu() {}
63 virtual void PlatformInit() OVERRIDE {}
64 virtual void PlatformCancel() OVERRIDE {}
65 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) OVERRIDE {
69 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu);
73 // This class can defer requests for arbitrary URLs.
74 class TestNavigationListener
75 : public base::RefCountedThreadSafe<TestNavigationListener> {
77 TestNavigationListener() {}
79 // Add |url| to the set of URLs we should delay.
80 void DelayRequestsForURL(const GURL& url) {
81 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
82 content::BrowserThread::PostTask(
83 content::BrowserThread::IO,
85 base::Bind(&TestNavigationListener::DelayRequestsForURL, this, url));
88 urls_to_delay_.insert(url);
91 // Resume all deferred requests.
93 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
94 content::BrowserThread::PostTask(
95 content::BrowserThread::IO,
97 base::Bind(&TestNavigationListener::ResumeAll, this));
100 WeakThrottleList::const_iterator it;
101 for (it = throttles_.begin(); it != throttles_.end(); ++it) {
108 // Constructs a ResourceThrottle if the request for |url| should be held.
110 // Needs to be invoked on the IO thread.
111 content::ResourceThrottle* CreateResourceThrottle(
113 ResourceType::Type resource_type) {
114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
115 if (urls_to_delay_.find(url) == urls_to_delay_.end())
118 Throttle* throttle = new Throttle();
119 throttles_.push_back(throttle->AsWeakPtr());
124 friend class base::RefCountedThreadSafe<TestNavigationListener>;
126 virtual ~TestNavigationListener() {}
128 // Stores a throttle per URL request that we have delayed.
129 class Throttle : public content::ResourceThrottle,
130 public base::SupportsWeakPtr<Throttle> {
133 controller()->Resume();
136 // content::ResourceThrottle implementation.
137 virtual void WillStartRequest(bool* defer) OVERRIDE {
141 virtual const char* GetNameForLogging() const OVERRIDE {
142 return "TestNavigationListener::Throttle";
145 typedef base::WeakPtr<Throttle> WeakThrottle;
146 typedef std::list<WeakThrottle> WeakThrottleList;
147 WeakThrottleList throttles_;
149 // The set of URLs to be delayed.
150 std::set<GURL> urls_to_delay_;
152 DISALLOW_COPY_AND_ASSIGN(TestNavigationListener);
155 // Waits for a WC to be created. Once it starts loading |delay_url| (after at
156 // least the first navigation has committed), it delays the load, executes
157 // |script| in the last committed RVH and resumes the load when a URL ending in
158 // |until_url_suffix| commits. This class expects |script| to trigger the load
159 // of an URL ending in |until_url_suffix|.
160 class DelayLoadStartAndExecuteJavascript
161 : public content::NotificationObserver,
162 public content::WebContentsObserver {
164 DelayLoadStartAndExecuteJavascript(
165 TestNavigationListener* test_navigation_listener,
166 const GURL& delay_url,
167 const std::string& script,
168 const std::string& until_url_suffix)
169 : content::WebContentsObserver(),
170 test_navigation_listener_(test_navigation_listener),
171 delay_url_(delay_url),
172 until_url_suffix_(until_url_suffix),
174 script_was_executed_(false),
177 chrome::NOTIFICATION_TAB_ADDED,
178 content::NotificationService::AllSources());
179 test_navigation_listener_->DelayRequestsForURL(delay_url_);
181 virtual ~DelayLoadStartAndExecuteJavascript() {}
183 virtual void Observe(int type,
184 const content::NotificationSource& source,
185 const content::NotificationDetails& details) OVERRIDE {
186 if (type != chrome::NOTIFICATION_TAB_ADDED) {
190 content::WebContentsObserver::Observe(
191 content::Details<content::WebContents>(details).ptr());
192 registrar_.RemoveAll();
195 virtual void DidStartProvisionalLoadForFrame(
197 int64 parent_frame_id,
199 const GURL& validated_url,
201 bool is_iframe_srcdoc,
202 content::RenderViewHost* render_view_host) OVERRIDE {
203 if (validated_url != delay_url_ || !rvh_)
206 rvh_->ExecuteJavascriptInWebFrame(base::string16(),
207 base::UTF8ToUTF16(script_));
208 script_was_executed_ = true;
211 virtual void DidCommitProvisionalLoadForFrame(
213 const base::string16& frame_unique_name,
216 content::PageTransition transition_type,
217 content::RenderViewHost* render_view_host) OVERRIDE {
218 if (script_was_executed_ && EndsWith(url.spec(), until_url_suffix_, true)) {
219 content::WebContentsObserver::Observe(NULL);
220 test_navigation_listener_->ResumeAll();
222 rvh_ = render_view_host;
226 content::NotificationRegistrar registrar_;
228 scoped_refptr<TestNavigationListener> test_navigation_listener_;
231 std::string until_url_suffix_;
233 bool script_was_executed_;
234 content::RenderViewHost* rvh_;
236 DISALLOW_COPY_AND_ASSIGN(DelayLoadStartAndExecuteJavascript);
239 // A ResourceDispatcherHostDelegate that adds a TestNavigationObserver.
240 class TestResourceDispatcherHostDelegate
241 : public ChromeResourceDispatcherHostDelegate {
243 TestResourceDispatcherHostDelegate(
244 prerender::PrerenderTracker* prerender_tracker,
245 TestNavigationListener* test_navigation_listener)
246 : ChromeResourceDispatcherHostDelegate(prerender_tracker),
247 test_navigation_listener_(test_navigation_listener) {
249 virtual ~TestResourceDispatcherHostDelegate() {}
251 virtual void RequestBeginning(
252 net::URLRequest* request,
253 content::ResourceContext* resource_context,
254 appcache::AppCacheService* appcache_service,
255 ResourceType::Type resource_type,
258 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE {
259 ChromeResourceDispatcherHostDelegate::RequestBeginning(
267 content::ResourceThrottle* throttle =
268 test_navigation_listener_->CreateResourceThrottle(request->url(),
271 throttles->push_back(throttle);
275 scoped_refptr<TestNavigationListener> test_navigation_listener_;
277 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate);
280 // Used to manage the lifetime of the TestResourceDispatcherHostDelegate which
281 // needs to be deleted before the threads are stopped.
282 class TestBrowserMainExtraParts : public ChromeBrowserMainExtraParts {
284 explicit TestBrowserMainExtraParts(
285 TestNavigationListener* test_navigation_listener)
286 : test_navigation_listener_(test_navigation_listener) {
288 virtual ~TestBrowserMainExtraParts() {}
290 TestResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() {
291 if (!resource_dispatcher_host_delegate_.get()) {
292 resource_dispatcher_host_delegate_.reset(
293 new TestResourceDispatcherHostDelegate(
294 g_browser_process->prerender_tracker(),
295 test_navigation_listener_.get()));
297 return resource_dispatcher_host_delegate_.get();
300 // ChromeBrowserMainExtraParts implementation.
301 virtual void PostMainMessageLoopRun() OVERRIDE {
302 resource_dispatcher_host_delegate_.reset();
306 scoped_refptr<TestNavigationListener> test_navigation_listener_;
307 scoped_ptr<TestResourceDispatcherHostDelegate>
308 resource_dispatcher_host_delegate_;
310 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts);
313 // A ContentBrowserClient that doesn't forward the RDH created signal.
314 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient {
316 explicit TestContentBrowserClient(
317 TestNavigationListener* test_navigation_listener)
318 : test_navigation_listener_(test_navigation_listener) {
320 virtual ~TestContentBrowserClient() {}
322 virtual void ResourceDispatcherHostCreated() OVERRIDE {
323 // Don't invoke ChromeContentBrowserClient::ResourceDispatcherHostCreated.
324 // It would notify BrowserProcessImpl which would create a
325 // ChromeResourceDispatcherHostDelegate and other objects. Not creating
326 // other objects might turn out to be a problem in the future.
327 content::ResourceDispatcherHost::Get()->SetDelegate(
328 browser_main_extra_parts_->resource_dispatcher_host_delegate());
331 virtual content::BrowserMainParts* CreateBrowserMainParts(
332 const content::MainFunctionParams& parameters) OVERRIDE {
333 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>(
334 ChromeContentBrowserClient::CreateBrowserMainParts(parameters));
336 browser_main_extra_parts_ =
337 new TestBrowserMainExtraParts(test_navigation_listener_.get());
338 main_parts->AddParts(browser_main_extra_parts_);
343 scoped_refptr<TestNavigationListener> test_navigation_listener_;
344 TestBrowserMainExtraParts* browser_main_extra_parts_;
346 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient);
351 class WebNavigationApiTest : public ExtensionApiTest {
353 WebNavigationApiTest() {}
354 virtual ~WebNavigationApiTest() {}
356 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
357 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
359 test_navigation_listener_ = new TestNavigationListener();
360 content_browser_client_.reset(
361 new TestContentBrowserClient(test_navigation_listener_.get()));
362 original_content_browser_client_ = content::SetBrowserClientForTesting(
363 content_browser_client_.get());
365 FrameNavigationState::set_allow_extension_scheme(true);
367 CommandLine::ForCurrentProcess()->AppendSwitch(
368 switches::kAllowLegacyExtensionManifests);
370 host_resolver()->AddRule("*", "127.0.0.1");
373 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
374 ExtensionApiTest::TearDownInProcessBrowserTestFixture();
375 content::SetBrowserClientForTesting(original_content_browser_client_);
378 TestNavigationListener* test_navigation_listener() {
379 return test_navigation_listener_.get();
383 scoped_refptr<TestNavigationListener> test_navigation_listener_;
384 scoped_ptr<TestContentBrowserClient> content_browser_client_;
385 content::ContentBrowserClient* original_content_browser_client_;
387 DISALLOW_COPY_AND_ASSIGN(WebNavigationApiTest);
390 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Api) {
391 ASSERT_TRUE(StartEmbeddedTestServer());
392 ASSERT_TRUE(RunExtensionTest("webnavigation/api")) << message_;
395 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, GetFrame) {
396 ASSERT_TRUE(StartEmbeddedTestServer());
397 ASSERT_TRUE(RunExtensionTest("webnavigation/getFrame")) << message_;
400 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ClientRedirect) {
401 ASSERT_TRUE(StartEmbeddedTestServer());
402 ASSERT_TRUE(RunExtensionTest("webnavigation/clientRedirect"))
406 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ServerRedirect) {
407 ASSERT_TRUE(StartEmbeddedTestServer());
408 ASSERT_TRUE(RunExtensionTest("webnavigation/serverRedirect"))
412 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Download) {
413 DownloadTestObserverNotInProgress download_observer(
414 content::BrowserContext::GetDownloadManager(profile()), 1);
415 download_observer.StartObserving();
416 ASSERT_TRUE(StartEmbeddedTestServer());
417 ASSERT_TRUE(RunExtensionTest("webnavigation/download"))
419 download_observer.WaitForFinished();
422 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ServerRedirectSingleProcess) {
423 ASSERT_TRUE(StartEmbeddedTestServer());
425 // Set max renderers to 1 to force running out of processes.
426 content::RenderProcessHost::SetMaxRendererProcessCount(1);
428 // Wait for the extension to set itself up and return control to us.
430 RunExtensionTest("webnavigation/serverRedirectSingleProcess"))
433 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
434 content::WaitForLoadStop(tab);
436 ResultCatcher catcher;
437 GURL url(base::StringPrintf(
438 "http://www.a.com:%d/"
439 "extensions/api_test/webnavigation/serverRedirectSingleProcess/a.html",
440 embedded_test_server()->port()));
442 ui_test_utils::NavigateToURL(browser(), url);
444 url = GURL(base::StringPrintf(
445 "http://www.b.com:%d/server-redirect?http://www.b.com:%d/",
446 embedded_test_server()->port(),
447 embedded_test_server()->port()));
449 ui_test_utils::NavigateToURL(browser(), url);
451 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
454 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ForwardBack) {
455 ASSERT_TRUE(StartEmbeddedTestServer());
456 ASSERT_TRUE(RunExtensionTest("webnavigation/forwardBack")) << message_;
459 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, IFrame) {
460 ASSERT_TRUE(StartEmbeddedTestServer());
461 ASSERT_TRUE(RunExtensionTest("webnavigation/iframe")) << message_;
464 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, SrcDoc) {
465 ASSERT_TRUE(StartEmbeddedTestServer());
466 ASSERT_TRUE(RunExtensionTest("webnavigation/srcdoc")) << message_;
469 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, OpenTab) {
470 ASSERT_TRUE(StartEmbeddedTestServer());
471 ASSERT_TRUE(RunExtensionTest("webnavigation/openTab")) << message_;
474 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ReferenceFragment) {
475 ASSERT_TRUE(StartEmbeddedTestServer());
476 ASSERT_TRUE(RunExtensionTest("webnavigation/referenceFragment"))
480 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, SimpleLoad) {
481 ASSERT_TRUE(StartEmbeddedTestServer());
482 ASSERT_TRUE(RunExtensionTest("webnavigation/simpleLoad")) << message_;
485 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Failures) {
486 ASSERT_TRUE(StartEmbeddedTestServer());
487 ASSERT_TRUE(RunExtensionTest("webnavigation/failures")) << message_;
490 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, FilteredTest) {
491 ASSERT_TRUE(StartEmbeddedTestServer());
492 ASSERT_TRUE(RunExtensionTest("webnavigation/filtered")) << message_;
495 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, UserAction) {
496 ASSERT_TRUE(StartEmbeddedTestServer());
498 // Wait for the extension to set itself up and return control to us.
499 ASSERT_TRUE(RunExtensionTest("webnavigation/userAction")) << message_;
501 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
502 content::WaitForLoadStop(tab);
504 ResultCatcher catcher;
506 ExtensionService* service = extensions::ExtensionSystem::Get(
507 browser()->profile())->extension_service();
508 const extensions::Extension* extension =
509 service->GetExtensionById(last_loaded_extension_id(), false);
510 GURL url = extension->GetResourceURL("a.html");
512 ui_test_utils::NavigateToURL(browser(), url);
514 // This corresponds to "Open link in new tab".
515 content::ContextMenuParams params;
516 params.is_editable = false;
517 params.media_type = blink::WebContextMenuData::MediaTypeNone;
518 params.page_url = url;
519 params.frame_id = WebNavigationTabObserver::Get(tab)->
520 frame_navigation_state().GetMainFrameID().frame_num;
521 params.link_url = extension->GetResourceURL("b.html");
523 TestRenderViewContextMenu menu(tab->GetMainFrame(), params);
525 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, 0);
527 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
530 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, RequestOpenTab) {
531 ASSERT_TRUE(StartEmbeddedTestServer());
533 // Wait for the extension to set itself up and return control to us.
534 ASSERT_TRUE(RunExtensionTest("webnavigation/requestOpenTab"))
537 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
538 content::WaitForLoadStop(tab);
540 ResultCatcher catcher;
542 ExtensionService* service = extensions::ExtensionSystem::Get(
543 browser()->profile())->extension_service();
544 const extensions::Extension* extension =
545 service->GetExtensionById(last_loaded_extension_id(), false);
546 GURL url = extension->GetResourceURL("a.html");
548 ui_test_utils::NavigateToURL(browser(), url);
550 // There's a link on a.html. Middle-click on it to open it in a new tab.
551 blink::WebMouseEvent mouse_event;
552 mouse_event.type = blink::WebInputEvent::MouseDown;
553 mouse_event.button = blink::WebMouseEvent::ButtonMiddle;
556 mouse_event.clickCount = 1;
557 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
558 mouse_event.type = blink::WebInputEvent::MouseUp;
559 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
561 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
564 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, TargetBlank) {
565 ASSERT_TRUE(StartEmbeddedTestServer());
567 // Wait for the extension to set itself up and return control to us.
568 ASSERT_TRUE(RunExtensionTest("webnavigation/targetBlank")) << message_;
570 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
571 content::WaitForLoadStop(tab);
573 ResultCatcher catcher;
575 GURL url = embedded_test_server()->GetURL(
576 "/extensions/api_test/webnavigation/targetBlank/a.html");
578 chrome::NavigateParams params(browser(), url, content::PAGE_TRANSITION_LINK);
579 ui_test_utils::NavigateToURL(¶ms);
581 // There's a link with target=_blank on a.html. Click on it to open it in a
583 blink::WebMouseEvent mouse_event;
584 mouse_event.type = blink::WebInputEvent::MouseDown;
585 mouse_event.button = blink::WebMouseEvent::ButtonLeft;
588 mouse_event.clickCount = 1;
589 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
590 mouse_event.type = blink::WebInputEvent::MouseUp;
591 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
593 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
596 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, TargetBlankIncognito) {
597 ASSERT_TRUE(StartEmbeddedTestServer());
599 // Wait for the extension to set itself up and return control to us.
600 ASSERT_TRUE(RunExtensionTestIncognito("webnavigation/targetBlank"))
603 ResultCatcher catcher;
605 GURL url = embedded_test_server()->GetURL(
606 "/extensions/api_test/webnavigation/targetBlank/a.html");
608 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord(
609 browser()->profile(), url);
610 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents();
612 // There's a link with target=_blank on a.html. Click on it to open it in a
614 blink::WebMouseEvent mouse_event;
615 mouse_event.type = blink::WebInputEvent::MouseDown;
616 mouse_event.button = blink::WebMouseEvent::ButtonLeft;
619 mouse_event.clickCount = 1;
620 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
621 mouse_event.type = blink::WebInputEvent::MouseUp;
622 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
624 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
627 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, History) {
628 ASSERT_TRUE(StartEmbeddedTestServer());
629 ASSERT_TRUE(RunExtensionTest("webnavigation/history")) << message_;
632 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcess) {
633 ASSERT_TRUE(StartEmbeddedTestServer());
635 LoadExtension(test_data_dir_.AppendASCII("webnavigation").AppendASCII("app"));
637 // See crossProcess/d.html.
638 DelayLoadStartAndExecuteJavascript call_script(
639 test_navigation_listener(),
640 embedded_test_server()->GetURL("/test1"),
644 ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcess")) << message_;
647 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcessFragment) {
648 ASSERT_TRUE(StartEmbeddedTestServer());
650 // See crossProcessFragment/f.html.
651 DelayLoadStartAndExecuteJavascript call_script3(
652 test_navigation_listener(),
653 embedded_test_server()->GetURL("/test3"),
655 base::StringPrintf("f.html?%d#foo", embedded_test_server()->port()));
657 // See crossProcessFragment/g.html.
658 DelayLoadStartAndExecuteJavascript call_script4(
659 test_navigation_listener(),
660 embedded_test_server()->GetURL("/test4"),
662 base::StringPrintf("g.html?%d#foo", embedded_test_server()->port()));
664 ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcessFragment"))
668 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcessHistory) {
669 ASSERT_TRUE(StartEmbeddedTestServer());
671 // See crossProcessHistory/e.html.
672 DelayLoadStartAndExecuteJavascript call_script2(
673 test_navigation_listener(),
674 embedded_test_server()->GetURL("/test2"),
678 // See crossProcessHistory/h.html.
679 DelayLoadStartAndExecuteJavascript call_script5(
680 test_navigation_listener(),
681 embedded_test_server()->GetURL("/test5"),
685 // See crossProcessHistory/i.html.
686 DelayLoadStartAndExecuteJavascript call_script6(
687 test_navigation_listener(),
688 embedded_test_server()->GetURL("/test6"),
692 ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcessHistory"))
696 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Crash) {
697 ASSERT_TRUE(StartEmbeddedTestServer());
699 // Wait for the extension to set itself up and return control to us.
700 ASSERT_TRUE(RunExtensionTest("webnavigation/crash")) << message_;
702 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
703 content::WaitForLoadStop(tab);
705 ResultCatcher catcher;
707 GURL url(base::StringPrintf(
708 "http://www.a.com:%d/"
709 "extensions/api_test/webnavigation/crash/a.html",
710 embedded_test_server()->port()));
711 ui_test_utils::NavigateToURL(browser(), url);
713 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL));
715 url = GURL(base::StringPrintf(
716 "http://www.a.com:%d/"
717 "extensions/api_test/webnavigation/crash/b.html",
718 embedded_test_server()->port()));
719 ui_test_utils::NavigateToURL(browser(), url);
721 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
724 } // namespace extensions