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/browser/apps/app_browsertest_util.h"
9 #include "chrome/browser/chrome_content_browser_client.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.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/app_window/native_app_window.h"
32 #include "extensions/browser/guest_view/guest_view_manager.h"
33 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
34 #include "extensions/common/extension.h"
35 #include "extensions/common/extensions_client.h"
36 #include "media/base/media_switches.h"
37 #include "net/test/embedded_test_server/embedded_test_server.h"
38 #include "net/test/embedded_test_server/http_request.h"
39 #include "net/test/embedded_test_server/http_response.h"
40 #include "ui/gl/gl_switches.h"
42 #if defined(OS_CHROMEOS)
43 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
44 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
47 // For fine-grained suppression on flaky tests.
49 #include "base/win/windows_version.h"
52 using extensions::ContextMenuMatcher
;
53 using extensions::MenuItem
;
54 using prerender::PrerenderLinkManager
;
55 using prerender::PrerenderLinkManagerFactory
;
56 using task_manager::browsertest_util::MatchAboutBlankTab
;
57 using task_manager::browsertest_util::MatchAnyApp
;
58 using task_manager::browsertest_util::MatchAnyBackground
;
59 using task_manager::browsertest_util::MatchAnyTab
;
60 using task_manager::browsertest_util::MatchAnyWebView
;
61 using task_manager::browsertest_util::MatchApp
;
62 using task_manager::browsertest_util::MatchBackground
;
63 using task_manager::browsertest_util::MatchWebView
;
64 using task_manager::browsertest_util::WaitForTaskManagerRows
;
68 const char kEmptyResponsePath
[] = "/close-socket";
69 const char kRedirectResponsePath
[] = "/server-redirect";
70 const char kRedirectResponseFullPath
[] =
71 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
73 // Platform-specific filename relative to the chrome executable.
75 const wchar_t library_name
[] = L
"ppapi_tests.dll";
76 #elif defined(OS_MACOSX)
77 const char library_name
[] = "ppapi_tests.plugin";
78 #elif defined(OS_POSIX)
79 const char library_name
[] = "libppapi_tests.so";
82 class EmptyHttpResponse
: public net::test_server::HttpResponse
{
84 virtual std::string
ToResponseString() const OVERRIDE
{
89 class TestInterstitialPageDelegate
: public content::InterstitialPageDelegate
{
91 TestInterstitialPageDelegate() {
93 virtual ~TestInterstitialPageDelegate() {}
94 virtual std::string
GetHTMLContents() OVERRIDE
{ return std::string(); }
97 class TestGuestViewManager
: public extensions::GuestViewManager
{
99 explicit TestGuestViewManager(content::BrowserContext
* context
) :
100 GuestViewManager(context
),
101 seen_guest_removed_(false),
102 web_contents_(NULL
) {}
104 content::WebContents
* WaitForGuestCreated() {
106 return web_contents_
;
108 created_message_loop_runner_
= new content::MessageLoopRunner
;
109 created_message_loop_runner_
->Run();
110 return web_contents_
;
113 void WaitForGuestDeleted() {
114 if (seen_guest_removed_
)
117 deleted_message_loop_runner_
= new content::MessageLoopRunner
;
118 deleted_message_loop_runner_
->Run();
122 // GuestViewManager override:
123 virtual void AddGuest(int guest_instance_id
,
124 content::WebContents
* guest_web_contents
) OVERRIDE
{
125 extensions::GuestViewManager::AddGuest(
126 guest_instance_id
, guest_web_contents
);
127 web_contents_
= guest_web_contents
;
128 seen_guest_removed_
= false;
130 if (created_message_loop_runner_
.get())
131 created_message_loop_runner_
->Quit();
134 virtual void RemoveGuest(int guest_instance_id
) OVERRIDE
{
135 extensions::GuestViewManager::RemoveGuest(guest_instance_id
);
136 web_contents_
= NULL
;
137 seen_guest_removed_
= true;
139 if (deleted_message_loop_runner_
.get())
140 deleted_message_loop_runner_
->Quit();
143 bool seen_guest_removed_
;
144 content::WebContents
* web_contents_
;
145 scoped_refptr
<content::MessageLoopRunner
> created_message_loop_runner_
;
146 scoped_refptr
<content::MessageLoopRunner
> deleted_message_loop_runner_
;
149 // Test factory for creating test instances of GuestViewManager.
150 class TestGuestViewManagerFactory
:
151 public extensions::GuestViewManagerFactory
{
153 TestGuestViewManagerFactory() :
154 test_guest_view_manager_(NULL
) {}
156 virtual ~TestGuestViewManagerFactory() {}
158 virtual extensions::GuestViewManager
* CreateGuestViewManager(
159 content::BrowserContext
* context
) OVERRIDE
{
160 return GetManager(context
);
163 TestGuestViewManager
* GetManager(content::BrowserContext
* context
) {
164 if (!test_guest_view_manager_
) {
165 test_guest_view_manager_
= new TestGuestViewManager(context
);
167 return test_guest_view_manager_
;
171 TestGuestViewManager
* test_guest_view_manager_
;
173 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory
);
176 class WebContentsHiddenObserver
: public content::WebContentsObserver
{
178 WebContentsHiddenObserver(content::WebContents
* web_contents
,
179 const base::Closure
& hidden_callback
)
180 : WebContentsObserver(web_contents
),
181 hidden_callback_(hidden_callback
),
182 hidden_observed_(false) {
185 // WebContentsObserver.
186 virtual void WasHidden() OVERRIDE
{
187 hidden_observed_
= true;
188 hidden_callback_
.Run();
191 bool hidden_observed() { return hidden_observed_
; }
194 base::Closure hidden_callback_
;
195 bool hidden_observed_
;
197 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver
);
200 class InterstitialObserver
: public content::WebContentsObserver
{
202 InterstitialObserver(content::WebContents
* web_contents
,
203 const base::Closure
& attach_callback
,
204 const base::Closure
& detach_callback
)
205 : WebContentsObserver(web_contents
),
206 attach_callback_(attach_callback
),
207 detach_callback_(detach_callback
) {
210 virtual void DidAttachInterstitialPage() OVERRIDE
{
211 attach_callback_
.Run();
214 virtual void DidDetachInterstitialPage() OVERRIDE
{
215 detach_callback_
.Run();
219 base::Closure attach_callback_
;
220 base::Closure detach_callback_
;
222 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver
);
225 void ExecuteScriptWaitForTitle(content::WebContents
* web_contents
,
228 base::string16
expected_title(base::ASCIIToUTF16(title
));
229 base::string16
error_title(base::ASCIIToUTF16("error"));
231 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
232 title_watcher
.AlsoWaitForTitle(error_title
);
233 EXPECT_TRUE(content::ExecuteScript(web_contents
, script
));
234 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
239 // This class intercepts media access request from the embedder. The request
240 // should be triggered only if the embedder API (from tests) allows the request
242 // We do not issue the actual media request; the fact that the request reached
243 // embedder's WebContents is good enough for our tests. This is also to make
244 // the test run successfully on trybots.
245 class MockWebContentsDelegate
: public content::WebContentsDelegate
{
247 MockWebContentsDelegate() : requested_(false) {}
248 virtual ~MockWebContentsDelegate() {}
250 virtual void RequestMediaAccessPermission(
251 content::WebContents
* web_contents
,
252 const content::MediaStreamRequest
& request
,
253 const content::MediaResponseCallback
& callback
) OVERRIDE
{
255 if (message_loop_runner_
.get())
256 message_loop_runner_
->Quit();
259 void WaitForSetMediaPermission() {
262 message_loop_runner_
= new content::MessageLoopRunner
;
263 message_loop_runner_
->Run();
268 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
270 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate
);
273 // This class intercepts download request from the guest.
274 class MockDownloadWebContentsDelegate
: public content::WebContentsDelegate
{
276 explicit MockDownloadWebContentsDelegate(
277 content::WebContentsDelegate
* orig_delegate
)
278 : orig_delegate_(orig_delegate
),
279 waiting_for_decision_(false),
280 expect_allow_(false),
281 decision_made_(false),
282 last_download_allowed_(false) {}
283 virtual ~MockDownloadWebContentsDelegate() {}
285 virtual void CanDownload(
286 content::RenderViewHost
* render_view_host
,
288 const std::string
& request_method
,
289 const base::Callback
<void(bool)>& callback
) OVERRIDE
{
290 orig_delegate_
->CanDownload(
291 render_view_host
, url
, request_method
,
292 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided
,
293 base::Unretained(this)));
296 void WaitForCanDownload(bool expect_allow
) {
297 EXPECT_FALSE(waiting_for_decision_
);
298 waiting_for_decision_
= true;
300 if (decision_made_
) {
301 EXPECT_EQ(expect_allow
, last_download_allowed_
);
305 expect_allow_
= expect_allow
;
306 message_loop_runner_
= new content::MessageLoopRunner
;
307 message_loop_runner_
->Run();
310 void DownloadDecided(bool allow
) {
311 EXPECT_FALSE(decision_made_
);
312 decision_made_
= true;
314 if (waiting_for_decision_
) {
315 EXPECT_EQ(expect_allow_
, allow
);
316 if (message_loop_runner_
.get())
317 message_loop_runner_
->Quit();
320 last_download_allowed_
= allow
;
324 waiting_for_decision_
= false;
325 decision_made_
= false;
329 content::WebContentsDelegate
* orig_delegate_
;
330 bool waiting_for_decision_
;
333 bool last_download_allowed_
;
334 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
336 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate
);
339 class WebViewTest
: public extensions::PlatformAppBrowserTest
{
341 virtual void SetUp() OVERRIDE
{
342 if (UsesFakeSpeech()) {
343 // SpeechRecognition test specific SetUp.
344 fake_speech_recognition_manager_
.reset(
345 new content::FakeSpeechRecognitionManager());
346 fake_speech_recognition_manager_
->set_should_send_fake_response(true);
347 // Inject the fake manager factory so that the test result is returned to
349 content::SpeechRecognitionManager::SetManagerForTesting(
350 fake_speech_recognition_manager_
.get());
352 extensions::PlatformAppBrowserTest::SetUp();
355 virtual void TearDown() OVERRIDE
{
356 if (UsesFakeSpeech()) {
357 // SpeechRecognition test specific TearDown.
358 content::SpeechRecognitionManager::SetManagerForTesting(NULL
);
361 extensions::PlatformAppBrowserTest::TearDown();
364 virtual void SetUpOnMainThread() OVERRIDE
{
365 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
366 const testing::TestInfo
* const test_info
=
367 testing::UnitTest::GetInstance()->current_test_info();
368 // Mock out geolocation for geolocation specific tests.
369 if (!strncmp(test_info
->name(), "GeolocationAPI",
370 strlen("GeolocationAPI"))) {
371 ui_test_utils::OverrideGeolocation(10, 20);
375 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
376 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
377 command_line
->AppendSwitchASCII(switches::kJavaScriptFlags
, "--expose-gc");
379 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
382 // This method is responsible for initializing a packaged app, which contains
383 // multiple webview tags. The tags have different partition identifiers and
384 // their WebContent objects are returned as output. The method also verifies
385 // the expected process allocation and storage partition assignment.
386 // The |navigate_to_url| parameter is used to navigate the main browser
389 // TODO(ajwong): This function is getting to be too large. Either refactor it
390 // so the test can specify a configuration of WebView tags that we will
391 // dynamically inject JS to generate, or move this test wholesale into
392 // something that RunPlatformAppTest() can execute purely in Javascript. This
393 // won't let us do a white-box examination of the StoragePartition equivalence
394 // directly, but we will be able to view the black box effects which is good
395 // enough. http://crbug.com/160361
396 void NavigateAndOpenAppForIsolation(
397 GURL navigate_to_url
,
398 content::WebContents
** default_tag_contents1
,
399 content::WebContents
** default_tag_contents2
,
400 content::WebContents
** named_partition_contents1
,
401 content::WebContents
** named_partition_contents2
,
402 content::WebContents
** persistent_partition_contents1
,
403 content::WebContents
** persistent_partition_contents2
,
404 content::WebContents
** persistent_partition_contents3
) {
405 GURL::Replacements replace_host
;
406 std::string
host_str("localhost"); // Must stay in scope with replace_host.
407 replace_host
.SetHostStr(host_str
);
409 navigate_to_url
= navigate_to_url
.ReplaceComponents(replace_host
);
411 GURL tag_url1
= embedded_test_server()->GetURL(
412 "/extensions/platform_apps/web_view/isolation/cookie.html");
413 tag_url1
= tag_url1
.ReplaceComponents(replace_host
);
414 GURL tag_url2
= embedded_test_server()->GetURL(
415 "/extensions/platform_apps/web_view/isolation/cookie2.html");
416 tag_url2
= tag_url2
.ReplaceComponents(replace_host
);
417 GURL tag_url3
= embedded_test_server()->GetURL(
418 "/extensions/platform_apps/web_view/isolation/storage1.html");
419 tag_url3
= tag_url3
.ReplaceComponents(replace_host
);
420 GURL tag_url4
= embedded_test_server()->GetURL(
421 "/extensions/platform_apps/web_view/isolation/storage2.html");
422 tag_url4
= tag_url4
.ReplaceComponents(replace_host
);
423 GURL tag_url5
= embedded_test_server()->GetURL(
424 "/extensions/platform_apps/web_view/isolation/storage1.html#p1");
425 tag_url5
= tag_url5
.ReplaceComponents(replace_host
);
426 GURL tag_url6
= embedded_test_server()->GetURL(
427 "/extensions/platform_apps/web_view/isolation/storage1.html#p2");
428 tag_url6
= tag_url6
.ReplaceComponents(replace_host
);
429 GURL tag_url7
= embedded_test_server()->GetURL(
430 "/extensions/platform_apps/web_view/isolation/storage1.html#p3");
431 tag_url7
= tag_url7
.ReplaceComponents(replace_host
);
433 ui_test_utils::NavigateToURLWithDisposition(
434 browser(), navigate_to_url
, CURRENT_TAB
,
435 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
437 ui_test_utils::UrlLoadObserver
observer1(
438 tag_url1
, content::NotificationService::AllSources());
439 ui_test_utils::UrlLoadObserver
observer2(
440 tag_url2
, content::NotificationService::AllSources());
441 ui_test_utils::UrlLoadObserver
observer3(
442 tag_url3
, content::NotificationService::AllSources());
443 ui_test_utils::UrlLoadObserver
observer4(
444 tag_url4
, content::NotificationService::AllSources());
445 ui_test_utils::UrlLoadObserver
observer5(
446 tag_url5
, content::NotificationService::AllSources());
447 ui_test_utils::UrlLoadObserver
observer6(
448 tag_url6
, content::NotificationService::AllSources());
449 ui_test_utils::UrlLoadObserver
observer7(
450 tag_url7
, content::NotificationService::AllSources());
451 LoadAndLaunchPlatformApp("web_view/isolation", "Launched");
460 content::Source
<content::NavigationController
> source1
= observer1
.source();
461 EXPECT_TRUE(source1
->GetWebContents()->GetRenderProcessHost()->
463 content::Source
<content::NavigationController
> source2
= observer2
.source();
464 EXPECT_TRUE(source2
->GetWebContents()->GetRenderProcessHost()->
466 content::Source
<content::NavigationController
> source3
= observer3
.source();
467 EXPECT_TRUE(source3
->GetWebContents()->GetRenderProcessHost()->
469 content::Source
<content::NavigationController
> source4
= observer4
.source();
470 EXPECT_TRUE(source4
->GetWebContents()->GetRenderProcessHost()->
472 content::Source
<content::NavigationController
> source5
= observer5
.source();
473 EXPECT_TRUE(source5
->GetWebContents()->GetRenderProcessHost()->
475 content::Source
<content::NavigationController
> source6
= observer6
.source();
476 EXPECT_TRUE(source6
->GetWebContents()->GetRenderProcessHost()->
478 content::Source
<content::NavigationController
> source7
= observer7
.source();
479 EXPECT_TRUE(source7
->GetWebContents()->GetRenderProcessHost()->
482 // Check that the first two tags use the same process and it is different
483 // than the process used by the other two.
484 EXPECT_EQ(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
485 source2
->GetWebContents()->GetRenderProcessHost()->GetID());
486 EXPECT_EQ(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
487 source4
->GetWebContents()->GetRenderProcessHost()->GetID());
488 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
489 source3
->GetWebContents()->GetRenderProcessHost()->GetID());
491 // The two sets of tags should also be isolated from the main browser.
492 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
493 browser()->tab_strip_model()->GetWebContentsAt(0)->
494 GetRenderProcessHost()->GetID());
495 EXPECT_NE(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
496 browser()->tab_strip_model()->GetWebContentsAt(0)->
497 GetRenderProcessHost()->GetID());
499 // Check that the storage partitions of the first two tags match and are
500 // different than the other two.
502 source1
->GetWebContents()->GetRenderProcessHost()->
503 GetStoragePartition(),
504 source2
->GetWebContents()->GetRenderProcessHost()->
505 GetStoragePartition());
507 source3
->GetWebContents()->GetRenderProcessHost()->
508 GetStoragePartition(),
509 source4
->GetWebContents()->GetRenderProcessHost()->
510 GetStoragePartition());
512 source1
->GetWebContents()->GetRenderProcessHost()->
513 GetStoragePartition(),
514 source3
->GetWebContents()->GetRenderProcessHost()->
515 GetStoragePartition());
517 // Ensure the persistent storage partitions are different.
519 source5
->GetWebContents()->GetRenderProcessHost()->
520 GetStoragePartition(),
521 source6
->GetWebContents()->GetRenderProcessHost()->
522 GetStoragePartition());
524 source5
->GetWebContents()->GetRenderProcessHost()->
525 GetStoragePartition(),
526 source7
->GetWebContents()->GetRenderProcessHost()->
527 GetStoragePartition());
529 source1
->GetWebContents()->GetRenderProcessHost()->
530 GetStoragePartition(),
531 source5
->GetWebContents()->GetRenderProcessHost()->
532 GetStoragePartition());
534 source1
->GetWebContents()->GetRenderProcessHost()->
535 GetStoragePartition(),
536 source7
->GetWebContents()->GetRenderProcessHost()->
537 GetStoragePartition());
539 *default_tag_contents1
= source1
->GetWebContents();
540 *default_tag_contents2
= source2
->GetWebContents();
541 *named_partition_contents1
= source3
->GetWebContents();
542 *named_partition_contents2
= source4
->GetWebContents();
543 if (persistent_partition_contents1
) {
544 *persistent_partition_contents1
= source5
->GetWebContents();
546 if (persistent_partition_contents2
) {
547 *persistent_partition_contents2
= source6
->GetWebContents();
549 if (persistent_partition_contents3
) {
550 *persistent_partition_contents3
= source7
->GetWebContents();
554 // Handles |request| by serving a redirect response.
555 static scoped_ptr
<net::test_server::HttpResponse
> RedirectResponseHandler(
556 const std::string
& path
,
557 const GURL
& redirect_target
,
558 const net::test_server::HttpRequest
& request
) {
559 if (!StartsWithASCII(path
, request
.relative_url
, true))
560 return scoped_ptr
<net::test_server::HttpResponse
>();
562 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
563 new net::test_server::BasicHttpResponse
);
564 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
565 http_response
->AddCustomHeader("Location", redirect_target
.spec());
566 return http_response
.PassAs
<net::test_server::HttpResponse
>();
569 // Handles |request| by serving an empty response.
570 static scoped_ptr
<net::test_server::HttpResponse
> EmptyResponseHandler(
571 const std::string
& path
,
572 const net::test_server::HttpRequest
& request
) {
573 if (StartsWithASCII(path
, request
.relative_url
, true)) {
574 return scoped_ptr
<net::test_server::HttpResponse
>(
575 new EmptyHttpResponse
);
578 return scoped_ptr
<net::test_server::HttpResponse
>();
581 // Shortcut to return the current MenuManager.
582 extensions::MenuManager
* menu_manager() {
583 return extensions::MenuManager::Get(browser()->profile());
586 // This gets all the items that any extension has registered for possible
587 // inclusion in context menus.
588 MenuItem::List
GetItems() {
589 MenuItem::List result
;
590 std::set
<MenuItem::ExtensionKey
> extension_ids
=
591 menu_manager()->ExtensionIds();
592 std::set
<MenuItem::ExtensionKey
>::iterator i
;
593 for (i
= extension_ids
.begin(); i
!= extension_ids
.end(); ++i
) {
594 const MenuItem::List
* list
= menu_manager()->MenuItems(*i
);
595 result
.insert(result
.end(), list
->begin(), list
->end());
605 void TestHelper(const std::string
& test_name
,
606 const std::string
& app_location
,
607 TestServer test_server
) {
608 // For serving guest pages.
609 if (test_server
== NEEDS_TEST_SERVER
) {
610 if (!StartEmbeddedTestServer()) {
611 LOG(ERROR
) << "FAILED TO START TEST SERVER.";
614 embedded_test_server()->RegisterRequestHandler(
615 base::Bind(&WebViewTest::RedirectResponseHandler
,
616 kRedirectResponsePath
,
617 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
619 embedded_test_server()->RegisterRequestHandler(
620 base::Bind(&WebViewTest::EmptyResponseHandler
, kEmptyResponsePath
));
623 LoadAndLaunchPlatformApp(app_location
.c_str(), "Launched");
625 // Flush any pending events to make sure we start with a clean slate.
626 content::RunAllPendingInMessageLoop();
628 content::WebContents
* embedder_web_contents
=
629 GetFirstAppWindowWebContents();
630 if (!embedder_web_contents
) {
631 LOG(ERROR
) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
635 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
636 done_listener
.set_failure_message("TEST_FAILED");
637 if (!content::ExecuteScript(
638 embedder_web_contents
,
639 base::StringPrintf("runTest('%s')", test_name
.c_str()))) {
640 LOG(ERROR
) << "UNABLE TO START TEST.";
643 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
646 content::WebContents
* LoadGuest(const std::string
& guest_path
,
647 const std::string
& app_path
) {
648 GURL::Replacements replace_host
;
649 std::string
host_str("localhost"); // Must stay in scope with replace_host.
650 replace_host
.SetHostStr(host_str
);
652 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
653 guest_url
= guest_url
.ReplaceComponents(replace_host
);
655 ui_test_utils::UrlLoadObserver
guest_observer(
656 guest_url
, content::NotificationService::AllSources());
658 LoadAndLaunchPlatformApp(app_path
.c_str(), "guest-loaded");
660 guest_observer
.Wait();
661 content::Source
<content::NavigationController
> source
=
662 guest_observer
.source();
663 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
666 content::WebContents
* guest_web_contents
= source
->GetWebContents();
667 return guest_web_contents
;
670 // Runs media_access/allow tests.
671 void MediaAccessAPIAllowTestHelper(const std::string
& test_name
);
673 // Runs media_access/deny tests, each of them are run separately otherwise
674 // they timeout (mostly on Windows).
675 void MediaAccessAPIDenyTestHelper(const std::string
& test_name
) {
676 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
677 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
679 content::WebContents
* embedder_web_contents
=
680 GetFirstAppWindowWebContents();
681 ASSERT_TRUE(embedder_web_contents
);
683 ExtensionTestMessageListener
test_run_listener("PASSED", false);
684 test_run_listener
.set_failure_message("FAILED");
686 content::ExecuteScript(
687 embedder_web_contents
,
688 base::StringPrintf("startDenyTest('%s')", test_name
.c_str())));
689 ASSERT_TRUE(test_run_listener
.WaitUntilSatisfied());
692 void WaitForInterstitial(content::WebContents
* web_contents
) {
693 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
694 new content::MessageLoopRunner
);
695 InterstitialObserver
observer(web_contents
,
696 loop_runner
->QuitClosure(),
698 if (!content::InterstitialPage::GetInterstitialPage(web_contents
))
702 void LoadAppWithGuest(const std::string
& app_path
) {
703 ExtensionTestMessageListener
launched_listener("WebViewTest.LAUNCHED",
705 launched_listener
.set_failure_message("WebViewTest.FAILURE");
706 LoadAndLaunchPlatformApp(app_path
.c_str(), &launched_listener
);
708 guest_web_contents_
= GetGuestViewManager()->WaitForGuestCreated();
711 void SendMessageToEmbedder(const std::string
& message
) {
713 content::ExecuteScript(
714 GetEmbedderWebContents(),
715 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
718 void SendMessageToGuestAndWait(const std::string
& message
,
719 const std::string
& wait_message
) {
720 scoped_ptr
<ExtensionTestMessageListener
> listener
;
721 if (!wait_message
.empty()) {
722 listener
.reset(new ExtensionTestMessageListener(wait_message
, false));
726 content::ExecuteScript(
727 GetGuestWebContents(),
728 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
731 ASSERT_TRUE(listener
->WaitUntilSatisfied());
735 content::WebContents
* GetGuestWebContents() {
736 return guest_web_contents_
;
739 content::WebContents
* GetEmbedderWebContents() {
740 if (!embedder_web_contents_
) {
741 embedder_web_contents_
= GetFirstAppWindowWebContents();
743 return embedder_web_contents_
;
746 TestGuestViewManager
* GetGuestViewManager() {
747 return factory_
.GetManager(browser()->profile());
750 WebViewTest() : guest_web_contents_(NULL
),
751 embedder_web_contents_(NULL
) {
752 extensions::GuestViewManager::set_factory_for_testing(&factory_
);
756 bool UsesFakeSpeech() {
757 const testing::TestInfo
* const test_info
=
758 testing::UnitTest::GetInstance()->current_test_info();
760 // SpeechRecognition test specific SetUp.
761 return !strcmp(test_info
->name(),
762 "SpeechRecognitionAPI_HasPermissionAllow");
765 scoped_ptr
<content::FakeSpeechRecognitionManager
>
766 fake_speech_recognition_manager_
;
768 TestGuestViewManagerFactory factory_
;
769 // Note that these are only set if you launch app using LoadAppWithGuest().
770 content::WebContents
* guest_web_contents_
;
771 content::WebContents
* embedder_web_contents_
;
774 // This test verifies that hiding the guest triggers WebContents::WasHidden().
775 IN_PROC_BROWSER_TEST_F(WebViewTest
, GuestVisibilityChanged
) {
776 LoadAppWithGuest("web_view/visibility_changed");
778 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
779 new content::MessageLoopRunner
);
780 WebContentsHiddenObserver
observer(GetGuestWebContents(),
781 loop_runner
->QuitClosure());
783 // Handled in platform_apps/web_view/visibility_changed/main.js
784 SendMessageToEmbedder("hide-guest");
785 if (!observer
.hidden_observed())
789 // This test verifies that hiding the embedder also hides the guest.
790 IN_PROC_BROWSER_TEST_F(WebViewTest
, EmbedderVisibilityChanged
) {
791 LoadAppWithGuest("web_view/visibility_changed");
793 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
794 new content::MessageLoopRunner
);
795 WebContentsHiddenObserver
observer(GetGuestWebContents(),
796 loop_runner
->QuitClosure());
798 // Handled in platform_apps/web_view/visibility_changed/main.js
799 SendMessageToEmbedder("hide-embedder");
800 if (!observer
.hidden_observed())
804 // This test verifies that reloading the embedder reloads the guest (and doest
806 IN_PROC_BROWSER_TEST_F(WebViewTest
, ReloadEmbedder
) {
807 // Just load a guest from other test, we do not want to add a separate
808 // platform_app for this test.
809 LoadAppWithGuest("web_view/visibility_changed");
811 ExtensionTestMessageListener
launched_again_listener("WebViewTest.LAUNCHED",
813 GetEmbedderWebContents()->GetController().Reload(false);
814 ASSERT_TRUE(launched_again_listener
.WaitUntilSatisfied());
817 IN_PROC_BROWSER_TEST_F(WebViewTest
, AcceptTouchEvents
) {
818 LoadAppWithGuest("web_view/accept_touch_events");
820 content::RenderViewHost
* embedder_rvh
=
821 GetEmbedderWebContents()->GetRenderViewHost();
823 bool embedder_has_touch_handler
=
824 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
825 EXPECT_FALSE(embedder_has_touch_handler
);
827 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
829 // Note that we need to wait for the installed/registered touch handler to
830 // appear in browser process before querying |embedder_rvh|.
831 // In practice, since we do a roundrtip from browser process to guest and
832 // back, this is sufficient.
833 embedder_has_touch_handler
=
834 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
835 EXPECT_TRUE(embedder_has_touch_handler
);
837 SendMessageToGuestAndWait("uninstall-touch-handler",
838 "uninstalled-touch-handler");
839 // Same as the note above about waiting.
840 embedder_has_touch_handler
=
841 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
842 EXPECT_FALSE(embedder_has_touch_handler
);
845 // This test ensures JavaScript errors ("Cannot redefine property") do not
846 // happen when a <webview> is removed from DOM and added back.
847 IN_PROC_BROWSER_TEST_F(WebViewTest
,
848 AddRemoveWebView_AddRemoveWebView
) {
849 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
850 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
854 IN_PROC_BROWSER_TEST_F(WebViewTest
, AutoSize
) {
856 // Flaky on XP bot http://crbug.com/299507
857 if (base::win::GetVersion() <= base::win::VERSION_XP
)
861 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
865 // Tests that a <webview> that is set to "display: none" after load and then
866 // setting "display: block" re-renders the plugin properly.
868 // Initially after loading the <webview> and the test sets <webview> to
870 // This causes the browser plugin to be destroyed, we then set the
871 // style.display of the <webview> to block again and check that loadstop
873 IN_PROC_BROWSER_TEST_F(WebViewTest
, DisplayNoneAndBack
) {
874 LoadAppWithGuest("web_view/display_none_and_back");
876 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
877 new content::MessageLoopRunner
);
878 WebContentsHiddenObserver
observer(GetGuestWebContents(),
879 loop_runner
->QuitClosure());
881 // Handled in platform_apps/web_view/display_none_and_back/main.js
882 SendMessageToEmbedder("hide-guest");
883 GetGuestViewManager()->WaitForGuestDeleted();
884 ExtensionTestMessageListener
test_passed_listener("WebViewTest.PASSED",
887 SendMessageToEmbedder("show-guest");
888 GetGuestViewManager()->WaitForGuestCreated();
889 EXPECT_TRUE(test_passed_listener
.WaitUntilSatisfied());
892 // http://crbug.com/326332
893 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_Shim_TestAutosizeAfterNavigation
) {
894 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER
);
897 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeBeforeNavigation
) {
898 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
900 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeRemoveAttributes
) {
901 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
904 // This test is disabled due to being flaky. http://crbug.com/282116
905 #if defined(OS_WIN) || defined(OS_MACOSX)
906 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
907 DISABLED_Shim_TestAutosizeWithPartialAttributes
909 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
910 Shim_TestAutosizeWithPartialAttributes
912 IN_PROC_BROWSER_TEST_F(WebViewTest
,
913 MAYBE_Shim_TestAutosizeWithPartialAttributes
) {
914 TestHelper("testAutosizeWithPartialAttributes",
919 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAPIMethodExistence
) {
920 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER
);
923 // Tests the existence of WebRequest API event objects on the request
924 // object, on the webview element, and hanging directly off webview.
925 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIExistence
) {
926 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER
);
929 // http://crbug.com/315920
930 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
931 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
933 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
935 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_Shim_TestChromeExtensionURL
) {
936 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
939 // http://crbug.com/315920
940 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
941 #define MAYBE_Shim_TestChromeExtensionRelativePath \
942 DISABLED_Shim_TestChromeExtensionRelativePath
944 #define MAYBE_Shim_TestChromeExtensionRelativePath \
945 Shim_TestChromeExtensionRelativePath
947 IN_PROC_BROWSER_TEST_F(WebViewTest
,
948 MAYBE_Shim_TestChromeExtensionRelativePath
) {
949 TestHelper("testChromeExtensionRelativePath",
954 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewLoad
) {
955 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER
);
958 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewRemoveChild
) {
959 TestHelper("testDisplayNoneWebviewRemoveChild",
960 "web_view/shim", NO_TEST_SERVER
);
963 IN_PROC_BROWSER_TEST_F(WebViewTest
,
964 Shim_TestInlineScriptFromAccessibleResources
) {
965 TestHelper("testInlineScriptFromAccessibleResources",
970 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestInvalidChromeExtensionURL
) {
971 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
974 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestEventName
) {
975 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER
);
978 // WebViewTest.Shim_TestOnEventProperty is flaky, so disable it.
979 // http://crbug.com/359832.
980 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_Shim_TestOnEventProperty
) {
981 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER
);
984 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadProgressEvent
) {
985 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER
);
988 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDestroyOnEventListener
) {
989 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER
);
992 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestCannotMutateEventName
) {
993 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER
);
996 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestPartitionRaisesException
) {
997 TestHelper("testPartitionRaisesException", "web_view/shim", NO_TEST_SERVER
);
1000 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1001 Shim_TestPartitionRemovalAfterNavigationFails
) {
1002 TestHelper("testPartitionRemovalAfterNavigationFails",
1007 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScriptFail
) {
1009 // Flaky on XP bot http://crbug.com/266185
1010 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1014 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER
);
1017 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScript
) {
1018 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER
);
1021 IN_PROC_BROWSER_TEST_F(
1023 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged
) {
1024 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
1029 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestTerminateAfterExit
) {
1030 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER
);
1033 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAssignSrcAfterCrash
) {
1034 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER
);
1037 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1038 Shim_TestNavOnConsecutiveSrcAttributeChanges
) {
1039 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
1044 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavOnSrcAttributeChange
) {
1045 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER
);
1048 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigateAfterResize
) {
1049 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER
);
1052 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveSrcAttribute
) {
1053 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1056 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReassignSrcAttribute
) {
1057 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1060 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindow
) {
1061 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER
);
1064 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowTwoListeners
) {
1065 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER
);
1068 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoPreventDefault
) {
1069 TestHelper("testNewWindowNoPreventDefault",
1074 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoReferrerLink
) {
1075 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER
);
1078 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestContentLoadEvent
) {
1079 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER
);
1082 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDeclarativeWebRequestAPI
) {
1083 TestHelper("testDeclarativeWebRequestAPI",
1088 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1089 Shim_TestDeclarativeWebRequestAPISendMessage
) {
1090 TestHelper("testDeclarativeWebRequestAPISendMessage",
1095 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPI
) {
1096 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER
);
1099 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIGoogleProperty
) {
1100 TestHelper("testWebRequestAPIGoogleProperty",
1105 // This test is disabled due to being flaky. http://crbug.com/309451
1107 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1108 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
1110 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1111 Shim_TestWebRequestListenerSurvivesReparenting
1113 IN_PROC_BROWSER_TEST_F(
1115 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting
) {
1116 TestHelper("testWebRequestListenerSurvivesReparenting",
1121 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadStartLoadRedirect
) {
1122 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER
);
1125 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1126 Shim_TestLoadAbortChromeExtensionURLWrongPartition
) {
1127 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1132 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortEmptyResponse
) {
1133 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER
);
1136 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalChromeURL
) {
1137 TestHelper("testLoadAbortIllegalChromeURL",
1142 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalFileURL
) {
1143 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER
);
1146 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalJavaScriptURL
) {
1147 TestHelper("testLoadAbortIllegalJavaScriptURL",
1152 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortInvalidNavigation
) {
1153 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER
);
1156 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortNonWebSafeScheme
) {
1157 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER
);
1160 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReload
) {
1161 TestHelper("testReload", "web_view/shim", NEEDS_TEST_SERVER
);
1164 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestGetProcessId
) {
1165 TestHelper("testGetProcessId", "web_view/shim", NEEDS_TEST_SERVER
);
1168 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestHiddenBeforeNavigation
) {
1169 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
1172 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewOnExit
) {
1173 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1175 // Launch the app and wait until it's ready to load a test.
1176 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1178 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1179 ASSERT_TRUE(embedder_web_contents
);
1181 GURL::Replacements replace_host
;
1182 std::string
host_str("localhost"); // Must stay in scope with replace_host.
1183 replace_host
.SetHostStr(host_str
);
1185 std::string
guest_path(
1186 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1187 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
1188 guest_url
= guest_url
.ReplaceComponents(replace_host
);
1190 ui_test_utils::UrlLoadObserver
guest_observer(
1191 guest_url
, content::NotificationService::AllSources());
1193 // Run the test and wait until the guest WebContents is available and has
1194 // finished loading.
1195 ExtensionTestMessageListener
guest_loaded_listener("guest-loaded", false);
1196 EXPECT_TRUE(content::ExecuteScript(
1197 embedder_web_contents
,
1198 "runTest('testRemoveWebviewOnExit')"));
1199 guest_observer
.Wait();
1201 content::Source
<content::NavigationController
> source
=
1202 guest_observer
.source();
1203 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
1206 ASSERT_TRUE(guest_loaded_listener
.WaitUntilSatisfied());
1208 content::WebContentsDestroyedWatcher
destroyed_watcher(
1209 source
->GetWebContents());
1211 // Tell the embedder to kill the guest.
1212 EXPECT_TRUE(content::ExecuteScript(
1213 embedder_web_contents
,
1214 "removeWebviewOnExitDoCrash();"));
1216 // Wait until the guest WebContents is destroyed.
1217 destroyed_watcher
.Wait();
1220 // Remove <webview> immediately after navigating it.
1221 // This is a regression test for http://crbug.com/276023.
1222 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewAfterNavigation
) {
1223 TestHelper("testRemoveWebviewAfterNavigation",
1228 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigationToExternalProtocol
) {
1229 TestHelper("testNavigationToExternalProtocol",
1234 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestResizeWebviewResizesContent
) {
1235 TestHelper("testResizeWebviewResizesContent",
1240 // This test makes sure we do not crash if app is closed while interstitial
1241 // page is being shown in guest.
1242 // Disabled under LeakSanitizer due to memory leaks. http://crbug.com/321662
1243 #if defined(LEAK_SANITIZER)
1244 #define MAYBE_InterstitialTeardown DISABLED_InterstitialTeardown
1246 #define MAYBE_InterstitialTeardown InterstitialTeardown
1248 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_InterstitialTeardown
) {
1250 // Flaky on XP bot http://crbug.com/297014
1251 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1255 // Start a HTTPS server so we can load an interstitial page inside guest.
1256 net::SpawnedTestServer::SSLOptions ssl_options
;
1257 ssl_options
.server_certificate
=
1258 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME
;
1259 net::SpawnedTestServer
https_server(
1260 net::SpawnedTestServer::TYPE_HTTPS
, ssl_options
,
1261 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1262 ASSERT_TRUE(https_server
.Start());
1264 net::HostPortPair host_and_port
= https_server
.host_port_pair();
1266 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded");
1268 // Now load the guest.
1269 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1270 ExtensionTestMessageListener
second("GuestAddedToDom", false);
1271 EXPECT_TRUE(content::ExecuteScript(
1272 embedder_web_contents
,
1273 base::StringPrintf("loadGuest(%d);\n", host_and_port
.port())));
1274 ASSERT_TRUE(second
.WaitUntilSatisfied());
1276 // Wait for interstitial page to be shown in guest.
1277 content::WebContents
* guest_web_contents
=
1278 GetGuestViewManager()->WaitForGuestCreated();
1279 ASSERT_TRUE(guest_web_contents
->GetRenderProcessHost()->IsIsolatedGuest());
1280 WaitForInterstitial(guest_web_contents
);
1282 // Now close the app while interstitial page being shown in guest.
1283 apps::AppWindow
* window
= GetFirstAppWindow();
1284 window
->GetBaseWindow()->Close();
1287 IN_PROC_BROWSER_TEST_F(WebViewTest
, ShimSrcAttribute
) {
1288 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1292 // This test verifies that prerendering has been disabled inside <webview>.
1293 // This test is here rather than in PrerenderBrowserTest for testing convenience
1294 // only. If it breaks then this is a bug in the prerenderer.
1295 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPrerenderer
) {
1296 ASSERT_TRUE(StartEmbeddedTestServer());
1297 content::WebContents
* guest_web_contents
=
1299 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1300 "web_view/noprerenderer");
1301 ASSERT_TRUE(guest_web_contents
!= NULL
);
1303 PrerenderLinkManager
* prerender_link_manager
=
1304 PrerenderLinkManagerFactory::GetForProfile(
1305 Profile::FromBrowserContext(guest_web_contents
->GetBrowserContext()));
1306 ASSERT_TRUE(prerender_link_manager
!= NULL
);
1307 EXPECT_TRUE(prerender_link_manager
->IsEmpty());
1310 // Verify that existing <webview>'s are detected when the task manager starts
1312 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerExistingWebView
) {
1313 ASSERT_TRUE(StartEmbeddedTestServer());
1315 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1316 "web_view/task_manager");
1318 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1320 const char* guest_title
= "WebViewed test content";
1321 const char* app_name
= "<webview> task manager test";
1322 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1323 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1324 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1325 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1327 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1328 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1329 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1330 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1333 // Verify that the task manager notices the creation of new <webview>'s.
1334 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerNewWebView
) {
1335 ASSERT_TRUE(StartEmbeddedTestServer());
1337 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1339 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1340 "web_view/task_manager");
1342 const char* guest_title
= "WebViewed test content";
1343 const char* app_name
= "<webview> task manager test";
1344 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1345 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1346 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1347 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1349 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1350 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1351 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1352 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1355 // This tests cookie isolation for packaged apps with webview tags. It navigates
1356 // the main browser window to a page that sets a cookie and loads an app with
1357 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1358 // storage isolation is enforced.
1359 IN_PROC_BROWSER_TEST_F(WebViewTest
, CookieIsolation
) {
1360 ASSERT_TRUE(StartEmbeddedTestServer());
1361 const std::string kExpire
=
1362 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1363 std::string
cookie_script1(kExpire
);
1364 cookie_script1
.append(
1365 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1366 std::string
cookie_script2(kExpire
);
1367 cookie_script2
.append(
1368 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1370 GURL::Replacements replace_host
;
1371 std::string
host_str("localhost"); // Must stay in scope with replace_host.
1372 replace_host
.SetHostStr(host_str
);
1374 GURL set_cookie_url
= embedded_test_server()->GetURL(
1375 "/extensions/platform_apps/isolation/set_cookie.html");
1376 set_cookie_url
= set_cookie_url
.ReplaceComponents(replace_host
);
1378 // The first two partitions will be used to set cookies and ensure they are
1379 // shared. The named partition is used to ensure that cookies are isolated
1380 // between partitions within the same app.
1381 content::WebContents
* cookie_contents1
;
1382 content::WebContents
* cookie_contents2
;
1383 content::WebContents
* named_partition_contents1
;
1384 content::WebContents
* named_partition_contents2
;
1386 NavigateAndOpenAppForIsolation(set_cookie_url
, &cookie_contents1
,
1387 &cookie_contents2
, &named_partition_contents1
,
1388 &named_partition_contents2
, NULL
, NULL
, NULL
);
1390 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1391 EXPECT_TRUE(content::ExecuteScript(cookie_contents2
, cookie_script2
));
1394 std::string cookie_value
;
1396 // Test the regular browser context to ensure we have only one cookie.
1397 ui_test_utils::GetCookies(GURL("http://localhost"),
1398 browser()->tab_strip_model()->GetWebContentsAt(0),
1399 &cookie_size
, &cookie_value
);
1400 EXPECT_EQ("testCookie=1", cookie_value
);
1402 // The default behavior is to combine webview tags with no explicit partition
1403 // declaration into the same in-memory partition. Test the webview tags to
1404 // ensure we have properly set the cookies and we have both cookies in both
1406 ui_test_utils::GetCookies(GURL("http://localhost"),
1408 &cookie_size
, &cookie_value
);
1409 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1411 ui_test_utils::GetCookies(GURL("http://localhost"),
1413 &cookie_size
, &cookie_value
);
1414 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1416 // The third tag should not have any cookies as it is in a separate partition.
1417 ui_test_utils::GetCookies(GURL("http://localhost"),
1418 named_partition_contents1
,
1419 &cookie_size
, &cookie_value
);
1420 EXPECT_EQ("", cookie_value
);
1423 // This tests that in-memory storage partitions are reset on browser restart,
1424 // but persistent ones maintain state for cookies and HTML5 storage.
1425 IN_PROC_BROWSER_TEST_F(WebViewTest
, PRE_StoragePersistence
) {
1426 ASSERT_TRUE(StartEmbeddedTestServer());
1427 const std::string kExpire
=
1428 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1429 std::string
cookie_script1(kExpire
);
1430 cookie_script1
.append(
1431 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1432 std::string
cookie_script2(kExpire
);
1433 cookie_script2
.append(
1434 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1435 std::string
cookie_script3(kExpire
);
1436 cookie_script3
.append(
1437 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1439 // We don't care where the main browser is on this test.
1440 GURL
blank_url("about:blank");
1442 // The first two partitions will be used to set cookies and ensure they are
1443 // shared. The named partition is used to ensure that cookies are isolated
1444 // between partitions within the same app.
1445 content::WebContents
* cookie_contents1
;
1446 content::WebContents
* cookie_contents2
;
1447 content::WebContents
* named_partition_contents1
;
1448 content::WebContents
* named_partition_contents2
;
1449 content::WebContents
* persistent_partition_contents1
;
1450 content::WebContents
* persistent_partition_contents2
;
1451 content::WebContents
* persistent_partition_contents3
;
1452 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1453 &cookie_contents2
, &named_partition_contents1
,
1454 &named_partition_contents2
,
1455 &persistent_partition_contents1
,
1456 &persistent_partition_contents2
,
1457 &persistent_partition_contents3
);
1459 // Set the inmemory=true cookie for tags with inmemory partitions.
1460 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1461 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1
,
1464 // For the two different persistent storage partitions, set the
1465 // two different cookies so we can check that they aren't comingled below.
1466 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1
,
1469 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3
,
1473 std::string cookie_value
;
1475 // Check that all in-memory partitions have a cookie set.
1476 ui_test_utils::GetCookies(GURL("http://localhost"),
1478 &cookie_size
, &cookie_value
);
1479 EXPECT_EQ("inmemory=true", cookie_value
);
1480 ui_test_utils::GetCookies(GURL("http://localhost"),
1482 &cookie_size
, &cookie_value
);
1483 EXPECT_EQ("inmemory=true", cookie_value
);
1484 ui_test_utils::GetCookies(GURL("http://localhost"),
1485 named_partition_contents1
,
1486 &cookie_size
, &cookie_value
);
1487 EXPECT_EQ("inmemory=true", cookie_value
);
1488 ui_test_utils::GetCookies(GURL("http://localhost"),
1489 named_partition_contents2
,
1490 &cookie_size
, &cookie_value
);
1491 EXPECT_EQ("inmemory=true", cookie_value
);
1493 // Check that all persistent partitions kept their state.
1494 ui_test_utils::GetCookies(GURL("http://localhost"),
1495 persistent_partition_contents1
,
1496 &cookie_size
, &cookie_value
);
1497 EXPECT_EQ("persist1=true", cookie_value
);
1498 ui_test_utils::GetCookies(GURL("http://localhost"),
1499 persistent_partition_contents2
,
1500 &cookie_size
, &cookie_value
);
1501 EXPECT_EQ("persist1=true", cookie_value
);
1502 ui_test_utils::GetCookies(GURL("http://localhost"),
1503 persistent_partition_contents3
,
1504 &cookie_size
, &cookie_value
);
1505 EXPECT_EQ("persist2=true", cookie_value
);
1508 // This is the post-reset portion of the StoragePersistence test. See
1509 // PRE_StoragePersistence for main comment.
1510 #if defined(OS_CHROMEOS)
1511 // http://crbug.com/223888
1512 #define MAYBE_StoragePersistence DISABLED_StoragePersistence
1514 #define MAYBE_StoragePersistence StoragePersistence
1516 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_StoragePersistence
) {
1517 ASSERT_TRUE(StartEmbeddedTestServer());
1519 // We don't care where the main browser is on this test.
1520 GURL
blank_url("about:blank");
1522 // The first two partitions will be used to set cookies and ensure they are
1523 // shared. The named partition is used to ensure that cookies are isolated
1524 // between partitions within the same app.
1525 content::WebContents
* cookie_contents1
;
1526 content::WebContents
* cookie_contents2
;
1527 content::WebContents
* named_partition_contents1
;
1528 content::WebContents
* named_partition_contents2
;
1529 content::WebContents
* persistent_partition_contents1
;
1530 content::WebContents
* persistent_partition_contents2
;
1531 content::WebContents
* persistent_partition_contents3
;
1532 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1533 &cookie_contents2
, &named_partition_contents1
,
1534 &named_partition_contents2
,
1535 &persistent_partition_contents1
,
1536 &persistent_partition_contents2
,
1537 &persistent_partition_contents3
);
1540 std::string cookie_value
;
1542 // Check that all in-memory partitions lost their state.
1543 ui_test_utils::GetCookies(GURL("http://localhost"),
1545 &cookie_size
, &cookie_value
);
1546 EXPECT_EQ("", cookie_value
);
1547 ui_test_utils::GetCookies(GURL("http://localhost"),
1549 &cookie_size
, &cookie_value
);
1550 EXPECT_EQ("", cookie_value
);
1551 ui_test_utils::GetCookies(GURL("http://localhost"),
1552 named_partition_contents1
,
1553 &cookie_size
, &cookie_value
);
1554 EXPECT_EQ("", cookie_value
);
1555 ui_test_utils::GetCookies(GURL("http://localhost"),
1556 named_partition_contents2
,
1557 &cookie_size
, &cookie_value
);
1558 EXPECT_EQ("", cookie_value
);
1560 // Check that all persistent partitions kept their state.
1561 ui_test_utils::GetCookies(GURL("http://localhost"),
1562 persistent_partition_contents1
,
1563 &cookie_size
, &cookie_value
);
1564 EXPECT_EQ("persist1=true", cookie_value
);
1565 ui_test_utils::GetCookies(GURL("http://localhost"),
1566 persistent_partition_contents2
,
1567 &cookie_size
, &cookie_value
);
1568 EXPECT_EQ("persist1=true", cookie_value
);
1569 ui_test_utils::GetCookies(GURL("http://localhost"),
1570 persistent_partition_contents3
,
1571 &cookie_size
, &cookie_value
);
1572 EXPECT_EQ("persist2=true", cookie_value
);
1575 // This tests DOM storage isolation for packaged apps with webview tags. It
1576 // loads an app with multiple webview tags and each tag sets DOM storage
1577 // entries, which the test checks to ensure proper storage isolation is
1579 IN_PROC_BROWSER_TEST_F(WebViewTest
, DOMStorageIsolation
) {
1580 ASSERT_TRUE(StartEmbeddedTestServer());
1581 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1584 std::string
get_local_storage("window.domAutomationController.send("
1585 "window.localStorage.getItem('foo') || 'badval')");
1586 std::string
get_session_storage("window.domAutomationController.send("
1587 "window.sessionStorage.getItem('bar') || 'badval')");
1589 content::WebContents
* default_tag_contents1
;
1590 content::WebContents
* default_tag_contents2
;
1591 content::WebContents
* storage_contents1
;
1592 content::WebContents
* storage_contents2
;
1594 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1595 &default_tag_contents2
, &storage_contents1
,
1596 &storage_contents2
, NULL
, NULL
, NULL
);
1598 // Initialize the storage for the first of the two tags that share a storage
1600 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1601 "initDomStorage('page1')"));
1603 // Let's test that the expected values are present in the first tag, as they
1604 // will be overwritten once we call the initDomStorage on the second tag.
1605 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1606 get_local_storage
.c_str(),
1608 EXPECT_STREQ("local-page1", output
.c_str());
1609 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1610 get_session_storage
.c_str(),
1612 EXPECT_STREQ("session-page1", output
.c_str());
1614 // Now, init the storage in the second tag in the same storage partition,
1615 // which will overwrite the shared localStorage.
1616 EXPECT_TRUE(content::ExecuteScript(storage_contents2
,
1617 "initDomStorage('page2')"));
1619 // The localStorage value now should reflect the one written through the
1621 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1622 get_local_storage
.c_str(),
1624 EXPECT_STREQ("local-page2", output
.c_str());
1625 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1626 get_local_storage
.c_str(),
1628 EXPECT_STREQ("local-page2", output
.c_str());
1630 // Session storage is not shared though, as each webview tag has separate
1631 // instance, even if they are in the same storage partition.
1632 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1633 get_session_storage
.c_str(),
1635 EXPECT_STREQ("session-page1", output
.c_str());
1636 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1637 get_session_storage
.c_str(),
1639 EXPECT_STREQ("session-page2", output
.c_str());
1641 // Also, let's check that the main browser and another tag that doesn't share
1642 // the same partition don't have those values stored.
1643 EXPECT_TRUE(ExecuteScriptAndExtractString(
1644 browser()->tab_strip_model()->GetWebContentsAt(0),
1645 get_local_storage
.c_str(),
1647 EXPECT_STREQ("badval", output
.c_str());
1648 EXPECT_TRUE(ExecuteScriptAndExtractString(
1649 browser()->tab_strip_model()->GetWebContentsAt(0),
1650 get_session_storage
.c_str(),
1652 EXPECT_STREQ("badval", output
.c_str());
1653 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1654 get_local_storage
.c_str(),
1656 EXPECT_STREQ("badval", output
.c_str());
1657 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1658 get_session_storage
.c_str(),
1660 EXPECT_STREQ("badval", output
.c_str());
1663 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1664 // an app with multiple webview tags and each tag creates an IndexedDB record,
1665 // which the test checks to ensure proper storage isolation is enforced.
1666 IN_PROC_BROWSER_TEST_F(WebViewTest
, IndexedDBIsolation
) {
1667 ASSERT_TRUE(StartEmbeddedTestServer());
1668 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1670 content::WebContents
* default_tag_contents1
;
1671 content::WebContents
* default_tag_contents2
;
1672 content::WebContents
* storage_contents1
;
1673 content::WebContents
* storage_contents2
;
1675 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1676 &default_tag_contents2
, &storage_contents1
,
1677 &storage_contents2
, NULL
, NULL
, NULL
);
1679 // Initialize the storage for the first of the two tags that share a storage
1681 ExecuteScriptWaitForTitle(storage_contents1
, "initIDB()", "idb created");
1682 ExecuteScriptWaitForTitle(storage_contents1
, "addItemIDB(7, 'page1')",
1683 "addItemIDB complete");
1684 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1685 "readItemIDB complete");
1688 std::string
get_value(
1689 "window.domAutomationController.send(getValueIDB() || 'badval')");
1691 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1692 get_value
.c_str(), &output
));
1693 EXPECT_STREQ("page1", output
.c_str());
1695 // Initialize the db in the second tag.
1696 ExecuteScriptWaitForTitle(storage_contents2
, "initIDB()", "idb open");
1698 // Since we share a partition, reading the value should return the existing
1700 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1701 "readItemIDB complete");
1702 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1703 get_value
.c_str(), &output
));
1704 EXPECT_STREQ("page1", output
.c_str());
1706 // Now write through the second tag and read it back.
1707 ExecuteScriptWaitForTitle(storage_contents2
, "addItemIDB(7, 'page2')",
1708 "addItemIDB complete");
1709 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1710 "readItemIDB complete");
1711 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1712 get_value
.c_str(), &output
));
1713 EXPECT_STREQ("page2", output
.c_str());
1715 // Reset the document title, otherwise the next call will not see a change and
1716 // will hang waiting for it.
1717 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1718 "document.title = 'foo'"));
1720 // Read through the first tag to ensure we have the second value.
1721 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1722 "readItemIDB complete");
1723 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1724 get_value
.c_str(), &output
));
1725 EXPECT_STREQ("page2", output
.c_str());
1727 // Now, let's confirm there is no database in the main browser and another
1728 // tag that doesn't share the same partition. Due to the IndexedDB API design,
1729 // open will succeed, but the version will be 1, since it creates the database
1730 // if it is not found. The two tags use database version 3, so we avoid
1732 const char* script
=
1733 "indexedDB.open('isolation').onsuccess = function(e) {"
1734 " if (e.target.result.version == 1)"
1735 " document.title = 'db not found';"
1737 " document.title = 'error';"
1739 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1740 script
, "db not found");
1741 ExecuteScriptWaitForTitle(default_tag_contents1
, script
, "db not found");
1744 // This test ensures that closing app window on 'loadcommit' does not crash.
1745 // The test launches an app with guest and closes the window on loadcommit. It
1746 // then launches the app window again. The process is repeated 3 times.
1747 // http://crbug.com/291278
1749 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1751 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1753 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_CloseOnLoadcommit
) {
1754 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1755 "done-close-on-loadcommit");
1758 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIDeny_TestDeny
) {
1759 MediaAccessAPIDenyTestHelper("testDeny");
1762 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1763 MediaAccessAPIDeny_TestDenyThenAllowThrows
) {
1764 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1768 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1769 MediaAccessAPIDeny_TestDenyWithPreventDefault
) {
1770 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1773 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1774 MediaAccessAPIDeny_TestNoListenersImplyDeny
) {
1775 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1778 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1779 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny
) {
1780 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1783 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string
& test_name
) {
1784 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1785 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1787 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1788 ASSERT_TRUE(embedder_web_contents
);
1789 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
1790 embedder_web_contents
->SetDelegate(mock
.get());
1792 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1793 done_listener
.set_failure_message("TEST_FAILED");
1795 content::ExecuteScript(
1796 embedder_web_contents
,
1797 base::StringPrintf("startAllowTest('%s')",
1798 test_name
.c_str())));
1799 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1801 mock
->WaitForSetMediaPermission();
1804 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenusAPI_Basic
) {
1805 LoadAppWithGuest("web_view/context_menus/basic");
1807 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1808 content::WebContents
* embedder
= GetEmbedderWebContents();
1809 ASSERT_TRUE(embedder
);
1811 // 1. Basic property test.
1812 ExecuteScriptWaitForTitle(embedder
, "checkProperties()", "ITEM_CHECKED");
1814 // 2. Create a menu item and wait for created callback to be called.
1815 ExecuteScriptWaitForTitle(embedder
, "createMenuItem()", "ITEM_CREATED");
1817 // 3. Click the created item, wait for the click handlers to fire from JS.
1818 ExtensionTestMessageListener
click_listener("ITEM_CLICKED", false);
1819 GURL
page_url("http://www.google.com");
1820 // Create and build our test context menu.
1821 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1822 guest_web_contents
, page_url
, GURL(), GURL()));
1824 // Look for the extension item in the menu, and execute it.
1825 int command_id
= ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1826 ASSERT_TRUE(menu
->IsCommandIdEnabled(command_id
));
1827 menu
->ExecuteCommand(command_id
, 0);
1829 // Wait for embedder's script to tell us its onclick fired, it does
1830 // chrome.test.sendMessage('ITEM_CLICKED')
1831 ASSERT_TRUE(click_listener
.WaitUntilSatisfied());
1833 // 4. Update the item's title and verify.
1834 ExecuteScriptWaitForTitle(embedder
, "updateMenuItem()", "ITEM_UPDATED");
1835 MenuItem::List items
= GetItems();
1836 ASSERT_EQ(1u, items
.size());
1837 MenuItem
* item
= items
.at(0);
1838 EXPECT_EQ("new_title", item
->title());
1840 // 5. Remove the item.
1841 ExecuteScriptWaitForTitle(embedder
, "removeItem()", "ITEM_REMOVED");
1842 MenuItem::List items_after_removal
= GetItems();
1843 ASSERT_EQ(0u, items_after_removal
.size());
1845 // 6. Add some more items.
1846 ExecuteScriptWaitForTitle(
1847 embedder
, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1848 MenuItem::List items_after_insertion
= GetItems();
1849 ASSERT_EQ(3u, items_after_insertion
.size());
1851 // 7. Test removeAll().
1852 ExecuteScriptWaitForTitle(embedder
, "removeAllItems()", "ITEM_ALL_REMOVED");
1853 MenuItem::List items_after_all_removal
= GetItems();
1854 ASSERT_EQ(0u, items_after_all_removal
.size());
1857 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllow
) {
1858 MediaAccessAPIAllowTestHelper("testAllow");
1861 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAndThenDeny
) {
1862 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1865 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowTwice
) {
1866 MediaAccessAPIAllowTestHelper("testAllowTwice");
1869 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAsync
) {
1870 MediaAccessAPIAllowTestHelper("testAllowAsync");
1873 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1875 IN_PROC_BROWSER_TEST_F(WebViewTest
, ScreenCoordinates
) {
1876 ASSERT_TRUE(RunPlatformAppTestWithArg(
1877 "platform_apps/web_view/common", "screen_coordinates"))
1881 #if defined(OS_CHROMEOS)
1882 IN_PROC_BROWSER_TEST_F(WebViewTest
, ChromeVoxInjection
) {
1884 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1886 ASSERT_TRUE(StartEmbeddedTestServer());
1887 content::WebContents
* guest_web_contents
= LoadGuest(
1888 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1889 "web_view/chromevox_injection");
1890 ASSERT_TRUE(guest_web_contents
);
1892 chromeos::SpeechMonitor monitor
;
1893 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1894 true, ash::A11Y_NOTIFICATION_NONE
);
1895 EXPECT_TRUE(monitor
.SkipChromeVoxEnabledMessage());
1897 EXPECT_EQ("chrome vox test title", monitor
.GetNextUtterance());
1901 // Flaky on Windows. http://crbug.com/303966
1903 #define MAYBE_TearDownTest DISABLED_TearDownTest
1905 #define MAYBE_TearDownTest TearDownTest
1907 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_TearDownTest
) {
1908 const extensions::Extension
* extension
=
1909 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded");
1910 apps::AppWindow
* window
= NULL
;
1911 if (!GetAppWindowCount())
1912 window
= CreateAppWindow(extension
);
1914 window
= GetFirstAppWindow();
1915 CloseAppWindow(window
);
1917 // Load the app again.
1918 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded");
1921 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1922 // platform app) does not have geolocation permission for this test.
1923 // No matter what the API does, geolocation permission would be denied.
1924 // Note that the test name prefix must be "GeolocationAPI".
1925 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessAllow
) {
1926 TestHelper("testDenyDenies",
1927 "web_view/geolocation/embedder_has_no_permission",
1931 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessDeny
) {
1932 TestHelper("testDenyDenies",
1933 "web_view/geolocation/embedder_has_no_permission",
1937 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1938 // platform app) has geolocation permission
1940 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1941 // geolocation in this case).
1943 // Also note that these are run separately because OverrideGeolocation() doesn't
1944 // mock out geolocation for multiple navigator.geolocation calls properly and
1945 // the tests become flaky.
1946 // GeolocationAPI* test 1 of 3.
1947 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessAllow
) {
1948 TestHelper("testAllow",
1949 "web_view/geolocation/embedder_has_permission",
1953 // GeolocationAPI* test 2 of 3.
1954 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessDeny
) {
1955 TestHelper("testDeny",
1956 "web_view/geolocation/embedder_has_permission",
1960 // GeolocationAPI* test 3 of 3.
1961 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1962 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow
) {
1963 TestHelper("testMultipleBridgeIdAllow",
1964 "web_view/geolocation/embedder_has_permission",
1969 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
1970 // is handled correctly (and does not crash).
1971 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPICancelGeolocation
) {
1972 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1973 ASSERT_TRUE(RunPlatformAppTest(
1974 "platform_apps/web_view/geolocation/cancel_request")) << message_
;
1977 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_GeolocationRequestGone
) {
1978 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1979 ASSERT_TRUE(RunPlatformAppTest(
1980 "platform_apps/web_view/geolocation/geolocation_request_gone"))
1984 // In following FilesystemAPIRequestFromMainThread* tests, guest request
1985 // filesystem access from main thread of the guest.
1986 // FileSystemAPIRequestFromMainThread* test 1 of 3
1987 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadAllow
) {
1988 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
1991 // FileSystemAPIRequestFromMainThread* test 2 of 3.
1992 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadDeny
) {
1993 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
1996 // FileSystemAPIRequestFromMainThread* test 3 of 3.
1997 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1998 FileSystemAPIRequestFromMainThreadDefaultAllow
) {
1999 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2002 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
2003 // to request filesystem access from worker thread.
2004 // FileSystemAPIRequestFromWorker* test 1 of 3
2005 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerAllow
) {
2006 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2009 // FileSystemAPIRequestFromWorker* test 2 of 3.
2010 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerDeny
) {
2011 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2014 // FileSystemAPIRequestFromWorker* test 3 of 3.
2015 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2016 FileSystemAPIRequestFromWorkerDefaultAllow
) {
2018 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2021 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
2022 // embedder contains a single webview guest. The guest creates a shared worker
2023 // to request filesystem access from worker thread.
2024 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
2025 IN_PROC_BROWSER_TEST_F(
2027 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow
) {
2028 TestHelper("testAllow",
2029 "web_view/filesystem/shared_worker/single",
2033 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
2034 IN_PROC_BROWSER_TEST_F(
2036 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny
) {
2037 TestHelper("testDeny",
2038 "web_view/filesystem/shared_worker/single",
2042 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2043 IN_PROC_BROWSER_TEST_F(
2045 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow
) {
2048 "web_view/filesystem/shared_worker/single",
2052 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2053 // embedder contains mutiple webview guests. Each guest creates a shared worker
2054 // to request filesystem access from worker thread.
2055 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2056 IN_PROC_BROWSER_TEST_F(
2058 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow
) {
2059 TestHelper("testAllow",
2060 "web_view/filesystem/shared_worker/multiple",
2064 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2065 IN_PROC_BROWSER_TEST_F(
2067 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny
) {
2068 TestHelper("testDeny",
2069 "web_view/filesystem/shared_worker/multiple",
2073 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2074 IN_PROC_BROWSER_TEST_F(
2076 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow
) {
2079 "web_view/filesystem/shared_worker/multiple",
2083 IN_PROC_BROWSER_TEST_F(WebViewTest
, ClearData
) {
2085 // Flaky on XP bot http://crbug.com/282674
2086 if (base::win::GetVersion() <= base::win::VERSION_XP
)
2090 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2091 ASSERT_TRUE(RunPlatformAppTestWithArg(
2092 "platform_apps/web_view/common", "cleardata"))
2096 // This test is disabled on Win due to being flaky. http://crbug.com/294592
2098 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
2100 #define MAYBE_ConsoleMessage ConsoleMessage
2102 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_ConsoleMessage
) {
2103 ASSERT_TRUE(RunPlatformAppTestWithArg(
2104 "platform_apps/web_view/common", "console_messages"))
2108 IN_PROC_BROWSER_TEST_F(WebViewTest
, DownloadPermission
) {
2109 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2110 content::WebContents
* guest_web_contents
=
2111 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2112 "web_view/download");
2113 ASSERT_TRUE(guest_web_contents
);
2115 // Replace WebContentsDelegate with mock version so we can intercept download
2117 content::WebContentsDelegate
* delegate
= guest_web_contents
->GetDelegate();
2118 scoped_ptr
<MockDownloadWebContentsDelegate
>
2119 mock_delegate(new MockDownloadWebContentsDelegate(delegate
));
2120 guest_web_contents
->SetDelegate(mock_delegate
.get());
2123 // 1. Guest requests a download that its embedder denies.
2124 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2125 "startDownload('download-link-1')"));
2126 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2127 mock_delegate
->Reset();
2129 // 2. Guest requests a download that its embedder allows.
2130 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2131 "startDownload('download-link-2')"));
2132 mock_delegate
->WaitForCanDownload(true); // Expect to allow.
2133 mock_delegate
->Reset();
2135 // 3. Guest requests a download that its embedder ignores, this implies deny.
2136 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2137 "startDownload('download-link-3')"));
2138 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2141 // This test makes sure loading <webview> does not crash when there is an
2142 // extension which has content script whitelisted/forced.
2143 IN_PROC_BROWSER_TEST_F(WebViewTest
, WhitelistedContentScript
) {
2144 // Whitelist the extension for running content script we are going to load.
2145 extensions::ExtensionsClient::ScriptingWhitelist whitelist
;
2146 const std::string extension_id
= "imeongpbjoodlnmlakaldhlcmijmhpbb";
2147 whitelist
.push_back(extension_id
);
2148 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist
);
2150 // Load the extension.
2151 const extensions::Extension
* content_script_whitelisted_extension
=
2152 LoadExtension(test_data_dir_
.AppendASCII(
2153 "platform_apps/web_view/extension_api/content_script"));
2154 ASSERT_TRUE(content_script_whitelisted_extension
);
2155 ASSERT_EQ(extension_id
, content_script_whitelisted_extension
->id());
2157 // Now load an app with <webview>.
2158 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2162 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentReady
) {
2163 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2167 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentInteractive
) {
2168 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2172 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionAllow
) {
2174 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2179 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionDeny
) {
2181 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2186 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_NoPermission
) {
2188 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2189 "speech_recognition_api_no_permission"))
2193 // Tests overriding user agent.
2194 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent
) {
2195 ASSERT_TRUE(RunPlatformAppTestWithArg(
2196 "platform_apps/web_view/common", "useragent")) << message_
;
2199 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent_NewWindow
) {
2200 ASSERT_TRUE(RunPlatformAppTestWithArg(
2201 "platform_apps/web_view/common",
2202 "useragent_newwindow")) << message_
;
2205 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPermission
) {
2206 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2210 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestAlertDialog
) {
2211 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER
);
2214 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestConfirmDialog
) {
2215 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER
);
2218 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogCancel
) {
2219 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER
);
2222 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultCancel
) {
2223 TestHelper("testConfirmDialogDefaultCancel",
2228 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultGCCancel
) {
2229 TestHelper("testConfirmDialogDefaultGCCancel",
2234 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestPromptDialog
) {
2235 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER
);
2238 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoContentSettingsAPI
) {
2239 // Load the extension.
2240 const extensions::Extension
* content_settings_extension
=
2242 test_data_dir_
.AppendASCII(
2243 "platform_apps/web_view/extension_api/content_settings"));
2244 ASSERT_TRUE(content_settings_extension
);
2245 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER
);
2248 #if defined(ENABLE_PLUGINS)
2249 class WebViewPluginTest
: public WebViewTest
{
2251 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
2252 WebViewTest::SetUpCommandLine(command_line
);
2254 // Append the switch to register the pepper plugin.
2255 // library name = <out dir>/<test_name>.<library_extension>
2256 // MIME type = application/x-ppapi-<test_name>
2257 base::FilePath plugin_dir
;
2258 EXPECT_TRUE(PathService::Get(base::DIR_MODULE
, &plugin_dir
));
2260 base::FilePath plugin_lib
= plugin_dir
.Append(library_name
);
2261 EXPECT_TRUE(base::PathExists(plugin_lib
));
2262 base::FilePath::StringType pepper_plugin
= plugin_lib
.value();
2263 pepper_plugin
.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
2264 command_line
->AppendSwitchNative(switches::kRegisterPepperPlugins
,
2269 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginEvent
) {
2270 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER
);
2272 #endif // defined(ENABLE_PLUGINS)
2274 class WebViewCaptureTest
: public WebViewTest
{
2276 WebViewCaptureTest() {}
2277 virtual ~WebViewCaptureTest() {}
2278 virtual void SetUp() OVERRIDE
{
2279 EnablePixelOutput();
2280 WebViewTest::SetUp();
2284 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestZoomAPI
) {
2285 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER
);
2288 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI
) {
2289 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER
);
2292 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI_findupdate
) {
2293 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER
);
2296 // <webview> screenshot capture fails with ubercomp.
2297 // See http://crbug.com/327035.
2298 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest
,
2299 DISABLED_Shim_ScreenshotCapture
) {
2300 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER
);
2304 // Test is disabled on Windows because it times out often.
2305 // http://crbug.com/403325
2306 #define MAYBE_WebViewInBackgroundPage \
2307 DISABLED_WebViewInBackgroundPage
2309 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2311 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_WebViewInBackgroundPage
) {
2312 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))