Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / guest_view / web_view / web_view_apitest.cc
blob5857b7397df4e6673a1868888233b2251fd394d9
1 // Copyright 2014 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.
5 #include "extensions/browser/guest_view/web_view/web_view_apitest.h"
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h"
11 #include "components/guest_view/browser/guest_view_manager.h"
12 #include "components/guest_view/browser/guest_view_manager_delegate.h"
13 #include "components/guest_view/browser/guest_view_manager_factory.h"
14 #include "components/guest_view/browser/test_guest_view_manager.h"
15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/test/browser_test_utils.h"
18 #include "content/public/test/test_renderer_host.h"
19 #include "content/public/test/test_utils.h"
20 #include "extensions/browser/api/extensions_api_client.h"
21 #include "extensions/browser/api/test/test_api.h"
22 #include "extensions/browser/app_window/app_window.h"
23 #include "extensions/browser/app_window/app_window_registry.h"
24 #include "extensions/browser/process_manager.h"
25 #include "extensions/common/extension.h"
26 #include "extensions/common/extension_paths.h"
27 #include "extensions/shell/browser/shell_content_browser_client.h"
28 #include "extensions/shell/browser/shell_extension_system.h"
29 #include "extensions/shell/test/shell_test.h"
30 #include "extensions/test/extension_test_message_listener.h"
31 #include "net/base/filename_util.h"
32 #include "net/test/embedded_test_server/embedded_test_server.h"
33 #include "net/test/embedded_test_server/http_request.h"
34 #include "net/test/embedded_test_server/http_response.h"
35 #include "ui/gfx/switches.h"
37 using guest_view::GuestViewManager;
38 using guest_view::TestGuestViewManager;
40 namespace {
42 const char kEmptyResponsePath[] = "/close-socket";
43 const char kRedirectResponsePath[] = "/server-redirect";
44 const char kRedirectResponseFullPath[] = "/guest_redirect.html";
45 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent";
46 const char kTestDataDirectory[] = "testDataDirectory";
47 const char kTestServerPort[] = "testServer.port";
48 const char kTestWebSocketPort[] = "testWebSocketPort";
49 const char kSitePerProcess[] = "sitePerProcess";
51 class EmptyHttpResponse : public net::test_server::HttpResponse {
52 public:
53 std::string ToResponseString() const override { return std::string(); }
56 // Handles |request| by serving a redirect response if the |User-Agent| is
57 // foobar.
58 static scoped_ptr<net::test_server::HttpResponse> UserAgentResponseHandler(
59 const std::string& path,
60 const GURL& redirect_target,
61 const net::test_server::HttpRequest& request) {
62 if (!base::StartsWith(path, request.relative_url,
63 base::CompareCase::SENSITIVE))
64 return scoped_ptr<net::test_server::HttpResponse>();
66 std::map<std::string, std::string>::const_iterator it =
67 request.headers.find("User-Agent");
68 EXPECT_TRUE(it != request.headers.end());
69 if (!base::StartsWith("foobar", it->second, base::CompareCase::SENSITIVE))
70 return scoped_ptr<net::test_server::HttpResponse>();
72 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
73 new net::test_server::BasicHttpResponse);
74 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
75 http_response->AddCustomHeader("Location", redirect_target.spec());
76 return http_response.Pass();
79 class WebContentsHiddenObserver : public content::WebContentsObserver {
80 public:
81 WebContentsHiddenObserver(content::WebContents* web_contents,
82 const base::Closure& hidden_callback)
83 : WebContentsObserver(web_contents),
84 hidden_callback_(hidden_callback),
85 hidden_observed_(false) {
88 // WebContentsObserver.
89 void WasHidden() override {
90 hidden_observed_ = true;
91 hidden_callback_.Run();
94 bool hidden_observed() { return hidden_observed_; }
96 private:
97 base::Closure hidden_callback_;
98 bool hidden_observed_;
100 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver);
103 // Handles |request| by serving a redirect response.
104 scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler(
105 const std::string& path,
106 const GURL& redirect_target,
107 const net::test_server::HttpRequest& request) {
108 if (!base::StartsWith(path, request.relative_url,
109 base::CompareCase::SENSITIVE))
110 return scoped_ptr<net::test_server::HttpResponse>();
112 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
113 new net::test_server::BasicHttpResponse);
114 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
115 http_response->AddCustomHeader("Location", redirect_target.spec());
116 return http_response.Pass();
119 // Handles |request| by serving an empty response.
120 scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler(
121 const std::string& path,
122 const net::test_server::HttpRequest& request) {
123 if (base::StartsWith(path, request.relative_url,
124 base::CompareCase::SENSITIVE)) {
125 return scoped_ptr<net::test_server::HttpResponse>(new EmptyHttpResponse);
128 return scoped_ptr<net::test_server::HttpResponse>();
131 } // namespace
133 namespace extensions {
135 WebViewAPITest::WebViewAPITest() {
136 GuestViewManager::set_factory_for_testing(&factory_);
139 void WebViewAPITest::LaunchApp(const std::string& app_location) {
140 base::FilePath test_data_dir;
141 PathService::Get(DIR_TEST_DATA, &test_data_dir);
142 test_data_dir = test_data_dir.AppendASCII(app_location.c_str());
144 test_config_.SetString(kTestDataDirectory,
145 net::FilePathToFileURL(test_data_dir).spec());
147 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
149 const Extension* extension = extension_system_->LoadApp(test_data_dir);
150 ASSERT_TRUE(extension);
151 extension_system_->LaunchApp(extension->id());
153 ExtensionTestMessageListener launch_listener("LAUNCHED", false);
154 launch_listener.set_failure_message("FAILURE");
155 ASSERT_TRUE(launch_listener.WaitUntilSatisfied());
157 embedder_web_contents_ = GetFirstAppWindowWebContents();
160 content::WebContents* WebViewAPITest::GetFirstAppWindowWebContents() {
161 const AppWindowRegistry::AppWindowList& app_window_list =
162 AppWindowRegistry::Get(browser_context_)->app_windows();
163 DCHECK_EQ(1u, app_window_list.size());
164 return (*app_window_list.begin())->web_contents();
167 void WebViewAPITest::RunTest(const std::string& test_name,
168 const std::string& app_location) {
169 LaunchApp(app_location);
171 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
172 done_listener.set_failure_message("TEST_FAILED");
173 ASSERT_TRUE(content::ExecuteScript(
174 embedder_web_contents_,
175 base::StringPrintf("runTest('%s')", test_name.c_str())))
176 << "Unable to start test.";
177 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
180 void WebViewAPITest::RunTestOnMainThreadLoop() {
181 AppShellTest::RunTestOnMainThreadLoop();
182 GetGuestViewManager()->WaitForAllGuestsDeleted();
185 void WebViewAPITest::SetUpCommandLine(base::CommandLine* command_line) {
186 AppShellTest::SetUpCommandLine(command_line);
187 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
190 void WebViewAPITest::SetUpOnMainThread() {
191 AppShellTest::SetUpOnMainThread();
193 TestGetConfigFunction::set_test_config_state(&test_config_);
194 base::FilePath test_data_dir;
195 test_config_.SetInteger(kTestWebSocketPort, 0);
196 test_config_.SetBoolean(kSitePerProcess,
197 base::CommandLine::ForCurrentProcess()->HasSwitch(
198 switches::kSitePerProcess));
201 void WebViewAPITest::StartTestServer() {
202 // For serving guest pages.
203 if (!embedded_test_server()->InitializeAndWaitUntilReady()) {
204 LOG(ERROR) << "Failed to start test server.";
205 return;
208 test_config_.SetInteger(kTestServerPort, embedded_test_server()->port());
210 embedded_test_server()->RegisterRequestHandler(
211 base::Bind(&RedirectResponseHandler,
212 kRedirectResponsePath,
213 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
215 embedded_test_server()->RegisterRequestHandler(
216 base::Bind(&EmptyResponseHandler, kEmptyResponsePath));
218 embedded_test_server()->RegisterRequestHandler(
219 base::Bind(
220 &UserAgentResponseHandler,
221 kUserAgentRedirectResponsePath,
222 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
225 void WebViewAPITest::StopTestServer() {
226 if (!embedded_test_server()->ShutdownAndWaitUntilComplete()) {
227 LOG(ERROR) << "Failed to shutdown test server.";
231 void WebViewAPITest::TearDownOnMainThread() {
232 TestGetConfigFunction::set_test_config_state(nullptr);
234 AppShellTest::TearDownOnMainThread();
237 void WebViewAPITest::SendMessageToEmbedder(const std::string& message) {
238 EXPECT_TRUE(
239 content::ExecuteScript(
240 GetEmbedderWebContents(),
241 base::StringPrintf("onAppCommand('%s');", message.c_str())));
244 content::WebContents* WebViewAPITest::GetEmbedderWebContents() {
245 if (!embedder_web_contents_)
246 embedder_web_contents_ = GetFirstAppWindowWebContents();
247 return embedder_web_contents_;
250 TestGuestViewManager* WebViewAPITest::GetGuestViewManager() {
251 content::BrowserContext* context =
252 ShellContentBrowserClient::Get()->GetBrowserContext();
253 TestGuestViewManager* manager = static_cast<TestGuestViewManager*>(
254 TestGuestViewManager::FromBrowserContext(context));
255 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called
256 // before a guest is created.
257 if (!manager) {
258 manager =
259 static_cast<TestGuestViewManager*>(GuestViewManager::CreateWithDelegate(
260 context,
261 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(
262 context)));
264 return manager;
267 void WebViewAPITest::SendMessageToGuestAndWait(
268 const std::string& message,
269 const std::string& wait_message) {
270 scoped_ptr<ExtensionTestMessageListener> listener;
271 if (!wait_message.empty())
272 listener.reset(new ExtensionTestMessageListener(wait_message, false));
274 EXPECT_TRUE(
275 content::ExecuteScript(
276 GetGuestWebContents(),
277 base::StringPrintf("onAppCommand('%s');", message.c_str())));
279 if (listener)
280 ASSERT_TRUE(listener->WaitUntilSatisfied());
283 void WebViewDPIAPITest::SetUp() {
284 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
285 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
286 base::StringPrintf("%f", scale()));
287 WebViewAPITest::SetUp();
290 content::WebContents* WebViewAPITest::GetGuestWebContents() {
291 return GetGuestViewManager()->WaitForSingleGuestCreated();
294 // Occasionally hits NOTIMPLEMENTED on Linux. https://crbug.com/422998
295 #if defined(OS_LINUX)
296 #define MAYBE_AcceptTouchEvents DISABLED_AcceptTouchEvents
297 #else
298 #define MAYBE_AcceptTouchEvents AcceptTouchEvents
299 #endif
300 IN_PROC_BROWSER_TEST_F(WebViewAPITest, MAYBE_AcceptTouchEvents) {
301 LaunchApp("web_view/accept_touch_events");
303 content::RenderViewHost* embedder_rvh =
304 GetEmbedderWebContents()->GetRenderViewHost();
306 bool embedder_has_touch_handler =
307 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
308 EXPECT_FALSE(embedder_has_touch_handler);
310 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
312 // Note that we need to wait for the installed/registered touch handler to
313 // appear in browser process before querying |embedder_rvh|.
314 // In practice, since we do a roundrtip from browser process to guest and
315 // back, this is sufficient.
316 embedder_has_touch_handler =
317 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
318 EXPECT_TRUE(embedder_has_touch_handler);
320 SendMessageToGuestAndWait("uninstall-touch-handler",
321 "uninstalled-touch-handler");
322 // Same as the note above about waiting.
323 embedder_has_touch_handler =
324 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
325 EXPECT_FALSE(embedder_has_touch_handler);
328 // This test verifies that hiding the embedder also hides the guest.
329 IN_PROC_BROWSER_TEST_F(WebViewAPITest, EmbedderVisibilityChanged) {
330 LaunchApp("web_view/visibility_changed");
332 scoped_refptr<content::MessageLoopRunner> loop_runner(
333 new content::MessageLoopRunner);
334 WebContentsHiddenObserver observer(GetGuestWebContents(),
335 loop_runner->QuitClosure());
337 // Handled in web_view/visibility_changed/main.js
338 SendMessageToEmbedder("hide-embedder");
339 if (!observer.hidden_observed())
340 loop_runner->Run();
343 // Test for http://crbug.com/419611.
344 IN_PROC_BROWSER_TEST_F(WebViewAPITest, DisplayNoneSetSrc) {
345 LaunchApp("web_view/display_none_set_src");
346 // Navigate the guest while it's in "display: none" state.
347 SendMessageToEmbedder("navigate-guest");
348 GetGuestViewManager()->WaitForSingleGuestCreated();
350 // Now attempt to navigate the guest again.
351 SendMessageToEmbedder("navigate-guest");
353 ExtensionTestMessageListener test_passed_listener("WebViewTest.PASSED",
354 false);
355 // Making the guest visible would trigger loadstop.
356 SendMessageToEmbedder("show-guest");
357 EXPECT_TRUE(test_passed_listener.WaitUntilSatisfied());
360 // This test verifies that hiding the guest triggers WebContents::WasHidden().
361 IN_PROC_BROWSER_TEST_F(WebViewAPITest, GuestVisibilityChanged) {
362 LaunchApp("web_view/visibility_changed");
364 scoped_refptr<content::MessageLoopRunner> loop_runner(
365 new content::MessageLoopRunner);
366 WebContentsHiddenObserver observer(GetGuestWebContents(),
367 loop_runner->QuitClosure());
369 // Handled in web_view/visibility_changed/main.js
370 SendMessageToEmbedder("hide-guest");
371 if (!observer.hidden_observed())
372 loop_runner->Run();
375 // This test ensures that closing app window on 'loadcommit' does not crash.
376 // The test launches an app with guest and closes the window on loadcommit. It
377 // then launches the app window again. The process is repeated 3 times.
378 // http://crbug.com/291278
379 #if defined(OS_WIN)
380 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
381 #else
382 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
383 #endif
384 IN_PROC_BROWSER_TEST_F(WebViewAPITest, MAYBE_CloseOnLoadcommit) {
385 LaunchApp("web_view/close_on_loadcommit");
386 ExtensionTestMessageListener test_done_listener("done-close-on-loadcommit",
387 false);
388 ASSERT_TRUE(test_done_listener.WaitUntilSatisfied());
391 // This test verifies that reloading the embedder reloads the guest (and doest
392 // not crash).
393 IN_PROC_BROWSER_TEST_F(WebViewAPITest, ReloadEmbedder) {
394 // Just load a guest from other test, we do not want to add a separate
395 // app for this test.
396 LaunchApp("web_view/visibility_changed");
398 ExtensionTestMessageListener launched_again_listener("LAUNCHED", false);
399 embedder_web_contents_->GetController().Reload(false);
400 ASSERT_TRUE(launched_again_listener.WaitUntilSatisfied());
403 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAllowTransparencyAttribute) {
404 RunTest("testAllowTransparencyAttribute", "web_view/apitest");
407 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAPIMethodExistence) {
408 RunTest("testAPIMethodExistence", "web_view/apitest");
411 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAssignSrcAfterCrash) {
412 RunTest("testAssignSrcAfterCrash", "web_view/apitest");
415 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAutosizeAfterNavigation) {
416 RunTest("testAutosizeAfterNavigation", "web_view/apitest");
419 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAutosizeBeforeNavigation) {
420 RunTest("testAutosizeBeforeNavigation", "web_view/apitest");
423 IN_PROC_BROWSER_TEST_F(WebViewDPIAPITest, TestAutosizeBeforeNavigation) {
424 RunTest("testAutosizeBeforeNavigation", "web_view/apitest");
427 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAutosizeHeight) {
428 RunTest("testAutosizeHeight", "web_view/apitest");
431 IN_PROC_BROWSER_TEST_F(WebViewDPIAPITest, TestAutosizeHeight) {
432 RunTest("testAutosizeHeight", "web_view/apitest");
435 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAutosizeRemoveAttributes) {
436 RunTest("testAutosizeRemoveAttributes", "web_view/apitest");
439 IN_PROC_BROWSER_TEST_F(WebViewDPIAPITest, TestAutosizeRemoveAttributes) {
440 RunTest("testAutosizeRemoveAttributes", "web_view/apitest");
443 // http://crbug.com/473177
444 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
445 DISABLED_TestAutosizeWithPartialAttributes) {
446 RunTest("testAutosizeWithPartialAttributes", "web_view/apitest");
449 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestCannotMutateEventName) {
450 RunTest("testCannotMutateEventName", "web_view/apitest");
453 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestChromeExtensionRelativePath) {
454 RunTest("testChromeExtensionRelativePath", "web_view/apitest");
457 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestChromeExtensionURL) {
458 RunTest("testChromeExtensionURL", "web_view/apitest");
461 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestContentLoadEvent) {
462 RunTest("testContentLoadEvent", "web_view/apitest");
465 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDeclarativeWebRequestAPI) {
466 StartTestServer();
467 RunTest("testDeclarativeWebRequestAPI", "web_view/apitest");
468 StopTestServer();
471 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
472 TestDeclarativeWebRequestAPISendMessage) {
473 StartTestServer();
474 RunTest("testDeclarativeWebRequestAPISendMessage", "web_view/apitest");
475 StopTestServer();
478 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDestroyOnEventListener) {
479 RunTest("testDestroyOnEventListener", "web_view/apitest");
482 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDialogAlert) {
483 RunTest("testDialogAlert", "web_view/dialog");
486 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDialogConfirm) {
487 RunTest("testDialogConfirm", "web_view/dialog");
490 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDialogConfirmCancel) {
491 RunTest("testDialogConfirmCancel", "web_view/dialog");
494 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDialogConfirmDefaultCancel) {
495 RunTest("testDialogConfirmDefaultCancel", "web_view/dialog");
498 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDialogConfirmDefaultGCCancel) {
499 RunTest("testDialogConfirmDefaultGCCancel", "web_view/dialog");
502 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDialogPrompt) {
503 RunTest("testDialogPrompt", "web_view/dialog");
506 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDisplayNoneWebviewLoad) {
507 RunTest("testDisplayNoneWebviewLoad", "web_view/apitest");
510 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestDisplayNoneWebviewRemoveChild) {
511 RunTest("testDisplayNoneWebviewRemoveChild", "web_view/apitest");
514 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestEventName) {
515 RunTest("testEventName", "web_view/apitest");
518 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestExecuteScript) {
519 RunTest("testExecuteScript", "web_view/apitest");
522 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestExecuteScriptFail) {
523 RunTest("testExecuteScriptFail", "web_view/apitest");
526 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
527 TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged) {
528 RunTest("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
529 "web_view/apitest");
532 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestFindAPI) {
533 RunTest("testFindAPI", "web_view/apitest");
536 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestFindAPI_findupdate) {
537 RunTest("testFindAPI_findupdate", "web_view/apitest");
540 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestGetProcessId) {
541 RunTest("testGetProcessId", "web_view/apitest");
544 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestHiddenBeforeNavigation) {
545 RunTest("testHiddenBeforeNavigation", "web_view/apitest");
548 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
549 TestInlineScriptFromAccessibleResources) {
550 RunTest("testInlineScriptFromAccessibleResources", "web_view/apitest");
553 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestInvalidChromeExtensionURL) {
554 RunTest("testInvalidChromeExtensionURL", "web_view/apitest");
557 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
558 TestLoadAbortChromeExtensionURLWrongPartition) {
559 RunTest("testLoadAbortChromeExtensionURLWrongPartition", "web_view/apitest");
562 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortEmptyResponse) {
563 StartTestServer();
564 RunTest("testLoadAbortEmptyResponse", "web_view/apitest");
565 StopTestServer();
568 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortIllegalChromeURL) {
569 RunTest("testLoadAbortIllegalChromeURL", "web_view/apitest");
572 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortIllegalFileURL) {
573 RunTest("testLoadAbortIllegalFileURL", "web_view/apitest");
576 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortIllegalJavaScriptURL) {
577 RunTest("testLoadAbortIllegalJavaScriptURL", "web_view/apitest");
580 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortInvalidNavigation) {
581 RunTest("testLoadAbortInvalidNavigation", "web_view/apitest");
584 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortNonWebSafeScheme) {
585 RunTest("testLoadAbortNonWebSafeScheme", "web_view/apitest");
588 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadProgressEvent) {
589 RunTest("testLoadProgressEvent", "web_view/apitest");
592 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadStartLoadRedirect) {
593 StartTestServer();
594 RunTest("testLoadStartLoadRedirect", "web_view/apitest");
595 StopTestServer();
598 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNavigateAfterResize) {
599 RunTest("testNavigateAfterResize", "web_view/apitest");
602 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNavigationToExternalProtocol) {
603 RunTest("testNavigationToExternalProtocol", "web_view/apitest");
606 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
607 TestNavOnConsecutiveSrcAttributeChanges) {
608 RunTest("testNavOnConsecutiveSrcAttributeChanges", "web_view/apitest");
611 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNavOnSrcAttributeChange) {
612 RunTest("testNavOnSrcAttributeChange", "web_view/apitest");
615 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNewWindow) {
616 StartTestServer();
617 RunTest("testNewWindow", "web_view/apitest");
618 StopTestServer();
621 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNewWindowNoPreventDefault) {
622 StartTestServer();
623 RunTest("testNewWindowNoPreventDefault", "web_view/apitest");
624 StopTestServer();
627 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNewWindowNoReferrerLink) {
628 StartTestServer();
629 RunTest("testNewWindowNoReferrerLink", "web_view/apitest");
630 StopTestServer();
633 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestNewWindowTwoListeners) {
634 StartTestServer();
635 RunTest("testNewWindowTwoListeners", "web_view/apitest");
636 StopTestServer();
639 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestOnEventProperty) {
640 RunTest("testOnEventProperties", "web_view/apitest");
643 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestPartitionChangeAfterNavigation) {
644 RunTest("testPartitionChangeAfterNavigation", "web_view/apitest");
647 IN_PROC_BROWSER_TEST_F(WebViewAPITest,
648 TestPartitionRemovalAfterNavigationFails) {
649 RunTest("testPartitionRemovalAfterNavigationFails", "web_view/apitest");
652 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestReassignSrcAttribute) {
653 RunTest("testReassignSrcAttribute", "web_view/apitest");
656 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestRemoveWebviewOnExit) {
657 StartTestServer();
659 // Launch the app and wait until it's ready to load a test.
660 LaunchApp("web_view/apitest");
662 GURL::Replacements replace_host;
663 replace_host.SetHostStr("localhost");
665 // Run the test and wait until the guest WebContents is available and has
666 // finished loading.
667 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
668 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_,
669 "runTest('testRemoveWebviewOnExit')"));
671 content::WebContents* guest_web_contents = GetGuestWebContents();
672 EXPECT_TRUE(guest_web_contents->GetRenderProcessHost()->IsForGuestsOnly());
673 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
675 content::WebContentsDestroyedWatcher destroyed_watcher(guest_web_contents);
677 // Tell the embedder to kill the guest.
678 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_,
679 "removeWebviewOnExitDoCrash()"));
681 // Wait until the guest WebContents is destroyed.
682 destroyed_watcher.Wait();
683 StopTestServer();
686 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestReload) {
687 RunTest("testReload", "web_view/apitest");
690 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestReloadAfterTerminate) {
691 RunTest("testReloadAfterTerminate", "web_view/apitest");
694 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestRemoveSrcAttribute) {
695 RunTest("testRemoveSrcAttribute", "web_view/apitest");
698 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestRemoveWebviewAfterNavigation) {
699 RunTest("testRemoveWebviewAfterNavigation", "web_view/apitest");
702 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestResizeWebviewResizesContent) {
703 RunTest("testResizeWebviewResizesContent", "web_view/apitest");
706 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestTerminateAfterExit) {
707 RunTest("testTerminateAfterExit", "web_view/apitest");
710 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebRequestAPI) {
711 StartTestServer();
712 RunTest("testWebRequestAPI", "web_view/apitest");
713 StopTestServer();
716 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebRequestAPIWithHeaders) {
717 StartTestServer();
718 RunTest("testWebRequestAPIWithHeaders", "web_view/apitest");
719 StopTestServer();
722 // Tests the existence of WebRequest API event objects on the request
723 // object, on the webview element, and hanging directly off webview.
724 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebRequestAPIExistence) {
725 RunTest("testWebRequestAPIExistence", "web_view/apitest");
728 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebRequestAPIGoogleProperty) {
729 RunTest("testWebRequestAPIGoogleProperty", "web_view/apitest");
732 // This test verifies that webview.contentWindow works inside an iframe
733 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebViewInsideFrame) {
734 LaunchApp("web_view/inside_iframe");
738 } // namespace extensions