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.
5 #include "base/path_service.h"
6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/apps/app_browsertest_util.h"
10 #include "chrome/browser/chrome_content_browser_client.h"
11 #include "chrome/browser/prerender/prerender_link_manager.h"
12 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
15 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
16 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_dialogs.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/gpu_data_manager.h"
22 #include "content/public/browser/interstitial_page.h"
23 #include "content/public/browser/interstitial_page_delegate.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/common/content_switches.h"
28 #include "content/public/test/browser_test_utils.h"
29 #include "content/public/test/fake_speech_recognition_manager.h"
30 #include "content/public/test/test_renderer_host.h"
31 #include "extensions/browser/api/declarative/rules_registry.h"
32 #include "extensions/browser/api/declarative/rules_registry_service.h"
33 #include "extensions/browser/api/declarative/test_rules_registry.h"
34 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
35 #include "extensions/browser/app_window/native_app_window.h"
36 #include "extensions/browser/guest_view/guest_view_manager.h"
37 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
38 #include "extensions/browser/guest_view/test_guest_view_manager.h"
39 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
40 #include "extensions/common/extension.h"
41 #include "extensions/common/extensions_client.h"
42 #include "extensions/test/extension_test_message_listener.h"
43 #include "media/base/media_switches.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h"
45 #include "net/test/embedded_test_server/http_request.h"
46 #include "net/test/embedded_test_server/http_response.h"
47 #include "ui/gfx/switches.h"
48 #include "ui/gl/gl_switches.h"
50 #if defined(ENABLE_PLUGINS)
51 #include "content/public/browser/plugin_service.h"
52 #include "content/public/common/webplugininfo.h"
55 #if defined(OS_CHROMEOS)
56 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
57 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
60 // For fine-grained suppression on flaky tests.
62 #include "base/win/windows_version.h"
65 using extensions::ContextMenuMatcher
;
66 using extensions::MenuItem
;
67 using prerender::PrerenderLinkManager
;
68 using prerender::PrerenderLinkManagerFactory
;
69 using task_manager::browsertest_util::MatchAboutBlankTab
;
70 using task_manager::browsertest_util::MatchAnyApp
;
71 using task_manager::browsertest_util::MatchAnyBackground
;
72 using task_manager::browsertest_util::MatchAnyTab
;
73 using task_manager::browsertest_util::MatchAnyWebView
;
74 using task_manager::browsertest_util::MatchApp
;
75 using task_manager::browsertest_util::MatchBackground
;
76 using task_manager::browsertest_util::MatchWebView
;
77 using task_manager::browsertest_util::WaitForTaskManagerRows
;
81 const char kEmptyResponsePath
[] = "/close-socket";
82 const char kRedirectResponsePath
[] = "/server-redirect";
83 const char kUserAgentRedirectResponsePath
[] = "/detect-user-agent";
84 const char kRedirectResponseFullPath
[] =
85 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
87 // Platform-specific filename relative to the chrome executable.
89 const wchar_t library_name
[] = L
"ppapi_tests.dll";
90 #elif defined(OS_MACOSX)
91 const char library_name
[] = "ppapi_tests.plugin";
92 #elif defined(OS_POSIX)
93 const char library_name
[] = "libppapi_tests.so";
96 class EmptyHttpResponse
: public net::test_server::HttpResponse
{
98 std::string
ToResponseString() const override
{ return std::string(); }
101 class TestInterstitialPageDelegate
: public content::InterstitialPageDelegate
{
103 TestInterstitialPageDelegate() {
105 ~TestInterstitialPageDelegate() override
{}
106 std::string
GetHTMLContents() override
{ return std::string(); }
109 class WebContentsHiddenObserver
: public content::WebContentsObserver
{
111 WebContentsHiddenObserver(content::WebContents
* web_contents
,
112 const base::Closure
& hidden_callback
)
113 : WebContentsObserver(web_contents
),
114 hidden_callback_(hidden_callback
),
115 hidden_observed_(false) {
118 // WebContentsObserver.
119 void WasHidden() override
{
120 hidden_observed_
= true;
121 hidden_callback_
.Run();
124 bool hidden_observed() { return hidden_observed_
; }
127 base::Closure hidden_callback_
;
128 bool hidden_observed_
;
130 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver
);
133 class EmbedderWebContentsObserver
: public content::WebContentsObserver
{
135 explicit EmbedderWebContentsObserver(content::WebContents
* web_contents
)
136 : WebContentsObserver(web_contents
), terminated_(false) {}
138 // WebContentsObserver.
139 void RenderProcessGone(base::TerminationStatus status
) override
{
141 if (message_loop_runner_
.get())
142 message_loop_runner_
->Quit();
145 void WaitForEmbedderRenderProcessTerminate() {
148 message_loop_runner_
= new content::MessageLoopRunner
;
149 message_loop_runner_
->Run();
154 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
156 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver
);
159 void ExecuteScriptWaitForTitle(content::WebContents
* web_contents
,
162 base::string16
expected_title(base::ASCIIToUTF16(title
));
163 base::string16
error_title(base::ASCIIToUTF16("error"));
165 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
166 title_watcher
.AlsoWaitForTitle(error_title
);
167 EXPECT_TRUE(content::ExecuteScript(web_contents
, script
));
168 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
173 // This class intercepts media access request from the embedder. The request
174 // should be triggered only if the embedder API (from tests) allows the request
176 // We do not issue the actual media request; the fact that the request reached
177 // embedder's WebContents is good enough for our tests. This is also to make
178 // the test run successfully on trybots.
179 class MockWebContentsDelegate
: public content::WebContentsDelegate
{
181 MockWebContentsDelegate()
184 ~MockWebContentsDelegate() override
{}
186 void RequestMediaAccessPermission(
187 content::WebContents
* web_contents
,
188 const content::MediaStreamRequest
& request
,
189 const content::MediaResponseCallback
& callback
) override
{
191 if (request_message_loop_runner_
.get())
192 request_message_loop_runner_
->Quit();
195 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
196 const GURL
& security_origin
,
197 content::MediaStreamType type
) override
{
199 if (check_message_loop_runner_
.get())
200 check_message_loop_runner_
->Quit();
204 void WaitForRequestMediaPermission() {
207 request_message_loop_runner_
= new content::MessageLoopRunner
;
208 request_message_loop_runner_
->Run();
211 void WaitForCheckMediaPermission() {
214 check_message_loop_runner_
= new content::MessageLoopRunner
;
215 check_message_loop_runner_
->Run();
221 scoped_refptr
<content::MessageLoopRunner
> request_message_loop_runner_
;
222 scoped_refptr
<content::MessageLoopRunner
> check_message_loop_runner_
;
224 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate
);
227 // This class intercepts download request from the guest.
228 class MockDownloadWebContentsDelegate
: public content::WebContentsDelegate
{
230 explicit MockDownloadWebContentsDelegate(
231 content::WebContentsDelegate
* orig_delegate
)
232 : orig_delegate_(orig_delegate
),
233 waiting_for_decision_(false),
234 expect_allow_(false),
235 decision_made_(false),
236 last_download_allowed_(false) {}
237 ~MockDownloadWebContentsDelegate() override
{}
239 void CanDownload(content::RenderViewHost
* render_view_host
,
241 const std::string
& request_method
,
242 const base::Callback
<void(bool)>& callback
) override
{
243 orig_delegate_
->CanDownload(
244 render_view_host
, url
, request_method
,
245 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided
,
246 base::Unretained(this)));
249 void WaitForCanDownload(bool expect_allow
) {
250 EXPECT_FALSE(waiting_for_decision_
);
251 waiting_for_decision_
= true;
253 if (decision_made_
) {
254 EXPECT_EQ(expect_allow
, last_download_allowed_
);
258 expect_allow_
= expect_allow
;
259 message_loop_runner_
= new content::MessageLoopRunner
;
260 message_loop_runner_
->Run();
263 void DownloadDecided(bool allow
) {
264 EXPECT_FALSE(decision_made_
);
265 decision_made_
= true;
267 if (waiting_for_decision_
) {
268 EXPECT_EQ(expect_allow_
, allow
);
269 if (message_loop_runner_
.get())
270 message_loop_runner_
->Quit();
273 last_download_allowed_
= allow
;
277 waiting_for_decision_
= false;
278 decision_made_
= false;
282 content::WebContentsDelegate
* orig_delegate_
;
283 bool waiting_for_decision_
;
286 bool last_download_allowed_
;
287 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
289 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate
);
292 class WebViewTest
: public extensions::PlatformAppBrowserTest
{
294 void SetUp() override
{
295 if (UsesFakeSpeech()) {
296 // SpeechRecognition test specific SetUp.
297 fake_speech_recognition_manager_
.reset(
298 new content::FakeSpeechRecognitionManager());
299 fake_speech_recognition_manager_
->set_should_send_fake_response(true);
300 // Inject the fake manager factory so that the test result is returned to
302 content::SpeechRecognitionManager::SetManagerForTesting(
303 fake_speech_recognition_manager_
.get());
305 extensions::PlatformAppBrowserTest::SetUp();
308 void TearDown() override
{
309 if (UsesFakeSpeech()) {
310 // SpeechRecognition test specific TearDown.
311 content::SpeechRecognitionManager::SetManagerForTesting(NULL
);
314 extensions::PlatformAppBrowserTest::TearDown();
317 void SetUpOnMainThread() override
{
318 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
319 const testing::TestInfo
* const test_info
=
320 testing::UnitTest::GetInstance()->current_test_info();
321 // Mock out geolocation for geolocation specific tests.
322 if (!strncmp(test_info
->name(), "GeolocationAPI",
323 strlen("GeolocationAPI"))) {
324 ui_test_utils::OverrideGeolocation(10, 20);
328 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
329 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
330 command_line
->AppendSwitchASCII(switches::kJavaScriptFlags
, "--expose-gc");
332 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
335 // This method is responsible for initializing a packaged app, which contains
336 // multiple webview tags. The tags have different partition identifiers and
337 // their WebContent objects are returned as output. The method also verifies
338 // the expected process allocation and storage partition assignment.
339 // The |navigate_to_url| parameter is used to navigate the main browser
342 // TODO(ajwong): This function is getting to be too large. Either refactor it
343 // so the test can specify a configuration of WebView tags that we will
344 // dynamically inject JS to generate, or move this test wholesale into
345 // something that RunPlatformAppTest() can execute purely in Javascript. This
346 // won't let us do a white-box examination of the StoragePartition equivalence
347 // directly, but we will be able to view the black box effects which is good
348 // enough. http://crbug.com/160361
349 void NavigateAndOpenAppForIsolation(
350 GURL navigate_to_url
,
351 content::WebContents
** default_tag_contents1
,
352 content::WebContents
** default_tag_contents2
,
353 content::WebContents
** named_partition_contents1
,
354 content::WebContents
** named_partition_contents2
,
355 content::WebContents
** persistent_partition_contents1
,
356 content::WebContents
** persistent_partition_contents2
,
357 content::WebContents
** persistent_partition_contents3
) {
358 GURL::Replacements replace_host
;
359 replace_host
.SetHostStr("localhost");
361 navigate_to_url
= navigate_to_url
.ReplaceComponents(replace_host
);
363 GURL tag_url1
= embedded_test_server()->GetURL(
364 "/extensions/platform_apps/web_view/isolation/cookie.html");
365 tag_url1
= tag_url1
.ReplaceComponents(replace_host
);
366 GURL tag_url2
= embedded_test_server()->GetURL(
367 "/extensions/platform_apps/web_view/isolation/cookie2.html");
368 tag_url2
= tag_url2
.ReplaceComponents(replace_host
);
369 GURL tag_url3
= embedded_test_server()->GetURL(
370 "/extensions/platform_apps/web_view/isolation/storage1.html");
371 tag_url3
= tag_url3
.ReplaceComponents(replace_host
);
372 GURL tag_url4
= embedded_test_server()->GetURL(
373 "/extensions/platform_apps/web_view/isolation/storage2.html");
374 tag_url4
= tag_url4
.ReplaceComponents(replace_host
);
375 GURL tag_url5
= embedded_test_server()->GetURL(
376 "/extensions/platform_apps/web_view/isolation/storage1.html#p1");
377 tag_url5
= tag_url5
.ReplaceComponents(replace_host
);
378 GURL tag_url6
= embedded_test_server()->GetURL(
379 "/extensions/platform_apps/web_view/isolation/storage1.html#p2");
380 tag_url6
= tag_url6
.ReplaceComponents(replace_host
);
381 GURL tag_url7
= embedded_test_server()->GetURL(
382 "/extensions/platform_apps/web_view/isolation/storage1.html#p3");
383 tag_url7
= tag_url7
.ReplaceComponents(replace_host
);
385 ui_test_utils::NavigateToURL(browser(), navigate_to_url
);
387 ui_test_utils::UrlLoadObserver
observer1(
388 tag_url1
, content::NotificationService::AllSources());
389 ui_test_utils::UrlLoadObserver
observer2(
390 tag_url2
, content::NotificationService::AllSources());
391 ui_test_utils::UrlLoadObserver
observer3(
392 tag_url3
, content::NotificationService::AllSources());
393 ui_test_utils::UrlLoadObserver
observer4(
394 tag_url4
, content::NotificationService::AllSources());
395 ui_test_utils::UrlLoadObserver
observer5(
396 tag_url5
, content::NotificationService::AllSources());
397 ui_test_utils::UrlLoadObserver
observer6(
398 tag_url6
, content::NotificationService::AllSources());
399 ui_test_utils::UrlLoadObserver
observer7(
400 tag_url7
, content::NotificationService::AllSources());
401 LoadAndLaunchPlatformApp("web_view/isolation", "Launched");
410 content::Source
<content::NavigationController
> source1
= observer1
.source();
411 EXPECT_TRUE(source1
->GetWebContents()->GetRenderProcessHost()->
413 content::Source
<content::NavigationController
> source2
= observer2
.source();
414 EXPECT_TRUE(source2
->GetWebContents()->GetRenderProcessHost()->
416 content::Source
<content::NavigationController
> source3
= observer3
.source();
417 EXPECT_TRUE(source3
->GetWebContents()->GetRenderProcessHost()->
419 content::Source
<content::NavigationController
> source4
= observer4
.source();
420 EXPECT_TRUE(source4
->GetWebContents()->GetRenderProcessHost()->
422 content::Source
<content::NavigationController
> source5
= observer5
.source();
423 EXPECT_TRUE(source5
->GetWebContents()->GetRenderProcessHost()->
425 content::Source
<content::NavigationController
> source6
= observer6
.source();
426 EXPECT_TRUE(source6
->GetWebContents()->GetRenderProcessHost()->
428 content::Source
<content::NavigationController
> source7
= observer7
.source();
429 EXPECT_TRUE(source7
->GetWebContents()->GetRenderProcessHost()->
432 // Check that the first two tags use the same process and it is different
433 // than the process used by the other two.
434 EXPECT_EQ(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
435 source2
->GetWebContents()->GetRenderProcessHost()->GetID());
436 EXPECT_EQ(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
437 source4
->GetWebContents()->GetRenderProcessHost()->GetID());
438 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
439 source3
->GetWebContents()->GetRenderProcessHost()->GetID());
441 // The two sets of tags should also be isolated from the main browser.
442 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
443 browser()->tab_strip_model()->GetWebContentsAt(0)->
444 GetRenderProcessHost()->GetID());
445 EXPECT_NE(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
446 browser()->tab_strip_model()->GetWebContentsAt(0)->
447 GetRenderProcessHost()->GetID());
449 // Check that the storage partitions of the first two tags match and are
450 // different than the other two.
452 source1
->GetWebContents()->GetRenderProcessHost()->
453 GetStoragePartition(),
454 source2
->GetWebContents()->GetRenderProcessHost()->
455 GetStoragePartition());
457 source3
->GetWebContents()->GetRenderProcessHost()->
458 GetStoragePartition(),
459 source4
->GetWebContents()->GetRenderProcessHost()->
460 GetStoragePartition());
462 source1
->GetWebContents()->GetRenderProcessHost()->
463 GetStoragePartition(),
464 source3
->GetWebContents()->GetRenderProcessHost()->
465 GetStoragePartition());
467 // Ensure the persistent storage partitions are different.
469 source5
->GetWebContents()->GetRenderProcessHost()->
470 GetStoragePartition(),
471 source6
->GetWebContents()->GetRenderProcessHost()->
472 GetStoragePartition());
474 source5
->GetWebContents()->GetRenderProcessHost()->
475 GetStoragePartition(),
476 source7
->GetWebContents()->GetRenderProcessHost()->
477 GetStoragePartition());
479 source1
->GetWebContents()->GetRenderProcessHost()->
480 GetStoragePartition(),
481 source5
->GetWebContents()->GetRenderProcessHost()->
482 GetStoragePartition());
484 source1
->GetWebContents()->GetRenderProcessHost()->
485 GetStoragePartition(),
486 source7
->GetWebContents()->GetRenderProcessHost()->
487 GetStoragePartition());
489 *default_tag_contents1
= source1
->GetWebContents();
490 *default_tag_contents2
= source2
->GetWebContents();
491 *named_partition_contents1
= source3
->GetWebContents();
492 *named_partition_contents2
= source4
->GetWebContents();
493 if (persistent_partition_contents1
) {
494 *persistent_partition_contents1
= source5
->GetWebContents();
496 if (persistent_partition_contents2
) {
497 *persistent_partition_contents2
= source6
->GetWebContents();
499 if (persistent_partition_contents3
) {
500 *persistent_partition_contents3
= source7
->GetWebContents();
504 // Handles |request| by serving a redirect response if the |User-Agent| is
506 static scoped_ptr
<net::test_server::HttpResponse
> UserAgentResponseHandler(
507 const std::string
& path
,
508 const GURL
& redirect_target
,
509 const net::test_server::HttpRequest
& request
) {
510 if (!StartsWithASCII(path
, request
.relative_url
, true))
511 return scoped_ptr
<net::test_server::HttpResponse
>();
513 std::map
<std::string
, std::string
>::const_iterator it
=
514 request
.headers
.find("User-Agent");
515 EXPECT_TRUE(it
!= request
.headers
.end());
516 if (!StartsWithASCII("foobar", it
->second
, true))
517 return scoped_ptr
<net::test_server::HttpResponse
>();
519 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
520 new net::test_server::BasicHttpResponse
);
521 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
522 http_response
->AddCustomHeader("Location", redirect_target
.spec());
523 return http_response
.Pass();
526 // Handles |request| by serving a redirect response.
527 static scoped_ptr
<net::test_server::HttpResponse
> RedirectResponseHandler(
528 const std::string
& path
,
529 const GURL
& redirect_target
,
530 const net::test_server::HttpRequest
& request
) {
531 if (!StartsWithASCII(path
, request
.relative_url
, true))
532 return scoped_ptr
<net::test_server::HttpResponse
>();
534 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
535 new net::test_server::BasicHttpResponse
);
536 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
537 http_response
->AddCustomHeader("Location", redirect_target
.spec());
538 return http_response
.Pass();
541 // Handles |request| by serving an empty response.
542 static scoped_ptr
<net::test_server::HttpResponse
> EmptyResponseHandler(
543 const std::string
& path
,
544 const net::test_server::HttpRequest
& request
) {
545 if (StartsWithASCII(path
, request
.relative_url
, true)) {
546 return scoped_ptr
<net::test_server::HttpResponse
>(
547 new EmptyHttpResponse
);
550 return scoped_ptr
<net::test_server::HttpResponse
>();
553 // Shortcut to return the current MenuManager.
554 extensions::MenuManager
* menu_manager() {
555 return extensions::MenuManager::Get(browser()->profile());
558 // This gets all the items that any extension has registered for possible
559 // inclusion in context menus.
560 MenuItem::List
GetItems() {
561 MenuItem::List result
;
562 std::set
<MenuItem::ExtensionKey
> extension_ids
=
563 menu_manager()->ExtensionIds();
564 std::set
<MenuItem::ExtensionKey
>::iterator i
;
565 for (i
= extension_ids
.begin(); i
!= extension_ids
.end(); ++i
) {
566 const MenuItem::List
* list
= menu_manager()->MenuItems(*i
);
567 result
.insert(result
.end(), list
->begin(), list
->end());
577 void TestHelper(const std::string
& test_name
,
578 const std::string
& app_location
,
579 TestServer test_server
) {
580 // For serving guest pages.
581 if (test_server
== NEEDS_TEST_SERVER
) {
582 if (!StartEmbeddedTestServer()) {
583 LOG(ERROR
) << "FAILED TO START TEST SERVER.";
586 embedded_test_server()->RegisterRequestHandler(
587 base::Bind(&WebViewTest::RedirectResponseHandler
,
588 kRedirectResponsePath
,
589 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
591 embedded_test_server()->RegisterRequestHandler(
592 base::Bind(&WebViewTest::EmptyResponseHandler
, kEmptyResponsePath
));
594 embedded_test_server()->RegisterRequestHandler(
596 &WebViewTest::UserAgentResponseHandler
,
597 kUserAgentRedirectResponsePath
,
598 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
601 LoadAndLaunchPlatformApp(app_location
.c_str(), "Launched");
603 // Flush any pending events to make sure we start with a clean slate.
604 content::RunAllPendingInMessageLoop();
606 content::WebContents
* embedder_web_contents
=
607 GetFirstAppWindowWebContents();
608 if (!embedder_web_contents
) {
609 LOG(ERROR
) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
613 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
614 done_listener
.set_failure_message("TEST_FAILED");
615 if (!content::ExecuteScript(
616 embedder_web_contents
,
617 base::StringPrintf("runTest('%s')", test_name
.c_str()))) {
618 LOG(ERROR
) << "UNABLE TO START TEST.";
621 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
624 content::WebContents
* LoadGuest(const std::string
& guest_path
,
625 const std::string
& app_path
) {
626 GURL::Replacements replace_host
;
627 replace_host
.SetHostStr("localhost");
629 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
630 guest_url
= guest_url
.ReplaceComponents(replace_host
);
632 ui_test_utils::UrlLoadObserver
guest_observer(
633 guest_url
, content::NotificationService::AllSources());
635 LoadAndLaunchPlatformApp(app_path
.c_str(), "guest-loaded");
637 guest_observer
.Wait();
638 content::Source
<content::NavigationController
> source
=
639 guest_observer
.source();
640 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
643 content::WebContents
* guest_web_contents
= source
->GetWebContents();
644 return guest_web_contents
;
647 // Runs media_access/allow tests.
648 void MediaAccessAPIAllowTestHelper(const std::string
& test_name
);
650 // Runs media_access/deny tests, each of them are run separately otherwise
651 // they timeout (mostly on Windows).
652 void MediaAccessAPIDenyTestHelper(const std::string
& test_name
) {
653 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
654 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
656 content::WebContents
* embedder_web_contents
=
657 GetFirstAppWindowWebContents();
658 ASSERT_TRUE(embedder_web_contents
);
660 ExtensionTestMessageListener
test_run_listener("PASSED", false);
661 test_run_listener
.set_failure_message("FAILED");
663 content::ExecuteScript(
664 embedder_web_contents
,
665 base::StringPrintf("startDenyTest('%s')", test_name
.c_str())));
666 ASSERT_TRUE(test_run_listener
.WaitUntilSatisfied());
669 void LoadAppWithGuest(const std::string
& app_path
) {
670 ExtensionTestMessageListener
launched_listener("WebViewTest.LAUNCHED",
672 launched_listener
.set_failure_message("WebViewTest.FAILURE");
673 LoadAndLaunchPlatformApp(app_path
.c_str(), &launched_listener
);
675 guest_web_contents_
= GetGuestViewManager()->WaitForSingleGuestCreated();
678 void SendMessageToEmbedder(const std::string
& message
) {
680 content::ExecuteScript(
681 GetEmbedderWebContents(),
682 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
685 void SendMessageToGuestAndWait(const std::string
& message
,
686 const std::string
& wait_message
) {
687 scoped_ptr
<ExtensionTestMessageListener
> listener
;
688 if (!wait_message
.empty()) {
689 listener
.reset(new ExtensionTestMessageListener(wait_message
, false));
693 content::ExecuteScript(
694 GetGuestWebContents(),
695 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
698 ASSERT_TRUE(listener
->WaitUntilSatisfied());
702 content::WebContents
* GetGuestWebContents() {
703 return guest_web_contents_
;
706 content::WebContents
* GetEmbedderWebContents() {
707 if (!embedder_web_contents_
) {
708 embedder_web_contents_
= GetFirstAppWindowWebContents();
710 return embedder_web_contents_
;
713 extensions::TestGuestViewManager
* GetGuestViewManager() {
714 return static_cast<extensions::TestGuestViewManager
*>(
715 extensions::TestGuestViewManager::FromBrowserContext(
716 browser()->profile()));
719 WebViewTest() : guest_web_contents_(NULL
),
720 embedder_web_contents_(NULL
) {
721 extensions::GuestViewManager::set_factory_for_testing(&factory_
);
725 bool UsesFakeSpeech() {
726 const testing::TestInfo
* const test_info
=
727 testing::UnitTest::GetInstance()->current_test_info();
729 // SpeechRecognition test specific SetUp.
730 return !strcmp(test_info
->name(),
731 "SpeechRecognitionAPI_HasPermissionAllow");
734 scoped_ptr
<content::FakeSpeechRecognitionManager
>
735 fake_speech_recognition_manager_
;
737 extensions::TestGuestViewManagerFactory factory_
;
738 // Note that these are only set if you launch app using LoadAppWithGuest().
739 content::WebContents
* guest_web_contents_
;
740 content::WebContents
* embedder_web_contents_
;
743 class WebViewDPITest
: public WebViewTest
{
745 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
746 WebViewTest::SetUpCommandLine(command_line
);
747 command_line
->AppendSwitchASCII(switches::kForceDeviceScaleFactor
,
748 base::StringPrintf("%f", scale()));
751 static float scale() { return 2.0f
; }
754 // This test verifies that hiding the guest triggers WebContents::WasHidden().
755 IN_PROC_BROWSER_TEST_F(WebViewTest
, GuestVisibilityChanged
) {
756 LoadAppWithGuest("web_view/visibility_changed");
758 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
759 new content::MessageLoopRunner
);
760 WebContentsHiddenObserver
observer(GetGuestWebContents(),
761 loop_runner
->QuitClosure());
763 // Handled in platform_apps/web_view/visibility_changed/main.js
764 SendMessageToEmbedder("hide-guest");
765 if (!observer
.hidden_observed())
769 // This test verifies that hiding the embedder also hides the guest.
770 IN_PROC_BROWSER_TEST_F(WebViewTest
, EmbedderVisibilityChanged
) {
771 LoadAppWithGuest("web_view/visibility_changed");
773 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
774 new content::MessageLoopRunner
);
775 WebContentsHiddenObserver
observer(GetGuestWebContents(),
776 loop_runner
->QuitClosure());
778 // Handled in platform_apps/web_view/visibility_changed/main.js
779 SendMessageToEmbedder("hide-embedder");
780 if (!observer
.hidden_observed())
784 // This test verifies that reloading the embedder reloads the guest (and doest
786 IN_PROC_BROWSER_TEST_F(WebViewTest
, ReloadEmbedder
) {
787 // Just load a guest from other test, we do not want to add a separate
788 // platform_app for this test.
789 LoadAppWithGuest("web_view/visibility_changed");
791 ExtensionTestMessageListener
launched_again_listener("WebViewTest.LAUNCHED",
793 GetEmbedderWebContents()->GetController().Reload(false);
794 ASSERT_TRUE(launched_again_listener
.WaitUntilSatisfied());
797 IN_PROC_BROWSER_TEST_F(WebViewTest
, AcceptTouchEvents
) {
798 LoadAppWithGuest("web_view/accept_touch_events");
800 content::RenderViewHost
* embedder_rvh
=
801 GetEmbedderWebContents()->GetRenderViewHost();
803 bool embedder_has_touch_handler
=
804 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
805 EXPECT_FALSE(embedder_has_touch_handler
);
807 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
809 // Note that we need to wait for the installed/registered touch handler to
810 // appear in browser process before querying |embedder_rvh|.
811 // In practice, since we do a roundrtip from browser process to guest and
812 // back, this is sufficient.
813 embedder_has_touch_handler
=
814 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
815 EXPECT_TRUE(embedder_has_touch_handler
);
817 SendMessageToGuestAndWait("uninstall-touch-handler",
818 "uninstalled-touch-handler");
819 // Same as the note above about waiting.
820 embedder_has_touch_handler
=
821 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
822 EXPECT_FALSE(embedder_has_touch_handler
);
825 // This test ensures JavaScript errors ("Cannot redefine property") do not
826 // happen when a <webview> is removed from DOM and added back.
827 IN_PROC_BROWSER_TEST_F(WebViewTest
,
828 AddRemoveWebView_AddRemoveWebView
) {
829 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
830 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
834 IN_PROC_BROWSER_TEST_F(WebViewTest
, AutoSize
) {
836 // Flaky on XP bot http://crbug.com/299507
837 if (base::win::GetVersion() <= base::win::VERSION_XP
)
841 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
845 // Test for http://crbug.com/419611.
846 IN_PROC_BROWSER_TEST_F(WebViewTest
, DisplayNoneSetSrc
) {
847 LoadAndLaunchPlatformApp("web_view/display_none_set_src",
848 "WebViewTest.LAUNCHED");
849 // Navigate the guest while it's in "display: none" state.
850 SendMessageToEmbedder("navigate-guest");
851 GetGuestViewManager()->WaitForSingleGuestCreated();
853 // Now attempt to navigate the guest again.
854 SendMessageToEmbedder("navigate-guest");
856 ExtensionTestMessageListener
test_passed_listener("WebViewTest.PASSED",
858 // Making the guest visible would trigger loadstop.
859 SendMessageToEmbedder("show-guest");
860 EXPECT_TRUE(test_passed_listener
.WaitUntilSatisfied());
863 // Checks that {allFrames: true} injects script correctly to subframes
865 IN_PROC_BROWSER_TEST_F(WebViewTest
, ExecuteScript
) {
866 ASSERT_TRUE(RunPlatformAppTestWithArg(
867 "platform_apps/web_view/common", "execute_script")) << message_
;
870 // http://crbug.com/326332
871 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_Shim_TestAutosizeAfterNavigation
) {
872 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER
);
875 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAllowTransparencyAttribute
) {
876 TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER
);
879 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeHeight
) {
880 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER
);
883 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeHeight
) {
884 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER
);
887 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeBeforeNavigation
) {
888 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
891 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeBeforeNavigation
) {
892 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
895 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeRemoveAttributes
) {
896 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
899 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeRemoveAttributes
) {
900 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
903 // This test is disabled due to being flaky. http://crbug.com/282116
904 #if defined(OS_WIN) || defined(OS_MACOSX)
905 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
906 DISABLED_Shim_TestAutosizeWithPartialAttributes
908 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
909 Shim_TestAutosizeWithPartialAttributes
911 IN_PROC_BROWSER_TEST_F(WebViewTest
,
912 MAYBE_Shim_TestAutosizeWithPartialAttributes
) {
913 TestHelper("testAutosizeWithPartialAttributes",
918 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAPIMethodExistence
) {
919 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER
);
922 // Tests the existence of WebRequest API event objects on the request
923 // object, on the webview element, and hanging directly off webview.
924 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIExistence
) {
925 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER
);
928 // http://crbug.com/315920
929 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
930 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
932 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
934 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_Shim_TestChromeExtensionURL
) {
935 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
938 // http://crbug.com/315920
939 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
940 #define MAYBE_Shim_TestChromeExtensionRelativePath \
941 DISABLED_Shim_TestChromeExtensionRelativePath
943 #define MAYBE_Shim_TestChromeExtensionRelativePath \
944 Shim_TestChromeExtensionRelativePath
946 IN_PROC_BROWSER_TEST_F(WebViewTest
,
947 MAYBE_Shim_TestChromeExtensionRelativePath
) {
948 TestHelper("testChromeExtensionRelativePath",
953 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewLoad
) {
954 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER
);
957 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewRemoveChild
) {
958 TestHelper("testDisplayNoneWebviewRemoveChild",
959 "web_view/shim", NO_TEST_SERVER
);
962 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayBlock
) {
963 TestHelper("testDisplayBlock", "web_view/shim", NO_TEST_SERVER
);
966 IN_PROC_BROWSER_TEST_F(WebViewTest
,
967 Shim_TestInlineScriptFromAccessibleResources
) {
968 TestHelper("testInlineScriptFromAccessibleResources",
973 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestInvalidChromeExtensionURL
) {
974 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
977 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestEventName
) {
978 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER
);
981 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestOnEventProperty
) {
982 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER
);
985 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadProgressEvent
) {
986 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER
);
989 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDestroyOnEventListener
) {
990 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER
);
993 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestCannotMutateEventName
) {
994 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER
);
997 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestPartitionChangeAfterNavigation
) {
998 TestHelper("testPartitionChangeAfterNavigation",
1003 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1004 Shim_TestPartitionRemovalAfterNavigationFails
) {
1005 TestHelper("testPartitionRemovalAfterNavigationFails",
1010 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScriptFail
) {
1012 // Flaky on XP bot http://crbug.com/266185
1013 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1017 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER
);
1020 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScript
) {
1021 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER
);
1024 IN_PROC_BROWSER_TEST_F(
1026 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged
) {
1027 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
1032 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestTerminateAfterExit
) {
1033 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER
);
1036 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAssignSrcAfterCrash
) {
1037 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER
);
1040 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1041 Shim_TestNavOnConsecutiveSrcAttributeChanges
) {
1042 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
1047 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavOnSrcAttributeChange
) {
1048 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER
);
1051 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigateAfterResize
) {
1052 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER
);
1055 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveSrcAttribute
) {
1056 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1059 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReassignSrcAttribute
) {
1060 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1063 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindow
) {
1064 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER
);
1067 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowTwoListeners
) {
1068 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER
);
1071 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoPreventDefault
) {
1072 TestHelper("testNewWindowNoPreventDefault",
1077 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoReferrerLink
) {
1078 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER
);
1081 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestContentLoadEvent
) {
1082 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER
);
1085 // TODO(fsamuel): Enable this test once <webview> can run in a detached state.
1086 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1087 Shim_TestContentLoadEventWithDisplayNone
) {
1088 TestHelper("testContentLoadEventWithDisplayNone",
1093 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDeclarativeWebRequestAPI
) {
1094 TestHelper("testDeclarativeWebRequestAPI",
1099 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1100 Shim_TestDeclarativeWebRequestAPISendMessage
) {
1101 TestHelper("testDeclarativeWebRequestAPISendMessage",
1106 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPI
) {
1107 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER
);
1110 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIWithHeaders
) {
1111 TestHelper("testWebRequestAPIWithHeaders",
1116 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIGoogleProperty
) {
1117 TestHelper("testWebRequestAPIGoogleProperty",
1122 // This test is disabled due to being flaky. http://crbug.com/309451
1124 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1125 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
1127 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1128 Shim_TestWebRequestListenerSurvivesReparenting
1130 IN_PROC_BROWSER_TEST_F(
1132 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting
) {
1133 TestHelper("testWebRequestListenerSurvivesReparenting",
1138 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadStartLoadRedirect
) {
1139 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER
);
1142 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1143 Shim_TestLoadAbortChromeExtensionURLWrongPartition
) {
1144 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1149 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortEmptyResponse
) {
1150 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER
);
1153 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalChromeURL
) {
1154 TestHelper("testLoadAbortIllegalChromeURL",
1159 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalFileURL
) {
1160 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER
);
1163 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalJavaScriptURL
) {
1164 TestHelper("testLoadAbortIllegalJavaScriptURL",
1169 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortInvalidNavigation
) {
1170 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER
);
1173 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortNonWebSafeScheme
) {
1174 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER
);
1177 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReload
) {
1178 TestHelper("testReload", "web_view/shim", NO_TEST_SERVER
);
1181 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReloadAfterTerminate
) {
1182 TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER
);
1185 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestGetProcessId
) {
1186 TestHelper("testGetProcessId", "web_view/shim", NO_TEST_SERVER
);
1189 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestHiddenBeforeNavigation
) {
1190 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
1193 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewOnExit
) {
1194 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1196 // Launch the app and wait until it's ready to load a test.
1197 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1199 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1200 ASSERT_TRUE(embedder_web_contents
);
1202 GURL::Replacements replace_host
;
1203 replace_host
.SetHostStr("localhost");
1205 std::string
guest_path(
1206 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1207 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
1208 guest_url
= guest_url
.ReplaceComponents(replace_host
);
1210 ui_test_utils::UrlLoadObserver
guest_observer(
1211 guest_url
, content::NotificationService::AllSources());
1213 // Run the test and wait until the guest WebContents is available and has
1214 // finished loading.
1215 ExtensionTestMessageListener
guest_loaded_listener("guest-loaded", false);
1216 EXPECT_TRUE(content::ExecuteScript(
1217 embedder_web_contents
,
1218 "runTest('testRemoveWebviewOnExit')"));
1219 guest_observer
.Wait();
1221 content::Source
<content::NavigationController
> source
=
1222 guest_observer
.source();
1223 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
1226 ASSERT_TRUE(guest_loaded_listener
.WaitUntilSatisfied());
1228 content::WebContentsDestroyedWatcher
destroyed_watcher(
1229 source
->GetWebContents());
1231 // Tell the embedder to kill the guest.
1232 EXPECT_TRUE(content::ExecuteScript(
1233 embedder_web_contents
,
1234 "removeWebviewOnExitDoCrash();"));
1236 // Wait until the guest WebContents is destroyed.
1237 destroyed_watcher
.Wait();
1240 // Remove <webview> immediately after navigating it.
1241 // This is a regression test for http://crbug.com/276023.
1242 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewAfterNavigation
) {
1243 TestHelper("testRemoveWebviewAfterNavigation",
1248 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigationToExternalProtocol
) {
1249 TestHelper("testNavigationToExternalProtocol",
1254 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1255 Shim_TestResizeWebviewWithDisplayNoneResizesContent
) {
1256 TestHelper("testResizeWebviewWithDisplayNoneResizesContent",
1261 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestResizeWebviewResizesContent
) {
1262 TestHelper("testResizeWebviewResizesContent",
1267 // This test makes sure we do not crash if app is closed while interstitial
1268 // page is being shown in guest.
1269 IN_PROC_BROWSER_TEST_F(WebViewTest
, InterstitialTeardown
) {
1271 // Flaky on XP bot http://crbug.com/297014
1272 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1276 // Start a HTTPS server so we can load an interstitial page inside guest.
1277 net::SpawnedTestServer::SSLOptions ssl_options
;
1278 ssl_options
.server_certificate
=
1279 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME
;
1280 net::SpawnedTestServer
https_server(
1281 net::SpawnedTestServer::TYPE_HTTPS
, ssl_options
,
1282 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1283 ASSERT_TRUE(https_server
.Start());
1285 net::HostPortPair host_and_port
= https_server
.host_port_pair();
1287 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded");
1289 // Now load the guest.
1290 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1291 ExtensionTestMessageListener
second("GuestAddedToDom", false);
1292 EXPECT_TRUE(content::ExecuteScript(
1293 embedder_web_contents
,
1294 base::StringPrintf("loadGuest(%d);\n", host_and_port
.port())));
1295 ASSERT_TRUE(second
.WaitUntilSatisfied());
1297 // Wait for interstitial page to be shown in guest.
1298 content::WebContents
* guest_web_contents
=
1299 GetGuestViewManager()->WaitForSingleGuestCreated();
1300 ASSERT_TRUE(guest_web_contents
->GetRenderProcessHost()->IsIsolatedGuest());
1301 content::WaitForInterstitialAttach(guest_web_contents
);
1303 // Now close the app while interstitial page being shown in guest.
1304 extensions::AppWindow
* window
= GetFirstAppWindow();
1305 window
->GetBaseWindow()->Close();
1308 IN_PROC_BROWSER_TEST_F(WebViewTest
, ShimSrcAttribute
) {
1309 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1313 // This test verifies that prerendering has been disabled inside <webview>.
1314 // This test is here rather than in PrerenderBrowserTest for testing convenience
1315 // only. If it breaks then this is a bug in the prerenderer.
1316 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPrerenderer
) {
1317 ASSERT_TRUE(StartEmbeddedTestServer());
1318 content::WebContents
* guest_web_contents
=
1320 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1321 "web_view/noprerenderer");
1322 ASSERT_TRUE(guest_web_contents
!= NULL
);
1324 PrerenderLinkManager
* prerender_link_manager
=
1325 PrerenderLinkManagerFactory::GetForProfile(
1326 Profile::FromBrowserContext(guest_web_contents
->GetBrowserContext()));
1327 ASSERT_TRUE(prerender_link_manager
!= NULL
);
1328 EXPECT_TRUE(prerender_link_manager
->IsEmpty());
1331 // Verify that existing <webview>'s are detected when the task manager starts
1333 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerExistingWebView
) {
1334 ASSERT_TRUE(StartEmbeddedTestServer());
1336 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1337 "web_view/task_manager");
1339 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1341 const char* guest_title
= "WebViewed test content";
1342 const char* app_name
= "<webview> task manager test";
1343 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1344 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1345 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1346 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1348 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1349 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1350 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1351 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1354 // Verify that the task manager notices the creation of new <webview>'s.
1355 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerNewWebView
) {
1356 ASSERT_TRUE(StartEmbeddedTestServer());
1358 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1360 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1361 "web_view/task_manager");
1363 const char* guest_title
= "WebViewed test content";
1364 const char* app_name
= "<webview> task manager test";
1365 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1366 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1367 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1368 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1370 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1371 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1372 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1373 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1376 // This tests cookie isolation for packaged apps with webview tags. It navigates
1377 // the main browser window to a page that sets a cookie and loads an app with
1378 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1379 // storage isolation is enforced.
1380 // This test is flaky. See http://crbug.com/294196.
1381 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_CookieIsolation
) {
1382 ASSERT_TRUE(StartEmbeddedTestServer());
1383 const std::string kExpire
=
1384 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1385 std::string
cookie_script1(kExpire
);
1386 cookie_script1
.append(
1387 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1388 std::string
cookie_script2(kExpire
);
1389 cookie_script2
.append(
1390 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1392 GURL::Replacements replace_host
;
1393 replace_host
.SetHostStr("localhost");
1395 GURL set_cookie_url
= embedded_test_server()->GetURL(
1396 "/extensions/platform_apps/isolation/set_cookie.html");
1397 set_cookie_url
= set_cookie_url
.ReplaceComponents(replace_host
);
1399 // The first two partitions will be used to set cookies and ensure they are
1400 // shared. The named partition is used to ensure that cookies are isolated
1401 // between partitions within the same app.
1402 content::WebContents
* cookie_contents1
;
1403 content::WebContents
* cookie_contents2
;
1404 content::WebContents
* named_partition_contents1
;
1405 content::WebContents
* named_partition_contents2
;
1407 NavigateAndOpenAppForIsolation(set_cookie_url
, &cookie_contents1
,
1408 &cookie_contents2
, &named_partition_contents1
,
1409 &named_partition_contents2
, NULL
, NULL
, NULL
);
1411 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1412 EXPECT_TRUE(content::ExecuteScript(cookie_contents2
, cookie_script2
));
1415 std::string cookie_value
;
1417 // Test the regular browser context to ensure we have only one cookie.
1418 ui_test_utils::GetCookies(GURL("http://localhost"),
1419 browser()->tab_strip_model()->GetWebContentsAt(0),
1420 &cookie_size
, &cookie_value
);
1421 EXPECT_EQ("testCookie=1", cookie_value
);
1423 // The default behavior is to combine webview tags with no explicit partition
1424 // declaration into the same in-memory partition. Test the webview tags to
1425 // ensure we have properly set the cookies and we have both cookies in both
1427 ui_test_utils::GetCookies(GURL("http://localhost"),
1429 &cookie_size
, &cookie_value
);
1430 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1432 ui_test_utils::GetCookies(GURL("http://localhost"),
1434 &cookie_size
, &cookie_value
);
1435 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1437 // The third tag should not have any cookies as it is in a separate partition.
1438 ui_test_utils::GetCookies(GURL("http://localhost"),
1439 named_partition_contents1
,
1440 &cookie_size
, &cookie_value
);
1441 EXPECT_EQ("", cookie_value
);
1444 // This tests that in-memory storage partitions are reset on browser restart,
1445 // but persistent ones maintain state for cookies and HTML5 storage.
1446 IN_PROC_BROWSER_TEST_F(WebViewTest
, PRE_StoragePersistence
) {
1447 ASSERT_TRUE(StartEmbeddedTestServer());
1448 const std::string kExpire
=
1449 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1450 std::string
cookie_script1(kExpire
);
1451 cookie_script1
.append(
1452 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1453 std::string
cookie_script2(kExpire
);
1454 cookie_script2
.append(
1455 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1456 std::string
cookie_script3(kExpire
);
1457 cookie_script3
.append(
1458 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1460 // We don't care where the main browser is on this test.
1461 GURL
blank_url("about:blank");
1463 // The first two partitions will be used to set cookies and ensure they are
1464 // shared. The named partition is used to ensure that cookies are isolated
1465 // between partitions within the same app.
1466 content::WebContents
* cookie_contents1
;
1467 content::WebContents
* cookie_contents2
;
1468 content::WebContents
* named_partition_contents1
;
1469 content::WebContents
* named_partition_contents2
;
1470 content::WebContents
* persistent_partition_contents1
;
1471 content::WebContents
* persistent_partition_contents2
;
1472 content::WebContents
* persistent_partition_contents3
;
1473 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1474 &cookie_contents2
, &named_partition_contents1
,
1475 &named_partition_contents2
,
1476 &persistent_partition_contents1
,
1477 &persistent_partition_contents2
,
1478 &persistent_partition_contents3
);
1480 // Set the inmemory=true cookie for tags with inmemory partitions.
1481 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1482 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1
,
1485 // For the two different persistent storage partitions, set the
1486 // two different cookies so we can check that they aren't comingled below.
1487 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1
,
1490 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3
,
1494 std::string cookie_value
;
1496 // Check that all in-memory partitions have a cookie set.
1497 ui_test_utils::GetCookies(GURL("http://localhost"),
1499 &cookie_size
, &cookie_value
);
1500 EXPECT_EQ("inmemory=true", cookie_value
);
1501 ui_test_utils::GetCookies(GURL("http://localhost"),
1503 &cookie_size
, &cookie_value
);
1504 EXPECT_EQ("inmemory=true", cookie_value
);
1505 ui_test_utils::GetCookies(GURL("http://localhost"),
1506 named_partition_contents1
,
1507 &cookie_size
, &cookie_value
);
1508 EXPECT_EQ("inmemory=true", cookie_value
);
1509 ui_test_utils::GetCookies(GURL("http://localhost"),
1510 named_partition_contents2
,
1511 &cookie_size
, &cookie_value
);
1512 EXPECT_EQ("inmemory=true", cookie_value
);
1514 // Check that all persistent partitions kept their state.
1515 ui_test_utils::GetCookies(GURL("http://localhost"),
1516 persistent_partition_contents1
,
1517 &cookie_size
, &cookie_value
);
1518 EXPECT_EQ("persist1=true", cookie_value
);
1519 ui_test_utils::GetCookies(GURL("http://localhost"),
1520 persistent_partition_contents2
,
1521 &cookie_size
, &cookie_value
);
1522 EXPECT_EQ("persist1=true", cookie_value
);
1523 ui_test_utils::GetCookies(GURL("http://localhost"),
1524 persistent_partition_contents3
,
1525 &cookie_size
, &cookie_value
);
1526 EXPECT_EQ("persist2=true", cookie_value
);
1529 // This is the post-reset portion of the StoragePersistence test. See
1530 // PRE_StoragePersistence for main comment.
1531 #if defined(OS_CHROMEOS)
1532 // http://crbug.com/223888
1533 #define MAYBE_StoragePersistence DISABLED_StoragePersistence
1535 #define MAYBE_StoragePersistence StoragePersistence
1537 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_StoragePersistence
) {
1538 ASSERT_TRUE(StartEmbeddedTestServer());
1540 // We don't care where the main browser is on this test.
1541 GURL
blank_url("about:blank");
1543 // The first two partitions will be used to set cookies and ensure they are
1544 // shared. The named partition is used to ensure that cookies are isolated
1545 // between partitions within the same app.
1546 content::WebContents
* cookie_contents1
;
1547 content::WebContents
* cookie_contents2
;
1548 content::WebContents
* named_partition_contents1
;
1549 content::WebContents
* named_partition_contents2
;
1550 content::WebContents
* persistent_partition_contents1
;
1551 content::WebContents
* persistent_partition_contents2
;
1552 content::WebContents
* persistent_partition_contents3
;
1553 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1554 &cookie_contents2
, &named_partition_contents1
,
1555 &named_partition_contents2
,
1556 &persistent_partition_contents1
,
1557 &persistent_partition_contents2
,
1558 &persistent_partition_contents3
);
1561 std::string cookie_value
;
1563 // Check that all in-memory partitions lost their state.
1564 ui_test_utils::GetCookies(GURL("http://localhost"),
1566 &cookie_size
, &cookie_value
);
1567 EXPECT_EQ("", cookie_value
);
1568 ui_test_utils::GetCookies(GURL("http://localhost"),
1570 &cookie_size
, &cookie_value
);
1571 EXPECT_EQ("", cookie_value
);
1572 ui_test_utils::GetCookies(GURL("http://localhost"),
1573 named_partition_contents1
,
1574 &cookie_size
, &cookie_value
);
1575 EXPECT_EQ("", cookie_value
);
1576 ui_test_utils::GetCookies(GURL("http://localhost"),
1577 named_partition_contents2
,
1578 &cookie_size
, &cookie_value
);
1579 EXPECT_EQ("", cookie_value
);
1581 // Check that all persistent partitions kept their state.
1582 ui_test_utils::GetCookies(GURL("http://localhost"),
1583 persistent_partition_contents1
,
1584 &cookie_size
, &cookie_value
);
1585 EXPECT_EQ("persist1=true", cookie_value
);
1586 ui_test_utils::GetCookies(GURL("http://localhost"),
1587 persistent_partition_contents2
,
1588 &cookie_size
, &cookie_value
);
1589 EXPECT_EQ("persist1=true", cookie_value
);
1590 ui_test_utils::GetCookies(GURL("http://localhost"),
1591 persistent_partition_contents3
,
1592 &cookie_size
, &cookie_value
);
1593 EXPECT_EQ("persist2=true", cookie_value
);
1596 // This tests DOM storage isolation for packaged apps with webview tags. It
1597 // loads an app with multiple webview tags and each tag sets DOM storage
1598 // entries, which the test checks to ensure proper storage isolation is
1600 // Times out regularly on Windows. See http://crbug.com/248873.
1602 #define MAYBE_DOMStorageIsolation DISABLED_DOMStorageIsolation
1604 #define MAYBE_DOMStorageIsolation DOMStorageIsolation
1606 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_DOMStorageIsolation
) {
1607 ASSERT_TRUE(StartEmbeddedTestServer());
1608 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1611 std::string
get_local_storage("window.domAutomationController.send("
1612 "window.localStorage.getItem('foo') || 'badval')");
1613 std::string
get_session_storage("window.domAutomationController.send("
1614 "window.sessionStorage.getItem('bar') || 'badval')");
1616 content::WebContents
* default_tag_contents1
;
1617 content::WebContents
* default_tag_contents2
;
1618 content::WebContents
* storage_contents1
;
1619 content::WebContents
* storage_contents2
;
1621 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1622 &default_tag_contents2
, &storage_contents1
,
1623 &storage_contents2
, NULL
, NULL
, NULL
);
1625 // Initialize the storage for the first of the two tags that share a storage
1627 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1628 "initDomStorage('page1')"));
1630 // Let's test that the expected values are present in the first tag, as they
1631 // will be overwritten once we call the initDomStorage on the second tag.
1632 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1633 get_local_storage
.c_str(),
1635 EXPECT_STREQ("local-page1", output
.c_str());
1636 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1637 get_session_storage
.c_str(),
1639 EXPECT_STREQ("session-page1", output
.c_str());
1641 // Now, init the storage in the second tag in the same storage partition,
1642 // which will overwrite the shared localStorage.
1643 EXPECT_TRUE(content::ExecuteScript(storage_contents2
,
1644 "initDomStorage('page2')"));
1646 // The localStorage value now should reflect the one written through the
1648 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1649 get_local_storage
.c_str(),
1651 EXPECT_STREQ("local-page2", output
.c_str());
1652 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1653 get_local_storage
.c_str(),
1655 EXPECT_STREQ("local-page2", output
.c_str());
1657 // Session storage is not shared though, as each webview tag has separate
1658 // instance, even if they are in the same storage partition.
1659 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1660 get_session_storage
.c_str(),
1662 EXPECT_STREQ("session-page1", output
.c_str());
1663 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1664 get_session_storage
.c_str(),
1666 EXPECT_STREQ("session-page2", output
.c_str());
1668 // Also, let's check that the main browser and another tag that doesn't share
1669 // the same partition don't have those values stored.
1670 EXPECT_TRUE(ExecuteScriptAndExtractString(
1671 browser()->tab_strip_model()->GetWebContentsAt(0),
1672 get_local_storage
.c_str(),
1674 EXPECT_STREQ("badval", output
.c_str());
1675 EXPECT_TRUE(ExecuteScriptAndExtractString(
1676 browser()->tab_strip_model()->GetWebContentsAt(0),
1677 get_session_storage
.c_str(),
1679 EXPECT_STREQ("badval", output
.c_str());
1680 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1681 get_local_storage
.c_str(),
1683 EXPECT_STREQ("badval", output
.c_str());
1684 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1685 get_session_storage
.c_str(),
1687 EXPECT_STREQ("badval", output
.c_str());
1690 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1691 // an app with multiple webview tags and each tag creates an IndexedDB record,
1692 // which the test checks to ensure proper storage isolation is enforced.
1693 // This test is flaky. See http://crbug.com/248500.
1694 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_IndexedDBIsolation
) {
1695 ASSERT_TRUE(StartEmbeddedTestServer());
1696 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1698 content::WebContents
* default_tag_contents1
;
1699 content::WebContents
* default_tag_contents2
;
1700 content::WebContents
* storage_contents1
;
1701 content::WebContents
* storage_contents2
;
1703 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1704 &default_tag_contents2
, &storage_contents1
,
1705 &storage_contents2
, NULL
, NULL
, NULL
);
1707 // Initialize the storage for the first of the two tags that share a storage
1709 ExecuteScriptWaitForTitle(storage_contents1
, "initIDB()", "idb created");
1710 ExecuteScriptWaitForTitle(storage_contents1
, "addItemIDB(7, 'page1')",
1711 "addItemIDB complete");
1712 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1713 "readItemIDB complete");
1716 std::string
get_value(
1717 "window.domAutomationController.send(getValueIDB() || 'badval')");
1719 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1720 get_value
.c_str(), &output
));
1721 EXPECT_STREQ("page1", output
.c_str());
1723 // Initialize the db in the second tag.
1724 ExecuteScriptWaitForTitle(storage_contents2
, "initIDB()", "idb open");
1726 // Since we share a partition, reading the value should return the existing
1728 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1729 "readItemIDB complete");
1730 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1731 get_value
.c_str(), &output
));
1732 EXPECT_STREQ("page1", output
.c_str());
1734 // Now write through the second tag and read it back.
1735 ExecuteScriptWaitForTitle(storage_contents2
, "addItemIDB(7, 'page2')",
1736 "addItemIDB complete");
1737 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1738 "readItemIDB complete");
1739 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1740 get_value
.c_str(), &output
));
1741 EXPECT_STREQ("page2", output
.c_str());
1743 // Reset the document title, otherwise the next call will not see a change and
1744 // will hang waiting for it.
1745 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1746 "document.title = 'foo'"));
1748 // Read through the first tag to ensure we have the second value.
1749 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1750 "readItemIDB complete");
1751 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1752 get_value
.c_str(), &output
));
1753 EXPECT_STREQ("page2", output
.c_str());
1755 // Now, let's confirm there is no database in the main browser and another
1756 // tag that doesn't share the same partition. Due to the IndexedDB API design,
1757 // open will succeed, but the version will be 1, since it creates the database
1758 // if it is not found. The two tags use database version 3, so we avoid
1760 const char* script
=
1761 "indexedDB.open('isolation').onsuccess = function(e) {"
1762 " if (e.target.result.version == 1)"
1763 " document.title = 'db not found';"
1765 " document.title = 'error';"
1767 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1768 script
, "db not found");
1769 ExecuteScriptWaitForTitle(default_tag_contents1
, script
, "db not found");
1772 // This test ensures that closing app window on 'loadcommit' does not crash.
1773 // The test launches an app with guest and closes the window on loadcommit. It
1774 // then launches the app window again. The process is repeated 3 times.
1775 // http://crbug.com/291278
1777 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1779 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1781 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_CloseOnLoadcommit
) {
1782 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1783 "done-close-on-loadcommit");
1786 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIDeny_TestDeny
) {
1787 MediaAccessAPIDenyTestHelper("testDeny");
1790 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1791 MediaAccessAPIDeny_TestDenyThenAllowThrows
) {
1792 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1795 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1796 MediaAccessAPIDeny_TestDenyWithPreventDefault
) {
1797 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1800 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1801 MediaAccessAPIDeny_TestNoListenersImplyDeny
) {
1802 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1805 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1806 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny
) {
1807 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1810 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string
& test_name
) {
1811 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1812 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1814 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1815 ASSERT_TRUE(embedder_web_contents
);
1816 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
1817 embedder_web_contents
->SetDelegate(mock
.get());
1819 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1820 done_listener
.set_failure_message("TEST_FAILED");
1822 content::ExecuteScript(
1823 embedder_web_contents
,
1824 base::StringPrintf("startAllowTest('%s')",
1825 test_name
.c_str())));
1826 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1828 mock
->WaitForRequestMediaPermission();
1831 IN_PROC_BROWSER_TEST_F(WebViewTest
, OpenURLFromTab_CurrentTab_Abort
) {
1832 LoadAppWithGuest("web_view/simple");
1834 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will
1835 // navigate the current <webview>.
1836 ExtensionTestMessageListener
load_listener("WebViewTest.LOADSTOP", false);
1838 // Navigating to a file URL is forbidden inside a <webview>.
1839 content::OpenURLParams
params(GURL("file://foo"),
1840 content::Referrer(),
1842 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
1843 true /* is_renderer_initiated */);
1844 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1845 GetGuestWebContents(), params
);
1847 ASSERT_TRUE(load_listener
.WaitUntilSatisfied());
1849 // Verify that the <webview> ends up at about:blank.
1850 EXPECT_EQ(GURL(url::kAboutBlankURL
),
1851 GetGuestWebContents()->GetLastCommittedURL());
1854 IN_PROC_BROWSER_TEST_F(WebViewTest
, OpenURLFromTab_NewWindow_Abort
) {
1855 LoadAppWithGuest("web_view/simple");
1857 // Verify that OpenURLFromTab with a window disposition of NEW_BACKGROUND_TAB
1858 // will trigger the <webview>'s New Window API.
1859 ExtensionTestMessageListener
new_window_listener(
1860 "WebViewTest.NEWWINDOW", false);
1862 // Navigating to a file URL is forbidden inside a <webview>.
1863 content::OpenURLParams
params(GURL("file://foo"),
1864 content::Referrer(),
1866 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
1867 true /* is_renderer_initiated */);
1868 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1869 GetGuestWebContents(), params
);
1871 ASSERT_TRUE(new_window_listener
.WaitUntilSatisfied());
1873 // Verify that a new guest was created.
1874 content::WebContents
* new_guest_web_contents
=
1875 GetGuestViewManager()->GetLastGuestCreated();
1876 EXPECT_NE(GetGuestWebContents(), new_guest_web_contents
);
1878 // Verify that the new <webview> guest ends up at about:blank.
1879 EXPECT_EQ(GURL(url::kAboutBlankURL
),
1880 new_guest_web_contents
->GetLastCommittedURL());
1883 // This test executes the context menu command 'LanguageSettings' which will
1884 // load chrome://settings/languages in a browser window. This is a browser-
1885 // initiated operation and so we expect this to succeed if the embedder is
1886 // allowed to perform the operation.
1887 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenuLanguageSettings
) {
1888 LoadAppWithGuest("web_view/context_menus/basic");
1890 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1891 content::WebContents
* embedder
= GetEmbedderWebContents();
1892 ASSERT_TRUE(embedder
);
1894 // Create and build our test context menu.
1895 content::WebContentsAddedObserver web_contents_added_observer
;
1897 GURL
page_url("http://www.google.com");
1898 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1899 guest_web_contents
, page_url
, GURL(), GURL()));
1900 menu
->ExecuteCommand(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS
, 0);
1902 content::WebContents
* new_contents
=
1903 web_contents_added_observer
.GetWebContents();
1905 // Verify that a new WebContents has been created that is at the Language
1907 EXPECT_EQ(GURL("chrome://settings/languages"),
1908 new_contents
->GetVisibleURL());
1911 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenusAPI_Basic
) {
1912 LoadAppWithGuest("web_view/context_menus/basic");
1914 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1915 content::WebContents
* embedder
= GetEmbedderWebContents();
1916 ASSERT_TRUE(embedder
);
1918 // 1. Basic property test.
1919 ExecuteScriptWaitForTitle(embedder
, "checkProperties()", "ITEM_CHECKED");
1921 // 2. Create a menu item and wait for created callback to be called.
1922 ExecuteScriptWaitForTitle(embedder
, "createMenuItem()", "ITEM_CREATED");
1924 // 3. Click the created item, wait for the click handlers to fire from JS.
1925 ExtensionTestMessageListener
click_listener("ITEM_CLICKED", false);
1926 GURL
page_url("http://www.google.com");
1927 // Create and build our test context menu.
1928 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1929 guest_web_contents
, page_url
, GURL(), GURL()));
1931 // Look for the extension item in the menu, and execute it.
1932 int command_id
= ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1933 ASSERT_TRUE(menu
->IsCommandIdEnabled(command_id
));
1934 menu
->ExecuteCommand(command_id
, 0);
1936 // Wait for embedder's script to tell us its onclick fired, it does
1937 // chrome.test.sendMessage('ITEM_CLICKED')
1938 ASSERT_TRUE(click_listener
.WaitUntilSatisfied());
1940 // 4. Update the item's title and verify.
1941 ExecuteScriptWaitForTitle(embedder
, "updateMenuItem()", "ITEM_UPDATED");
1942 MenuItem::List items
= GetItems();
1943 ASSERT_EQ(1u, items
.size());
1944 MenuItem
* item
= items
.at(0);
1945 EXPECT_EQ("new_title", item
->title());
1947 // 5. Remove the item.
1948 ExecuteScriptWaitForTitle(embedder
, "removeItem()", "ITEM_REMOVED");
1949 MenuItem::List items_after_removal
= GetItems();
1950 ASSERT_EQ(0u, items_after_removal
.size());
1952 // 6. Add some more items.
1953 ExecuteScriptWaitForTitle(
1954 embedder
, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1955 MenuItem::List items_after_insertion
= GetItems();
1956 ASSERT_EQ(3u, items_after_insertion
.size());
1958 // 7. Test removeAll().
1959 ExecuteScriptWaitForTitle(embedder
, "removeAllItems()", "ITEM_ALL_REMOVED");
1960 MenuItem::List items_after_all_removal
= GetItems();
1961 ASSERT_EQ(0u, items_after_all_removal
.size());
1964 // Called in the TestContextMenu test to cancel the context menu after its
1965 // shown notification is received.
1966 static bool ContextMenuNotificationCallback(
1967 const content::NotificationSource
& source
,
1968 const content::NotificationDetails
& details
) {
1969 auto context_menu
= content::Source
<RenderViewContextMenu
>(source
).ptr();
1970 base::MessageLoop::current()->PostTask(
1971 FROM_HERE
, base::Bind(&RenderViewContextMenuBase::Cancel
,
1972 base::Unretained(context_menu
)));
1976 // Tests that a context menu is created when right-clicking in the webview. This
1977 // also tests that the 'contextmenu' event is handled correctly.
1978 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestContextMenu
) {
1979 LoadAppWithGuest("web_view/context_menus/basic");
1980 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1982 // Register an observer for the context menu.
1983 content::WindowedNotificationObserver
menu_observer(
1984 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
,
1985 base::Bind(ContextMenuNotificationCallback
));
1987 // Open a context menu.
1988 blink::WebMouseEvent mouse_event
;
1989 mouse_event
.type
= blink::WebInputEvent::MouseDown
;
1990 mouse_event
.button
= blink::WebMouseEvent::ButtonRight
;
1993 guest_web_contents
->GetRenderViewHost()->ForwardMouseEvent(mouse_event
);
1994 mouse_event
.type
= blink::WebInputEvent::MouseUp
;
1995 guest_web_contents
->GetRenderViewHost()->ForwardMouseEvent(mouse_event
);
1997 // Wait for the context menu to be visible.
1998 menu_observer
.Wait();
2001 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllow
) {
2002 MediaAccessAPIAllowTestHelper("testAllow");
2005 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAndThenDeny
) {
2006 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
2009 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowTwice
) {
2010 MediaAccessAPIAllowTestHelper("testAllowTwice");
2013 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAsync
) {
2014 MediaAccessAPIAllowTestHelper("testAllowAsync");
2017 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestCheck
) {
2018 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2019 LoadAndLaunchPlatformApp("web_view/media_access/check", "Launched");
2021 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
2022 ASSERT_TRUE(embedder_web_contents
);
2023 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
2024 embedder_web_contents
->SetDelegate(mock
.get());
2026 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
2027 done_listener
.set_failure_message("TEST_FAILED");
2029 content::ExecuteScript(
2030 embedder_web_contents
,
2031 base::StringPrintf("startCheckTest('')")));
2032 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
2034 mock
->WaitForCheckMediaPermission();
2037 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
2039 IN_PROC_BROWSER_TEST_F(WebViewTest
, ScreenCoordinates
) {
2040 ASSERT_TRUE(RunPlatformAppTestWithArg(
2041 "platform_apps/web_view/common", "screen_coordinates"))
2045 #if defined(OS_CHROMEOS)
2046 IN_PROC_BROWSER_TEST_F(WebViewTest
, ChromeVoxInjection
) {
2048 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
2050 ASSERT_TRUE(StartEmbeddedTestServer());
2051 content::WebContents
* guest_web_contents
= LoadGuest(
2052 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
2053 "web_view/chromevox_injection");
2054 ASSERT_TRUE(guest_web_contents
);
2056 chromeos::SpeechMonitor monitor
;
2057 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
2058 true, ui::A11Y_NOTIFICATION_NONE
);
2059 EXPECT_TRUE(monitor
.SkipChromeVoxEnabledMessage());
2061 EXPECT_EQ("chrome vox test title", monitor
.GetNextUtterance());
2065 // Flaky on Windows. http://crbug.com/303966
2067 #define MAYBE_TearDownTest DISABLED_TearDownTest
2069 #define MAYBE_TearDownTest TearDownTest
2071 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_TearDownTest
) {
2072 const extensions::Extension
* extension
=
2073 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
2074 extensions::AppWindow
* window
= NULL
;
2075 if (!GetAppWindowCount())
2076 window
= CreateAppWindow(extension
);
2078 window
= GetFirstAppWindow();
2079 CloseAppWindow(window
);
2081 // Load the app again.
2082 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
2085 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
2086 // platform app) does not have geolocation permission for this test.
2087 // No matter what the API does, geolocation permission would be denied.
2088 // Note that the test name prefix must be "GeolocationAPI".
2089 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessAllow
) {
2090 TestHelper("testDenyDenies",
2091 "web_view/geolocation/embedder_has_no_permission",
2095 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessDeny
) {
2096 TestHelper("testDenyDenies",
2097 "web_view/geolocation/embedder_has_no_permission",
2101 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
2102 // platform app) has geolocation permission
2104 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
2105 // geolocation in this case).
2107 // Also note that these are run separately because OverrideGeolocation() doesn't
2108 // mock out geolocation for multiple navigator.geolocation calls properly and
2109 // the tests become flaky.
2110 // GeolocationAPI* test 1 of 3.
2111 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessAllow
) {
2112 TestHelper("testAllow",
2113 "web_view/geolocation/embedder_has_permission",
2117 // GeolocationAPI* test 2 of 3.
2118 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessDeny
) {
2119 TestHelper("testDeny",
2120 "web_view/geolocation/embedder_has_permission",
2124 // GeolocationAPI* test 3 of 3.
2125 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2126 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow
) {
2127 TestHelper("testMultipleBridgeIdAllow",
2128 "web_view/geolocation/embedder_has_permission",
2133 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
2134 // is handled correctly (and does not crash).
2135 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPICancelGeolocation
) {
2136 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2137 ASSERT_TRUE(RunPlatformAppTest(
2138 "platform_apps/web_view/geolocation/cancel_request")) << message_
;
2141 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_GeolocationRequestGone
) {
2142 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2143 ASSERT_TRUE(RunPlatformAppTest(
2144 "platform_apps/web_view/geolocation/geolocation_request_gone"))
2148 // In following FilesystemAPIRequestFromMainThread* tests, guest request
2149 // filesystem access from main thread of the guest.
2150 // FileSystemAPIRequestFromMainThread* test 1 of 3
2151 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadAllow
) {
2152 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2155 // FileSystemAPIRequestFromMainThread* test 2 of 3.
2156 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadDeny
) {
2157 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2160 // FileSystemAPIRequestFromMainThread* test 3 of 3.
2161 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2162 FileSystemAPIRequestFromMainThreadDefaultAllow
) {
2163 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2166 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
2167 // to request filesystem access from worker thread.
2168 // FileSystemAPIRequestFromWorker* test 1 of 3
2169 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerAllow
) {
2170 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2173 // FileSystemAPIRequestFromWorker* test 2 of 3.
2174 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerDeny
) {
2175 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2178 // FileSystemAPIRequestFromWorker* test 3 of 3.
2179 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2180 FileSystemAPIRequestFromWorkerDefaultAllow
) {
2182 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2185 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
2186 // embedder contains a single webview guest. The guest creates a shared worker
2187 // to request filesystem access from worker thread.
2188 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
2189 IN_PROC_BROWSER_TEST_F(
2191 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow
) {
2192 TestHelper("testAllow",
2193 "web_view/filesystem/shared_worker/single",
2197 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
2198 IN_PROC_BROWSER_TEST_F(
2200 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny
) {
2201 TestHelper("testDeny",
2202 "web_view/filesystem/shared_worker/single",
2206 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2207 IN_PROC_BROWSER_TEST_F(
2209 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow
) {
2212 "web_view/filesystem/shared_worker/single",
2216 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2217 // embedder contains mutiple webview guests. Each guest creates a shared worker
2218 // to request filesystem access from worker thread.
2219 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2220 IN_PROC_BROWSER_TEST_F(
2222 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow
) {
2223 TestHelper("testAllow",
2224 "web_view/filesystem/shared_worker/multiple",
2228 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2229 IN_PROC_BROWSER_TEST_F(
2231 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny
) {
2232 TestHelper("testDeny",
2233 "web_view/filesystem/shared_worker/multiple",
2237 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2238 IN_PROC_BROWSER_TEST_F(
2240 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow
) {
2243 "web_view/filesystem/shared_worker/multiple",
2247 IN_PROC_BROWSER_TEST_F(WebViewTest
, ClearData
) {
2249 // Flaky on XP bot http://crbug.com/282674
2250 if (base::win::GetVersion() <= base::win::VERSION_XP
)
2254 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2255 ASSERT_TRUE(RunPlatformAppTestWithArg(
2256 "platform_apps/web_view/common", "cleardata"))
2260 // This test is disabled on Win due to being flaky. http://crbug.com/294592
2262 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
2264 #define MAYBE_ConsoleMessage ConsoleMessage
2266 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_ConsoleMessage
) {
2267 ASSERT_TRUE(RunPlatformAppTestWithArg(
2268 "platform_apps/web_view/common", "console_messages"))
2272 IN_PROC_BROWSER_TEST_F(WebViewTest
, DownloadPermission
) {
2273 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2274 content::WebContents
* guest_web_contents
=
2275 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2276 "web_view/download");
2277 ASSERT_TRUE(guest_web_contents
);
2279 // Replace WebContentsDelegate with mock version so we can intercept download
2281 content::WebContentsDelegate
* delegate
= guest_web_contents
->GetDelegate();
2282 scoped_ptr
<MockDownloadWebContentsDelegate
>
2283 mock_delegate(new MockDownloadWebContentsDelegate(delegate
));
2284 guest_web_contents
->SetDelegate(mock_delegate
.get());
2287 // 1. Guest requests a download that its embedder denies.
2288 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2289 "startDownload('download-link-1')"));
2290 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2291 mock_delegate
->Reset();
2293 // 2. Guest requests a download that its embedder allows.
2294 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2295 "startDownload('download-link-2')"));
2296 mock_delegate
->WaitForCanDownload(true); // Expect to allow.
2297 mock_delegate
->Reset();
2299 // 3. Guest requests a download that its embedder ignores, this implies deny.
2300 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2301 "startDownload('download-link-3')"));
2302 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2305 // This test makes sure loading <webview> does not crash when there is an
2306 // extension which has content script whitelisted/forced.
2307 IN_PROC_BROWSER_TEST_F(WebViewTest
, WhitelistedContentScript
) {
2308 // Whitelist the extension for running content script we are going to load.
2309 extensions::ExtensionsClient::ScriptingWhitelist whitelist
;
2310 const std::string extension_id
= "imeongpbjoodlnmlakaldhlcmijmhpbb";
2311 whitelist
.push_back(extension_id
);
2312 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist
);
2314 // Load the extension.
2315 const extensions::Extension
* content_script_whitelisted_extension
=
2316 LoadExtension(test_data_dir_
.AppendASCII(
2317 "platform_apps/web_view/extension_api/content_script"));
2318 ASSERT_TRUE(content_script_whitelisted_extension
);
2319 ASSERT_EQ(extension_id
, content_script_whitelisted_extension
->id());
2321 // Now load an app with <webview>.
2322 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2326 IN_PROC_BROWSER_TEST_F(WebViewTest
, SendMessageToExtensionFromGuest
) {
2327 // Load the extension as a normal, non-component extension.
2328 const extensions::Extension
* extension
=
2329 LoadExtension(test_data_dir_
.AppendASCII(
2330 "platform_apps/web_view/extension_api/component_extension"));
2331 ASSERT_TRUE(extension
);
2333 TestHelper("testNonComponentExtension", "web_view/component_extension",
2337 IN_PROC_BROWSER_TEST_F(WebViewTest
, SendMessageToComponentExtensionFromGuest
) {
2338 const extensions::Extension
* component_extension
=
2339 LoadExtensionAsComponent(test_data_dir_
.AppendASCII(
2340 "platform_apps/web_view/extension_api/component_extension"));
2341 ASSERT_TRUE(component_extension
);
2343 TestHelper("testComponentExtension", "web_view/component_extension",
2348 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentReady
) {
2349 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2353 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentInteractive
) {
2354 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2358 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionAllow
) {
2360 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2365 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionDeny
) {
2367 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2372 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_NoPermission
) {
2374 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2375 "speech_recognition_api_no_permission"))
2379 // Tests overriding user agent.
2380 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent
) {
2381 ASSERT_TRUE(RunPlatformAppTestWithArg(
2382 "platform_apps/web_view/common", "useragent")) << message_
;
2385 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent_NewWindow
) {
2386 ASSERT_TRUE(RunPlatformAppTestWithArg(
2387 "platform_apps/web_view/common",
2388 "useragent_newwindow")) << message_
;
2391 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPermission
) {
2392 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2396 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestAlertDialog
) {
2397 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER
);
2400 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestConfirmDialog
) {
2401 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER
);
2404 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogCancel
) {
2405 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER
);
2408 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultCancel
) {
2409 TestHelper("testConfirmDialogDefaultCancel",
2414 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultGCCancel
) {
2415 TestHelper("testConfirmDialogDefaultGCCancel",
2420 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestPromptDialog
) {
2421 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER
);
2424 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoContentSettingsAPI
) {
2425 // Load the extension.
2426 const extensions::Extension
* content_settings_extension
=
2428 test_data_dir_
.AppendASCII(
2429 "platform_apps/web_view/extension_api/content_settings"));
2430 ASSERT_TRUE(content_settings_extension
);
2431 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER
);
2434 #if defined(ENABLE_PLUGINS)
2435 class WebViewPluginTest
: public WebViewTest
{
2437 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
2438 WebViewTest::SetUpCommandLine(command_line
);
2440 // Append the switch to register the pepper plugin.
2441 // library name = <out dir>/<test_name>.<library_extension>
2442 // MIME type = application/x-ppapi-<test_name>
2443 base::FilePath plugin_lib
= GetPluginPath();
2444 EXPECT_TRUE(base::PathExists(plugin_lib
));
2445 base::FilePath::StringType pepper_plugin
= plugin_lib
.value();
2446 pepper_plugin
.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
2447 command_line
->AppendSwitchNative(switches::kRegisterPepperPlugins
,
2451 base::FilePath
GetPluginPath() const {
2452 base::FilePath plugin_dir
;
2453 EXPECT_TRUE(PathService::Get(base::DIR_MODULE
, &plugin_dir
));
2454 return plugin_dir
.Append(library_name
);
2458 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginEvent
) {
2459 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER
);
2462 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginInternalResource
) {
2463 const char kTestMimeType
[] = "application/pdf";
2464 const char kTestFileType
[] = "pdf";
2465 content::WebPluginInfo plugin_info
;
2466 plugin_info
.type
= content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
;
2467 plugin_info
.mime_types
.push_back(
2468 content::WebPluginMimeType(kTestMimeType
, kTestFileType
, std::string()));
2469 content::PluginService::GetInstance()->RegisterInternalPlugin(plugin_info
,
2472 TestHelper("testPluginLoadInternalResource", "web_view/shim", NO_TEST_SERVER
);
2474 #endif // defined(ENABLE_PLUGINS)
2476 class WebViewCaptureTest
: public WebViewTest
{
2478 WebViewCaptureTest() {}
2479 ~WebViewCaptureTest() override
{}
2480 void SetUp() override
{
2481 EnablePixelOutput();
2482 WebViewTest::SetUp();
2486 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestZoomAPI
) {
2487 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER
);
2490 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI
) {
2491 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER
);
2494 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI_findupdate
) {
2495 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER
);
2498 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadDataAPI
) {
2499 TestHelper("testLoadDataAPI", "web_view/shim", NEEDS_TEST_SERVER
);
2502 // This test verifies that the resize and contentResize events work correctly.
2503 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestResizeEvents
) {
2504 TestHelper("testResizeEvents", "web_view/shim", NO_TEST_SERVER
);
2507 // This test verify that the set of rules registries of a webview will be
2508 // removed from RulesRegistryService after the webview is gone.
2509 // http://crbug.com/438327
2510 IN_PROC_BROWSER_TEST_F(
2512 DISABLED_Shim_TestRulesRegistryIDAreRemovedAfterWebViewIsGone
) {
2513 LoadAppWithGuest("web_view/rules_registry");
2515 content::WebContents
* embedder_web_contents
= GetEmbedderWebContents();
2516 ASSERT_TRUE(embedder_web_contents
);
2517 scoped_ptr
<EmbedderWebContentsObserver
> observer(
2518 new EmbedderWebContentsObserver(embedder_web_contents
));
2520 content::WebContents
* guest_web_contents
= GetGuestWebContents();
2521 ASSERT_TRUE(guest_web_contents
);
2522 extensions::WebViewGuest
* guest
=
2523 extensions::WebViewGuest::FromWebContents(guest_web_contents
);
2526 // Register rule for the guest.
2527 Profile
* profile
= browser()->profile();
2528 int rules_registry_id
=
2529 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2530 guest
->owner_web_contents()->GetRenderProcessHost()->GetID(),
2531 guest
->view_instance_id());
2533 extensions::RulesRegistryService
* registry_service
=
2534 extensions::RulesRegistryService::Get(profile
);
2535 extensions::TestRulesRegistry
* rules_registry
=
2536 new extensions::TestRulesRegistry(
2537 content::BrowserThread::UI
, "ui", rules_registry_id
);
2538 registry_service
->RegisterRulesRegistry(make_scoped_refptr(rules_registry
));
2540 EXPECT_TRUE(registry_service
->GetRulesRegistry(
2541 rules_registry_id
, "ui").get());
2543 // Kill the embedder's render process, so the webview will go as well.
2544 content::RenderProcessHost
* host
=
2545 embedder_web_contents
->GetRenderProcessHost();
2546 base::KillProcess(host
->GetHandle(), 0, false);
2547 observer
->WaitForEmbedderRenderProcessTerminate();
2549 EXPECT_FALSE(registry_service
->GetRulesRegistry(
2550 rules_registry_id
, "ui").get());
2553 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_WebViewWebRequestRegistryHasNoCache
) {
2554 LoadAppWithGuest("web_view/rules_registry");
2556 content::WebContents
* guest_web_contents
= GetGuestWebContents();
2557 ASSERT_TRUE(guest_web_contents
);
2558 extensions::WebViewGuest
* guest
=
2559 extensions::WebViewGuest::FromWebContents(guest_web_contents
);
2562 Profile
* profile
= browser()->profile();
2563 extensions::RulesRegistryService
* registry_service
=
2564 extensions::RulesRegistryService::Get(profile
);
2565 int rules_registry_id
=
2566 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2567 guest
->owner_web_contents()->GetRenderProcessHost()->GetID(),
2568 guest
->view_instance_id());
2570 // Get an existing registered rule for the guest.
2571 extensions::RulesRegistry
* registry
=
2572 registry_service
->GetRulesRegistry(
2574 extensions::declarative_webrequest_constants::kOnRequest
).get();
2576 EXPECT_TRUE(registry
);
2577 EXPECT_FALSE(registry
->rules_cache_delegate_for_testing());
2580 // This test verifies that webview.contentWindow works inside an iframe.
2581 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebViewInsideFrame
) {
2582 LoadAppWithGuest("web_view/inside_iframe");
2585 // <webview> screenshot capture fails with ubercomp.
2586 // See http://crbug.com/327035.
2587 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest
,
2588 DISABLED_Shim_ScreenshotCapture
) {
2589 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER
);
2593 // Test is disabled on Windows because it times out often.
2594 // http://crbug.com/403325
2595 #define MAYBE_WebViewInBackgroundPage \
2596 DISABLED_WebViewInBackgroundPage
2598 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2600 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_WebViewInBackgroundPage
) {
2601 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))