1 // Copyright 2013 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.
7 #include "base/location.h"
8 #include "base/path_service.h"
9 #include "base/process/process.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/apps/app_browsertest_util.h"
16 #include "chrome/browser/chrome_content_browser_client.h"
17 #include "chrome/browser/lifetime/application_lifetime.h"
18 #include "chrome/browser/pdf/pdf_extension_test_util.h"
19 #include "chrome/browser/prerender/prerender_link_manager.h"
20 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
23 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
24 #include "chrome/browser/task_management/task_management_browsertest_util.h"
25 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_dialogs.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/test/base/ui_test_utils.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/guest_view/browser/guest_view_manager.h"
32 #include "components/guest_view/browser/guest_view_manager_delegate.h"
33 #include "components/guest_view/browser/guest_view_manager_factory.h"
34 #include "components/guest_view/browser/test_guest_view_manager.h"
35 #include "content/public/browser/gpu_data_manager.h"
36 #include "content/public/browser/interstitial_page.h"
37 #include "content/public/browser/interstitial_page_delegate.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/web_contents_delegate.h"
41 #include "content/public/common/child_process_host.h"
42 #include "content/public/common/content_switches.h"
43 #include "content/public/test/browser_test_utils.h"
44 #include "content/public/test/fake_speech_recognition_manager.h"
45 #include "content/public/test/test_renderer_host.h"
46 #include "extensions/browser/api/declarative/rules_registry.h"
47 #include "extensions/browser/api/declarative/rules_registry_service.h"
48 #include "extensions/browser/api/declarative/test_rules_registry.h"
49 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
50 #include "extensions/browser/api/extensions_api_client.h"
51 #include "extensions/browser/app_window/native_app_window.h"
52 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
53 #include "extensions/common/extension.h"
54 #include "extensions/common/extensions_client.h"
55 #include "extensions/test/extension_test_message_listener.h"
56 #include "media/base/media_switches.h"
57 #include "net/test/embedded_test_server/embedded_test_server.h"
58 #include "net/test/embedded_test_server/http_request.h"
59 #include "net/test/embedded_test_server/http_response.h"
60 #include "ui/aura/window.h"
61 #include "ui/base/l10n/l10n_util.h"
62 #include "ui/compositor/compositor.h"
63 #include "ui/compositor/compositor_observer.h"
64 #include "ui/events/event_switches.h"
65 #include "ui/gfx/switches.h"
66 #include "ui/gl/gl_switches.h"
67 #include "ui/views/view.h"
68 #include "ui/views/widget/widget.h"
70 #if defined(ENABLE_PLUGINS)
71 #include "content/public/browser/plugin_service.h"
72 #include "content/public/common/webplugininfo.h"
73 #include "content/public/test/ppapi_test_utils.h"
76 #if defined(OS_CHROMEOS)
77 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
78 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
81 // For fine-grained suppression on flaky tests.
83 #include "base/win/windows_version.h"
86 using extensions::ContextMenuMatcher
;
87 using extensions::ExtensionsAPIClient
;
88 using extensions::MenuItem
;
89 using guest_view::GuestViewManager
;
90 using guest_view::TestGuestViewManager
;
91 using guest_view::TestGuestViewManagerFactory
;
92 using prerender::PrerenderLinkManager
;
93 using prerender::PrerenderLinkManagerFactory
;
94 using task_manager::browsertest_util::MatchAboutBlankTab
;
95 using task_manager::browsertest_util::MatchAnyApp
;
96 using task_manager::browsertest_util::MatchAnyBackground
;
97 using task_manager::browsertest_util::MatchAnyTab
;
98 using task_manager::browsertest_util::MatchAnyWebView
;
99 using task_manager::browsertest_util::MatchApp
;
100 using task_manager::browsertest_util::MatchBackground
;
101 using task_manager::browsertest_util::MatchWebView
;
102 using task_manager::browsertest_util::WaitForTaskManagerRows
;
106 const char kEmptyResponsePath
[] = "/close-socket";
107 const char kRedirectResponsePath
[] = "/server-redirect";
108 const char kUserAgentRedirectResponsePath
[] = "/detect-user-agent";
109 const char kCacheResponsePath
[] = "/cache-control-response";
110 const char kRedirectResponseFullPath
[] =
111 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
113 class EmptyHttpResponse
: public net::test_server::HttpResponse
{
115 std::string
ToResponseString() const override
{ return std::string(); }
118 class TestInterstitialPageDelegate
: public content::InterstitialPageDelegate
{
120 TestInterstitialPageDelegate() {
122 ~TestInterstitialPageDelegate() override
{}
123 std::string
GetHTMLContents() override
{ return std::string(); }
126 class WebContentsHiddenObserver
: public content::WebContentsObserver
{
128 WebContentsHiddenObserver(content::WebContents
* web_contents
,
129 const base::Closure
& hidden_callback
)
130 : WebContentsObserver(web_contents
),
131 hidden_callback_(hidden_callback
),
132 hidden_observed_(false) {
135 // WebContentsObserver.
136 void WasHidden() override
{
137 hidden_observed_
= true;
138 hidden_callback_
.Run();
141 bool hidden_observed() { return hidden_observed_
; }
144 base::Closure hidden_callback_
;
145 bool hidden_observed_
;
147 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver
);
150 // Watches for context menu to be shown, records count of how many times
151 // context menu was shown.
152 class ContextMenuCallCountObserver
{
154 ContextMenuCallCountObserver()
155 : num_times_shown_(0),
156 menu_observer_(chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
,
157 base::Bind(&ContextMenuCallCountObserver::OnMenuShown
,
158 base::Unretained(this))) {
160 ~ContextMenuCallCountObserver() {}
162 bool OnMenuShown(const content::NotificationSource
& source
,
163 const content::NotificationDetails
& details
) {
165 auto context_menu
= content::Source
<RenderViewContextMenu
>(source
).ptr();
166 base::ThreadTaskRunnerHandle::Get()->PostTask(
167 FROM_HERE
, base::Bind(&RenderViewContextMenuBase::Cancel
,
168 base::Unretained(context_menu
)));
172 void Wait() { menu_observer_
.Wait(); }
174 int num_times_shown() { return num_times_shown_
; }
177 int num_times_shown_
;
178 content::WindowedNotificationObserver menu_observer_
;
180 DISALLOW_COPY_AND_ASSIGN(ContextMenuCallCountObserver
);
183 class EmbedderWebContentsObserver
: public content::WebContentsObserver
{
185 explicit EmbedderWebContentsObserver(content::WebContents
* web_contents
)
186 : WebContentsObserver(web_contents
), terminated_(false) {}
188 // WebContentsObserver.
189 void RenderProcessGone(base::TerminationStatus status
) override
{
191 if (message_loop_runner_
.get())
192 message_loop_runner_
->Quit();
195 void WaitForEmbedderRenderProcessTerminate() {
198 message_loop_runner_
= new content::MessageLoopRunner
;
199 message_loop_runner_
->Run();
204 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
206 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver
);
209 void ExecuteScriptWaitForTitle(content::WebContents
* web_contents
,
212 base::string16
expected_title(base::ASCIIToUTF16(title
));
213 base::string16
error_title(base::ASCIIToUTF16("error"));
215 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
216 title_watcher
.AlsoWaitForTitle(error_title
);
217 EXPECT_TRUE(content::ExecuteScript(web_contents
, script
));
218 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
221 #if defined (USE_AURA)
222 views::View
* FindWebView(views::View
* view
) {
223 std::queue
<views::View
*> queue
;
225 while (!queue
.empty()) {
226 views::View
* current
= queue
.front();
228 if (std::string(current
->GetClassName()).find("WebView") !=
233 for (int i
= 0; i
< current
->child_count(); ++i
)
234 queue
.push(current
->child_at(i
));
242 // This class intercepts media access request from the embedder. The request
243 // should be triggered only if the embedder API (from tests) allows the request
245 // We do not issue the actual media request; the fact that the request reached
246 // embedder's WebContents is good enough for our tests. This is also to make
247 // the test run successfully on trybots.
248 class MockWebContentsDelegate
: public content::WebContentsDelegate
{
250 MockWebContentsDelegate()
253 ~MockWebContentsDelegate() override
{}
255 void RequestMediaAccessPermission(
256 content::WebContents
* web_contents
,
257 const content::MediaStreamRequest
& request
,
258 const content::MediaResponseCallback
& callback
) override
{
260 if (request_message_loop_runner_
.get())
261 request_message_loop_runner_
->Quit();
264 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
265 const GURL
& security_origin
,
266 content::MediaStreamType type
) override
{
268 if (check_message_loop_runner_
.get())
269 check_message_loop_runner_
->Quit();
273 void WaitForRequestMediaPermission() {
276 request_message_loop_runner_
= new content::MessageLoopRunner
;
277 request_message_loop_runner_
->Run();
280 void WaitForCheckMediaPermission() {
283 check_message_loop_runner_
= new content::MessageLoopRunner
;
284 check_message_loop_runner_
->Run();
290 scoped_refptr
<content::MessageLoopRunner
> request_message_loop_runner_
;
291 scoped_refptr
<content::MessageLoopRunner
> check_message_loop_runner_
;
293 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate
);
296 // This class intercepts download request from the guest.
297 class MockDownloadWebContentsDelegate
: public content::WebContentsDelegate
{
299 explicit MockDownloadWebContentsDelegate(
300 content::WebContentsDelegate
* orig_delegate
)
301 : orig_delegate_(orig_delegate
),
302 waiting_for_decision_(false),
303 expect_allow_(false),
304 decision_made_(false),
305 last_download_allowed_(false) {}
306 ~MockDownloadWebContentsDelegate() override
{}
308 void CanDownload(const GURL
& url
,
309 const std::string
& request_method
,
310 const base::Callback
<void(bool)>& callback
) override
{
311 orig_delegate_
->CanDownload(
313 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided
,
314 base::Unretained(this)));
317 void WaitForCanDownload(bool expect_allow
) {
318 EXPECT_FALSE(waiting_for_decision_
);
319 waiting_for_decision_
= true;
321 if (decision_made_
) {
322 EXPECT_EQ(expect_allow
, last_download_allowed_
);
326 expect_allow_
= expect_allow
;
327 message_loop_runner_
= new content::MessageLoopRunner
;
328 message_loop_runner_
->Run();
331 void DownloadDecided(bool allow
) {
332 EXPECT_FALSE(decision_made_
);
333 decision_made_
= true;
335 if (waiting_for_decision_
) {
336 EXPECT_EQ(expect_allow_
, allow
);
337 if (message_loop_runner_
.get())
338 message_loop_runner_
->Quit();
341 last_download_allowed_
= allow
;
345 waiting_for_decision_
= false;
346 decision_made_
= false;
350 content::WebContentsDelegate
* orig_delegate_
;
351 bool waiting_for_decision_
;
354 bool last_download_allowed_
;
355 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
357 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate
);
360 // TODO(wjmaclean): Fix this test class at some point so it can be re-enabled on
361 // the site isolation bots, and then look at re-enabling WebViewFocusTest when
363 // https://crbug.com/503751
364 class WebViewTest
: public extensions::PlatformAppBrowserTest
{
366 void SetUp() override
{
367 if (UsesFakeSpeech()) {
368 // SpeechRecognition test specific SetUp.
369 fake_speech_recognition_manager_
.reset(
370 new content::FakeSpeechRecognitionManager());
371 fake_speech_recognition_manager_
->set_should_send_fake_response(true);
372 // Inject the fake manager factory so that the test result is returned to
374 content::SpeechRecognitionManager::SetManagerForTesting(
375 fake_speech_recognition_manager_
.get());
377 extensions::PlatformAppBrowserTest::SetUp();
380 void TearDown() override
{
381 if (UsesFakeSpeech()) {
382 // SpeechRecognition test specific TearDown.
383 content::SpeechRecognitionManager::SetManagerForTesting(NULL
);
386 extensions::PlatformAppBrowserTest::TearDown();
389 void SetUpOnMainThread() override
{
390 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
391 const testing::TestInfo
* const test_info
=
392 testing::UnitTest::GetInstance()->current_test_info();
393 // Mock out geolocation for geolocation specific tests.
394 if (!strncmp(test_info
->name(), "GeolocationAPI",
395 strlen("GeolocationAPI"))) {
396 ui_test_utils::OverrideGeolocation(10, 20);
400 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
401 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
402 command_line
->AppendSwitchASCII(switches::kJavaScriptFlags
, "--expose-gc");
404 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
407 // Handles |request| by serving a redirect response if the |User-Agent| is
409 static scoped_ptr
<net::test_server::HttpResponse
> UserAgentResponseHandler(
410 const std::string
& path
,
411 const GURL
& redirect_target
,
412 const net::test_server::HttpRequest
& request
) {
413 if (!base::StartsWith(path
, request
.relative_url
,
414 base::CompareCase::SENSITIVE
))
415 return scoped_ptr
<net::test_server::HttpResponse
>();
417 std::map
<std::string
, std::string
>::const_iterator it
=
418 request
.headers
.find("User-Agent");
419 EXPECT_TRUE(it
!= request
.headers
.end());
420 if (!base::StartsWith("foobar", it
->second
,
421 base::CompareCase::SENSITIVE
))
422 return scoped_ptr
<net::test_server::HttpResponse
>();
424 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
425 new net::test_server::BasicHttpResponse
);
426 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
427 http_response
->AddCustomHeader("Location", redirect_target
.spec());
428 return http_response
.Pass();
431 // Handles |request| by serving a redirect response.
432 static scoped_ptr
<net::test_server::HttpResponse
> RedirectResponseHandler(
433 const std::string
& path
,
434 const GURL
& redirect_target
,
435 const net::test_server::HttpRequest
& request
) {
436 if (!base::StartsWith(path
, request
.relative_url
,
437 base::CompareCase::SENSITIVE
))
438 return scoped_ptr
<net::test_server::HttpResponse
>();
440 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
441 new net::test_server::BasicHttpResponse
);
442 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
443 http_response
->AddCustomHeader("Location", redirect_target
.spec());
444 return http_response
.Pass();
447 // Handles |request| by serving an empty response.
448 static scoped_ptr
<net::test_server::HttpResponse
> EmptyResponseHandler(
449 const std::string
& path
,
450 const net::test_server::HttpRequest
& request
) {
451 if (base::StartsWith(path
, request
.relative_url
,
452 base::CompareCase::SENSITIVE
))
453 return scoped_ptr
<net::test_server::HttpResponse
>(new EmptyHttpResponse
);
455 return scoped_ptr
<net::test_server::HttpResponse
>();
458 // Handles |request| by serving cache-able response.
459 static scoped_ptr
<net::test_server::HttpResponse
> CacheControlResponseHandler(
460 const std::string
& path
,
461 const net::test_server::HttpRequest
& request
) {
462 if (!base::StartsWith(path
, request
.relative_url
,
463 base::CompareCase::SENSITIVE
))
464 return scoped_ptr
<net::test_server::HttpResponse
>();
466 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
467 new net::test_server::BasicHttpResponse
);
468 http_response
->AddCustomHeader("Cache-control", "max-age=3600");
469 http_response
->set_content_type("text/plain");
470 http_response
->set_content("dummy text");
471 return http_response
.Pass();
474 // Shortcut to return the current MenuManager.
475 extensions::MenuManager
* menu_manager() {
476 return extensions::MenuManager::Get(browser()->profile());
479 // This gets all the items that any extension has registered for possible
480 // inclusion in context menus.
481 MenuItem::List
GetItems() {
482 MenuItem::List result
;
483 std::set
<MenuItem::ExtensionKey
> extension_ids
=
484 menu_manager()->ExtensionIds();
485 std::set
<MenuItem::ExtensionKey
>::iterator i
;
486 for (i
= extension_ids
.begin(); i
!= extension_ids
.end(); ++i
) {
487 const MenuItem::List
* list
= menu_manager()->MenuItems(*i
);
488 result
.insert(result
.end(), list
->begin(), list
->end());
498 void TestHelper(const std::string
& test_name
,
499 const std::string
& app_location
,
500 TestServer test_server
) {
501 // For serving guest pages.
502 if (test_server
== NEEDS_TEST_SERVER
) {
503 if (!StartEmbeddedTestServer()) {
504 LOG(ERROR
) << "FAILED TO START TEST SERVER.";
507 embedded_test_server()->RegisterRequestHandler(
508 base::Bind(&WebViewTest::RedirectResponseHandler
,
509 kRedirectResponsePath
,
510 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
512 embedded_test_server()->RegisterRequestHandler(
513 base::Bind(&WebViewTest::EmptyResponseHandler
, kEmptyResponsePath
));
515 embedded_test_server()->RegisterRequestHandler(
517 &WebViewTest::UserAgentResponseHandler
,
518 kUserAgentRedirectResponsePath
,
519 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
521 embedded_test_server()->RegisterRequestHandler(base::Bind(
522 &WebViewTest::CacheControlResponseHandler
, kCacheResponsePath
));
525 LoadAndLaunchPlatformApp(app_location
.c_str(), "Launched");
527 // Flush any pending events to make sure we start with a clean slate.
528 content::RunAllPendingInMessageLoop();
530 content::WebContents
* embedder_web_contents
=
531 GetFirstAppWindowWebContents();
532 if (!embedder_web_contents
) {
533 LOG(ERROR
) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
537 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
538 done_listener
.set_failure_message("TEST_FAILED");
539 if (!content::ExecuteScript(
540 embedder_web_contents
,
541 base::StringPrintf("runTest('%s')", test_name
.c_str()))) {
542 LOG(ERROR
) << "UNABLE TO START TEST.";
545 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
548 content::WebContents
* LoadGuest(const std::string
& guest_path
,
549 const std::string
& app_path
) {
550 GURL::Replacements replace_host
;
551 replace_host
.SetHostStr("localhost");
553 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
554 guest_url
= guest_url
.ReplaceComponents(replace_host
);
556 ui_test_utils::UrlLoadObserver
guest_observer(
557 guest_url
, content::NotificationService::AllSources());
559 LoadAndLaunchPlatformApp(app_path
.c_str(), "guest-loaded");
561 guest_observer
.Wait();
562 content::Source
<content::NavigationController
> source
=
563 guest_observer
.source();
564 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
567 content::WebContents
* guest_web_contents
= source
->GetWebContents();
568 return guest_web_contents
;
571 // Helper to load interstitial page in a <webview>.
572 void InterstitialTeardownTestHelper() {
573 // Start a HTTPS server so we can load an interstitial page inside guest.
574 net::SpawnedTestServer::SSLOptions ssl_options
;
575 ssl_options
.server_certificate
=
576 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME
;
577 net::SpawnedTestServer
https_server(
578 net::SpawnedTestServer::TYPE_HTTPS
, ssl_options
,
579 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
580 ASSERT_TRUE(https_server
.Start());
582 net::HostPortPair host_and_port
= https_server
.host_port_pair();
584 LoadAndLaunchPlatformApp("web_view/interstitial_teardown",
587 // Now load the guest.
588 content::WebContents
* embedder_web_contents
=
589 GetFirstAppWindowWebContents();
590 ExtensionTestMessageListener
second("GuestAddedToDom", false);
591 EXPECT_TRUE(content::ExecuteScript(
592 embedder_web_contents
,
593 base::StringPrintf("loadGuest(%d);\n", host_and_port
.port())));
594 ASSERT_TRUE(second
.WaitUntilSatisfied());
596 // Wait for interstitial page to be shown in guest.
597 content::WebContents
* guest_web_contents
=
598 GetGuestViewManager()->WaitForSingleGuestCreated();
599 ASSERT_TRUE(guest_web_contents
->GetRenderProcessHost()->IsForGuestsOnly());
600 content::WaitForInterstitialAttach(guest_web_contents
);
603 // Runs media_access/allow tests.
604 void MediaAccessAPIAllowTestHelper(const std::string
& test_name
);
606 // Runs media_access/deny tests, each of them are run separately otherwise
607 // they timeout (mostly on Windows).
608 void MediaAccessAPIDenyTestHelper(const std::string
& test_name
) {
609 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
610 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
612 content::WebContents
* embedder_web_contents
=
613 GetFirstAppWindowWebContents();
614 ASSERT_TRUE(embedder_web_contents
);
616 ExtensionTestMessageListener
test_run_listener("PASSED", false);
617 test_run_listener
.set_failure_message("FAILED");
619 content::ExecuteScript(
620 embedder_web_contents
,
621 base::StringPrintf("startDenyTest('%s')", test_name
.c_str())));
622 ASSERT_TRUE(test_run_listener
.WaitUntilSatisfied());
625 // Loads an app with a <webview> in it, returns once a guest is created.
626 void LoadAppWithGuest(const std::string
& app_path
) {
627 ExtensionTestMessageListener
launched_listener("WebViewTest.LAUNCHED",
629 launched_listener
.set_failure_message("WebViewTest.FAILURE");
630 LoadAndLaunchPlatformApp(app_path
.c_str(), &launched_listener
);
632 guest_web_contents_
= GetGuestViewManager()->WaitForSingleGuestCreated();
635 void SendMessageToEmbedder(const std::string
& message
) {
637 content::ExecuteScript(
638 GetEmbedderWebContents(),
639 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
642 void SendMessageToGuestAndWait(const std::string
& message
,
643 const std::string
& wait_message
) {
644 scoped_ptr
<ExtensionTestMessageListener
> listener
;
645 if (!wait_message
.empty()) {
646 listener
.reset(new ExtensionTestMessageListener(wait_message
, false));
650 content::ExecuteScript(
651 GetGuestWebContents(),
652 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
655 ASSERT_TRUE(listener
->WaitUntilSatisfied());
659 void OpenContextMenu(content::WebContents
* web_contents
) {
660 blink::WebMouseEvent mouse_event
;
661 mouse_event
.type
= blink::WebInputEvent::MouseDown
;
662 mouse_event
.button
= blink::WebMouseEvent::ButtonRight
;
665 web_contents
->GetRenderViewHost()->ForwardMouseEvent(mouse_event
);
666 mouse_event
.type
= blink::WebInputEvent::MouseUp
;
667 web_contents
->GetRenderViewHost()->ForwardMouseEvent(mouse_event
);
670 content::WebContents
* GetGuestWebContents() {
671 return guest_web_contents_
;
674 content::WebContents
* GetEmbedderWebContents() {
675 if (!embedder_web_contents_
) {
676 embedder_web_contents_
= GetFirstAppWindowWebContents();
678 return embedder_web_contents_
;
681 TestGuestViewManager
* GetGuestViewManager() {
682 TestGuestViewManager
* manager
= static_cast<TestGuestViewManager
*>(
683 TestGuestViewManager::FromBrowserContext(browser()->profile()));
684 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called
685 // before a guest is created.
687 manager
= static_cast<TestGuestViewManager
*>(
688 GuestViewManager::CreateWithDelegate(
689 browser()->profile(),
690 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(
691 browser()->profile())));
696 WebViewTest() : guest_web_contents_(NULL
),
697 embedder_web_contents_(NULL
) {
698 GuestViewManager::set_factory_for_testing(&factory_
);
702 scoped_refptr
<content::FrameWatcher
> frame_watcher_
;
705 bool UsesFakeSpeech() {
706 const testing::TestInfo
* const test_info
=
707 testing::UnitTest::GetInstance()->current_test_info();
709 // SpeechRecognition test specific SetUp.
710 return !strcmp(test_info
->name(),
711 "SpeechRecognitionAPI_HasPermissionAllow");
714 scoped_ptr
<content::FakeSpeechRecognitionManager
>
715 fake_speech_recognition_manager_
;
717 TestGuestViewManagerFactory factory_
;
718 // Note that these are only set if you launch app using LoadAppWithGuest().
719 content::WebContents
* guest_web_contents_
;
720 content::WebContents
* embedder_web_contents_
;
723 // The following test suits are created to group tests based on specific
724 // features of <webview>.
725 // These features current would not work with --site-per-process and is
726 // disabled on site isolation FYI bots.
727 class WebViewNewWindowTest
: public WebViewTest
{};
728 class WebViewSizeTest
: public WebViewTest
{};
729 class WebViewSpeechAPITest
: public WebViewTest
{};
730 class WebViewVisibilityTest
: public WebViewTest
{};
732 // Test suite that containts tests that are meant to run with and without
733 // --site-per-process.
734 class WebViewCommonTest
: public extensions::PlatformAppBrowserTest
{};
736 class WebViewDPITest
: public WebViewTest
{
738 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
739 WebViewTest::SetUpCommandLine(command_line
);
740 command_line
->AppendSwitchASCII(switches::kForceDeviceScaleFactor
,
741 base::StringPrintf("%f", scale()));
744 static float scale() { return 2.0f
; }
747 // This test verifies that hiding the guest triggers WebContents::WasHidden().
748 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest
, GuestVisibilityChanged
) {
749 LoadAppWithGuest("web_view/visibility_changed");
751 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
752 new content::MessageLoopRunner
);
753 WebContentsHiddenObserver
observer(GetGuestWebContents(),
754 loop_runner
->QuitClosure());
756 // Handled in platform_apps/web_view/visibility_changed/main.js
757 SendMessageToEmbedder("hide-guest");
758 if (!observer
.hidden_observed())
762 // This test verifies that hiding the embedder also hides the guest.
763 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest
, EmbedderVisibilityChanged
) {
764 LoadAppWithGuest("web_view/visibility_changed");
766 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
767 new content::MessageLoopRunner
);
768 WebContentsHiddenObserver
observer(GetGuestWebContents(),
769 loop_runner
->QuitClosure());
771 // Handled in platform_apps/web_view/visibility_changed/main.js
772 SendMessageToEmbedder("hide-embedder");
773 if (!observer
.hidden_observed())
777 // This test verifies that reloading the embedder reloads the guest (and doest
779 IN_PROC_BROWSER_TEST_F(WebViewTest
, ReloadEmbedder
) {
780 // Just load a guest from other test, we do not want to add a separate
781 // platform_app for this test.
782 LoadAppWithGuest("web_view/visibility_changed");
784 ExtensionTestMessageListener
launched_again_listener("WebViewTest.LAUNCHED",
786 GetEmbedderWebContents()->GetController().Reload(false);
787 ASSERT_TRUE(launched_again_listener
.WaitUntilSatisfied());
790 IN_PROC_BROWSER_TEST_F(WebViewTest
, AcceptTouchEvents
) {
791 LoadAppWithGuest("web_view/accept_touch_events");
793 content::RenderViewHost
* embedder_rvh
=
794 GetEmbedderWebContents()->GetRenderViewHost();
796 bool embedder_has_touch_handler
=
797 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
798 EXPECT_FALSE(embedder_has_touch_handler
);
800 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
802 // Note that we need to wait for the installed/registered touch handler to
803 // appear in browser process before querying |embedder_rvh|.
804 // In practice, since we do a roundrtip from browser process to guest and
805 // back, this is sufficient.
806 embedder_has_touch_handler
=
807 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
808 EXPECT_TRUE(embedder_has_touch_handler
);
810 SendMessageToGuestAndWait("uninstall-touch-handler",
811 "uninstalled-touch-handler");
812 // Same as the note above about waiting.
813 embedder_has_touch_handler
=
814 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
815 EXPECT_FALSE(embedder_has_touch_handler
);
818 // This test ensures JavaScript errors ("Cannot redefine property") do not
819 // happen when a <webview> is removed from DOM and added back.
820 IN_PROC_BROWSER_TEST_F(WebViewTest
,
821 AddRemoveWebView_AddRemoveWebView
) {
822 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
823 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
827 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
, AutoSize
) {
829 // Flaky on XP bot http://crbug.com/299507
830 if (base::win::GetVersion() <= base::win::VERSION_XP
)
834 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
838 // Test for http://crbug.com/419611.
839 IN_PROC_BROWSER_TEST_F(WebViewTest
, DisplayNoneSetSrc
) {
840 LoadAndLaunchPlatformApp("web_view/display_none_set_src",
841 "WebViewTest.LAUNCHED");
842 // Navigate the guest while it's in "display: none" state.
843 SendMessageToEmbedder("navigate-guest");
844 GetGuestViewManager()->WaitForSingleGuestCreated();
846 // Now attempt to navigate the guest again.
847 SendMessageToEmbedder("navigate-guest");
849 ExtensionTestMessageListener
test_passed_listener("WebViewTest.PASSED",
851 // Making the guest visible would trigger loadstop.
852 SendMessageToEmbedder("show-guest");
853 EXPECT_TRUE(test_passed_listener
.WaitUntilSatisfied());
856 // Checks that {allFrames: true} injects script correctly to subframes
858 IN_PROC_BROWSER_TEST_F(WebViewTest
, ExecuteScript
) {
859 ASSERT_TRUE(RunPlatformAppTestWithArg(
860 "platform_apps/web_view/common", "execute_script")) << message_
;
863 // http://crbug.com/326332
864 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
,
865 DISABLED_Shim_TestAutosizeAfterNavigation
) {
866 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER
);
869 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAllowTransparencyAttribute
) {
870 TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER
);
873 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeHeight
) {
874 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER
);
877 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
, Shim_TestAutosizeHeight
) {
878 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER
);
881 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeBeforeNavigation
) {
882 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
885 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
, Shim_TestAutosizeBeforeNavigation
) {
886 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
889 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeRemoveAttributes
) {
890 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
893 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
, Shim_TestAutosizeRemoveAttributes
) {
894 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
897 // This test is disabled due to being flaky. http://crbug.com/282116
898 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
,
899 DISABLED_Shim_TestAutosizeWithPartialAttributes
) {
900 TestHelper("testAutosizeWithPartialAttributes",
905 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAPIMethodExistence
) {
906 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER
);
909 // Tests the existence of WebRequest API event objects on the request
910 // object, on the webview element, and hanging directly off webview.
911 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIExistence
) {
912 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER
);
915 // http://crbug.com/315920
916 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
917 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
919 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
921 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_Shim_TestChromeExtensionURL
) {
922 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
925 // http://crbug.com/315920
926 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
927 #define MAYBE_Shim_TestChromeExtensionRelativePath \
928 DISABLED_Shim_TestChromeExtensionRelativePath
930 #define MAYBE_Shim_TestChromeExtensionRelativePath \
931 Shim_TestChromeExtensionRelativePath
933 IN_PROC_BROWSER_TEST_F(WebViewTest
,
934 MAYBE_Shim_TestChromeExtensionRelativePath
) {
935 TestHelper("testChromeExtensionRelativePath",
940 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewLoad
) {
941 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER
);
944 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewRemoveChild
) {
945 TestHelper("testDisplayNoneWebviewRemoveChild",
946 "web_view/shim", NO_TEST_SERVER
);
949 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayBlock
) {
950 TestHelper("testDisplayBlock", "web_view/shim", NO_TEST_SERVER
);
953 IN_PROC_BROWSER_TEST_F(WebViewTest
,
954 Shim_TestInlineScriptFromAccessibleResources
) {
955 TestHelper("testInlineScriptFromAccessibleResources",
960 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestInvalidChromeExtensionURL
) {
961 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
964 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestEventName
) {
965 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER
);
968 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestOnEventProperty
) {
969 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER
);
972 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadProgressEvent
) {
973 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER
);
976 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDestroyOnEventListener
) {
977 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER
);
980 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestCannotMutateEventName
) {
981 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER
);
984 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestPartitionChangeAfterNavigation
) {
985 TestHelper("testPartitionChangeAfterNavigation",
990 IN_PROC_BROWSER_TEST_F(WebViewTest
,
991 Shim_TestPartitionRemovalAfterNavigationFails
) {
992 TestHelper("testPartitionRemovalAfterNavigationFails",
997 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAddContentScript
) {
998 TestHelper("testAddContentScript", "web_view/shim", NEEDS_TEST_SERVER
);
1001 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAddMultipleContentScripts
) {
1002 TestHelper("testAddMultipleContentScripts", "web_view/shim",
1006 IN_PROC_BROWSER_TEST_F(
1008 Shim_TestAddContentScriptWithSameNameShouldOverwriteTheExistingOne
) {
1009 TestHelper("testAddContentScriptWithSameNameShouldOverwriteTheExistingOne",
1010 "web_view/shim", NEEDS_TEST_SERVER
);
1013 IN_PROC_BROWSER_TEST_F(
1015 Shim_TestAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView
) {
1016 TestHelper("testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView",
1017 "web_view/shim", NEEDS_TEST_SERVER
);
1020 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAddAndRemoveContentScripts
) {
1021 TestHelper("testAddAndRemoveContentScripts", "web_view/shim",
1025 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
,
1026 Shim_TestAddContentScriptsWithNewWindowAPI
) {
1027 TestHelper("testAddContentScriptsWithNewWindowAPI", "web_view/shim",
1031 IN_PROC_BROWSER_TEST_F(
1033 Shim_TestContentScriptIsInjectedAfterTerminateAndReloadWebView
) {
1034 TestHelper("testContentScriptIsInjectedAfterTerminateAndReloadWebView",
1035 "web_view/shim", NEEDS_TEST_SERVER
);
1038 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1039 Shim_TestContentScriptExistsAsLongAsWebViewTagExists
) {
1040 TestHelper("testContentScriptExistsAsLongAsWebViewTagExists", "web_view/shim",
1044 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAddContentScriptWithCode
) {
1045 TestHelper("testAddContentScriptWithCode", "web_view/shim",
1049 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScriptFail
) {
1051 // Flaky on XP bot http://crbug.com/266185
1052 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1056 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER
);
1059 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScript
) {
1060 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER
);
1063 IN_PROC_BROWSER_TEST_F(
1065 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged
) {
1066 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
1071 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestTerminateAfterExit
) {
1072 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER
);
1075 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAssignSrcAfterCrash
) {
1076 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER
);
1079 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1080 Shim_TestNavOnConsecutiveSrcAttributeChanges
) {
1081 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
1086 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavOnSrcAttributeChange
) {
1087 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER
);
1090 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigateAfterResize
) {
1091 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER
);
1094 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNestedCrossOriginSubframes
) {
1095 TestHelper("testNestedCrossOriginSubframes",
1096 "web_view/shim", NEEDS_TEST_SERVER
);
1099 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNestedSubframes
) {
1100 TestHelper("testNestedSubframes", "web_view/shim", NO_TEST_SERVER
);
1103 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveSrcAttribute
) {
1104 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1107 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReassignSrcAttribute
) {
1108 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1111 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
, Shim_TestNewWindow
) {
1112 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER
);
1115 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
, Shim_TestNewWindowTwoListeners
) {
1116 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER
);
1119 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
,
1120 Shim_TestNewWindowNoPreventDefault
) {
1121 TestHelper("testNewWindowNoPreventDefault",
1126 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
, Shim_TestNewWindowNoReferrerLink
) {
1127 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER
);
1130 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestContentLoadEvent
) {
1131 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER
);
1134 // TODO(fsamuel): Enable this test once <webview> can run in a detached state.
1135 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1136 Shim_TestContentLoadEventWithDisplayNone
) {
1137 TestHelper("testContentLoadEventWithDisplayNone",
1142 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDeclarativeWebRequestAPI
) {
1143 TestHelper("testDeclarativeWebRequestAPI",
1148 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1149 Shim_TestDeclarativeWebRequestAPISendMessage
) {
1150 TestHelper("testDeclarativeWebRequestAPISendMessage",
1155 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPI
) {
1156 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER
);
1159 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIWithHeaders
) {
1160 TestHelper("testWebRequestAPIWithHeaders",
1165 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIGoogleProperty
) {
1166 TestHelper("testWebRequestAPIGoogleProperty",
1171 IN_PROC_BROWSER_TEST_F(
1172 WebViewTest
, Shim_TestWebRequestListenerSurvivesReparenting
) {
1174 // Flaky on XP bot http://crbug.com/309451.
1175 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1179 TestHelper("testWebRequestListenerSurvivesReparenting",
1184 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadStartLoadRedirect
) {
1185 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER
);
1188 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1189 Shim_TestLoadAbortChromeExtensionURLWrongPartition
) {
1190 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1195 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortEmptyResponse
) {
1196 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER
);
1199 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalChromeURL
) {
1200 TestHelper("testLoadAbortIllegalChromeURL",
1205 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalFileURL
) {
1206 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER
);
1209 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalJavaScriptURL
) {
1210 TestHelper("testLoadAbortIllegalJavaScriptURL",
1215 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortInvalidNavigation
) {
1216 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER
);
1219 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortNonWebSafeScheme
) {
1220 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER
);
1223 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReload
) {
1224 TestHelper("testReload", "web_view/shim", NO_TEST_SERVER
);
1227 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReloadAfterTerminate
) {
1228 TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER
);
1231 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestGetProcessId
) {
1232 TestHelper("testGetProcessId", "web_view/shim", NO_TEST_SERVER
);
1235 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest
, Shim_TestHiddenBeforeNavigation
) {
1236 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
1239 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewOnExit
) {
1240 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1242 // Launch the app and wait until it's ready to load a test.
1243 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1245 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1246 ASSERT_TRUE(embedder_web_contents
);
1248 GURL::Replacements replace_host
;
1249 replace_host
.SetHostStr("localhost");
1251 std::string
guest_path(
1252 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1253 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
1254 guest_url
= guest_url
.ReplaceComponents(replace_host
);
1256 ui_test_utils::UrlLoadObserver
guest_observer(
1257 guest_url
, content::NotificationService::AllSources());
1259 // Run the test and wait until the guest WebContents is available and has
1260 // finished loading.
1261 ExtensionTestMessageListener
guest_loaded_listener("guest-loaded", false);
1262 EXPECT_TRUE(content::ExecuteScript(
1263 embedder_web_contents
,
1264 "runTest('testRemoveWebviewOnExit')"));
1265 guest_observer
.Wait();
1267 content::Source
<content::NavigationController
> source
=
1268 guest_observer
.source();
1269 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
1272 ASSERT_TRUE(guest_loaded_listener
.WaitUntilSatisfied());
1274 content::WebContentsDestroyedWatcher
destroyed_watcher(
1275 source
->GetWebContents());
1277 // Tell the embedder to kill the guest.
1278 EXPECT_TRUE(content::ExecuteScript(
1279 embedder_web_contents
,
1280 "removeWebviewOnExitDoCrash();"));
1282 // Wait until the guest WebContents is destroyed.
1283 destroyed_watcher
.Wait();
1286 // Remove <webview> immediately after navigating it.
1287 // This is a regression test for http://crbug.com/276023.
1288 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewAfterNavigation
) {
1289 TestHelper("testRemoveWebviewAfterNavigation",
1294 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigationToExternalProtocol
) {
1295 TestHelper("testNavigationToExternalProtocol",
1300 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
,
1301 Shim_TestResizeWebviewWithDisplayNoneResizesContent
) {
1302 TestHelper("testResizeWebviewWithDisplayNoneResizesContent",
1307 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
, Shim_TestResizeWebviewResizesContent
) {
1308 TestHelper("testResizeWebviewResizesContent",
1313 // This test makes sure the browser process does not crash if app is closed
1314 // while an interstitial page is being shown in guest.
1315 IN_PROC_BROWSER_TEST_F(WebViewTest
, InterstitialTeardown
) {
1317 // Flaky on XP bot http://crbug.com/297014
1318 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1322 InterstitialTeardownTestHelper();
1324 // Now close the app while interstitial page being shown in guest.
1325 extensions::AppWindow
* window
= GetFirstAppWindow();
1326 window
->GetBaseWindow()->Close();
1329 // This test makes sure the browser process does not crash if browser is shut
1330 // down while an interstitial page is being shown in guest.
1331 IN_PROC_BROWSER_TEST_F(WebViewTest
, InterstitialTeardownOnBrowserShutdown
) {
1333 // http://crbug.com/297014
1334 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1338 InterstitialTeardownTestHelper();
1340 // Now close the app while interstitial page being shown in guest.
1341 extensions::AppWindow
* window
= GetFirstAppWindow();
1342 window
->GetBaseWindow()->Close();
1344 // InterstitialPage is not destroyed immediately, so the
1345 // RenderWidgetHostViewGuest for it is still there, closing all
1346 // renderer processes will cause the RWHVGuest's RenderProcessGone()
1347 // shutdown path to be exercised.
1348 chrome::CloseAllBrowsers();
1351 IN_PROC_BROWSER_TEST_F(WebViewTest
, ShimSrcAttribute
) {
1352 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1356 // This test verifies that prerendering has been disabled inside <webview>.
1357 // This test is here rather than in PrerenderBrowserTest for testing convenience
1358 // only. If it breaks then this is a bug in the prerenderer.
1359 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPrerenderer
) {
1360 ASSERT_TRUE(StartEmbeddedTestServer());
1361 content::WebContents
* guest_web_contents
=
1363 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1364 "web_view/noprerenderer");
1365 ASSERT_TRUE(guest_web_contents
!= NULL
);
1367 PrerenderLinkManager
* prerender_link_manager
=
1368 PrerenderLinkManagerFactory::GetForProfile(
1369 Profile::FromBrowserContext(guest_web_contents
->GetBrowserContext()));
1370 ASSERT_TRUE(prerender_link_manager
!= NULL
);
1371 EXPECT_TRUE(prerender_link_manager
->IsEmpty());
1374 // Verify that existing <webview>'s are detected when the task manager starts
1376 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerExistingWebView
) {
1377 // This test is for the old implementation of the task manager. We must
1378 // explicitly disable the new one.
1379 task_manager::browsertest_util::EnableOldTaskManager();
1381 ASSERT_TRUE(StartEmbeddedTestServer());
1383 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1384 "web_view/task_manager");
1386 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1388 const char* guest_title
= "WebViewed test content";
1389 const char* app_name
= "<webview> task manager test";
1390 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1391 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1392 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1393 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1395 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1396 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1397 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1398 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1401 // Verify that the task manager notices the creation of new <webview>'s.
1402 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerNewWebView
) {
1403 // This test is for the old implementation of the task manager. We must
1404 // explicitly disable the new one.
1405 task_manager::browsertest_util::EnableOldTaskManager();
1407 ASSERT_TRUE(StartEmbeddedTestServer());
1409 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1411 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1412 "web_view/task_manager");
1414 const char* guest_title
= "WebViewed test content";
1415 const char* app_name
= "<webview> task manager test";
1416 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1417 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1418 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1419 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1421 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1422 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1423 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1424 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1427 // This tests cookie isolation for packaged apps with webview tags. It navigates
1428 // the main browser window to a page that sets a cookie and loads an app with
1429 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1430 // storage isolation is enforced.
1431 IN_PROC_BROWSER_TEST_F(WebViewTest
, CookieIsolation
) {
1432 ASSERT_TRUE(StartEmbeddedTestServer());
1433 // Navigate the browser to a page which writes a sample cookie
1434 // The cookie is "testCookie=1"
1435 GURL set_cookie_url
= embedded_test_server()->GetURL(
1436 "/extensions/platform_apps/web_view/cookie_isolation/set_cookie.html");
1437 GURL::Replacements replace_host
;
1438 replace_host
.SetHostStr("localhost");
1439 set_cookie_url
= set_cookie_url
.ReplaceComponents(replace_host
);
1441 ui_test_utils::NavigateToURL(browser(), set_cookie_url
);
1442 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/cookie_isolation"))
1444 // Finally, verify that the browser cookie has not changed.
1446 std::string cookie_value
;
1448 ui_test_utils::GetCookies(GURL("http://localhost"),
1449 browser()->tab_strip_model()->GetWebContentsAt(0),
1450 &cookie_size
, &cookie_value
);
1451 EXPECT_EQ("testCookie=1", cookie_value
);
1454 // This tests that in-memory storage partitions are reset on browser restart,
1455 // but persistent ones maintain state for cookies and HTML5 storage.
1456 IN_PROC_BROWSER_TEST_F(WebViewTest
, PRE_StoragePersistence
) {
1457 ASSERT_TRUE(StartEmbeddedTestServer());
1458 // We don't care where the main browser is on this test.
1459 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1460 // Start the app for the pre-test.
1461 LoadAndLaunchPlatformApp("web_view/storage_persistence",
1462 "WebViewTest.LAUNCHED");
1464 // Send a message to run the PRE_StoragePersistence part of the test.
1465 SendMessageToEmbedder("run-pre-test");
1467 ExtensionTestMessageListener
test_passed_listener("WebViewTest.PASSED",
1469 EXPECT_TRUE(test_passed_listener
.WaitUntilSatisfied());
1472 // This is the post-reset portion of the StoragePersistence test. See
1473 // PRE_StoragePersistence for main comment.
1474 IN_PROC_BROWSER_TEST_F(WebViewTest
, StoragePersistence
) {
1475 ASSERT_TRUE(StartEmbeddedTestServer());
1476 // We don't care where the main browser is on this test.
1477 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1478 // Start the app for the pre-test.
1479 LoadAndLaunchPlatformApp("web_view/storage_persistence",
1480 "WebViewTest.LAUNCHED");
1482 // Send a message to run the StoragePersistence part of the test.
1483 SendMessageToEmbedder("run-test");
1485 ExtensionTestMessageListener
test_passed_listener("WebViewTest.PASSED",
1487 EXPECT_TRUE(test_passed_listener
.WaitUntilSatisfied());
1490 // This tests DOM storage isolation for packaged apps with webview tags. It
1491 // loads an app with multiple webview tags and each tag sets DOM storage
1492 // entries, which the test checks to ensure proper storage isolation is
1494 IN_PROC_BROWSER_TEST_F(WebViewTest
, DOMStorageIsolation
) {
1495 ASSERT_TRUE(StartEmbeddedTestServer());
1497 GURL navigate_to_url
= embedded_test_server()->GetURL(
1498 "/extensions/platform_apps/web_view/dom_storage_isolation/page.html");
1499 GURL::Replacements replace_host
;
1500 replace_host
.SetHostStr("localhost");
1501 navigate_to_url
= navigate_to_url
.ReplaceComponents(replace_host
);
1503 ui_test_utils::NavigateToURL(browser(), navigate_to_url
);
1505 RunPlatformAppTest("platform_apps/web_view/dom_storage_isolation"));
1506 // Verify that the browser tab's local/session storage does not have the same
1507 // values which were stored by the webviews.
1509 std::string
get_local_storage(
1510 "window.domAutomationController.send("
1511 "window.localStorage.getItem('foo') || 'badval')");
1512 std::string
get_session_storage(
1513 "window.domAutomationController.send("
1514 "window.localStorage.getItem('baz') || 'badval')");
1515 ASSERT_TRUE(ExecuteScriptAndExtractString(
1516 browser()->tab_strip_model()->GetWebContentsAt(0),
1517 get_local_storage
.c_str(), &output
));
1518 EXPECT_STREQ("badval", output
.c_str());
1519 ASSERT_TRUE(ExecuteScriptAndExtractString(
1520 browser()->tab_strip_model()->GetWebContentsAt(0),
1521 get_session_storage
.c_str(), &output
));
1522 EXPECT_STREQ("badval", output
.c_str());
1525 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1526 // an app with multiple webview tags and each tag creates an IndexedDB record,
1527 // which the test checks to ensure proper storage isolation is enforced.
1528 IN_PROC_BROWSER_TEST_F(WebViewTest
, IndexedDBIsolation
) {
1529 ASSERT_TRUE(StartEmbeddedTestServer());
1530 ASSERT_TRUE(RunPlatformAppTest(
1531 "platform_apps/web_view/isolation_indexeddb")) << message_
;
1534 // This test ensures that closing app window on 'loadcommit' does not crash.
1535 // The test launches an app with guest and closes the window on loadcommit. It
1536 // then launches the app window again. The process is repeated 3 times.
1537 // http://crbug.com/291278
1539 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1541 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1543 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_CloseOnLoadcommit
) {
1544 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1545 "done-close-on-loadcommit");
1548 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIDeny_TestDeny
) {
1549 MediaAccessAPIDenyTestHelper("testDeny");
1552 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1553 MediaAccessAPIDeny_TestDenyThenAllowThrows
) {
1554 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1557 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1558 MediaAccessAPIDeny_TestDenyWithPreventDefault
) {
1559 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1562 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1563 MediaAccessAPIDeny_TestNoListenersImplyDeny
) {
1564 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1567 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1568 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny
) {
1569 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1572 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string
& test_name
) {
1573 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1574 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1576 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1577 ASSERT_TRUE(embedder_web_contents
);
1578 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
1579 embedder_web_contents
->SetDelegate(mock
.get());
1581 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1582 done_listener
.set_failure_message("TEST_FAILED");
1584 content::ExecuteScript(
1585 embedder_web_contents
,
1586 base::StringPrintf("startAllowTest('%s')",
1587 test_name
.c_str())));
1588 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1590 mock
->WaitForRequestMediaPermission();
1593 IN_PROC_BROWSER_TEST_F(WebViewTest
, OpenURLFromTab_CurrentTab_Abort
) {
1594 LoadAppWithGuest("web_view/simple");
1596 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will
1597 // navigate the current <webview>.
1598 ExtensionTestMessageListener
load_listener("WebViewTest.LOADSTOP", false);
1600 // Navigating to a file URL is forbidden inside a <webview>.
1601 content::OpenURLParams
params(GURL("file://foo"),
1602 content::Referrer(),
1604 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
1605 true /* is_renderer_initiated */);
1606 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1607 GetGuestWebContents(), params
);
1609 ASSERT_TRUE(load_listener
.WaitUntilSatisfied());
1611 // Verify that the <webview> ends up at about:blank.
1612 EXPECT_EQ(GURL(url::kAboutBlankURL
),
1613 GetGuestWebContents()->GetLastCommittedURL());
1616 // A navigation to a web-safe URL should succeed, even if it is not renderer-
1617 // initiated, such as a navigation from the PDF viewer.
1618 IN_PROC_BROWSER_TEST_F(WebViewTest
, OpenURLFromTab_CurrentTab_Succeed
) {
1619 LoadAppWithGuest("web_view/simple");
1621 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will
1622 // navigate the current <webview>.
1623 ExtensionTestMessageListener
load_listener("WebViewTest.LOADSTOP", false);
1625 GURL
test_url("http://www.google.com");
1626 content::OpenURLParams
params(test_url
,
1627 content::Referrer(),
1629 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
1630 false /* is_renderer_initiated */);
1631 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1632 GetGuestWebContents(), params
);
1634 ASSERT_TRUE(load_listener
.WaitUntilSatisfied());
1636 EXPECT_EQ(test_url
, GetGuestWebContents()->GetLastCommittedURL());
1639 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
, OpenURLFromTab_NewWindow_Abort
) {
1640 LoadAppWithGuest("web_view/simple");
1642 // Verify that OpenURLFromTab with a window disposition of NEW_BACKGROUND_TAB
1643 // will trigger the <webview>'s New Window API.
1644 ExtensionTestMessageListener
new_window_listener(
1645 "WebViewTest.NEWWINDOW", false);
1647 // Navigating to a file URL is forbidden inside a <webview>.
1648 content::OpenURLParams
params(GURL("file://foo"),
1649 content::Referrer(),
1651 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
1652 true /* is_renderer_initiated */);
1653 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1654 GetGuestWebContents(), params
);
1656 ASSERT_TRUE(new_window_listener
.WaitUntilSatisfied());
1658 // Verify that a new guest was created.
1659 content::WebContents
* new_guest_web_contents
=
1660 GetGuestViewManager()->GetLastGuestCreated();
1661 EXPECT_NE(GetGuestWebContents(), new_guest_web_contents
);
1663 // Verify that the new <webview> guest ends up at about:blank.
1664 EXPECT_EQ(GURL(url::kAboutBlankURL
),
1665 new_guest_web_contents
->GetLastCommittedURL());
1668 // This test executes the context menu command 'LanguageSettings' which will
1669 // load chrome://settings/languages in a browser window. This is a browser-
1670 // initiated operation and so we expect this to succeed if the embedder is
1671 // allowed to perform the operation.
1672 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenuLanguageSettings
) {
1673 LoadAppWithGuest("web_view/context_menus/basic");
1675 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1676 content::WebContents
* embedder
= GetEmbedderWebContents();
1677 ASSERT_TRUE(embedder
);
1679 // Create and build our test context menu.
1680 content::WebContentsAddedObserver web_contents_added_observer
;
1682 GURL
page_url("http://www.google.com");
1683 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1684 guest_web_contents
, page_url
, GURL(), GURL()));
1685 menu
->ExecuteCommand(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS
, 0);
1687 content::WebContents
* new_contents
=
1688 web_contents_added_observer
.GetWebContents();
1690 // Verify that a new WebContents has been created that is at the Language
1692 EXPECT_EQ(GURL("chrome://settings/languages"),
1693 new_contents
->GetVisibleURL());
1696 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenusAPI_Basic
) {
1697 LoadAppWithGuest("web_view/context_menus/basic");
1699 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1700 content::WebContents
* embedder
= GetEmbedderWebContents();
1701 ASSERT_TRUE(embedder
);
1703 // 1. Basic property test.
1704 ExecuteScriptWaitForTitle(embedder
, "checkProperties()", "ITEM_CHECKED");
1706 // 2. Create a menu item and wait for created callback to be called.
1707 ExecuteScriptWaitForTitle(embedder
, "createMenuItem()", "ITEM_CREATED");
1709 // 3. Click the created item, wait for the click handlers to fire from JS.
1710 ExtensionTestMessageListener
click_listener("ITEM_CLICKED", false);
1711 GURL
page_url("http://www.google.com");
1712 // Create and build our test context menu.
1713 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1714 guest_web_contents
, page_url
, GURL(), GURL()));
1715 // Look for the extension item in the menu, and execute it.
1716 int command_id
= ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1717 ASSERT_TRUE(menu
->IsCommandIdEnabled(command_id
));
1718 menu
->ExecuteCommand(command_id
, 0);
1719 // Wait for embedder's script to tell us its onclick fired, it does
1720 // chrome.test.sendMessage('ITEM_CLICKED')
1721 ASSERT_TRUE(click_listener
.WaitUntilSatisfied());
1723 // 4. Update the item's title and verify.
1724 ExecuteScriptWaitForTitle(embedder
, "updateMenuItem()", "ITEM_UPDATED");
1725 MenuItem::List items
= GetItems();
1726 ASSERT_EQ(1u, items
.size());
1727 MenuItem
* item
= items
.at(0);
1728 EXPECT_EQ("new_title", item
->title());
1730 // 5. Remove the item.
1731 ExecuteScriptWaitForTitle(embedder
, "removeItem()", "ITEM_REMOVED");
1732 MenuItem::List items_after_removal
= GetItems();
1733 ASSERT_EQ(0u, items_after_removal
.size());
1735 // 6. Add some more items.
1736 ExecuteScriptWaitForTitle(
1737 embedder
, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1738 MenuItem::List items_after_insertion
= GetItems();
1739 ASSERT_EQ(3u, items_after_insertion
.size());
1741 // 7. Test removeAll().
1742 ExecuteScriptWaitForTitle(embedder
, "removeAllItems()", "ITEM_ALL_REMOVED");
1743 MenuItem::List items_after_all_removal
= GetItems();
1744 ASSERT_EQ(0u, items_after_all_removal
.size());
1747 // Called in the TestContextMenu test to cancel the context menu after its
1748 // shown notification is received.
1749 static bool ContextMenuNotificationCallback(
1750 const content::NotificationSource
& source
,
1751 const content::NotificationDetails
& details
) {
1752 auto context_menu
= content::Source
<RenderViewContextMenu
>(source
).ptr();
1753 base::ThreadTaskRunnerHandle::Get()->PostTask(
1754 FROM_HERE
, base::Bind(&RenderViewContextMenuBase::Cancel
,
1755 base::Unretained(context_menu
)));
1759 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenusAPI_PreventDefault
) {
1760 LoadAppWithGuest("web_view/context_menus/basic");
1762 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1763 content::WebContents
* embedder
= GetEmbedderWebContents();
1764 ASSERT_TRUE(embedder
);
1766 // Add a preventDefault() call on context menu event so context menu
1767 // does not show up.
1768 ExtensionTestMessageListener
prevent_default_listener(
1769 "WebViewTest.CONTEXT_MENU_DEFAULT_PREVENTED", false);
1770 EXPECT_TRUE(content::ExecuteScript(embedder
, "registerPreventDefault()"));
1771 ContextMenuCallCountObserver context_menu_shown_observer
;
1773 OpenContextMenu(guest_web_contents
);
1775 EXPECT_TRUE(prevent_default_listener
.WaitUntilSatisfied());
1776 // Expect the menu to not show up.
1777 EXPECT_EQ(0, context_menu_shown_observer
.num_times_shown());
1779 // Now remove the preventDefault() and expect context menu to be shown.
1780 ExecuteScriptWaitForTitle(
1781 embedder
, "removePreventDefault()", "PREVENT_DEFAULT_LISTENER_REMOVED");
1782 OpenContextMenu(guest_web_contents
);
1784 // We expect to see a context menu for the second call to |OpenContextMenu|.
1785 context_menu_shown_observer
.Wait();
1786 EXPECT_EQ(1, context_menu_shown_observer
.num_times_shown());
1789 // Tests that a context menu is created when right-clicking in the webview. This
1790 // also tests that the 'contextmenu' event is handled correctly.
1791 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestContextMenu
) {
1792 LoadAppWithGuest("web_view/context_menus/basic");
1793 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1795 // Register an observer for the context menu.
1796 content::WindowedNotificationObserver
menu_observer(
1797 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
,
1798 base::Bind(ContextMenuNotificationCallback
));
1800 OpenContextMenu(guest_web_contents
);
1802 // Wait for the context menu to be visible.
1803 menu_observer
.Wait();
1806 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllow
) {
1807 MediaAccessAPIAllowTestHelper("testAllow");
1810 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAndThenDeny
) {
1811 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1814 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowTwice
) {
1815 MediaAccessAPIAllowTestHelper("testAllowTwice");
1818 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAsync
) {
1819 MediaAccessAPIAllowTestHelper("testAllowAsync");
1822 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestCheck
) {
1823 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1824 LoadAndLaunchPlatformApp("web_view/media_access/check", "Launched");
1826 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1827 ASSERT_TRUE(embedder_web_contents
);
1828 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
1829 embedder_web_contents
->SetDelegate(mock
.get());
1831 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1832 done_listener
.set_failure_message("TEST_FAILED");
1834 content::ExecuteScript(
1835 embedder_web_contents
,
1836 base::StringPrintf("startCheckTest('')")));
1837 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1839 mock
->WaitForCheckMediaPermission();
1842 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1844 IN_PROC_BROWSER_TEST_F(WebViewTest
, ScreenCoordinates
) {
1845 ASSERT_TRUE(RunPlatformAppTestWithArg(
1846 "platform_apps/web_view/common", "screen_coordinates"))
1850 #if defined(OS_CHROMEOS)
1851 IN_PROC_BROWSER_TEST_F(WebViewTest
, ChromeVoxInjection
) {
1853 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1855 chromeos::SpeechMonitor monitor
;
1856 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1857 true, ui::A11Y_NOTIFICATION_NONE
);
1858 EXPECT_TRUE(monitor
.SkipChromeVoxEnabledMessage());
1860 ASSERT_TRUE(StartEmbeddedTestServer());
1861 content::WebContents
* guest_web_contents
= LoadGuest(
1862 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1863 "web_view/chromevox_injection");
1864 ASSERT_TRUE(guest_web_contents
);
1866 EXPECT_EQ("chrome vox test title", monitor
.GetNextUtterance());
1870 // Flaky on Windows. http://crbug.com/303966
1872 #define MAYBE_TearDownTest DISABLED_TearDownTest
1874 #define MAYBE_TearDownTest TearDownTest
1876 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_TearDownTest
) {
1877 const extensions::Extension
* extension
=
1878 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
1879 extensions::AppWindow
* window
= NULL
;
1880 if (!GetAppWindowCount())
1881 window
= CreateAppWindow(extension
);
1883 window
= GetFirstAppWindow();
1884 CloseAppWindow(window
);
1886 // Load the app again.
1887 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
1890 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1891 // platform app) does not have geolocation permission for this test.
1892 // No matter what the API does, geolocation permission would be denied.
1893 // Note that the test name prefix must be "GeolocationAPI".
1894 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessAllow
) {
1895 TestHelper("testDenyDenies",
1896 "web_view/geolocation/embedder_has_no_permission",
1900 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessDeny
) {
1901 TestHelper("testDenyDenies",
1902 "web_view/geolocation/embedder_has_no_permission",
1906 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1907 // platform app) has geolocation permission
1909 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1910 // geolocation in this case).
1912 // Also note that these are run separately because OverrideGeolocation() doesn't
1913 // mock out geolocation for multiple navigator.geolocation calls properly and
1914 // the tests become flaky.
1916 // GeolocationAPI* test 1 of 3.
1917 // Currently disabled until crbug.com/526788 is fixed.
1918 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1919 DISABLED_GeolocationAPIEmbedderHasAccessAllow
) {
1920 TestHelper("testAllow",
1921 "web_view/geolocation/embedder_has_permission",
1925 // GeolocationAPI* test 2 of 3.
1926 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessDeny
) {
1927 TestHelper("testDeny",
1928 "web_view/geolocation/embedder_has_permission",
1932 // GeolocationAPI* test 3 of 3.
1933 // Currently disabled until crbug.com/526788 is fixed.
1934 IN_PROC_BROWSER_TEST_F(
1936 DISABLED_GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow
) {
1937 TestHelper("testMultipleBridgeIdAllow",
1938 "web_view/geolocation/embedder_has_permission",
1943 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
1944 // is handled correctly (and does not crash).
1945 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPICancelGeolocation
) {
1946 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1947 ASSERT_TRUE(RunPlatformAppTest(
1948 "platform_apps/web_view/geolocation/cancel_request")) << message_
;
1951 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_GeolocationRequestGone
) {
1952 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1953 ASSERT_TRUE(RunPlatformAppTest(
1954 "platform_apps/web_view/geolocation/geolocation_request_gone"))
1958 // In following FilesystemAPIRequestFromMainThread* tests, guest request
1959 // filesystem access from main thread of the guest.
1960 // FileSystemAPIRequestFromMainThread* test 1 of 3
1961 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadAllow
) {
1962 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
1965 // FileSystemAPIRequestFromMainThread* test 2 of 3.
1966 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadDeny
) {
1967 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
1970 // FileSystemAPIRequestFromMainThread* test 3 of 3.
1971 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1972 FileSystemAPIRequestFromMainThreadDefaultAllow
) {
1973 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
1976 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
1977 // to request filesystem access from worker thread.
1978 // FileSystemAPIRequestFromWorker* test 1 of 3
1979 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerAllow
) {
1980 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
1983 // FileSystemAPIRequestFromWorker* test 2 of 3.
1984 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerDeny
) {
1985 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
1988 // FileSystemAPIRequestFromWorker* test 3 of 3.
1989 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1990 FileSystemAPIRequestFromWorkerDefaultAllow
) {
1992 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
1995 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
1996 // embedder contains a single webview guest. The guest creates a shared worker
1997 // to request filesystem access from worker thread.
1998 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
1999 IN_PROC_BROWSER_TEST_F(
2001 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow
) {
2002 TestHelper("testAllow",
2003 "web_view/filesystem/shared_worker/single",
2007 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
2008 IN_PROC_BROWSER_TEST_F(
2010 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny
) {
2011 TestHelper("testDeny",
2012 "web_view/filesystem/shared_worker/single",
2016 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2017 IN_PROC_BROWSER_TEST_F(
2019 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow
) {
2022 "web_view/filesystem/shared_worker/single",
2026 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2027 // embedder contains mutiple webview guests. Each guest creates a shared worker
2028 // to request filesystem access from worker thread.
2029 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2030 IN_PROC_BROWSER_TEST_F(
2032 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow
) {
2033 TestHelper("testAllow",
2034 "web_view/filesystem/shared_worker/multiple",
2038 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2039 IN_PROC_BROWSER_TEST_F(
2041 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny
) {
2042 TestHelper("testDeny",
2043 "web_view/filesystem/shared_worker/multiple",
2047 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2048 IN_PROC_BROWSER_TEST_F(
2050 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow
) {
2053 "web_view/filesystem/shared_worker/multiple",
2057 IN_PROC_BROWSER_TEST_F(WebViewTest
, ClearData
) {
2059 // Flaky on XP bot http://crbug.com/282674
2060 if (base::win::GetVersion() <= base::win::VERSION_XP
)
2064 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2065 ASSERT_TRUE(RunPlatformAppTestWithArg(
2066 "platform_apps/web_view/common", "cleardata"))
2071 // Test is disabled on Windows because it fails often (~9% time)
2072 // http://crbug.com/489088
2073 #define MAYBE_ClearDataCache DISABLED_ClearDataCache
2075 #define MAYBE_ClearDataCache ClearDataCache
2077 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_ClearDataCache
) {
2078 TestHelper("testClearCache", "web_view/clear_data_cache", NEEDS_TEST_SERVER
);
2081 IN_PROC_BROWSER_TEST_F(WebViewTest
, ConsoleMessage
) {
2082 ASSERT_TRUE(RunPlatformAppTestWithArg(
2083 "platform_apps/web_view/common", "console_messages"))
2087 IN_PROC_BROWSER_TEST_F(WebViewTest
, DownloadPermission
) {
2088 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2089 content::WebContents
* guest_web_contents
=
2090 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2091 "web_view/download");
2092 ASSERT_TRUE(guest_web_contents
);
2094 // Replace WebContentsDelegate with mock version so we can intercept download
2096 content::WebContentsDelegate
* delegate
= guest_web_contents
->GetDelegate();
2097 scoped_ptr
<MockDownloadWebContentsDelegate
>
2098 mock_delegate(new MockDownloadWebContentsDelegate(delegate
));
2099 guest_web_contents
->SetDelegate(mock_delegate
.get());
2102 // 1. Guest requests a download that its embedder denies.
2103 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2104 "startDownload('download-link-1')"));
2105 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2106 mock_delegate
->Reset();
2108 // 2. Guest requests a download that its embedder allows.
2109 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2110 "startDownload('download-link-2')"));
2111 mock_delegate
->WaitForCanDownload(true); // Expect to allow.
2112 mock_delegate
->Reset();
2114 // 3. Guest requests a download that its embedder ignores, this implies deny.
2115 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2116 "startDownload('download-link-3')"));
2117 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2120 // This test makes sure loading <webview> does not crash when there is an
2121 // extension which has content script whitelisted/forced.
2122 IN_PROC_BROWSER_TEST_F(WebViewTest
, WhitelistedContentScript
) {
2123 // Whitelist the extension for running content script we are going to load.
2124 extensions::ExtensionsClient::ScriptingWhitelist whitelist
;
2125 const std::string extension_id
= "imeongpbjoodlnmlakaldhlcmijmhpbb";
2126 whitelist
.push_back(extension_id
);
2127 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist
);
2129 // Load the extension.
2130 const extensions::Extension
* content_script_whitelisted_extension
=
2131 LoadExtension(test_data_dir_
.AppendASCII(
2132 "platform_apps/web_view/extension_api/content_script"));
2133 ASSERT_TRUE(content_script_whitelisted_extension
);
2134 ASSERT_EQ(extension_id
, content_script_whitelisted_extension
->id());
2136 // Now load an app with <webview>.
2137 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2141 IN_PROC_BROWSER_TEST_F(WebViewTest
, SendMessageToExtensionFromGuest
) {
2142 // Load the extension as a normal, non-component extension.
2143 const extensions::Extension
* extension
=
2144 LoadExtension(test_data_dir_
.AppendASCII(
2145 "platform_apps/web_view/extension_api/component_extension"));
2146 ASSERT_TRUE(extension
);
2148 TestHelper("testNonComponentExtension", "web_view/component_extension",
2152 IN_PROC_BROWSER_TEST_F(WebViewTest
, SendMessageToComponentExtensionFromGuest
) {
2153 const extensions::Extension
* component_extension
=
2154 LoadExtensionAsComponent(test_data_dir_
.AppendASCII(
2155 "platform_apps/web_view/extension_api/component_extension"));
2156 ASSERT_TRUE(component_extension
);
2158 TestHelper("testComponentExtension", "web_view/component_extension",
2161 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
2162 ASSERT_TRUE(embedder_web_contents
);
2164 // Retrive the guestProcessId and guestRenderFrameRoutingId from the
2166 int guest_process_id
= content::ChildProcessHost::kInvalidUniqueID
;
2167 content::ExecuteScriptAndGetValue(embedder_web_contents
->GetMainFrame(),
2168 "window.guestProcessId")
2169 ->GetAsInteger(&guest_process_id
);
2170 int guest_render_frame_routing_id
= MSG_ROUTING_NONE
;
2171 content::ExecuteScriptAndGetValue(embedder_web_contents
->GetMainFrame(),
2172 "window.guestRenderFrameRoutingId")
2173 ->GetAsInteger(&guest_render_frame_routing_id
);
2175 auto* guest_rfh
= content::RenderFrameHost::FromID(
2176 guest_process_id
, guest_render_frame_routing_id
);
2177 // Verify that the guest related info (guest_process_id and
2178 // guest_render_frame_routing_id) actually points to a WebViewGuest.
2179 ASSERT_TRUE(extensions::WebViewGuest::FromWebContents(
2180 content::WebContents::FromRenderFrameHost(guest_rfh
)));
2183 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentReady
) {
2184 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2188 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentInteractive
) {
2189 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2193 IN_PROC_BROWSER_TEST_F(WebViewSpeechAPITest
,
2194 SpeechRecognitionAPI_HasPermissionAllow
) {
2196 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2201 IN_PROC_BROWSER_TEST_F(WebViewSpeechAPITest
,
2202 SpeechRecognitionAPI_HasPermissionDeny
) {
2204 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2209 IN_PROC_BROWSER_TEST_F(WebViewSpeechAPITest
,
2210 SpeechRecognitionAPI_NoPermission
) {
2212 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2213 "speech_recognition_api_no_permission"))
2217 // Tests overriding user agent.
2218 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent
) {
2219 ASSERT_TRUE(RunPlatformAppTestWithArg(
2220 "platform_apps/web_view/common", "useragent")) << message_
;
2223 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest
, UserAgent_NewWindow
) {
2224 ASSERT_TRUE(RunPlatformAppTestWithArg(
2225 "platform_apps/web_view/common",
2226 "useragent_newwindow")) << message_
;
2229 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPermission
) {
2230 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2234 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestAlertDialog
) {
2235 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER
);
2238 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestConfirmDialog
) {
2239 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER
);
2242 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogCancel
) {
2243 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER
);
2246 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultCancel
) {
2247 TestHelper("testConfirmDialogDefaultCancel",
2252 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultGCCancel
) {
2253 TestHelper("testConfirmDialogDefaultGCCancel",
2258 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestPromptDialog
) {
2259 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER
);
2262 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoContentSettingsAPI
) {
2263 // Load the extension.
2264 const extensions::Extension
* content_settings_extension
=
2266 test_data_dir_
.AppendASCII(
2267 "platform_apps/web_view/extension_api/content_settings"));
2268 ASSERT_TRUE(content_settings_extension
);
2269 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER
);
2272 #if defined(ENABLE_PLUGINS)
2273 class WebViewPluginTest
: public WebViewTest
{
2275 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
2276 WebViewTest::SetUpCommandLine(command_line
);
2277 ASSERT_TRUE(ppapi::RegisterTestPlugin(command_line
));
2281 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginEvent
) {
2282 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER
);
2285 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginInternalResource
) {
2286 const char kTestMimeType
[] = "application/pdf";
2287 const char kTestFileType
[] = "pdf";
2288 content::WebPluginInfo plugin_info
;
2289 plugin_info
.type
= content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
;
2290 plugin_info
.mime_types
.push_back(
2291 content::WebPluginMimeType(kTestMimeType
, kTestFileType
, std::string()));
2292 content::PluginService::GetInstance()->RegisterInternalPlugin(plugin_info
,
2295 TestHelper("testPluginLoadInternalResource", "web_view/shim", NO_TEST_SERVER
);
2297 #endif // defined(ENABLE_PLUGINS)
2299 class WebViewCaptureTest
: public WebViewTest
{
2301 WebViewCaptureTest() {}
2302 ~WebViewCaptureTest() override
{}
2303 void SetUp() override
{
2304 EnablePixelOutput();
2305 WebViewTest::SetUp();
2309 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestZoomAPI
) {
2310 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER
);
2313 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI
) {
2314 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER
);
2317 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI_findupdate
) {
2318 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER
);
2321 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadDataAPI
) {
2322 TestHelper("testLoadDataAPI", "web_view/shim", NEEDS_TEST_SERVER
);
2325 // This test verifies that the resize and contentResize events work correctly.
2326 IN_PROC_BROWSER_TEST_F(WebViewSizeTest
, Shim_TestResizeEvents
) {
2327 TestHelper("testResizeEvents", "web_view/shim", NO_TEST_SERVER
);
2330 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestPerOriginZoomMode
) {
2331 TestHelper("testPerOriginZoomMode", "web_view/shim", NO_TEST_SERVER
);
2334 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestPerViewZoomMode
) {
2335 TestHelper("testPerViewZoomMode", "web_view/shim", NO_TEST_SERVER
);
2338 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisabledZoomMode
) {
2339 TestHelper("testDisabledZoomMode", "web_view/shim", NO_TEST_SERVER
);
2342 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestZoomBeforeNavigation
) {
2343 TestHelper("testZoomBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
2346 // This test verify that the set of rules registries of a webview will be
2347 // removed from RulesRegistryService after the webview is gone.
2348 // http://crbug.com/438327
2349 IN_PROC_BROWSER_TEST_F(
2351 DISABLED_Shim_TestRulesRegistryIDAreRemovedAfterWebViewIsGone
) {
2352 LoadAppWithGuest("web_view/rules_registry");
2354 content::WebContents
* embedder_web_contents
= GetEmbedderWebContents();
2355 ASSERT_TRUE(embedder_web_contents
);
2356 scoped_ptr
<EmbedderWebContentsObserver
> observer(
2357 new EmbedderWebContentsObserver(embedder_web_contents
));
2359 content::WebContents
* guest_web_contents
= GetGuestWebContents();
2360 ASSERT_TRUE(guest_web_contents
);
2361 extensions::WebViewGuest
* guest
=
2362 extensions::WebViewGuest::FromWebContents(guest_web_contents
);
2365 // Register rule for the guest.
2366 Profile
* profile
= browser()->profile();
2367 int rules_registry_id
=
2368 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2369 guest
->owner_web_contents()->GetRenderProcessHost()->GetID(),
2370 guest
->view_instance_id());
2372 extensions::RulesRegistryService
* registry_service
=
2373 extensions::RulesRegistryService::Get(profile
);
2374 extensions::TestRulesRegistry
* rules_registry
=
2375 new extensions::TestRulesRegistry(
2376 content::BrowserThread::UI
, "ui", rules_registry_id
);
2377 registry_service
->RegisterRulesRegistry(make_scoped_refptr(rules_registry
));
2379 EXPECT_TRUE(registry_service
->GetRulesRegistry(
2380 rules_registry_id
, "ui").get());
2382 // Kill the embedder's render process, so the webview will go as well.
2383 base::Process process
= base::Process::DeprecatedGetProcessFromHandle(
2384 embedder_web_contents
->GetRenderProcessHost()->GetHandle());
2385 process
.Terminate(0, false);
2386 observer
->WaitForEmbedderRenderProcessTerminate();
2388 EXPECT_FALSE(registry_service
->GetRulesRegistry(
2389 rules_registry_id
, "ui").get());
2392 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_WebViewWebRequestRegistryHasNoCache
) {
2393 LoadAppWithGuest("web_view/rules_registry");
2395 content::WebContents
* guest_web_contents
= GetGuestWebContents();
2396 ASSERT_TRUE(guest_web_contents
);
2397 extensions::WebViewGuest
* guest
=
2398 extensions::WebViewGuest::FromWebContents(guest_web_contents
);
2401 Profile
* profile
= browser()->profile();
2402 extensions::RulesRegistryService
* registry_service
=
2403 extensions::RulesRegistryService::Get(profile
);
2404 int rules_registry_id
=
2405 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2406 guest
->owner_web_contents()->GetRenderProcessHost()->GetID(),
2407 guest
->view_instance_id());
2409 // Get an existing registered rule for the guest.
2410 extensions::RulesRegistry
* registry
=
2411 registry_service
->GetRulesRegistry(
2413 extensions::declarative_webrequest_constants::kOnRequest
).get();
2415 EXPECT_TRUE(registry
);
2416 EXPECT_FALSE(registry
->rules_cache_delegate_for_testing());
2419 // This test verifies that webview.contentWindow works inside an iframe.
2420 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebViewInsideFrame
) {
2421 LoadAppWithGuest("web_view/inside_iframe");
2424 // <webview> screenshot capture fails with ubercomp.
2425 // See http://crbug.com/327035.
2426 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest
,
2427 DISABLED_Shim_ScreenshotCapture
) {
2428 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER
);
2431 // Tests that browser process does not crash when loading plugin inside
2432 // <webview> with content settings set to CONTENT_SETTING_BLOCK.
2433 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestPlugin
) {
2434 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
2435 CONTENT_SETTINGS_TYPE_PLUGINS
, CONTENT_SETTING_BLOCK
);
2436 TestHelper("testPlugin", "web_view/shim", NEEDS_TEST_SERVER
);
2440 // Test is disabled on Windows because it times out often.
2441 // http://crbug.com/403325
2442 #define MAYBE_WebViewInBackgroundPage \
2443 DISABLED_WebViewInBackgroundPage
2445 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2447 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_WebViewInBackgroundPage
) {
2448 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))
2452 // This test verifies that the allowtransparency attribute properly propagates.
2453 IN_PROC_BROWSER_TEST_F(WebViewTest
, AllowTransparencyAndAllowScalingPropagate
) {
2454 LoadAppWithGuest("web_view/simple");
2456 ASSERT_TRUE(GetGuestWebContents());
2457 extensions::WebViewGuest
* guest
=
2458 extensions::WebViewGuest::FromWebContents(GetGuestWebContents());
2459 ASSERT_TRUE(guest
->allow_transparency());
2460 ASSERT_TRUE(guest
->allow_scaling());
2463 IN_PROC_BROWSER_TEST_F(WebViewCommonTest
, BasicPostMessage
) {
2464 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2465 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/post_message/basic"))
2469 // Tests that webviews do get garbage collected.
2470 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestGarbageCollect
) {
2471 TestHelper("testGarbageCollect", "web_view/shim", NO_TEST_SERVER
);
2472 GetGuestViewManager()->WaitForSingleViewGarbageCollected();
2475 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestCloseNewWindowCleanup
) {
2476 TestHelper("testCloseNewWindowCleanup", "web_view/shim", NEEDS_TEST_SERVER
);
2477 auto gvm
= GetGuestViewManager();
2478 gvm
->WaitForLastGuestDeleted();
2479 ASSERT_EQ(gvm
->num_embedder_processes_destroyed(), 0);
2482 // Ensure that focusing a WebView while it is already focused does not blur the
2484 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFocusWhileFocused
) {
2485 TestHelper("testFocusWhileFocused", "web_view/shim", NO_TEST_SERVER
);
2488 IN_PROC_BROWSER_TEST_F(WebViewTest
, NestedGuestContainerBounds
) {
2489 TestHelper("testPDFInWebview", "web_view/shim", NO_TEST_SERVER
);
2491 std::vector
<content::WebContents
*> guest_web_contents_list
;
2492 GetGuestViewManager()->WaitForNumGuestsCreated(2u);
2493 GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list
);
2494 ASSERT_EQ(2u, guest_web_contents_list
.size());
2496 content::WebContents
* web_view_contents
= guest_web_contents_list
[0];
2497 content::WebContents
* mime_handler_view_contents
= guest_web_contents_list
[1];
2499 // Make sure we've completed loading |mime_handler_view_guest|.
2500 bool load_success
= pdf_extension_test_util::EnsurePDFHasLoaded(
2502 EXPECT_TRUE(load_success
);
2504 gfx::Rect web_view_container_bounds
= web_view_contents
->GetContainerBounds();
2505 gfx::Rect mime_handler_view_container_bounds
=
2506 mime_handler_view_contents
->GetContainerBounds();
2507 EXPECT_EQ(web_view_container_bounds
.origin(),
2508 mime_handler_view_container_bounds
.origin());
2511 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestMailtoLink
) {
2512 TestHelper("testMailtoLink", "web_view/shim", NEEDS_TEST_SERVER
);
2515 // Tests that a renderer navigation from an unattached guest that results in a
2516 // server redirect works properly.
2517 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2518 Shim_TestRendererNavigationRedirectWhileUnattached
) {
2519 TestHelper("testRendererNavigationRedirectWhileUnattached",
2520 "web_view/shim", NEEDS_TEST_SERVER
);
2523 #if defined(USE_AURA)
2524 // TODO(wjmaclean): when WebViewTest is re-enabled on the site-isolation
2525 // bots, then re-enable this test class as well.
2526 // https://crbug.com/503751
2527 class WebViewFocusTest
: public WebViewTest
{
2529 ~WebViewFocusTest() override
{}
2531 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
2532 WebViewTest::SetUpCommandLine(command_line
);
2534 command_line
->AppendSwitchASCII(switches::kTouchEvents
,
2535 switches::kTouchEventsEnabled
);
2538 void ForceCompositorFrame() {
2539 if (!frame_watcher_
) {
2540 frame_watcher_
= new content::FrameWatcher();
2541 frame_watcher_
->AttachTo(GetEmbedderWebContents());
2544 while (!RequestFrame(GetEmbedderWebContents())) {
2545 // RequestFrame failed because we were waiting on an ack ... wait a short
2547 base::RunLoop run_loop
;
2548 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2549 FROM_HERE
, run_loop
.QuitClosure(),
2550 base::TimeDelta::FromMilliseconds(10));
2553 frame_watcher_
->WaitFrames(1);
2557 scoped_refptr
<content::FrameWatcher
> frame_watcher_
;
2560 class FocusWaiter
: public views::FocusChangeListener
{
2562 explicit FocusWaiter(views::View
* view_to_wait_for
)
2563 : view_to_wait_for_(view_to_wait_for
) {
2564 view_to_wait_for_
->GetFocusManager()->AddFocusChangeListener(this);
2566 ~FocusWaiter() override
{
2567 view_to_wait_for_
->GetFocusManager()->RemoveFocusChangeListener(this);
2571 if (view_to_wait_for_
->HasFocus())
2574 base::MessageLoop::current()->Run();
2577 // FocusChangeListener implementation.
2578 void OnWillChangeFocus(views::View
* focused_before
,
2579 views::View
* focused_now
) override
{}
2580 void OnDidChangeFocus(views::View
* focused_before
,
2581 views::View
* focused_now
) override
{
2582 if (view_to_wait_for_
== focused_now
)
2583 base::MessageLoop::current()->QuitWhenIdle();
2587 views::View
* view_to_wait_for_
;
2589 DISALLOW_COPY_AND_ASSIGN(FocusWaiter
);
2592 // The following test verifies that a views::WebView hosting an embedder
2593 // gains focus on touchstart.
2594 IN_PROC_BROWSER_TEST_F(WebViewFocusTest
, TouchFocusesEmbedder
) {
2595 LoadAppWithGuest("web_view/accept_touch_events");
2597 content::WebContents
* web_contents
= GetEmbedderWebContents();
2598 content::RenderViewHost
* embedder_rvh
= web_contents
->GetRenderViewHost();
2600 bool embedder_has_touch_handler
=
2601 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
2602 EXPECT_FALSE(embedder_has_touch_handler
);
2604 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
2606 // Note that we need to wait for the installed/registered touch handler to
2607 // appear in browser process before querying |embedder_rvh|.
2608 // In practice, since we do a roundrtip from browser process to guest and
2609 // back, this is sufficient.
2610 embedder_has_touch_handler
=
2611 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
2612 EXPECT_TRUE(embedder_has_touch_handler
);
2614 extensions::AppWindow
* app_window
= GetFirstAppWindowForBrowser(browser());
2615 aura::Window
* window
= app_window
->GetNativeWindow();
2616 EXPECT_TRUE(app_window
);
2617 EXPECT_TRUE(window
);
2618 views::Widget
* widget
= views::Widget::GetWidgetForNativeView(window
);
2619 EXPECT_TRUE(widget
->GetRootView());
2620 // We only expect a single views::webview in the view hierarchy.
2621 views::View
* aura_webview
= FindWebView(widget
->GetRootView());
2622 ASSERT_TRUE(aura_webview
);
2623 gfx::Rect
bounds(aura_webview
->bounds());
2624 EXPECT_TRUE(aura_webview
->IsFocusable());
2626 views::View
* other_focusable_view
= new views::View();
2627 other_focusable_view
->SetBounds(bounds
.x() + bounds
.width(), bounds
.y(), 100,
2629 other_focusable_view
->SetFocusable(true);
2630 aura_webview
->parent()->AddChildView(other_focusable_view
);
2631 other_focusable_view
->SetPosition(gfx::Point(bounds
.x() + bounds
.width(), 0));
2633 // Sync changes to compositor.
2634 ForceCompositorFrame();
2636 aura_webview
->RequestFocus();
2637 // Verify that other_focusable_view can steal focus from aura_webview.
2638 EXPECT_TRUE(aura_webview
->HasFocus());
2639 other_focusable_view
->RequestFocus();
2640 EXPECT_TRUE(other_focusable_view
->HasFocus());
2641 EXPECT_FALSE(aura_webview
->HasFocus());
2643 // Compute location of guest within embedder so we can more accurately
2644 // target our touch event.
2645 gfx::Rect guest_rect
= GetGuestWebContents()->GetContainerBounds();
2646 gfx::Point embedder_origin
=
2647 GetEmbedderWebContents()->GetContainerBounds().origin();
2648 guest_rect
.Offset(-embedder_origin
.x(), -embedder_origin
.y());
2650 // Generate and send synthetic touch event.
2651 FocusWaiter
waiter(aura_webview
);
2652 content::SimulateTouchPressAt(GetEmbedderWebContents(),
2653 guest_rect
.CenterPoint());
2655 // Wait for the TouchStart to propagate and restore focus. Test times out
2661 #if defined(ENABLE_TASK_MANAGER)
2665 base::string16
GetExpectedPrefix(content::WebContents
* web_contents
) {
2666 DCHECK(web_contents
);
2667 guest_view::GuestViewBase
* guest
=
2668 guest_view::GuestViewBase::FromWebContents(web_contents
);
2671 return l10n_util::GetStringFUTF16(guest
->GetTaskPrefix(), base::string16());
2674 const std::vector
<task_management::WebContentsTag
*>& GetTrackedTags() {
2675 return task_management::WebContentsTagsManager::GetInstance()->
2681 // Tests that the pre-existing WebViews are provided to the task manager.
2682 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagementPreExistingWebViews
) {
2683 ASSERT_TRUE(StartEmbeddedTestServer());
2685 // Browser tests start with a single tab.
2686 EXPECT_EQ(1U, GetTrackedTags().size());
2688 content::WebContents
* guest_contents
=
2689 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
2690 "web_view/task_manager");
2692 task_management::MockWebContentsTaskManager task_manager
;
2693 task_manager
.StartObserving();
2695 // The pre-existing tab and guest tasks are provided.
2696 // 4 tasks expected in the following order:
2697 // Tab: about:blank,
2698 // Background Page: <webview> task manager test,
2699 // App: <webview> task manager test,
2700 // Webview: WebViewed test content.
2701 EXPECT_EQ(4U, task_manager
.tasks().size());
2703 const task_management::Task
* task
= task_manager
.tasks().back();
2704 EXPECT_EQ(task_management::Task::GUEST
, task
->GetType());
2705 const base::string16 title
= task
->title();
2706 const base::string16 expected_prefix
= GetExpectedPrefix(guest_contents
);
2707 EXPECT_TRUE(base::StartsWith(title
,
2709 base::CompareCase::INSENSITIVE_ASCII
));
2712 // Tests that the post-existing WebViews are provided to the task manager.
2713 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagementPostExistingWebViews
) {
2714 ASSERT_TRUE(StartEmbeddedTestServer());
2716 // Browser tests start with a single tab.
2717 EXPECT_EQ(1U, GetTrackedTags().size());
2719 task_management::MockWebContentsTaskManager task_manager
;
2720 task_manager
.StartObserving();
2722 // Only the "about:blank" tab shows at the moment.
2723 EXPECT_EQ(1U, task_manager
.tasks().size());
2724 const task_management::Task
* about_blank_task
= task_manager
.tasks().back();
2725 EXPECT_EQ(task_management::Task::RENDERER
, about_blank_task
->GetType());
2726 EXPECT_EQ(base::UTF8ToUTF16("Tab: about:blank"), about_blank_task
->title());
2728 // Now load a guest web view.
2729 content::WebContents
* guest_contents
=
2730 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
2731 "web_view/task_manager");
2732 // 4 tasks expected in the following order:
2733 // Tab: about:blank,
2734 // Background Page: <webview> task manager test,
2735 // App: <webview> task manager test,
2736 // Webview: WebViewed test content.
2737 EXPECT_EQ(4U, task_manager
.tasks().size());
2739 const task_management::Task
* task
= task_manager
.tasks().back();
2740 EXPECT_EQ(task_management::Task::GUEST
, task
->GetType());
2741 const base::string16 title
= task
->title();
2742 const base::string16 expected_prefix
= GetExpectedPrefix(guest_contents
);
2743 EXPECT_TRUE(base::StartsWith(title
,
2745 base::CompareCase::INSENSITIVE_ASCII
));
2748 #endif // defined(ENABLE_TASK_MANAGER)