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/prerender/prerender_link_manager.h"
11 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
15 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_dialogs.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/gpu_data_manager.h"
21 #include "content/public/browser/interstitial_page.h"
22 #include "content/public/browser/interstitial_page_delegate.h"
23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/web_contents_delegate.h"
26 #include "content/public/common/content_switches.h"
27 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/fake_speech_recognition_manager.h"
29 #include "content/public/test/test_renderer_host.h"
30 #include "extensions/browser/api/declarative/rules_registry.h"
31 #include "extensions/browser/api/declarative/rules_registry_service.h"
32 #include "extensions/browser/api/declarative/test_rules_registry.h"
33 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
34 #include "extensions/browser/app_window/native_app_window.h"
35 #include "extensions/browser/guest_view/guest_view_manager.h"
36 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
37 #include "extensions/browser/guest_view/test_guest_view_manager.h"
38 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
39 #include "extensions/common/extension.h"
40 #include "extensions/common/extensions_client.h"
41 #include "extensions/test/extension_test_message_listener.h"
42 #include "media/base/media_switches.h"
43 #include "net/test/embedded_test_server/embedded_test_server.h"
44 #include "net/test/embedded_test_server/http_request.h"
45 #include "net/test/embedded_test_server/http_response.h"
46 #include "ui/gfx/switches.h"
47 #include "ui/gl/gl_switches.h"
49 #if defined(ENABLE_PLUGINS)
50 #include "content/public/browser/plugin_service.h"
51 #include "content/public/common/webplugininfo.h"
54 #if defined(OS_CHROMEOS)
55 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
56 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
59 // For fine-grained suppression on flaky tests.
61 #include "base/win/windows_version.h"
64 using extensions::ContextMenuMatcher
;
65 using extensions::MenuItem
;
66 using prerender::PrerenderLinkManager
;
67 using prerender::PrerenderLinkManagerFactory
;
68 using task_manager::browsertest_util::MatchAboutBlankTab
;
69 using task_manager::browsertest_util::MatchAnyApp
;
70 using task_manager::browsertest_util::MatchAnyBackground
;
71 using task_manager::browsertest_util::MatchAnyTab
;
72 using task_manager::browsertest_util::MatchAnyWebView
;
73 using task_manager::browsertest_util::MatchApp
;
74 using task_manager::browsertest_util::MatchBackground
;
75 using task_manager::browsertest_util::MatchWebView
;
76 using task_manager::browsertest_util::WaitForTaskManagerRows
;
80 const char kEmptyResponsePath
[] = "/close-socket";
81 const char kRedirectResponsePath
[] = "/server-redirect";
82 const char kUserAgentRedirectResponsePath
[] = "/detect-user-agent";
83 const char kRedirectResponseFullPath
[] =
84 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
86 // Platform-specific filename relative to the chrome executable.
88 const wchar_t library_name
[] = L
"ppapi_tests.dll";
89 #elif defined(OS_MACOSX)
90 const char library_name
[] = "ppapi_tests.plugin";
91 #elif defined(OS_POSIX)
92 const char library_name
[] = "libppapi_tests.so";
95 class EmptyHttpResponse
: public net::test_server::HttpResponse
{
97 std::string
ToResponseString() const override
{ return std::string(); }
100 class TestInterstitialPageDelegate
: public content::InterstitialPageDelegate
{
102 TestInterstitialPageDelegate() {
104 ~TestInterstitialPageDelegate() override
{}
105 std::string
GetHTMLContents() override
{ return std::string(); }
108 class WebContentsHiddenObserver
: public content::WebContentsObserver
{
110 WebContentsHiddenObserver(content::WebContents
* web_contents
,
111 const base::Closure
& hidden_callback
)
112 : WebContentsObserver(web_contents
),
113 hidden_callback_(hidden_callback
),
114 hidden_observed_(false) {
117 // WebContentsObserver.
118 void WasHidden() override
{
119 hidden_observed_
= true;
120 hidden_callback_
.Run();
123 bool hidden_observed() { return hidden_observed_
; }
126 base::Closure hidden_callback_
;
127 bool hidden_observed_
;
129 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver
);
132 class EmbedderWebContentsObserver
: public content::WebContentsObserver
{
134 explicit EmbedderWebContentsObserver(content::WebContents
* web_contents
)
135 : WebContentsObserver(web_contents
), terminated_(false) {}
137 // WebContentsObserver.
138 void RenderProcessGone(base::TerminationStatus status
) override
{
140 if (message_loop_runner_
.get())
141 message_loop_runner_
->Quit();
144 void WaitForEmbedderRenderProcessTerminate() {
147 message_loop_runner_
= new content::MessageLoopRunner
;
148 message_loop_runner_
->Run();
153 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
155 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver
);
158 void ExecuteScriptWaitForTitle(content::WebContents
* web_contents
,
161 base::string16
expected_title(base::ASCIIToUTF16(title
));
162 base::string16
error_title(base::ASCIIToUTF16("error"));
164 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
165 title_watcher
.AlsoWaitForTitle(error_title
);
166 EXPECT_TRUE(content::ExecuteScript(web_contents
, script
));
167 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
172 // This class intercepts media access request from the embedder. The request
173 // should be triggered only if the embedder API (from tests) allows the request
175 // We do not issue the actual media request; the fact that the request reached
176 // embedder's WebContents is good enough for our tests. This is also to make
177 // the test run successfully on trybots.
178 class MockWebContentsDelegate
: public content::WebContentsDelegate
{
180 MockWebContentsDelegate()
183 ~MockWebContentsDelegate() override
{}
185 void RequestMediaAccessPermission(
186 content::WebContents
* web_contents
,
187 const content::MediaStreamRequest
& request
,
188 const content::MediaResponseCallback
& callback
) override
{
190 if (request_message_loop_runner_
.get())
191 request_message_loop_runner_
->Quit();
194 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
195 const GURL
& security_origin
,
196 content::MediaStreamType type
) override
{
198 if (check_message_loop_runner_
.get())
199 check_message_loop_runner_
->Quit();
203 void WaitForRequestMediaPermission() {
206 request_message_loop_runner_
= new content::MessageLoopRunner
;
207 request_message_loop_runner_
->Run();
210 void WaitForCheckMediaPermission() {
213 check_message_loop_runner_
= new content::MessageLoopRunner
;
214 check_message_loop_runner_
->Run();
220 scoped_refptr
<content::MessageLoopRunner
> request_message_loop_runner_
;
221 scoped_refptr
<content::MessageLoopRunner
> check_message_loop_runner_
;
223 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate
);
226 // This class intercepts download request from the guest.
227 class MockDownloadWebContentsDelegate
: public content::WebContentsDelegate
{
229 explicit MockDownloadWebContentsDelegate(
230 content::WebContentsDelegate
* orig_delegate
)
231 : orig_delegate_(orig_delegate
),
232 waiting_for_decision_(false),
233 expect_allow_(false),
234 decision_made_(false),
235 last_download_allowed_(false) {}
236 ~MockDownloadWebContentsDelegate() override
{}
238 void CanDownload(content::RenderViewHost
* render_view_host
,
240 const std::string
& request_method
,
241 const base::Callback
<void(bool)>& callback
) override
{
242 orig_delegate_
->CanDownload(
243 render_view_host
, url
, request_method
,
244 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided
,
245 base::Unretained(this)));
248 void WaitForCanDownload(bool expect_allow
) {
249 EXPECT_FALSE(waiting_for_decision_
);
250 waiting_for_decision_
= true;
252 if (decision_made_
) {
253 EXPECT_EQ(expect_allow
, last_download_allowed_
);
257 expect_allow_
= expect_allow
;
258 message_loop_runner_
= new content::MessageLoopRunner
;
259 message_loop_runner_
->Run();
262 void DownloadDecided(bool allow
) {
263 EXPECT_FALSE(decision_made_
);
264 decision_made_
= true;
266 if (waiting_for_decision_
) {
267 EXPECT_EQ(expect_allow_
, allow
);
268 if (message_loop_runner_
.get())
269 message_loop_runner_
->Quit();
272 last_download_allowed_
= allow
;
276 waiting_for_decision_
= false;
277 decision_made_
= false;
281 content::WebContentsDelegate
* orig_delegate_
;
282 bool waiting_for_decision_
;
285 bool last_download_allowed_
;
286 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
288 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate
);
291 class WebViewTest
: public extensions::PlatformAppBrowserTest
{
293 void SetUp() override
{
294 if (UsesFakeSpeech()) {
295 // SpeechRecognition test specific SetUp.
296 fake_speech_recognition_manager_
.reset(
297 new content::FakeSpeechRecognitionManager());
298 fake_speech_recognition_manager_
->set_should_send_fake_response(true);
299 // Inject the fake manager factory so that the test result is returned to
301 content::SpeechRecognitionManager::SetManagerForTesting(
302 fake_speech_recognition_manager_
.get());
304 extensions::PlatformAppBrowserTest::SetUp();
307 void TearDown() override
{
308 if (UsesFakeSpeech()) {
309 // SpeechRecognition test specific TearDown.
310 content::SpeechRecognitionManager::SetManagerForTesting(NULL
);
313 extensions::PlatformAppBrowserTest::TearDown();
316 void SetUpOnMainThread() override
{
317 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
318 const testing::TestInfo
* const test_info
=
319 testing::UnitTest::GetInstance()->current_test_info();
320 // Mock out geolocation for geolocation specific tests.
321 if (!strncmp(test_info
->name(), "GeolocationAPI",
322 strlen("GeolocationAPI"))) {
323 ui_test_utils::OverrideGeolocation(10, 20);
327 void SetUpCommandLine(CommandLine
* command_line
) override
{
328 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
329 command_line
->AppendSwitchASCII(switches::kJavaScriptFlags
, "--expose-gc");
331 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
334 // This method is responsible for initializing a packaged app, which contains
335 // multiple webview tags. The tags have different partition identifiers and
336 // their WebContent objects are returned as output. The method also verifies
337 // the expected process allocation and storage partition assignment.
338 // The |navigate_to_url| parameter is used to navigate the main browser
341 // TODO(ajwong): This function is getting to be too large. Either refactor it
342 // so the test can specify a configuration of WebView tags that we will
343 // dynamically inject JS to generate, or move this test wholesale into
344 // something that RunPlatformAppTest() can execute purely in Javascript. This
345 // won't let us do a white-box examination of the StoragePartition equivalence
346 // directly, but we will be able to view the black box effects which is good
347 // enough. http://crbug.com/160361
348 void NavigateAndOpenAppForIsolation(
349 GURL navigate_to_url
,
350 content::WebContents
** default_tag_contents1
,
351 content::WebContents
** default_tag_contents2
,
352 content::WebContents
** named_partition_contents1
,
353 content::WebContents
** named_partition_contents2
,
354 content::WebContents
** persistent_partition_contents1
,
355 content::WebContents
** persistent_partition_contents2
,
356 content::WebContents
** persistent_partition_contents3
) {
357 GURL::Replacements replace_host
;
358 std::string
host_str("localhost"); // Must stay in scope with replace_host.
359 replace_host
.SetHostStr(host_str
);
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::NavigateToURLWithDisposition(
386 browser(), navigate_to_url
, CURRENT_TAB
,
387 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
389 ui_test_utils::UrlLoadObserver
observer1(
390 tag_url1
, content::NotificationService::AllSources());
391 ui_test_utils::UrlLoadObserver
observer2(
392 tag_url2
, content::NotificationService::AllSources());
393 ui_test_utils::UrlLoadObserver
observer3(
394 tag_url3
, content::NotificationService::AllSources());
395 ui_test_utils::UrlLoadObserver
observer4(
396 tag_url4
, content::NotificationService::AllSources());
397 ui_test_utils::UrlLoadObserver
observer5(
398 tag_url5
, content::NotificationService::AllSources());
399 ui_test_utils::UrlLoadObserver
observer6(
400 tag_url6
, content::NotificationService::AllSources());
401 ui_test_utils::UrlLoadObserver
observer7(
402 tag_url7
, content::NotificationService::AllSources());
403 LoadAndLaunchPlatformApp("web_view/isolation", "Launched");
412 content::Source
<content::NavigationController
> source1
= observer1
.source();
413 EXPECT_TRUE(source1
->GetWebContents()->GetRenderProcessHost()->
415 content::Source
<content::NavigationController
> source2
= observer2
.source();
416 EXPECT_TRUE(source2
->GetWebContents()->GetRenderProcessHost()->
418 content::Source
<content::NavigationController
> source3
= observer3
.source();
419 EXPECT_TRUE(source3
->GetWebContents()->GetRenderProcessHost()->
421 content::Source
<content::NavigationController
> source4
= observer4
.source();
422 EXPECT_TRUE(source4
->GetWebContents()->GetRenderProcessHost()->
424 content::Source
<content::NavigationController
> source5
= observer5
.source();
425 EXPECT_TRUE(source5
->GetWebContents()->GetRenderProcessHost()->
427 content::Source
<content::NavigationController
> source6
= observer6
.source();
428 EXPECT_TRUE(source6
->GetWebContents()->GetRenderProcessHost()->
430 content::Source
<content::NavigationController
> source7
= observer7
.source();
431 EXPECT_TRUE(source7
->GetWebContents()->GetRenderProcessHost()->
434 // Check that the first two tags use the same process and it is different
435 // than the process used by the other two.
436 EXPECT_EQ(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
437 source2
->GetWebContents()->GetRenderProcessHost()->GetID());
438 EXPECT_EQ(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
439 source4
->GetWebContents()->GetRenderProcessHost()->GetID());
440 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
441 source3
->GetWebContents()->GetRenderProcessHost()->GetID());
443 // The two sets of tags should also be isolated from the main browser.
444 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
445 browser()->tab_strip_model()->GetWebContentsAt(0)->
446 GetRenderProcessHost()->GetID());
447 EXPECT_NE(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
448 browser()->tab_strip_model()->GetWebContentsAt(0)->
449 GetRenderProcessHost()->GetID());
451 // Check that the storage partitions of the first two tags match and are
452 // different than the other two.
454 source1
->GetWebContents()->GetRenderProcessHost()->
455 GetStoragePartition(),
456 source2
->GetWebContents()->GetRenderProcessHost()->
457 GetStoragePartition());
459 source3
->GetWebContents()->GetRenderProcessHost()->
460 GetStoragePartition(),
461 source4
->GetWebContents()->GetRenderProcessHost()->
462 GetStoragePartition());
464 source1
->GetWebContents()->GetRenderProcessHost()->
465 GetStoragePartition(),
466 source3
->GetWebContents()->GetRenderProcessHost()->
467 GetStoragePartition());
469 // Ensure the persistent storage partitions are different.
471 source5
->GetWebContents()->GetRenderProcessHost()->
472 GetStoragePartition(),
473 source6
->GetWebContents()->GetRenderProcessHost()->
474 GetStoragePartition());
476 source5
->GetWebContents()->GetRenderProcessHost()->
477 GetStoragePartition(),
478 source7
->GetWebContents()->GetRenderProcessHost()->
479 GetStoragePartition());
481 source1
->GetWebContents()->GetRenderProcessHost()->
482 GetStoragePartition(),
483 source5
->GetWebContents()->GetRenderProcessHost()->
484 GetStoragePartition());
486 source1
->GetWebContents()->GetRenderProcessHost()->
487 GetStoragePartition(),
488 source7
->GetWebContents()->GetRenderProcessHost()->
489 GetStoragePartition());
491 *default_tag_contents1
= source1
->GetWebContents();
492 *default_tag_contents2
= source2
->GetWebContents();
493 *named_partition_contents1
= source3
->GetWebContents();
494 *named_partition_contents2
= source4
->GetWebContents();
495 if (persistent_partition_contents1
) {
496 *persistent_partition_contents1
= source5
->GetWebContents();
498 if (persistent_partition_contents2
) {
499 *persistent_partition_contents2
= source6
->GetWebContents();
501 if (persistent_partition_contents3
) {
502 *persistent_partition_contents3
= source7
->GetWebContents();
506 // Handles |request| by serving a redirect response if the |User-Agent| is
508 static scoped_ptr
<net::test_server::HttpResponse
> UserAgentResponseHandler(
509 const std::string
& path
,
510 const GURL
& redirect_target
,
511 const net::test_server::HttpRequest
& request
) {
512 if (!StartsWithASCII(path
, request
.relative_url
, true))
513 return scoped_ptr
<net::test_server::HttpResponse
>();
515 std::map
<std::string
, std::string
>::const_iterator it
=
516 request
.headers
.find("User-Agent");
517 EXPECT_TRUE(it
!= request
.headers
.end());
518 if (!StartsWithASCII("foobar", it
->second
, true))
519 return scoped_ptr
<net::test_server::HttpResponse
>();
521 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
522 new net::test_server::BasicHttpResponse
);
523 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
524 http_response
->AddCustomHeader("Location", redirect_target
.spec());
525 return http_response
.Pass();
528 // Handles |request| by serving a redirect response.
529 static scoped_ptr
<net::test_server::HttpResponse
> RedirectResponseHandler(
530 const std::string
& path
,
531 const GURL
& redirect_target
,
532 const net::test_server::HttpRequest
& request
) {
533 if (!StartsWithASCII(path
, request
.relative_url
, true))
534 return scoped_ptr
<net::test_server::HttpResponse
>();
536 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
537 new net::test_server::BasicHttpResponse
);
538 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
539 http_response
->AddCustomHeader("Location", redirect_target
.spec());
540 return http_response
.Pass();
543 // Handles |request| by serving an empty response.
544 static scoped_ptr
<net::test_server::HttpResponse
> EmptyResponseHandler(
545 const std::string
& path
,
546 const net::test_server::HttpRequest
& request
) {
547 if (StartsWithASCII(path
, request
.relative_url
, true)) {
548 return scoped_ptr
<net::test_server::HttpResponse
>(
549 new EmptyHttpResponse
);
552 return scoped_ptr
<net::test_server::HttpResponse
>();
555 // Shortcut to return the current MenuManager.
556 extensions::MenuManager
* menu_manager() {
557 return extensions::MenuManager::Get(browser()->profile());
560 // This gets all the items that any extension has registered for possible
561 // inclusion in context menus.
562 MenuItem::List
GetItems() {
563 MenuItem::List result
;
564 std::set
<MenuItem::ExtensionKey
> extension_ids
=
565 menu_manager()->ExtensionIds();
566 std::set
<MenuItem::ExtensionKey
>::iterator i
;
567 for (i
= extension_ids
.begin(); i
!= extension_ids
.end(); ++i
) {
568 const MenuItem::List
* list
= menu_manager()->MenuItems(*i
);
569 result
.insert(result
.end(), list
->begin(), list
->end());
579 void TestHelper(const std::string
& test_name
,
580 const std::string
& app_location
,
581 TestServer test_server
) {
582 // For serving guest pages.
583 if (test_server
== NEEDS_TEST_SERVER
) {
584 if (!StartEmbeddedTestServer()) {
585 LOG(ERROR
) << "FAILED TO START TEST SERVER.";
588 embedded_test_server()->RegisterRequestHandler(
589 base::Bind(&WebViewTest::RedirectResponseHandler
,
590 kRedirectResponsePath
,
591 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
593 embedded_test_server()->RegisterRequestHandler(
594 base::Bind(&WebViewTest::EmptyResponseHandler
, kEmptyResponsePath
));
596 embedded_test_server()->RegisterRequestHandler(
598 &WebViewTest::UserAgentResponseHandler
,
599 kUserAgentRedirectResponsePath
,
600 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
603 LoadAndLaunchPlatformApp(app_location
.c_str(), "Launched");
605 // Flush any pending events to make sure we start with a clean slate.
606 content::RunAllPendingInMessageLoop();
608 content::WebContents
* embedder_web_contents
=
609 GetFirstAppWindowWebContents();
610 if (!embedder_web_contents
) {
611 LOG(ERROR
) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
615 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
616 done_listener
.set_failure_message("TEST_FAILED");
617 if (!content::ExecuteScript(
618 embedder_web_contents
,
619 base::StringPrintf("runTest('%s')", test_name
.c_str()))) {
620 LOG(ERROR
) << "UNABLE TO START TEST.";
623 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
626 content::WebContents
* LoadGuest(const std::string
& guest_path
,
627 const std::string
& app_path
) {
628 GURL::Replacements replace_host
;
629 std::string
host_str("localhost"); // Must stay in scope with replace_host.
630 replace_host
.SetHostStr(host_str
);
632 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
633 guest_url
= guest_url
.ReplaceComponents(replace_host
);
635 ui_test_utils::UrlLoadObserver
guest_observer(
636 guest_url
, content::NotificationService::AllSources());
638 LoadAndLaunchPlatformApp(app_path
.c_str(), "guest-loaded");
640 guest_observer
.Wait();
641 content::Source
<content::NavigationController
> source
=
642 guest_observer
.source();
643 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
646 content::WebContents
* guest_web_contents
= source
->GetWebContents();
647 return guest_web_contents
;
650 // Runs media_access/allow tests.
651 void MediaAccessAPIAllowTestHelper(const std::string
& test_name
);
653 // Runs media_access/deny tests, each of them are run separately otherwise
654 // they timeout (mostly on Windows).
655 void MediaAccessAPIDenyTestHelper(const std::string
& test_name
) {
656 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
657 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
659 content::WebContents
* embedder_web_contents
=
660 GetFirstAppWindowWebContents();
661 ASSERT_TRUE(embedder_web_contents
);
663 ExtensionTestMessageListener
test_run_listener("PASSED", false);
664 test_run_listener
.set_failure_message("FAILED");
666 content::ExecuteScript(
667 embedder_web_contents
,
668 base::StringPrintf("startDenyTest('%s')", test_name
.c_str())));
669 ASSERT_TRUE(test_run_listener
.WaitUntilSatisfied());
672 void LoadAppWithGuest(const std::string
& app_path
) {
673 ExtensionTestMessageListener
launched_listener("WebViewTest.LAUNCHED",
675 launched_listener
.set_failure_message("WebViewTest.FAILURE");
676 LoadAndLaunchPlatformApp(app_path
.c_str(), &launched_listener
);
678 guest_web_contents_
= GetGuestViewManager()->WaitForSingleGuestCreated();
681 void SendMessageToEmbedder(const std::string
& message
) {
683 content::ExecuteScript(
684 GetEmbedderWebContents(),
685 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
688 void SendMessageToGuestAndWait(const std::string
& message
,
689 const std::string
& wait_message
) {
690 scoped_ptr
<ExtensionTestMessageListener
> listener
;
691 if (!wait_message
.empty()) {
692 listener
.reset(new ExtensionTestMessageListener(wait_message
, false));
696 content::ExecuteScript(
697 GetGuestWebContents(),
698 base::StringPrintf("onAppCommand('%s');", message
.c_str())));
701 ASSERT_TRUE(listener
->WaitUntilSatisfied());
705 content::WebContents
* GetGuestWebContents() {
706 return guest_web_contents_
;
709 content::WebContents
* GetEmbedderWebContents() {
710 if (!embedder_web_contents_
) {
711 embedder_web_contents_
= GetFirstAppWindowWebContents();
713 return embedder_web_contents_
;
716 extensions::TestGuestViewManager
* GetGuestViewManager() {
717 return static_cast<extensions::TestGuestViewManager
*>(
718 extensions::TestGuestViewManager::FromBrowserContext(
719 browser()->profile()));
722 WebViewTest() : guest_web_contents_(NULL
),
723 embedder_web_contents_(NULL
) {
724 extensions::GuestViewManager::set_factory_for_testing(&factory_
);
728 bool UsesFakeSpeech() {
729 const testing::TestInfo
* const test_info
=
730 testing::UnitTest::GetInstance()->current_test_info();
732 // SpeechRecognition test specific SetUp.
733 return !strcmp(test_info
->name(),
734 "SpeechRecognitionAPI_HasPermissionAllow");
737 scoped_ptr
<content::FakeSpeechRecognitionManager
>
738 fake_speech_recognition_manager_
;
740 extensions::TestGuestViewManagerFactory factory_
;
741 // Note that these are only set if you launch app using LoadAppWithGuest().
742 content::WebContents
* guest_web_contents_
;
743 content::WebContents
* embedder_web_contents_
;
746 class WebViewDPITest
: public WebViewTest
{
748 void SetUpCommandLine(CommandLine
* command_line
) override
{
749 WebViewTest::SetUpCommandLine(command_line
);
750 command_line
->AppendSwitchASCII(switches::kForceDeviceScaleFactor
,
751 base::StringPrintf("%f", scale()));
754 static float scale() { return 2.0f
; }
757 // This test verifies that hiding the guest triggers WebContents::WasHidden().
758 IN_PROC_BROWSER_TEST_F(WebViewTest
, GuestVisibilityChanged
) {
759 LoadAppWithGuest("web_view/visibility_changed");
761 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
762 new content::MessageLoopRunner
);
763 WebContentsHiddenObserver
observer(GetGuestWebContents(),
764 loop_runner
->QuitClosure());
766 // Handled in platform_apps/web_view/visibility_changed/main.js
767 SendMessageToEmbedder("hide-guest");
768 if (!observer
.hidden_observed())
772 // This test verifies that hiding the embedder also hides the guest.
773 IN_PROC_BROWSER_TEST_F(WebViewTest
, EmbedderVisibilityChanged
) {
774 LoadAppWithGuest("web_view/visibility_changed");
776 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
777 new content::MessageLoopRunner
);
778 WebContentsHiddenObserver
observer(GetGuestWebContents(),
779 loop_runner
->QuitClosure());
781 // Handled in platform_apps/web_view/visibility_changed/main.js
782 SendMessageToEmbedder("hide-embedder");
783 if (!observer
.hidden_observed())
787 // This test verifies that reloading the embedder reloads the guest (and doest
789 IN_PROC_BROWSER_TEST_F(WebViewTest
, ReloadEmbedder
) {
790 // Just load a guest from other test, we do not want to add a separate
791 // platform_app for this test.
792 LoadAppWithGuest("web_view/visibility_changed");
794 ExtensionTestMessageListener
launched_again_listener("WebViewTest.LAUNCHED",
796 GetEmbedderWebContents()->GetController().Reload(false);
797 ASSERT_TRUE(launched_again_listener
.WaitUntilSatisfied());
800 IN_PROC_BROWSER_TEST_F(WebViewTest
, AcceptTouchEvents
) {
801 LoadAppWithGuest("web_view/accept_touch_events");
803 content::RenderViewHost
* embedder_rvh
=
804 GetEmbedderWebContents()->GetRenderViewHost();
806 bool embedder_has_touch_handler
=
807 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
808 EXPECT_FALSE(embedder_has_touch_handler
);
810 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
812 // Note that we need to wait for the installed/registered touch handler to
813 // appear in browser process before querying |embedder_rvh|.
814 // In practice, since we do a roundrtip from browser process to guest and
815 // back, this is sufficient.
816 embedder_has_touch_handler
=
817 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
818 EXPECT_TRUE(embedder_has_touch_handler
);
820 SendMessageToGuestAndWait("uninstall-touch-handler",
821 "uninstalled-touch-handler");
822 // Same as the note above about waiting.
823 embedder_has_touch_handler
=
824 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh
);
825 EXPECT_FALSE(embedder_has_touch_handler
);
828 // This test ensures JavaScript errors ("Cannot redefine property") do not
829 // happen when a <webview> is removed from DOM and added back.
830 IN_PROC_BROWSER_TEST_F(WebViewTest
,
831 AddRemoveWebView_AddRemoveWebView
) {
832 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
833 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
837 IN_PROC_BROWSER_TEST_F(WebViewTest
, AutoSize
) {
839 // Flaky on XP bot http://crbug.com/299507
840 if (base::win::GetVersion() <= base::win::VERSION_XP
)
844 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
848 // Test for http://crbug.com/419611.
849 IN_PROC_BROWSER_TEST_F(WebViewTest
, DisplayNoneSetSrc
) {
850 LoadAndLaunchPlatformApp("web_view/display_none_set_src",
851 "WebViewTest.LAUNCHED");
852 // Navigate the guest while it's in "display: none" state.
853 SendMessageToEmbedder("navigate-guest");
854 GetGuestViewManager()->WaitForSingleGuestCreated();
856 // Now attempt to navigate the guest again.
857 SendMessageToEmbedder("navigate-guest");
859 ExtensionTestMessageListener
test_passed_listener("WebViewTest.PASSED",
861 // Making the guest visible would trigger loadstop.
862 SendMessageToEmbedder("show-guest");
863 EXPECT_TRUE(test_passed_listener
.WaitUntilSatisfied());
866 // http://crbug.com/326332
867 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_Shim_TestAutosizeAfterNavigation
) {
868 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER
);
871 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAllowTransparencyAttribute
) {
872 TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER
);
875 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeHeight
) {
876 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER
);
879 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeHeight
) {
880 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER
);
883 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeBeforeNavigation
) {
884 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
887 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeBeforeNavigation
) {
888 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
891 IN_PROC_BROWSER_TEST_F(WebViewDPITest
, Shim_TestAutosizeRemoveAttributes
) {
892 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
895 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeRemoveAttributes
) {
896 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
899 // This test is disabled due to being flaky. http://crbug.com/282116
900 #if defined(OS_WIN) || defined(OS_MACOSX)
901 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
902 DISABLED_Shim_TestAutosizeWithPartialAttributes
904 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
905 Shim_TestAutosizeWithPartialAttributes
907 IN_PROC_BROWSER_TEST_F(WebViewTest
,
908 MAYBE_Shim_TestAutosizeWithPartialAttributes
) {
909 TestHelper("testAutosizeWithPartialAttributes",
914 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAPIMethodExistence
) {
915 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER
);
918 // Tests the existence of WebRequest API event objects on the request
919 // object, on the webview element, and hanging directly off webview.
920 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIExistence
) {
921 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER
);
924 // http://crbug.com/315920
925 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
926 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
928 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
930 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_Shim_TestChromeExtensionURL
) {
931 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
934 // http://crbug.com/315920
935 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
936 #define MAYBE_Shim_TestChromeExtensionRelativePath \
937 DISABLED_Shim_TestChromeExtensionRelativePath
939 #define MAYBE_Shim_TestChromeExtensionRelativePath \
940 Shim_TestChromeExtensionRelativePath
942 IN_PROC_BROWSER_TEST_F(WebViewTest
,
943 MAYBE_Shim_TestChromeExtensionRelativePath
) {
944 TestHelper("testChromeExtensionRelativePath",
949 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewLoad
) {
950 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER
);
953 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDisplayNoneWebviewRemoveChild
) {
954 TestHelper("testDisplayNoneWebviewRemoveChild",
955 "web_view/shim", NO_TEST_SERVER
);
958 IN_PROC_BROWSER_TEST_F(WebViewTest
,
959 Shim_TestInlineScriptFromAccessibleResources
) {
960 TestHelper("testInlineScriptFromAccessibleResources",
965 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestInvalidChromeExtensionURL
) {
966 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
969 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestEventName
) {
970 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER
);
973 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestOnEventProperty
) {
974 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER
);
977 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadProgressEvent
) {
978 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER
);
981 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDestroyOnEventListener
) {
982 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER
);
985 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestCannotMutateEventName
) {
986 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER
);
989 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestPartitionChangeAfterNavigation
) {
990 TestHelper("testPartitionChangeAfterNavigation",
995 IN_PROC_BROWSER_TEST_F(WebViewTest
,
996 Shim_TestPartitionRemovalAfterNavigationFails
) {
997 TestHelper("testPartitionRemovalAfterNavigationFails",
1002 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScriptFail
) {
1004 // Flaky on XP bot http://crbug.com/266185
1005 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1009 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER
);
1012 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScript
) {
1013 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER
);
1016 IN_PROC_BROWSER_TEST_F(
1018 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged
) {
1019 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
1024 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestTerminateAfterExit
) {
1025 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER
);
1028 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAssignSrcAfterCrash
) {
1029 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER
);
1032 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1033 Shim_TestNavOnConsecutiveSrcAttributeChanges
) {
1034 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
1039 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavOnSrcAttributeChange
) {
1040 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER
);
1043 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigateAfterResize
) {
1044 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER
);
1047 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveSrcAttribute
) {
1048 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1051 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReassignSrcAttribute
) {
1052 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
1055 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindow
) {
1056 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER
);
1059 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowTwoListeners
) {
1060 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER
);
1063 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoPreventDefault
) {
1064 TestHelper("testNewWindowNoPreventDefault",
1069 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoReferrerLink
) {
1070 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER
);
1073 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestContentLoadEvent
) {
1074 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER
);
1077 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestDeclarativeWebRequestAPI
) {
1078 TestHelper("testDeclarativeWebRequestAPI",
1083 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1084 Shim_TestDeclarativeWebRequestAPISendMessage
) {
1085 TestHelper("testDeclarativeWebRequestAPISendMessage",
1090 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPI
) {
1091 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER
);
1094 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIWithHeaders
) {
1095 TestHelper("testWebRequestAPIWithHeaders",
1100 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIGoogleProperty
) {
1101 TestHelper("testWebRequestAPIGoogleProperty",
1106 // This test is disabled due to being flaky. http://crbug.com/309451
1108 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1109 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
1111 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1112 Shim_TestWebRequestListenerSurvivesReparenting
1114 IN_PROC_BROWSER_TEST_F(
1116 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting
) {
1117 TestHelper("testWebRequestListenerSurvivesReparenting",
1122 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadStartLoadRedirect
) {
1123 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER
);
1126 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1127 Shim_TestLoadAbortChromeExtensionURLWrongPartition
) {
1128 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1133 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortEmptyResponse
) {
1134 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER
);
1137 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalChromeURL
) {
1138 TestHelper("testLoadAbortIllegalChromeURL",
1143 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalFileURL
) {
1144 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER
);
1147 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalJavaScriptURL
) {
1148 TestHelper("testLoadAbortIllegalJavaScriptURL",
1153 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortInvalidNavigation
) {
1154 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER
);
1157 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortNonWebSafeScheme
) {
1158 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER
);
1161 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReload
) {
1162 TestHelper("testReload", "web_view/shim", NO_TEST_SERVER
);
1165 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReloadAfterTerminate
) {
1166 TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER
);
1169 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestGetProcessId
) {
1170 TestHelper("testGetProcessId", "web_view/shim", NO_TEST_SERVER
);
1173 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestHiddenBeforeNavigation
) {
1174 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
1177 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewOnExit
) {
1178 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1180 // Launch the app and wait until it's ready to load a test.
1181 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1183 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1184 ASSERT_TRUE(embedder_web_contents
);
1186 GURL::Replacements replace_host
;
1187 std::string
host_str("localhost"); // Must stay in scope with replace_host.
1188 replace_host
.SetHostStr(host_str
);
1190 std::string
guest_path(
1191 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1192 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
1193 guest_url
= guest_url
.ReplaceComponents(replace_host
);
1195 ui_test_utils::UrlLoadObserver
guest_observer(
1196 guest_url
, content::NotificationService::AllSources());
1198 // Run the test and wait until the guest WebContents is available and has
1199 // finished loading.
1200 ExtensionTestMessageListener
guest_loaded_listener("guest-loaded", false);
1201 EXPECT_TRUE(content::ExecuteScript(
1202 embedder_web_contents
,
1203 "runTest('testRemoveWebviewOnExit')"));
1204 guest_observer
.Wait();
1206 content::Source
<content::NavigationController
> source
=
1207 guest_observer
.source();
1208 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->
1211 ASSERT_TRUE(guest_loaded_listener
.WaitUntilSatisfied());
1213 content::WebContentsDestroyedWatcher
destroyed_watcher(
1214 source
->GetWebContents());
1216 // Tell the embedder to kill the guest.
1217 EXPECT_TRUE(content::ExecuteScript(
1218 embedder_web_contents
,
1219 "removeWebviewOnExitDoCrash();"));
1221 // Wait until the guest WebContents is destroyed.
1222 destroyed_watcher
.Wait();
1225 // Remove <webview> immediately after navigating it.
1226 // This is a regression test for http://crbug.com/276023.
1227 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewAfterNavigation
) {
1228 TestHelper("testRemoveWebviewAfterNavigation",
1233 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigationToExternalProtocol
) {
1234 TestHelper("testNavigationToExternalProtocol",
1239 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1240 Shim_TestResizeWebviewWithDisplayNoneResizesContent
) {
1241 TestHelper("testResizeWebviewWithDisplayNoneResizesContent",
1246 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestResizeWebviewResizesContent
) {
1247 TestHelper("testResizeWebviewResizesContent",
1252 // This test makes sure we do not crash if app is closed while interstitial
1253 // page is being shown in guest.
1254 IN_PROC_BROWSER_TEST_F(WebViewTest
, InterstitialTeardown
) {
1256 // Flaky on XP bot http://crbug.com/297014
1257 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1261 // Start a HTTPS server so we can load an interstitial page inside guest.
1262 net::SpawnedTestServer::SSLOptions ssl_options
;
1263 ssl_options
.server_certificate
=
1264 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME
;
1265 net::SpawnedTestServer
https_server(
1266 net::SpawnedTestServer::TYPE_HTTPS
, ssl_options
,
1267 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1268 ASSERT_TRUE(https_server
.Start());
1270 net::HostPortPair host_and_port
= https_server
.host_port_pair();
1272 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded");
1274 // Now load the guest.
1275 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1276 ExtensionTestMessageListener
second("GuestAddedToDom", false);
1277 EXPECT_TRUE(content::ExecuteScript(
1278 embedder_web_contents
,
1279 base::StringPrintf("loadGuest(%d);\n", host_and_port
.port())));
1280 ASSERT_TRUE(second
.WaitUntilSatisfied());
1282 // Wait for interstitial page to be shown in guest.
1283 content::WebContents
* guest_web_contents
=
1284 GetGuestViewManager()->WaitForSingleGuestCreated();
1285 ASSERT_TRUE(guest_web_contents
->GetRenderProcessHost()->IsIsolatedGuest());
1286 content::WaitForInterstitialAttach(guest_web_contents
);
1288 // Now close the app while interstitial page being shown in guest.
1289 extensions::AppWindow
* window
= GetFirstAppWindow();
1290 window
->GetBaseWindow()->Close();
1293 IN_PROC_BROWSER_TEST_F(WebViewTest
, ShimSrcAttribute
) {
1294 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1298 // This test verifies that prerendering has been disabled inside <webview>.
1299 // This test is here rather than in PrerenderBrowserTest for testing convenience
1300 // only. If it breaks then this is a bug in the prerenderer.
1301 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPrerenderer
) {
1302 ASSERT_TRUE(StartEmbeddedTestServer());
1303 content::WebContents
* guest_web_contents
=
1305 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1306 "web_view/noprerenderer");
1307 ASSERT_TRUE(guest_web_contents
!= NULL
);
1309 PrerenderLinkManager
* prerender_link_manager
=
1310 PrerenderLinkManagerFactory::GetForProfile(
1311 Profile::FromBrowserContext(guest_web_contents
->GetBrowserContext()));
1312 ASSERT_TRUE(prerender_link_manager
!= NULL
);
1313 EXPECT_TRUE(prerender_link_manager
->IsEmpty());
1316 // Verify that existing <webview>'s are detected when the task manager starts
1318 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerExistingWebView
) {
1319 ASSERT_TRUE(StartEmbeddedTestServer());
1321 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1322 "web_view/task_manager");
1324 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1326 const char* guest_title
= "WebViewed test content";
1327 const char* app_name
= "<webview> task manager test";
1328 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1329 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1330 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1331 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1333 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1334 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1335 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1336 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1339 // Verify that the task manager notices the creation of new <webview>'s.
1340 IN_PROC_BROWSER_TEST_F(WebViewTest
, TaskManagerNewWebView
) {
1341 ASSERT_TRUE(StartEmbeddedTestServer());
1343 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1345 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1346 "web_view/task_manager");
1348 const char* guest_title
= "WebViewed test content";
1349 const char* app_name
= "<webview> task manager test";
1350 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title
)));
1351 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1352 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name
)));
1353 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name
)));
1355 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1356 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1357 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1358 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1361 // This tests cookie isolation for packaged apps with webview tags. It navigates
1362 // the main browser window to a page that sets a cookie and loads an app with
1363 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1364 // storage isolation is enforced.
1365 // This test is flaky. See http://crbug.com/294196.
1366 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_CookieIsolation
) {
1367 ASSERT_TRUE(StartEmbeddedTestServer());
1368 const std::string kExpire
=
1369 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1370 std::string
cookie_script1(kExpire
);
1371 cookie_script1
.append(
1372 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1373 std::string
cookie_script2(kExpire
);
1374 cookie_script2
.append(
1375 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1377 GURL::Replacements replace_host
;
1378 std::string
host_str("localhost"); // Must stay in scope with replace_host.
1379 replace_host
.SetHostStr(host_str
);
1381 GURL set_cookie_url
= embedded_test_server()->GetURL(
1382 "/extensions/platform_apps/isolation/set_cookie.html");
1383 set_cookie_url
= set_cookie_url
.ReplaceComponents(replace_host
);
1385 // The first two partitions will be used to set cookies and ensure they are
1386 // shared. The named partition is used to ensure that cookies are isolated
1387 // between partitions within the same app.
1388 content::WebContents
* cookie_contents1
;
1389 content::WebContents
* cookie_contents2
;
1390 content::WebContents
* named_partition_contents1
;
1391 content::WebContents
* named_partition_contents2
;
1393 NavigateAndOpenAppForIsolation(set_cookie_url
, &cookie_contents1
,
1394 &cookie_contents2
, &named_partition_contents1
,
1395 &named_partition_contents2
, NULL
, NULL
, NULL
);
1397 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1398 EXPECT_TRUE(content::ExecuteScript(cookie_contents2
, cookie_script2
));
1401 std::string cookie_value
;
1403 // Test the regular browser context to ensure we have only one cookie.
1404 ui_test_utils::GetCookies(GURL("http://localhost"),
1405 browser()->tab_strip_model()->GetWebContentsAt(0),
1406 &cookie_size
, &cookie_value
);
1407 EXPECT_EQ("testCookie=1", cookie_value
);
1409 // The default behavior is to combine webview tags with no explicit partition
1410 // declaration into the same in-memory partition. Test the webview tags to
1411 // ensure we have properly set the cookies and we have both cookies in both
1413 ui_test_utils::GetCookies(GURL("http://localhost"),
1415 &cookie_size
, &cookie_value
);
1416 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1418 ui_test_utils::GetCookies(GURL("http://localhost"),
1420 &cookie_size
, &cookie_value
);
1421 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1423 // The third tag should not have any cookies as it is in a separate partition.
1424 ui_test_utils::GetCookies(GURL("http://localhost"),
1425 named_partition_contents1
,
1426 &cookie_size
, &cookie_value
);
1427 EXPECT_EQ("", cookie_value
);
1430 // This tests that in-memory storage partitions are reset on browser restart,
1431 // but persistent ones maintain state for cookies and HTML5 storage.
1432 IN_PROC_BROWSER_TEST_F(WebViewTest
, PRE_StoragePersistence
) {
1433 ASSERT_TRUE(StartEmbeddedTestServer());
1434 const std::string kExpire
=
1435 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1436 std::string
cookie_script1(kExpire
);
1437 cookie_script1
.append(
1438 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1439 std::string
cookie_script2(kExpire
);
1440 cookie_script2
.append(
1441 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1442 std::string
cookie_script3(kExpire
);
1443 cookie_script3
.append(
1444 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1446 // We don't care where the main browser is on this test.
1447 GURL
blank_url("about:blank");
1449 // The first two partitions will be used to set cookies and ensure they are
1450 // shared. The named partition is used to ensure that cookies are isolated
1451 // between partitions within the same app.
1452 content::WebContents
* cookie_contents1
;
1453 content::WebContents
* cookie_contents2
;
1454 content::WebContents
* named_partition_contents1
;
1455 content::WebContents
* named_partition_contents2
;
1456 content::WebContents
* persistent_partition_contents1
;
1457 content::WebContents
* persistent_partition_contents2
;
1458 content::WebContents
* persistent_partition_contents3
;
1459 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1460 &cookie_contents2
, &named_partition_contents1
,
1461 &named_partition_contents2
,
1462 &persistent_partition_contents1
,
1463 &persistent_partition_contents2
,
1464 &persistent_partition_contents3
);
1466 // Set the inmemory=true cookie for tags with inmemory partitions.
1467 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1468 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1
,
1471 // For the two different persistent storage partitions, set the
1472 // two different cookies so we can check that they aren't comingled below.
1473 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1
,
1476 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3
,
1480 std::string cookie_value
;
1482 // Check that all in-memory partitions have a cookie set.
1483 ui_test_utils::GetCookies(GURL("http://localhost"),
1485 &cookie_size
, &cookie_value
);
1486 EXPECT_EQ("inmemory=true", cookie_value
);
1487 ui_test_utils::GetCookies(GURL("http://localhost"),
1489 &cookie_size
, &cookie_value
);
1490 EXPECT_EQ("inmemory=true", cookie_value
);
1491 ui_test_utils::GetCookies(GURL("http://localhost"),
1492 named_partition_contents1
,
1493 &cookie_size
, &cookie_value
);
1494 EXPECT_EQ("inmemory=true", cookie_value
);
1495 ui_test_utils::GetCookies(GURL("http://localhost"),
1496 named_partition_contents2
,
1497 &cookie_size
, &cookie_value
);
1498 EXPECT_EQ("inmemory=true", cookie_value
);
1500 // Check that all persistent partitions kept their state.
1501 ui_test_utils::GetCookies(GURL("http://localhost"),
1502 persistent_partition_contents1
,
1503 &cookie_size
, &cookie_value
);
1504 EXPECT_EQ("persist1=true", cookie_value
);
1505 ui_test_utils::GetCookies(GURL("http://localhost"),
1506 persistent_partition_contents2
,
1507 &cookie_size
, &cookie_value
);
1508 EXPECT_EQ("persist1=true", cookie_value
);
1509 ui_test_utils::GetCookies(GURL("http://localhost"),
1510 persistent_partition_contents3
,
1511 &cookie_size
, &cookie_value
);
1512 EXPECT_EQ("persist2=true", cookie_value
);
1515 // This is the post-reset portion of the StoragePersistence test. See
1516 // PRE_StoragePersistence for main comment.
1517 #if defined(OS_CHROMEOS)
1518 // http://crbug.com/223888
1519 #define MAYBE_StoragePersistence DISABLED_StoragePersistence
1521 #define MAYBE_StoragePersistence StoragePersistence
1523 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_StoragePersistence
) {
1524 ASSERT_TRUE(StartEmbeddedTestServer());
1526 // We don't care where the main browser is on this test.
1527 GURL
blank_url("about:blank");
1529 // The first two partitions will be used to set cookies and ensure they are
1530 // shared. The named partition is used to ensure that cookies are isolated
1531 // between partitions within the same app.
1532 content::WebContents
* cookie_contents1
;
1533 content::WebContents
* cookie_contents2
;
1534 content::WebContents
* named_partition_contents1
;
1535 content::WebContents
* named_partition_contents2
;
1536 content::WebContents
* persistent_partition_contents1
;
1537 content::WebContents
* persistent_partition_contents2
;
1538 content::WebContents
* persistent_partition_contents3
;
1539 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1540 &cookie_contents2
, &named_partition_contents1
,
1541 &named_partition_contents2
,
1542 &persistent_partition_contents1
,
1543 &persistent_partition_contents2
,
1544 &persistent_partition_contents3
);
1547 std::string cookie_value
;
1549 // Check that all in-memory partitions lost their state.
1550 ui_test_utils::GetCookies(GURL("http://localhost"),
1552 &cookie_size
, &cookie_value
);
1553 EXPECT_EQ("", cookie_value
);
1554 ui_test_utils::GetCookies(GURL("http://localhost"),
1556 &cookie_size
, &cookie_value
);
1557 EXPECT_EQ("", cookie_value
);
1558 ui_test_utils::GetCookies(GURL("http://localhost"),
1559 named_partition_contents1
,
1560 &cookie_size
, &cookie_value
);
1561 EXPECT_EQ("", cookie_value
);
1562 ui_test_utils::GetCookies(GURL("http://localhost"),
1563 named_partition_contents2
,
1564 &cookie_size
, &cookie_value
);
1565 EXPECT_EQ("", cookie_value
);
1567 // Check that all persistent partitions kept their state.
1568 ui_test_utils::GetCookies(GURL("http://localhost"),
1569 persistent_partition_contents1
,
1570 &cookie_size
, &cookie_value
);
1571 EXPECT_EQ("persist1=true", cookie_value
);
1572 ui_test_utils::GetCookies(GURL("http://localhost"),
1573 persistent_partition_contents2
,
1574 &cookie_size
, &cookie_value
);
1575 EXPECT_EQ("persist1=true", cookie_value
);
1576 ui_test_utils::GetCookies(GURL("http://localhost"),
1577 persistent_partition_contents3
,
1578 &cookie_size
, &cookie_value
);
1579 EXPECT_EQ("persist2=true", cookie_value
);
1582 // This tests DOM storage isolation for packaged apps with webview tags. It
1583 // loads an app with multiple webview tags and each tag sets DOM storage
1584 // entries, which the test checks to ensure proper storage isolation is
1586 // Times out regularly on Windows. See http://crbug.com/248873.
1588 #define MAYBE_DOMStorageIsolation DISABLED_DOMStorageIsolation
1590 #define MAYBE_DOMStorageIsolation DOMStorageIsolation
1592 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_DOMStorageIsolation
) {
1593 ASSERT_TRUE(StartEmbeddedTestServer());
1594 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1597 std::string
get_local_storage("window.domAutomationController.send("
1598 "window.localStorage.getItem('foo') || 'badval')");
1599 std::string
get_session_storage("window.domAutomationController.send("
1600 "window.sessionStorage.getItem('bar') || 'badval')");
1602 content::WebContents
* default_tag_contents1
;
1603 content::WebContents
* default_tag_contents2
;
1604 content::WebContents
* storage_contents1
;
1605 content::WebContents
* storage_contents2
;
1607 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1608 &default_tag_contents2
, &storage_contents1
,
1609 &storage_contents2
, NULL
, NULL
, NULL
);
1611 // Initialize the storage for the first of the two tags that share a storage
1613 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1614 "initDomStorage('page1')"));
1616 // Let's test that the expected values are present in the first tag, as they
1617 // will be overwritten once we call the initDomStorage on the second tag.
1618 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1619 get_local_storage
.c_str(),
1621 EXPECT_STREQ("local-page1", output
.c_str());
1622 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1623 get_session_storage
.c_str(),
1625 EXPECT_STREQ("session-page1", output
.c_str());
1627 // Now, init the storage in the second tag in the same storage partition,
1628 // which will overwrite the shared localStorage.
1629 EXPECT_TRUE(content::ExecuteScript(storage_contents2
,
1630 "initDomStorage('page2')"));
1632 // The localStorage value now should reflect the one written through the
1634 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1635 get_local_storage
.c_str(),
1637 EXPECT_STREQ("local-page2", output
.c_str());
1638 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1639 get_local_storage
.c_str(),
1641 EXPECT_STREQ("local-page2", output
.c_str());
1643 // Session storage is not shared though, as each webview tag has separate
1644 // instance, even if they are in the same storage partition.
1645 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1646 get_session_storage
.c_str(),
1648 EXPECT_STREQ("session-page1", output
.c_str());
1649 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1650 get_session_storage
.c_str(),
1652 EXPECT_STREQ("session-page2", output
.c_str());
1654 // Also, let's check that the main browser and another tag that doesn't share
1655 // the same partition don't have those values stored.
1656 EXPECT_TRUE(ExecuteScriptAndExtractString(
1657 browser()->tab_strip_model()->GetWebContentsAt(0),
1658 get_local_storage
.c_str(),
1660 EXPECT_STREQ("badval", output
.c_str());
1661 EXPECT_TRUE(ExecuteScriptAndExtractString(
1662 browser()->tab_strip_model()->GetWebContentsAt(0),
1663 get_session_storage
.c_str(),
1665 EXPECT_STREQ("badval", output
.c_str());
1666 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1667 get_local_storage
.c_str(),
1669 EXPECT_STREQ("badval", output
.c_str());
1670 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1671 get_session_storage
.c_str(),
1673 EXPECT_STREQ("badval", output
.c_str());
1676 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1677 // an app with multiple webview tags and each tag creates an IndexedDB record,
1678 // which the test checks to ensure proper storage isolation is enforced.
1679 // This test is flaky. See http://crbug.com/248500.
1680 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_IndexedDBIsolation
) {
1681 ASSERT_TRUE(StartEmbeddedTestServer());
1682 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1684 content::WebContents
* default_tag_contents1
;
1685 content::WebContents
* default_tag_contents2
;
1686 content::WebContents
* storage_contents1
;
1687 content::WebContents
* storage_contents2
;
1689 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1690 &default_tag_contents2
, &storage_contents1
,
1691 &storage_contents2
, NULL
, NULL
, NULL
);
1693 // Initialize the storage for the first of the two tags that share a storage
1695 ExecuteScriptWaitForTitle(storage_contents1
, "initIDB()", "idb created");
1696 ExecuteScriptWaitForTitle(storage_contents1
, "addItemIDB(7, 'page1')",
1697 "addItemIDB complete");
1698 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1699 "readItemIDB complete");
1702 std::string
get_value(
1703 "window.domAutomationController.send(getValueIDB() || 'badval')");
1705 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1706 get_value
.c_str(), &output
));
1707 EXPECT_STREQ("page1", output
.c_str());
1709 // Initialize the db in the second tag.
1710 ExecuteScriptWaitForTitle(storage_contents2
, "initIDB()", "idb open");
1712 // Since we share a partition, reading the value should return the existing
1714 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1715 "readItemIDB complete");
1716 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1717 get_value
.c_str(), &output
));
1718 EXPECT_STREQ("page1", output
.c_str());
1720 // Now write through the second tag and read it back.
1721 ExecuteScriptWaitForTitle(storage_contents2
, "addItemIDB(7, 'page2')",
1722 "addItemIDB complete");
1723 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1724 "readItemIDB complete");
1725 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1726 get_value
.c_str(), &output
));
1727 EXPECT_STREQ("page2", output
.c_str());
1729 // Reset the document title, otherwise the next call will not see a change and
1730 // will hang waiting for it.
1731 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1732 "document.title = 'foo'"));
1734 // Read through the first tag to ensure we have the second value.
1735 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1736 "readItemIDB complete");
1737 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1738 get_value
.c_str(), &output
));
1739 EXPECT_STREQ("page2", output
.c_str());
1741 // Now, let's confirm there is no database in the main browser and another
1742 // tag that doesn't share the same partition. Due to the IndexedDB API design,
1743 // open will succeed, but the version will be 1, since it creates the database
1744 // if it is not found. The two tags use database version 3, so we avoid
1746 const char* script
=
1747 "indexedDB.open('isolation').onsuccess = function(e) {"
1748 " if (e.target.result.version == 1)"
1749 " document.title = 'db not found';"
1751 " document.title = 'error';"
1753 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1754 script
, "db not found");
1755 ExecuteScriptWaitForTitle(default_tag_contents1
, script
, "db not found");
1758 // This test ensures that closing app window on 'loadcommit' does not crash.
1759 // The test launches an app with guest and closes the window on loadcommit. It
1760 // then launches the app window again. The process is repeated 3 times.
1761 // http://crbug.com/291278
1763 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1765 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1767 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_CloseOnLoadcommit
) {
1768 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1769 "done-close-on-loadcommit");
1772 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIDeny_TestDeny
) {
1773 MediaAccessAPIDenyTestHelper("testDeny");
1776 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1777 MediaAccessAPIDeny_TestDenyThenAllowThrows
) {
1778 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1782 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1783 MediaAccessAPIDeny_TestDenyWithPreventDefault
) {
1784 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1787 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1788 MediaAccessAPIDeny_TestNoListenersImplyDeny
) {
1789 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1792 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1793 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny
) {
1794 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1797 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string
& test_name
) {
1798 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1799 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1801 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1802 ASSERT_TRUE(embedder_web_contents
);
1803 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
1804 embedder_web_contents
->SetDelegate(mock
.get());
1806 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1807 done_listener
.set_failure_message("TEST_FAILED");
1809 content::ExecuteScript(
1810 embedder_web_contents
,
1811 base::StringPrintf("startAllowTest('%s')",
1812 test_name
.c_str())));
1813 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1815 mock
->WaitForRequestMediaPermission();
1818 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenusAPI_Basic
) {
1819 LoadAppWithGuest("web_view/context_menus/basic");
1821 content::WebContents
* guest_web_contents
= GetGuestWebContents();
1822 content::WebContents
* embedder
= GetEmbedderWebContents();
1823 ASSERT_TRUE(embedder
);
1825 // 1. Basic property test.
1826 ExecuteScriptWaitForTitle(embedder
, "checkProperties()", "ITEM_CHECKED");
1828 // 2. Create a menu item and wait for created callback to be called.
1829 ExecuteScriptWaitForTitle(embedder
, "createMenuItem()", "ITEM_CREATED");
1831 // 3. Click the created item, wait for the click handlers to fire from JS.
1832 ExtensionTestMessageListener
click_listener("ITEM_CLICKED", false);
1833 GURL
page_url("http://www.google.com");
1834 // Create and build our test context menu.
1835 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1836 guest_web_contents
, page_url
, GURL(), GURL()));
1838 // Look for the extension item in the menu, and execute it.
1839 int command_id
= ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1840 ASSERT_TRUE(menu
->IsCommandIdEnabled(command_id
));
1841 menu
->ExecuteCommand(command_id
, 0);
1843 // Wait for embedder's script to tell us its onclick fired, it does
1844 // chrome.test.sendMessage('ITEM_CLICKED')
1845 ASSERT_TRUE(click_listener
.WaitUntilSatisfied());
1847 // 4. Update the item's title and verify.
1848 ExecuteScriptWaitForTitle(embedder
, "updateMenuItem()", "ITEM_UPDATED");
1849 MenuItem::List items
= GetItems();
1850 ASSERT_EQ(1u, items
.size());
1851 MenuItem
* item
= items
.at(0);
1852 EXPECT_EQ("new_title", item
->title());
1854 // 5. Remove the item.
1855 ExecuteScriptWaitForTitle(embedder
, "removeItem()", "ITEM_REMOVED");
1856 MenuItem::List items_after_removal
= GetItems();
1857 ASSERT_EQ(0u, items_after_removal
.size());
1859 // 6. Add some more items.
1860 ExecuteScriptWaitForTitle(
1861 embedder
, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1862 MenuItem::List items_after_insertion
= GetItems();
1863 ASSERT_EQ(3u, items_after_insertion
.size());
1865 // 7. Test removeAll().
1866 ExecuteScriptWaitForTitle(embedder
, "removeAllItems()", "ITEM_ALL_REMOVED");
1867 MenuItem::List items_after_all_removal
= GetItems();
1868 ASSERT_EQ(0u, items_after_all_removal
.size());
1871 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllow
) {
1872 MediaAccessAPIAllowTestHelper("testAllow");
1875 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAndThenDeny
) {
1876 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1879 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowTwice
) {
1880 MediaAccessAPIAllowTestHelper("testAllowTwice");
1883 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAsync
) {
1884 MediaAccessAPIAllowTestHelper("testAllowAsync");
1887 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestCheck
) {
1888 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1889 LoadAndLaunchPlatformApp("web_view/media_access/check", "Launched");
1891 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1892 ASSERT_TRUE(embedder_web_contents
);
1893 scoped_ptr
<MockWebContentsDelegate
> mock(new MockWebContentsDelegate());
1894 embedder_web_contents
->SetDelegate(mock
.get());
1896 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1897 done_listener
.set_failure_message("TEST_FAILED");
1899 content::ExecuteScript(
1900 embedder_web_contents
,
1901 base::StringPrintf("startCheckTest('')")));
1902 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1904 mock
->WaitForCheckMediaPermission();
1907 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1909 IN_PROC_BROWSER_TEST_F(WebViewTest
, ScreenCoordinates
) {
1910 ASSERT_TRUE(RunPlatformAppTestWithArg(
1911 "platform_apps/web_view/common", "screen_coordinates"))
1915 #if defined(OS_CHROMEOS)
1916 IN_PROC_BROWSER_TEST_F(WebViewTest
, ChromeVoxInjection
) {
1918 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1920 ASSERT_TRUE(StartEmbeddedTestServer());
1921 content::WebContents
* guest_web_contents
= LoadGuest(
1922 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1923 "web_view/chromevox_injection");
1924 ASSERT_TRUE(guest_web_contents
);
1926 chromeos::SpeechMonitor monitor
;
1927 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1928 true, ui::A11Y_NOTIFICATION_NONE
);
1929 EXPECT_TRUE(monitor
.SkipChromeVoxEnabledMessage());
1931 EXPECT_EQ("chrome vox test title", monitor
.GetNextUtterance());
1935 // Flaky on Windows. http://crbug.com/303966
1937 #define MAYBE_TearDownTest DISABLED_TearDownTest
1939 #define MAYBE_TearDownTest TearDownTest
1941 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_TearDownTest
) {
1942 const extensions::Extension
* extension
=
1943 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded");
1944 extensions::AppWindow
* window
= NULL
;
1945 if (!GetAppWindowCount())
1946 window
= CreateAppWindow(extension
);
1948 window
= GetFirstAppWindow();
1949 CloseAppWindow(window
);
1951 // Load the app again.
1952 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded");
1955 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1956 // platform app) does not have geolocation permission for this test.
1957 // No matter what the API does, geolocation permission would be denied.
1958 // Note that the test name prefix must be "GeolocationAPI".
1959 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessAllow
) {
1960 TestHelper("testDenyDenies",
1961 "web_view/geolocation/embedder_has_no_permission",
1965 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessDeny
) {
1966 TestHelper("testDenyDenies",
1967 "web_view/geolocation/embedder_has_no_permission",
1971 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1972 // platform app) has geolocation permission
1974 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1975 // geolocation in this case).
1977 // Also note that these are run separately because OverrideGeolocation() doesn't
1978 // mock out geolocation for multiple navigator.geolocation calls properly and
1979 // the tests become flaky.
1980 // GeolocationAPI* test 1 of 3.
1981 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessAllow
) {
1982 TestHelper("testAllow",
1983 "web_view/geolocation/embedder_has_permission",
1987 // GeolocationAPI* test 2 of 3.
1988 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessDeny
) {
1989 TestHelper("testDeny",
1990 "web_view/geolocation/embedder_has_permission",
1994 // GeolocationAPI* test 3 of 3.
1995 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1996 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow
) {
1997 TestHelper("testMultipleBridgeIdAllow",
1998 "web_view/geolocation/embedder_has_permission",
2003 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
2004 // is handled correctly (and does not crash).
2005 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPICancelGeolocation
) {
2006 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2007 ASSERT_TRUE(RunPlatformAppTest(
2008 "platform_apps/web_view/geolocation/cancel_request")) << message_
;
2011 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_GeolocationRequestGone
) {
2012 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2013 ASSERT_TRUE(RunPlatformAppTest(
2014 "platform_apps/web_view/geolocation/geolocation_request_gone"))
2018 // In following FilesystemAPIRequestFromMainThread* tests, guest request
2019 // filesystem access from main thread of the guest.
2020 // FileSystemAPIRequestFromMainThread* test 1 of 3
2021 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadAllow
) {
2022 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2025 // FileSystemAPIRequestFromMainThread* test 2 of 3.
2026 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromMainThreadDeny
) {
2027 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2030 // FileSystemAPIRequestFromMainThread* test 3 of 3.
2031 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2032 FileSystemAPIRequestFromMainThreadDefaultAllow
) {
2033 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER
);
2036 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
2037 // to request filesystem access from worker thread.
2038 // FileSystemAPIRequestFromWorker* test 1 of 3
2039 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerAllow
) {
2040 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2043 // FileSystemAPIRequestFromWorker* test 2 of 3.
2044 IN_PROC_BROWSER_TEST_F(WebViewTest
, FileSystemAPIRequestFromWorkerDeny
) {
2045 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2048 // FileSystemAPIRequestFromWorker* test 3 of 3.
2049 IN_PROC_BROWSER_TEST_F(WebViewTest
,
2050 FileSystemAPIRequestFromWorkerDefaultAllow
) {
2052 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER
);
2055 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
2056 // embedder contains a single webview guest. The guest creates a shared worker
2057 // to request filesystem access from worker thread.
2058 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
2059 IN_PROC_BROWSER_TEST_F(
2061 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow
) {
2062 TestHelper("testAllow",
2063 "web_view/filesystem/shared_worker/single",
2067 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
2068 IN_PROC_BROWSER_TEST_F(
2070 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny
) {
2071 TestHelper("testDeny",
2072 "web_view/filesystem/shared_worker/single",
2076 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2077 IN_PROC_BROWSER_TEST_F(
2079 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow
) {
2082 "web_view/filesystem/shared_worker/single",
2086 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2087 // embedder contains mutiple webview guests. Each guest creates a shared worker
2088 // to request filesystem access from worker thread.
2089 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2090 IN_PROC_BROWSER_TEST_F(
2092 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow
) {
2093 TestHelper("testAllow",
2094 "web_view/filesystem/shared_worker/multiple",
2098 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2099 IN_PROC_BROWSER_TEST_F(
2101 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny
) {
2102 TestHelper("testDeny",
2103 "web_view/filesystem/shared_worker/multiple",
2107 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2108 IN_PROC_BROWSER_TEST_F(
2110 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow
) {
2113 "web_view/filesystem/shared_worker/multiple",
2117 IN_PROC_BROWSER_TEST_F(WebViewTest
, ClearData
) {
2119 // Flaky on XP bot http://crbug.com/282674
2120 if (base::win::GetVersion() <= base::win::VERSION_XP
)
2124 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2125 ASSERT_TRUE(RunPlatformAppTestWithArg(
2126 "platform_apps/web_view/common", "cleardata"))
2130 // This test is disabled on Win due to being flaky. http://crbug.com/294592
2132 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
2134 #define MAYBE_ConsoleMessage ConsoleMessage
2136 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_ConsoleMessage
) {
2137 ASSERT_TRUE(RunPlatformAppTestWithArg(
2138 "platform_apps/web_view/common", "console_messages"))
2142 IN_PROC_BROWSER_TEST_F(WebViewTest
, DownloadPermission
) {
2143 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2144 content::WebContents
* guest_web_contents
=
2145 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2146 "web_view/download");
2147 ASSERT_TRUE(guest_web_contents
);
2149 // Replace WebContentsDelegate with mock version so we can intercept download
2151 content::WebContentsDelegate
* delegate
= guest_web_contents
->GetDelegate();
2152 scoped_ptr
<MockDownloadWebContentsDelegate
>
2153 mock_delegate(new MockDownloadWebContentsDelegate(delegate
));
2154 guest_web_contents
->SetDelegate(mock_delegate
.get());
2157 // 1. Guest requests a download that its embedder denies.
2158 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2159 "startDownload('download-link-1')"));
2160 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2161 mock_delegate
->Reset();
2163 // 2. Guest requests a download that its embedder allows.
2164 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2165 "startDownload('download-link-2')"));
2166 mock_delegate
->WaitForCanDownload(true); // Expect to allow.
2167 mock_delegate
->Reset();
2169 // 3. Guest requests a download that its embedder ignores, this implies deny.
2170 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
2171 "startDownload('download-link-3')"));
2172 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
2175 // This test makes sure loading <webview> does not crash when there is an
2176 // extension which has content script whitelisted/forced.
2177 IN_PROC_BROWSER_TEST_F(WebViewTest
, WhitelistedContentScript
) {
2178 // Whitelist the extension for running content script we are going to load.
2179 extensions::ExtensionsClient::ScriptingWhitelist whitelist
;
2180 const std::string extension_id
= "imeongpbjoodlnmlakaldhlcmijmhpbb";
2181 whitelist
.push_back(extension_id
);
2182 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist
);
2184 // Load the extension.
2185 const extensions::Extension
* content_script_whitelisted_extension
=
2186 LoadExtension(test_data_dir_
.AppendASCII(
2187 "platform_apps/web_view/extension_api/content_script"));
2188 ASSERT_TRUE(content_script_whitelisted_extension
);
2189 ASSERT_EQ(extension_id
, content_script_whitelisted_extension
->id());
2191 // Now load an app with <webview>.
2192 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2196 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentReady
) {
2197 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2201 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentInteractive
) {
2202 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2206 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionAllow
) {
2208 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2213 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionDeny
) {
2215 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2220 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_NoPermission
) {
2222 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2223 "speech_recognition_api_no_permission"))
2227 // Tests overriding user agent.
2228 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent
) {
2229 ASSERT_TRUE(RunPlatformAppTestWithArg(
2230 "platform_apps/web_view/common", "useragent")) << message_
;
2233 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent_NewWindow
) {
2234 ASSERT_TRUE(RunPlatformAppTestWithArg(
2235 "platform_apps/web_view/common",
2236 "useragent_newwindow")) << message_
;
2239 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPermission
) {
2240 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2244 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestAlertDialog
) {
2245 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER
);
2248 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestConfirmDialog
) {
2249 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER
);
2252 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogCancel
) {
2253 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER
);
2256 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultCancel
) {
2257 TestHelper("testConfirmDialogDefaultCancel",
2262 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultGCCancel
) {
2263 TestHelper("testConfirmDialogDefaultGCCancel",
2268 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestPromptDialog
) {
2269 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER
);
2272 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoContentSettingsAPI
) {
2273 // Load the extension.
2274 const extensions::Extension
* content_settings_extension
=
2276 test_data_dir_
.AppendASCII(
2277 "platform_apps/web_view/extension_api/content_settings"));
2278 ASSERT_TRUE(content_settings_extension
);
2279 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER
);
2282 #if defined(ENABLE_PLUGINS)
2283 class WebViewPluginTest
: public WebViewTest
{
2285 void SetUpCommandLine(CommandLine
* command_line
) override
{
2286 WebViewTest::SetUpCommandLine(command_line
);
2288 // Append the switch to register the pepper plugin.
2289 // library name = <out dir>/<test_name>.<library_extension>
2290 // MIME type = application/x-ppapi-<test_name>
2291 base::FilePath plugin_lib
= GetPluginPath();
2292 EXPECT_TRUE(base::PathExists(plugin_lib
));
2293 base::FilePath::StringType pepper_plugin
= plugin_lib
.value();
2294 pepper_plugin
.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
2295 command_line
->AppendSwitchNative(switches::kRegisterPepperPlugins
,
2299 base::FilePath
GetPluginPath() const {
2300 base::FilePath plugin_dir
;
2301 EXPECT_TRUE(PathService::Get(base::DIR_MODULE
, &plugin_dir
));
2302 return plugin_dir
.Append(library_name
);
2306 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginEvent
) {
2307 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER
);
2310 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginInternalResource
) {
2311 const char kTestMimeType
[] = "application/pdf";
2312 const char kTestFileType
[] = "pdf";
2313 content::WebPluginInfo plugin_info
;
2314 plugin_info
.type
= content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS
;
2315 plugin_info
.mime_types
.push_back(
2316 content::WebPluginMimeType(kTestMimeType
, kTestFileType
, std::string()));
2317 content::PluginService::GetInstance()->RegisterInternalPlugin(plugin_info
,
2320 TestHelper("testPluginLoadInternalResource", "web_view/shim", NO_TEST_SERVER
);
2322 #endif // defined(ENABLE_PLUGINS)
2324 class WebViewCaptureTest
: public WebViewTest
{
2326 WebViewCaptureTest() {}
2327 ~WebViewCaptureTest() override
{}
2328 void SetUp() override
{
2329 EnablePixelOutput();
2330 WebViewTest::SetUp();
2334 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestZoomAPI
) {
2335 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER
);
2338 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI
) {
2339 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER
);
2342 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI_findupdate
) {
2343 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER
);
2346 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadDataAPI
) {
2347 TestHelper("testLoadDataAPI", "web_view/shim", NEEDS_TEST_SERVER
);
2350 // This test verify that the set of rules registries of a webview will be
2351 // removed from RulesRegistryService after the webview is gone.
2352 // http://crbug.com/438327
2353 IN_PROC_BROWSER_TEST_F(
2355 DISABLED_Shim_TestRulesRegistryIDAreRemovedAfterWebViewIsGone
) {
2356 LoadAppWithGuest("web_view/rules_registry");
2358 content::WebContents
* embedder_web_contents
= GetEmbedderWebContents();
2359 ASSERT_TRUE(embedder_web_contents
);
2360 scoped_ptr
<EmbedderWebContentsObserver
> observer(
2361 new EmbedderWebContentsObserver(embedder_web_contents
));
2363 content::WebContents
* guest_web_contents
= GetGuestWebContents();
2364 ASSERT_TRUE(guest_web_contents
);
2365 extensions::WebViewGuest
* guest
=
2366 extensions::WebViewGuest::FromWebContents(guest_web_contents
);
2369 // Register rule for the guest.
2370 Profile
* profile
= browser()->profile();
2371 int rules_registry_id
=
2372 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2373 guest
->owner_render_process_id(),
2374 guest
->view_instance_id(),
2377 extensions::RulesRegistryService
* registry_service
=
2378 extensions::RulesRegistryService::Get(profile
);
2379 extensions::TestRulesRegistry
* rules_registry
=
2380 new extensions::TestRulesRegistry(
2381 content::BrowserThread::UI
, "ui", rules_registry_id
);
2382 registry_service
->RegisterRulesRegistry(make_scoped_refptr(rules_registry
));
2384 EXPECT_TRUE(registry_service
->GetRulesRegistry(
2385 rules_registry_id
, "ui").get());
2387 // Kill the embedder's render process, so the webview will go as well.
2388 content::RenderProcessHost
* host
=
2389 embedder_web_contents
->GetRenderProcessHost();
2390 base::KillProcess(host
->GetHandle(), 0, false);
2391 observer
->WaitForEmbedderRenderProcessTerminate();
2393 EXPECT_FALSE(registry_service
->GetRulesRegistry(
2394 rules_registry_id
, "ui").get());
2397 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_WebViewWebRequestRegistryHasNoCache
) {
2398 LoadAppWithGuest("web_view/rules_registry");
2400 content::WebContents
* guest_web_contents
= GetGuestWebContents();
2401 ASSERT_TRUE(guest_web_contents
);
2402 extensions::WebViewGuest
* guest
=
2403 extensions::WebViewGuest::FromWebContents(guest_web_contents
);
2406 Profile
* profile
= browser()->profile();
2407 extensions::RulesRegistryService
* registry_service
=
2408 extensions::RulesRegistryService::Get(profile
);
2409 int rules_registry_id
=
2410 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2411 guest
->owner_render_process_id(),
2412 guest
->view_instance_id(),
2415 // Get an existing registered rule for the guest.
2416 extensions::RulesRegistry
* registry
=
2417 registry_service
->GetRulesRegistry(
2419 extensions::declarative_webrequest_constants::kOnRequest
).get();
2421 EXPECT_TRUE(registry
);
2422 EXPECT_FALSE(registry
->rules_cache_delegate_for_testing());
2425 // <webview> screenshot capture fails with ubercomp.
2426 // See http://crbug.com/327035.
2427 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest
,
2428 DISABLED_Shim_ScreenshotCapture
) {
2429 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER
);
2433 // Test is disabled on Windows because it times out often.
2434 // http://crbug.com/403325
2435 #define MAYBE_WebViewInBackgroundPage \
2436 DISABLED_WebViewInBackgroundPage
2438 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2440 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_WebViewInBackgroundPage
) {
2441 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))