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 "apps/ui/native_app_window.h"
6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/automation/automation_util.h"
12 #include "chrome/browser/chrome_content_browser_client.h"
13 #include "chrome/browser/extensions/extension_test_message_listener.h"
14 #include "chrome/browser/prerender/prerender_link_manager.h"
15 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/gpu_data_manager.h"
23 #include "content/public/browser/interstitial_page.h"
24 #include "content/public/browser/interstitial_page_delegate.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/render_process_host.h"
27 #include "content/public/browser/web_contents_delegate.h"
28 #include "content/public/common/content_switches.h"
29 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/fake_speech_recognition_manager.h"
31 #include "extensions/common/extension.h"
32 #include "extensions/common/extensions_client.h"
33 #include "net/test/embedded_test_server/embedded_test_server.h"
34 #include "net/test/embedded_test_server/http_request.h"
35 #include "net/test/embedded_test_server/http_response.h"
36 #include "ui/gl/gl_switches.h"
38 #if defined(OS_CHROMEOS)
39 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
40 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
43 // For fine-grained suppression on flaky tests.
45 #include "base/win/windows_version.h"
48 using extensions::MenuItem
;
49 using prerender::PrerenderLinkManager
;
50 using prerender::PrerenderLinkManagerFactory
;
54 const char kEmptyResponsePath
[] = "/close-socket";
55 const char kRedirectResponsePath
[] = "/server-redirect";
56 const char kRedirectResponseFullPath
[] =
57 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
59 // Platform-specific filename relative to the chrome executable.
61 const wchar_t library_name
[] = L
"ppapi_tests.dll";
62 #elif defined(OS_MACOSX)
63 const char library_name
[] = "ppapi_tests.plugin";
64 #elif defined(OS_POSIX)
65 const char library_name
[] = "libppapi_tests.so";
68 class EmptyHttpResponse
: public net::test_server::HttpResponse
{
70 virtual std::string
ToResponseString() const OVERRIDE
{
75 class TestInterstitialPageDelegate
: public content::InterstitialPageDelegate
{
77 TestInterstitialPageDelegate() {
79 virtual ~TestInterstitialPageDelegate() {}
80 virtual std::string
GetHTMLContents() OVERRIDE
{ return std::string(); }
83 // Used to get notified when a guest is created.
84 class GuestContentBrowserClient
: public chrome::ChromeContentBrowserClient
{
86 GuestContentBrowserClient() : web_contents_(NULL
) {}
88 content::WebContents
* WaitForGuestCreated() {
92 message_loop_runner_
= new content::MessageLoopRunner
;
93 message_loop_runner_
->Run();
98 // ChromeContentBrowserClient implementation:
99 virtual void GuestWebContentsAttached(
100 content::WebContents
* guest_web_contents
,
101 content::WebContents
* embedder_web_contents
,
102 const base::DictionaryValue
& extra_params
) OVERRIDE
{
103 ChromeContentBrowserClient::GuestWebContentsAttached(
104 guest_web_contents
, embedder_web_contents
, extra_params
);
105 web_contents_
= guest_web_contents
;
107 if (message_loop_runner_
)
108 message_loop_runner_
->Quit();
111 content::WebContents
* web_contents_
;
112 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
115 class InterstitialObserver
: public content::WebContentsObserver
{
117 InterstitialObserver(content::WebContents
* web_contents
,
118 const base::Closure
& attach_callback
,
119 const base::Closure
& detach_callback
)
120 : WebContentsObserver(web_contents
),
121 attach_callback_(attach_callback
),
122 detach_callback_(detach_callback
) {
125 virtual void DidAttachInterstitialPage() OVERRIDE
{
126 attach_callback_
.Run();
129 virtual void DidDetachInterstitialPage() OVERRIDE
{
130 detach_callback_
.Run();
134 base::Closure attach_callback_
;
135 base::Closure detach_callback_
;
137 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver
);
142 // This class intercepts media access request from the embedder. The request
143 // should be triggered only if the embedder API (from tests) allows the request
145 // We do not issue the actual media request; the fact that the request reached
146 // embedder's WebContents is good enough for our tests. This is also to make
147 // the test run successfully on trybots.
148 class MockWebContentsDelegate
: public content::WebContentsDelegate
{
150 MockWebContentsDelegate() : requested_(false) {}
151 virtual ~MockWebContentsDelegate() {}
153 virtual void RequestMediaAccessPermission(
154 content::WebContents
* web_contents
,
155 const content::MediaStreamRequest
& request
,
156 const content::MediaResponseCallback
& callback
) OVERRIDE
{
158 if (message_loop_runner_
.get())
159 message_loop_runner_
->Quit();
162 void WaitForSetMediaPermission() {
165 message_loop_runner_
= new content::MessageLoopRunner
;
166 message_loop_runner_
->Run();
171 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
173 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate
);
176 // This class intercepts download request from the guest.
177 class MockDownloadWebContentsDelegate
: public content::WebContentsDelegate
{
179 explicit MockDownloadWebContentsDelegate(
180 content::WebContentsDelegate
* orig_delegate
)
181 : orig_delegate_(orig_delegate
),
182 waiting_for_decision_(false),
183 expect_allow_(false),
184 decision_made_(false),
185 last_download_allowed_(false) {}
186 virtual ~MockDownloadWebContentsDelegate() {}
188 virtual void CanDownload(
189 content::RenderViewHost
* render_view_host
,
191 const std::string
& request_method
,
192 const base::Callback
<void(bool)>& callback
) OVERRIDE
{
193 orig_delegate_
->CanDownload(
194 render_view_host
, request_id
, request_method
,
195 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided
,
196 base::Unretained(this)));
199 void WaitForCanDownload(bool expect_allow
) {
200 EXPECT_FALSE(waiting_for_decision_
);
201 waiting_for_decision_
= true;
203 if (decision_made_
) {
204 EXPECT_EQ(expect_allow
, last_download_allowed_
);
208 expect_allow_
= expect_allow
;
209 message_loop_runner_
= new content::MessageLoopRunner
;
210 message_loop_runner_
->Run();
213 void DownloadDecided(bool allow
) {
214 EXPECT_FALSE(decision_made_
);
215 decision_made_
= true;
217 if (waiting_for_decision_
) {
218 EXPECT_EQ(expect_allow_
, allow
);
219 if (message_loop_runner_
.get())
220 message_loop_runner_
->Quit();
223 last_download_allowed_
= allow
;
227 waiting_for_decision_
= false;
228 decision_made_
= false;
232 content::WebContentsDelegate
* orig_delegate_
;
233 bool waiting_for_decision_
;
236 bool last_download_allowed_
;
237 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
239 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate
);
242 class WebViewTest
: public extensions::PlatformAppBrowserTest
{
244 virtual void SetUp() OVERRIDE
{
245 if (UsesFakeSpeech()) {
246 // SpeechRecognition test specific SetUp.
247 fake_speech_recognition_manager_
.reset(
248 new content::FakeSpeechRecognitionManager());
249 fake_speech_recognition_manager_
->set_should_send_fake_response(true);
250 // Inject the fake manager factory so that the test result is returned to
252 content::SpeechRecognitionManager::SetManagerForTesting(
253 fake_speech_recognition_manager_
.get());
255 extensions::PlatformAppBrowserTest::SetUp();
258 virtual void TearDown() OVERRIDE
{
259 if (UsesFakeSpeech()) {
260 // SpeechRecognition test specific TearDown.
261 content::SpeechRecognitionManager::SetManagerForTesting(NULL
);
264 extensions::PlatformAppBrowserTest::TearDown();
267 virtual void SetUpOnMainThread() OVERRIDE
{
268 const testing::TestInfo
* const test_info
=
269 testing::UnitTest::GetInstance()->current_test_info();
270 // Mock out geolocation for geolocation specific tests.
271 if (!strncmp(test_info
->name(), "GeolocationAPI",
272 strlen("GeolocationAPI"))) {
273 ui_test_utils::OverrideGeolocation(10, 20);
277 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
278 const testing::TestInfo
* const test_info
=
279 testing::UnitTest::GetInstance()->current_test_info();
281 command_line
->AppendSwitchASCII(switches::kJavaScriptFlags
, "--expose-gc");
283 // Force SW rendering to check autosize bug.
284 if (!strncmp(test_info
->name(), "AutoSizeSW", strlen("AutosizeSW")))
285 command_line
->AppendSwitch(switches::kDisableForceCompositingMode
);
287 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
290 // This method is responsible for initializing a packaged app, which contains
291 // multiple webview tags. The tags have different partition identifiers and
292 // their WebContent objects are returned as output. The method also verifies
293 // the expected process allocation and storage partition assignment.
294 // The |navigate_to_url| parameter is used to navigate the main browser
297 // TODO(ajwong): This function is getting to be too large. Either refactor it
298 // so the test can specify a configuration of WebView tags that we will
299 // dynamically inject JS to generate, or move this test wholesale into
300 // something that RunPlatformAppTest() can execute purely in Javascript. This
301 // won't let us do a white-box examination of the StoragePartition equivalence
302 // directly, but we will be able to view the black box effects which is good
303 // enough. http://crbug.com/160361
304 void NavigateAndOpenAppForIsolation(
305 GURL navigate_to_url
,
306 content::WebContents
** default_tag_contents1
,
307 content::WebContents
** default_tag_contents2
,
308 content::WebContents
** named_partition_contents1
,
309 content::WebContents
** named_partition_contents2
,
310 content::WebContents
** persistent_partition_contents1
,
311 content::WebContents
** persistent_partition_contents2
,
312 content::WebContents
** persistent_partition_contents3
) {
313 GURL::Replacements replace_host
;
314 std::string
host_str("localhost"); // Must stay in scope with replace_host.
315 replace_host
.SetHostStr(host_str
);
317 navigate_to_url
= navigate_to_url
.ReplaceComponents(replace_host
);
319 GURL tag_url1
= embedded_test_server()->GetURL(
320 "/extensions/platform_apps/web_view/isolation/cookie.html");
321 tag_url1
= tag_url1
.ReplaceComponents(replace_host
);
322 GURL tag_url2
= embedded_test_server()->GetURL(
323 "/extensions/platform_apps/web_view/isolation/cookie2.html");
324 tag_url2
= tag_url2
.ReplaceComponents(replace_host
);
325 GURL tag_url3
= embedded_test_server()->GetURL(
326 "/extensions/platform_apps/web_view/isolation/storage1.html");
327 tag_url3
= tag_url3
.ReplaceComponents(replace_host
);
328 GURL tag_url4
= embedded_test_server()->GetURL(
329 "/extensions/platform_apps/web_view/isolation/storage2.html");
330 tag_url4
= tag_url4
.ReplaceComponents(replace_host
);
331 GURL tag_url5
= embedded_test_server()->GetURL(
332 "/extensions/platform_apps/web_view/isolation/storage1.html#p1");
333 tag_url5
= tag_url5
.ReplaceComponents(replace_host
);
334 GURL tag_url6
= embedded_test_server()->GetURL(
335 "/extensions/platform_apps/web_view/isolation/storage1.html#p2");
336 tag_url6
= tag_url6
.ReplaceComponents(replace_host
);
337 GURL tag_url7
= embedded_test_server()->GetURL(
338 "/extensions/platform_apps/web_view/isolation/storage1.html#p3");
339 tag_url7
= tag_url7
.ReplaceComponents(replace_host
);
341 ui_test_utils::NavigateToURLWithDisposition(
342 browser(), navigate_to_url
, CURRENT_TAB
,
343 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
345 ui_test_utils::UrlLoadObserver
observer1(
346 tag_url1
, content::NotificationService::AllSources());
347 ui_test_utils::UrlLoadObserver
observer2(
348 tag_url2
, content::NotificationService::AllSources());
349 ui_test_utils::UrlLoadObserver
observer3(
350 tag_url3
, content::NotificationService::AllSources());
351 ui_test_utils::UrlLoadObserver
observer4(
352 tag_url4
, content::NotificationService::AllSources());
353 ui_test_utils::UrlLoadObserver
observer5(
354 tag_url5
, content::NotificationService::AllSources());
355 ui_test_utils::UrlLoadObserver
observer6(
356 tag_url6
, content::NotificationService::AllSources());
357 ui_test_utils::UrlLoadObserver
observer7(
358 tag_url7
, content::NotificationService::AllSources());
359 LoadAndLaunchPlatformApp("web_view/isolation");
368 content::Source
<content::NavigationController
> source1
= observer1
.source();
369 EXPECT_TRUE(source1
->GetWebContents()->GetRenderProcessHost()->IsGuest());
370 content::Source
<content::NavigationController
> source2
= observer2
.source();
371 EXPECT_TRUE(source2
->GetWebContents()->GetRenderProcessHost()->IsGuest());
372 content::Source
<content::NavigationController
> source3
= observer3
.source();
373 EXPECT_TRUE(source3
->GetWebContents()->GetRenderProcessHost()->IsGuest());
374 content::Source
<content::NavigationController
> source4
= observer4
.source();
375 EXPECT_TRUE(source4
->GetWebContents()->GetRenderProcessHost()->IsGuest());
376 content::Source
<content::NavigationController
> source5
= observer5
.source();
377 EXPECT_TRUE(source5
->GetWebContents()->GetRenderProcessHost()->IsGuest());
378 content::Source
<content::NavigationController
> source6
= observer6
.source();
379 EXPECT_TRUE(source6
->GetWebContents()->GetRenderProcessHost()->IsGuest());
380 content::Source
<content::NavigationController
> source7
= observer7
.source();
381 EXPECT_TRUE(source7
->GetWebContents()->GetRenderProcessHost()->IsGuest());
383 // Check that the first two tags use the same process and it is different
384 // than the process used by the other two.
385 EXPECT_EQ(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
386 source2
->GetWebContents()->GetRenderProcessHost()->GetID());
387 EXPECT_EQ(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
388 source4
->GetWebContents()->GetRenderProcessHost()->GetID());
389 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
390 source3
->GetWebContents()->GetRenderProcessHost()->GetID());
392 // The two sets of tags should also be isolated from the main browser.
393 EXPECT_NE(source1
->GetWebContents()->GetRenderProcessHost()->GetID(),
394 browser()->tab_strip_model()->GetWebContentsAt(0)->
395 GetRenderProcessHost()->GetID());
396 EXPECT_NE(source3
->GetWebContents()->GetRenderProcessHost()->GetID(),
397 browser()->tab_strip_model()->GetWebContentsAt(0)->
398 GetRenderProcessHost()->GetID());
400 // Check that the storage partitions of the first two tags match and are
401 // different than the other two.
403 source1
->GetWebContents()->GetRenderProcessHost()->
404 GetStoragePartition(),
405 source2
->GetWebContents()->GetRenderProcessHost()->
406 GetStoragePartition());
408 source3
->GetWebContents()->GetRenderProcessHost()->
409 GetStoragePartition(),
410 source4
->GetWebContents()->GetRenderProcessHost()->
411 GetStoragePartition());
413 source1
->GetWebContents()->GetRenderProcessHost()->
414 GetStoragePartition(),
415 source3
->GetWebContents()->GetRenderProcessHost()->
416 GetStoragePartition());
418 // Ensure the persistent storage partitions are different.
420 source5
->GetWebContents()->GetRenderProcessHost()->
421 GetStoragePartition(),
422 source6
->GetWebContents()->GetRenderProcessHost()->
423 GetStoragePartition());
425 source5
->GetWebContents()->GetRenderProcessHost()->
426 GetStoragePartition(),
427 source7
->GetWebContents()->GetRenderProcessHost()->
428 GetStoragePartition());
430 source1
->GetWebContents()->GetRenderProcessHost()->
431 GetStoragePartition(),
432 source5
->GetWebContents()->GetRenderProcessHost()->
433 GetStoragePartition());
435 source1
->GetWebContents()->GetRenderProcessHost()->
436 GetStoragePartition(),
437 source7
->GetWebContents()->GetRenderProcessHost()->
438 GetStoragePartition());
440 *default_tag_contents1
= source1
->GetWebContents();
441 *default_tag_contents2
= source2
->GetWebContents();
442 *named_partition_contents1
= source3
->GetWebContents();
443 *named_partition_contents2
= source4
->GetWebContents();
444 if (persistent_partition_contents1
) {
445 *persistent_partition_contents1
= source5
->GetWebContents();
447 if (persistent_partition_contents2
) {
448 *persistent_partition_contents2
= source6
->GetWebContents();
450 if (persistent_partition_contents3
) {
451 *persistent_partition_contents3
= source7
->GetWebContents();
455 void ExecuteScriptWaitForTitle(content::WebContents
* web_contents
,
458 base::string16
expected_title(base::ASCIIToUTF16(title
));
459 base::string16
error_title(base::ASCIIToUTF16("error"));
461 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
462 title_watcher
.AlsoWaitForTitle(error_title
);
463 EXPECT_TRUE(content::ExecuteScript(web_contents
, script
));
464 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
467 // Handles |request| by serving a redirect response.
468 static scoped_ptr
<net::test_server::HttpResponse
> RedirectResponseHandler(
469 const std::string
& path
,
470 const GURL
& redirect_target
,
471 const net::test_server::HttpRequest
& request
) {
472 if (!StartsWithASCII(path
, request
.relative_url
, true))
473 return scoped_ptr
<net::test_server::HttpResponse
>();
475 scoped_ptr
<net::test_server::BasicHttpResponse
> http_response(
476 new net::test_server::BasicHttpResponse
);
477 http_response
->set_code(net::HTTP_MOVED_PERMANENTLY
);
478 http_response
->AddCustomHeader("Location", redirect_target
.spec());
479 return http_response
.PassAs
<net::test_server::HttpResponse
>();
482 // Handles |request| by serving an empty response.
483 static scoped_ptr
<net::test_server::HttpResponse
> EmptyResponseHandler(
484 const std::string
& path
,
485 const net::test_server::HttpRequest
& request
) {
486 if (StartsWithASCII(path
, request
.relative_url
, true)) {
487 return scoped_ptr
<net::test_server::HttpResponse
>(
488 new EmptyHttpResponse
);
491 return scoped_ptr
<net::test_server::HttpResponse
>();
494 // Shortcut to return the current MenuManager.
495 extensions::MenuManager
* menu_manager() {
496 return extensions::MenuManager::Get(browser()->profile());
499 // This gets all the items that any extension has registered for possible
500 // inclusion in context menus.
501 MenuItem::List
GetItems() {
502 MenuItem::List result
;
503 std::set
<MenuItem::ExtensionKey
> extension_ids
=
504 menu_manager()->ExtensionIds();
505 std::set
<MenuItem::ExtensionKey
>::iterator i
;
506 for (i
= extension_ids
.begin(); i
!= extension_ids
.end(); ++i
) {
507 const MenuItem::List
* list
= menu_manager()->MenuItems(*i
);
508 result
.insert(result
.end(), list
->begin(), list
->end());
518 void TestHelper(const std::string
& test_name
,
519 const std::string
& app_location
,
520 TestServer test_server
) {
521 // For serving guest pages.
522 if (test_server
== NEEDS_TEST_SERVER
) {
523 if (!StartEmbeddedTestServer()) {
524 LOG(ERROR
) << "FAILED TO START TEST SERVER.";
527 embedded_test_server()->RegisterRequestHandler(
528 base::Bind(&WebViewTest::RedirectResponseHandler
,
529 kRedirectResponsePath
,
530 embedded_test_server()->GetURL(kRedirectResponseFullPath
)));
532 embedded_test_server()->RegisterRequestHandler(
533 base::Bind(&WebViewTest::EmptyResponseHandler
, kEmptyResponsePath
));
536 ExtensionTestMessageListener
launched_listener("Launched", false);
537 LoadAndLaunchPlatformApp(app_location
.c_str());
538 if (!launched_listener
.WaitUntilSatisfied()) {
539 LOG(ERROR
) << "TEST DID NOT LAUNCH.";
543 // Flush any pending events to make sure we start with a clean slate.
544 content::RunAllPendingInMessageLoop();
546 content::WebContents
* embedder_web_contents
=
547 GetFirstAppWindowWebContents();
548 if (!embedder_web_contents
) {
549 LOG(ERROR
) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
553 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
554 done_listener
.AlsoListenForFailureMessage("TEST_FAILED");
555 if (!content::ExecuteScript(
556 embedder_web_contents
,
557 base::StringPrintf("runTest('%s')", test_name
.c_str()))) {
558 LOG(ERROR
) << "UNABLE TO START TEST.";
561 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
564 content::WebContents
* LoadGuest(const std::string
& guest_path
,
565 const std::string
& app_path
) {
566 GURL::Replacements replace_host
;
567 std::string
host_str("localhost"); // Must stay in scope with replace_host.
568 replace_host
.SetHostStr(host_str
);
570 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
571 guest_url
= guest_url
.ReplaceComponents(replace_host
);
573 ui_test_utils::UrlLoadObserver
guest_observer(
574 guest_url
, content::NotificationService::AllSources());
576 ExtensionTestMessageListener
guest_loaded_listener("guest-loaded", false);
577 LoadAndLaunchPlatformApp(app_path
.c_str());
578 guest_observer
.Wait();
580 content::Source
<content::NavigationController
> source
=
581 guest_observer
.source();
582 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->IsGuest());
584 bool satisfied
= guest_loaded_listener
.WaitUntilSatisfied();
588 content::WebContents
* guest_web_contents
= source
->GetWebContents();
589 return guest_web_contents
;
592 // Runs media_access/allow tests.
593 void MediaAccessAPIAllowTestHelper(const std::string
& test_name
);
595 // Runs media_access/deny tests, each of them are run separately otherwise
596 // they timeout (mostly on Windows).
597 void MediaAccessAPIDenyTestHelper(const std::string
& test_name
) {
598 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
599 ExtensionTestMessageListener
loaded_listener("loaded", false);
600 LoadAndLaunchPlatformApp("web_view/media_access/deny");
601 ASSERT_TRUE(loaded_listener
.WaitUntilSatisfied());
603 content::WebContents
* embedder_web_contents
=
604 GetFirstAppWindowWebContents();
605 ASSERT_TRUE(embedder_web_contents
);
607 ExtensionTestMessageListener
test_run_listener("PASSED", false);
608 test_run_listener
.AlsoListenForFailureMessage("FAILED");
610 content::ExecuteScript(
611 embedder_web_contents
,
612 base::StringPrintf("startDenyTest('%s')", test_name
.c_str())));
613 ASSERT_TRUE(test_run_listener
.WaitUntilSatisfied());
616 void WaitForInterstitial(content::WebContents
* web_contents
) {
617 scoped_refptr
<content::MessageLoopRunner
> loop_runner(
618 new content::MessageLoopRunner
);
619 InterstitialObserver
observer(web_contents
,
620 loop_runner
->QuitClosure(),
622 if (!content::InterstitialPage::GetInterstitialPage(web_contents
))
627 bool UsesFakeSpeech() {
628 const testing::TestInfo
* const test_info
=
629 testing::UnitTest::GetInstance()->current_test_info();
631 // SpeechRecognition test specific SetUp.
632 return !strcmp(test_info
->name(), "SpeechRecognition") ||
633 !strcmp(test_info
->name(),
634 "SpeechRecognitionAPI_HasPermissionAllow");
637 scoped_ptr
<content::FakeSpeechRecognitionManager
>
638 fake_speech_recognition_manager_
;
641 // This test ensures JavaScript errors ("Cannot redefine property") do not
642 // happen when a <webview> is removed from DOM and added back.
643 IN_PROC_BROWSER_TEST_F(WebViewTest
,
644 AddRemoveWebView_AddRemoveWebView
) {
645 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
646 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
650 IN_PROC_BROWSER_TEST_F(WebViewTest
, AutoSize
) {
652 // Flaky on XP bot http://crbug.com/299507
653 if (base::win::GetVersion() <= base::win::VERSION_XP
)
657 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
661 #if !defined(OS_CHROMEOS)
662 // This test ensures <webview> doesn't crash in SW rendering when autosize is
664 #if defined(OS_MACOSX) || defined(USE_AURA)
665 #define MAYBE_AutoSizeSW DISABLED_AutoSizeSW
667 #define MAYBE_AutoSizeSW AutoSizeSW
669 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_AutoSizeSW
) {
670 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
675 // http://crbug.com/326332
676 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_Shim_TestAutosizeAfterNavigation
) {
677 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER
);
680 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeBeforeNavigation
) {
681 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER
);
683 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAutosizeRemoveAttributes
) {
684 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER
);
687 // This test is disabled due to being flaky. http://crbug.com/282116
689 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
690 DISABLED_Shim_TestAutosizeWithPartialAttributes
692 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
693 Shim_TestAutosizeWithPartialAttributes
695 IN_PROC_BROWSER_TEST_F(WebViewTest
,
696 MAYBE_Shim_TestAutosizeWithPartialAttributes
) {
697 TestHelper("testAutosizeWithPartialAttributes",
702 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAPIMethodExistence
) {
703 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER
);
706 // Tests the existence of WebRequest API event objects on the request
707 // object, on the webview element, and hanging directly off webview.
708 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIExistence
) {
709 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER
);
712 // http://crbug.com/315920
713 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
714 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
716 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
718 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_Shim_TestChromeExtensionURL
) {
719 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
722 // http://crbug.com/315920
723 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
724 #define MAYBE_Shim_TestChromeExtensionRelativePath \
725 DISABLED_Shim_TestChromeExtensionRelativePath
727 #define MAYBE_Shim_TestChromeExtensionRelativePath \
728 Shim_TestChromeExtensionRelativePath
730 IN_PROC_BROWSER_TEST_F(WebViewTest
,
731 MAYBE_Shim_TestChromeExtensionRelativePath
) {
732 TestHelper("testChromeExtensionRelativePath",
737 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestInvalidChromeExtensionURL
) {
738 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER
);
741 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestEventName
) {
742 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER
);
745 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestOnEventProperty
) {
746 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER
);
749 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadProgressEvent
) {
750 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER
);
753 // WebViewTest.Shim_TestDestroyOnEventListener is flaky, so disable it.
754 // http://crbug.com/255106
755 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_Shim_TestDestroyOnEventListener
) {
756 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER
);
759 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestCannotMutateEventName
) {
760 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER
);
763 // http://crbug.com/267304
765 #define MAYBE_Shim_TestPartitionRaisesException \
766 DISABLED_Shim_TestPartitionRaisesException
768 #define MAYBE_Shim_TestPartitionRaisesException \
769 Shim_TestPartitionRaisesException
772 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_Shim_TestPartitionRaisesException
) {
773 TestHelper("testPartitionRaisesException",
778 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScriptFail
) {
780 // Flaky on XP bot http://crbug.com/266185
781 if (base::win::GetVersion() <= base::win::VERSION_XP
)
785 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER
);
788 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestExecuteScript
) {
789 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER
);
792 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestTerminateAfterExit
) {
793 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER
);
796 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestAssignSrcAfterCrash
) {
797 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER
);
800 IN_PROC_BROWSER_TEST_F(WebViewTest
,
801 Shim_TestNavOnConsecutiveSrcAttributeChanges
) {
802 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
807 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavOnSrcAttributeChange
) {
808 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER
);
811 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveSrcAttribute
) {
812 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
815 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReassignSrcAttribute
) {
816 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER
);
819 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestBrowserPluginNotAllowed
) {
821 // Flaky on XP bots. http://crbug.com/267300
822 if (base::win::GetVersion() <= base::win::VERSION_XP
)
826 TestHelper("testBrowserPluginNotAllowed", "web_view/shim", NO_TEST_SERVER
);
829 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindow
) {
830 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER
);
833 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowTwoListeners
) {
834 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER
);
837 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoPreventDefault
) {
838 TestHelper("testNewWindowNoPreventDefault",
843 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNewWindowNoReferrerLink
) {
844 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER
);
847 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestContentLoadEvent
) {
848 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER
);
851 // http://crbug.com/326330
852 IN_PROC_BROWSER_TEST_F(WebViewTest
,
853 DISABLED_Shim_TestDeclarativeWebRequestAPI
) {
854 TestHelper("testDeclarativeWebRequestAPI",
859 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPI
) {
860 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER
);
863 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestWebRequestAPIGoogleProperty
) {
864 TestHelper("testWebRequestAPIGoogleProperty",
869 // This test is disabled due to being flaky. http://crbug.com/309451
871 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
872 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
874 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
875 Shim_TestWebRequestListenerSurvivesReparenting
877 IN_PROC_BROWSER_TEST_F(
879 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting
) {
880 TestHelper("testWebRequestListenerSurvivesReparenting",
885 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadStartLoadRedirect
) {
886 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER
);
889 IN_PROC_BROWSER_TEST_F(WebViewTest
,
890 Shim_TestLoadAbortChromeExtensionURLWrongPartition
) {
891 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
896 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortEmptyResponse
) {
897 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER
);
900 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalChromeURL
) {
901 TestHelper("testLoadAbortIllegalChromeURL",
906 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalFileURL
) {
907 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER
);
910 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestLoadAbortIllegalJavaScriptURL
) {
911 TestHelper("testLoadAbortIllegalJavaScriptURL",
916 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestReload
) {
917 TestHelper("testReload", "web_view/shim", NEEDS_TEST_SERVER
);
920 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestGetProcessId
) {
921 TestHelper("testGetProcessId", "web_view/shim", NEEDS_TEST_SERVER
);
924 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewOnExit
) {
925 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
927 // Launch the app and wait until it's ready to load a test.
928 ExtensionTestMessageListener
launched_listener("Launched", false);
929 LoadAndLaunchPlatformApp("web_view/shim");
930 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
932 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
933 ASSERT_TRUE(embedder_web_contents
);
935 GURL::Replacements replace_host
;
936 std::string
host_str("localhost"); // Must stay in scope with replace_host.
937 replace_host
.SetHostStr(host_str
);
939 std::string
guest_path(
940 "/extensions/platform_apps/web_view/shim/empty_guest.html");
941 GURL guest_url
= embedded_test_server()->GetURL(guest_path
);
942 guest_url
= guest_url
.ReplaceComponents(replace_host
);
944 ui_test_utils::UrlLoadObserver
guest_observer(
945 guest_url
, content::NotificationService::AllSources());
947 // Run the test and wait until the guest WebContents is available and has
949 ExtensionTestMessageListener
guest_loaded_listener("guest-loaded", false);
950 EXPECT_TRUE(content::ExecuteScript(
951 embedder_web_contents
,
952 "runTest('testRemoveWebviewOnExit')"));
953 guest_observer
.Wait();
955 content::Source
<content::NavigationController
> source
=
956 guest_observer
.source();
957 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->IsGuest());
959 ASSERT_TRUE(guest_loaded_listener
.WaitUntilSatisfied());
961 content::WebContentsDestroyedWatcher
destroyed_watcher(
962 source
->GetWebContents());
964 // Tell the embedder to kill the guest.
965 EXPECT_TRUE(content::ExecuteScript(
966 embedder_web_contents
,
967 "removeWebviewOnExitDoCrash();"));
969 // Wait until the guest WebContents is destroyed.
970 destroyed_watcher
.Wait();
973 // Remove <webview> immediately after navigating it.
974 // This is a regression test for http://crbug.com/276023.
975 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestRemoveWebviewAfterNavigation
) {
976 TestHelper("testRemoveWebviewAfterNavigation",
981 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestNavigationToExternalProtocol
) {
982 TestHelper("testNavigationToExternalProtocol",
987 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestResizeWebviewResizesContent
) {
988 TestHelper("testResizeWebviewResizesContent",
993 // This test makes sure we do not crash if app is closed while interstitial
994 // page is being shown in guest.
995 // Disabled under LeakSanitizer due to memory leaks. http://crbug.com/321662
996 #if defined(LEAK_SANITIZER)
997 #define MAYBE_InterstitialTeardown DISABLED_InterstitialTeardown
999 #define MAYBE_InterstitialTeardown InterstitialTeardown
1001 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_InterstitialTeardown
) {
1003 // Flaky on XP bot http://crbug.com/297014
1004 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1008 // Start a HTTPS server so we can load an interstitial page inside guest.
1009 net::SpawnedTestServer::SSLOptions ssl_options
;
1010 ssl_options
.server_certificate
=
1011 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME
;
1012 net::SpawnedTestServer
https_server(
1013 net::SpawnedTestServer::TYPE_HTTPS
, ssl_options
,
1014 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1015 ASSERT_TRUE(https_server
.Start());
1017 net::HostPortPair host_and_port
= https_server
.host_port_pair();
1019 ExtensionTestMessageListener
embedder_loaded_listener("EmbedderLoaded",
1021 LoadAndLaunchPlatformApp("web_view/interstitial_teardown");
1022 ASSERT_TRUE(embedder_loaded_listener
.WaitUntilSatisfied());
1024 GuestContentBrowserClient new_client
;
1025 content::ContentBrowserClient
* old_client
=
1026 SetBrowserClientForTesting(&new_client
);
1028 // Now load the guest.
1029 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1030 ExtensionTestMessageListener
second("GuestAddedToDom", false);
1031 EXPECT_TRUE(content::ExecuteScript(
1032 embedder_web_contents
,
1033 base::StringPrintf("loadGuest(%d);\n", host_and_port
.port())));
1034 ASSERT_TRUE(second
.WaitUntilSatisfied());
1036 // Wait for interstitial page to be shown in guest.
1037 content::WebContents
* guest_web_contents
= new_client
.WaitForGuestCreated();
1038 SetBrowserClientForTesting(old_client
);
1039 ASSERT_TRUE(guest_web_contents
->GetRenderProcessHost()->IsGuest());
1040 WaitForInterstitial(guest_web_contents
);
1042 // Now close the app while interstitial page being shown in guest.
1043 apps::AppWindow
* window
= GetFirstAppWindow();
1044 window
->GetBaseWindow()->Close();
1047 IN_PROC_BROWSER_TEST_F(WebViewTest
, ShimSrcAttribute
) {
1048 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1052 // This test verifies that prerendering has been disabled inside <webview>.
1053 // This test is here rather than in PrerenderBrowserTest for testing convenience
1054 // only. If it breaks then this is a bug in the prerenderer.
1055 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPrerenderer
) {
1056 ASSERT_TRUE(StartEmbeddedTestServer());
1057 content::WebContents
* guest_web_contents
=
1059 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1060 "web_view/noprerenderer");
1061 ASSERT_TRUE(guest_web_contents
!= NULL
);
1063 PrerenderLinkManager
* prerender_link_manager
=
1064 PrerenderLinkManagerFactory::GetForProfile(
1065 Profile::FromBrowserContext(guest_web_contents
->GetBrowserContext()));
1066 ASSERT_TRUE(prerender_link_manager
!= NULL
);
1067 EXPECT_TRUE(prerender_link_manager
->IsEmpty());
1070 // This tests cookie isolation for packaged apps with webview tags. It navigates
1071 // the main browser window to a page that sets a cookie and loads an app with
1072 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1073 // storage isolation is enforced.
1074 // This test is disabled due to being flaky. http://crbug.com/294196
1076 #define MAYBE_CookieIsolation DISABLED_CookieIsolation
1078 #define MAYBE_CookieIsolation CookieIsolation
1080 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_CookieIsolation
) {
1081 ASSERT_TRUE(StartEmbeddedTestServer());
1082 const std::string kExpire
=
1083 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1084 std::string
cookie_script1(kExpire
);
1085 cookie_script1
.append(
1086 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1087 std::string
cookie_script2(kExpire
);
1088 cookie_script2
.append(
1089 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1091 GURL::Replacements replace_host
;
1092 std::string
host_str("localhost"); // Must stay in scope with replace_host.
1093 replace_host
.SetHostStr(host_str
);
1095 GURL set_cookie_url
= embedded_test_server()->GetURL(
1096 "/extensions/platform_apps/isolation/set_cookie.html");
1097 set_cookie_url
= set_cookie_url
.ReplaceComponents(replace_host
);
1099 // The first two partitions will be used to set cookies and ensure they are
1100 // shared. The named partition is used to ensure that cookies are isolated
1101 // between partitions within the same app.
1102 content::WebContents
* cookie_contents1
;
1103 content::WebContents
* cookie_contents2
;
1104 content::WebContents
* named_partition_contents1
;
1105 content::WebContents
* named_partition_contents2
;
1107 NavigateAndOpenAppForIsolation(set_cookie_url
, &cookie_contents1
,
1108 &cookie_contents2
, &named_partition_contents1
,
1109 &named_partition_contents2
, NULL
, NULL
, NULL
);
1111 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1112 EXPECT_TRUE(content::ExecuteScript(cookie_contents2
, cookie_script2
));
1115 std::string cookie_value
;
1117 // Test the regular browser context to ensure we have only one cookie.
1118 automation_util::GetCookies(GURL("http://localhost"),
1119 browser()->tab_strip_model()->GetWebContentsAt(0),
1120 &cookie_size
, &cookie_value
);
1121 EXPECT_EQ("testCookie=1", cookie_value
);
1123 // The default behavior is to combine webview tags with no explicit partition
1124 // declaration into the same in-memory partition. Test the webview tags to
1125 // ensure we have properly set the cookies and we have both cookies in both
1127 automation_util::GetCookies(GURL("http://localhost"),
1129 &cookie_size
, &cookie_value
);
1130 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1132 automation_util::GetCookies(GURL("http://localhost"),
1134 &cookie_size
, &cookie_value
);
1135 EXPECT_EQ("guest1=true; guest2=true", cookie_value
);
1137 // The third tag should not have any cookies as it is in a separate partition.
1138 automation_util::GetCookies(GURL("http://localhost"),
1139 named_partition_contents1
,
1140 &cookie_size
, &cookie_value
);
1141 EXPECT_EQ("", cookie_value
);
1144 // This tests that in-memory storage partitions are reset on browser restart,
1145 // but persistent ones maintain state for cookies and HTML5 storage.
1146 IN_PROC_BROWSER_TEST_F(WebViewTest
, PRE_StoragePersistence
) {
1147 ASSERT_TRUE(StartEmbeddedTestServer());
1148 const std::string kExpire
=
1149 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1150 std::string
cookie_script1(kExpire
);
1151 cookie_script1
.append(
1152 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1153 std::string
cookie_script2(kExpire
);
1154 cookie_script2
.append(
1155 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1156 std::string
cookie_script3(kExpire
);
1157 cookie_script3
.append(
1158 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1160 // We don't care where the main browser is on this test.
1161 GURL
blank_url("about:blank");
1163 // The first two partitions will be used to set cookies and ensure they are
1164 // shared. The named partition is used to ensure that cookies are isolated
1165 // between partitions within the same app.
1166 content::WebContents
* cookie_contents1
;
1167 content::WebContents
* cookie_contents2
;
1168 content::WebContents
* named_partition_contents1
;
1169 content::WebContents
* named_partition_contents2
;
1170 content::WebContents
* persistent_partition_contents1
;
1171 content::WebContents
* persistent_partition_contents2
;
1172 content::WebContents
* persistent_partition_contents3
;
1173 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1174 &cookie_contents2
, &named_partition_contents1
,
1175 &named_partition_contents2
,
1176 &persistent_partition_contents1
,
1177 &persistent_partition_contents2
,
1178 &persistent_partition_contents3
);
1180 // Set the inmemory=true cookie for tags with inmemory partitions.
1181 EXPECT_TRUE(content::ExecuteScript(cookie_contents1
, cookie_script1
));
1182 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1
,
1185 // For the two different persistent storage partitions, set the
1186 // two different cookies so we can check that they aren't comingled below.
1187 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1
,
1190 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3
,
1194 std::string cookie_value
;
1196 // Check that all in-memory partitions have a cookie set.
1197 automation_util::GetCookies(GURL("http://localhost"),
1199 &cookie_size
, &cookie_value
);
1200 EXPECT_EQ("inmemory=true", cookie_value
);
1201 automation_util::GetCookies(GURL("http://localhost"),
1203 &cookie_size
, &cookie_value
);
1204 EXPECT_EQ("inmemory=true", cookie_value
);
1205 automation_util::GetCookies(GURL("http://localhost"),
1206 named_partition_contents1
,
1207 &cookie_size
, &cookie_value
);
1208 EXPECT_EQ("inmemory=true", cookie_value
);
1209 automation_util::GetCookies(GURL("http://localhost"),
1210 named_partition_contents2
,
1211 &cookie_size
, &cookie_value
);
1212 EXPECT_EQ("inmemory=true", cookie_value
);
1214 // Check that all persistent partitions kept their state.
1215 automation_util::GetCookies(GURL("http://localhost"),
1216 persistent_partition_contents1
,
1217 &cookie_size
, &cookie_value
);
1218 EXPECT_EQ("persist1=true", cookie_value
);
1219 automation_util::GetCookies(GURL("http://localhost"),
1220 persistent_partition_contents2
,
1221 &cookie_size
, &cookie_value
);
1222 EXPECT_EQ("persist1=true", cookie_value
);
1223 automation_util::GetCookies(GURL("http://localhost"),
1224 persistent_partition_contents3
,
1225 &cookie_size
, &cookie_value
);
1226 EXPECT_EQ("persist2=true", cookie_value
);
1229 // This is the post-reset portion of the StoragePersistence test. See
1230 // PRE_StoragePersistence for main comment.
1231 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_StoragePersistence
) {
1232 ASSERT_TRUE(StartEmbeddedTestServer());
1234 // We don't care where the main browser is on this test.
1235 GURL
blank_url("about:blank");
1237 // The first two partitions will be used to set cookies and ensure they are
1238 // shared. The named partition is used to ensure that cookies are isolated
1239 // between partitions within the same app.
1240 content::WebContents
* cookie_contents1
;
1241 content::WebContents
* cookie_contents2
;
1242 content::WebContents
* named_partition_contents1
;
1243 content::WebContents
* named_partition_contents2
;
1244 content::WebContents
* persistent_partition_contents1
;
1245 content::WebContents
* persistent_partition_contents2
;
1246 content::WebContents
* persistent_partition_contents3
;
1247 NavigateAndOpenAppForIsolation(blank_url
, &cookie_contents1
,
1248 &cookie_contents2
, &named_partition_contents1
,
1249 &named_partition_contents2
,
1250 &persistent_partition_contents1
,
1251 &persistent_partition_contents2
,
1252 &persistent_partition_contents3
);
1255 std::string cookie_value
;
1257 // Check that all in-memory partitions lost their state.
1258 automation_util::GetCookies(GURL("http://localhost"),
1260 &cookie_size
, &cookie_value
);
1261 EXPECT_EQ("", cookie_value
);
1262 automation_util::GetCookies(GURL("http://localhost"),
1264 &cookie_size
, &cookie_value
);
1265 EXPECT_EQ("", cookie_value
);
1266 automation_util::GetCookies(GURL("http://localhost"),
1267 named_partition_contents1
,
1268 &cookie_size
, &cookie_value
);
1269 EXPECT_EQ("", cookie_value
);
1270 automation_util::GetCookies(GURL("http://localhost"),
1271 named_partition_contents2
,
1272 &cookie_size
, &cookie_value
);
1273 EXPECT_EQ("", cookie_value
);
1275 // Check that all persistent partitions kept their state.
1276 automation_util::GetCookies(GURL("http://localhost"),
1277 persistent_partition_contents1
,
1278 &cookie_size
, &cookie_value
);
1279 EXPECT_EQ("persist1=true", cookie_value
);
1280 automation_util::GetCookies(GURL("http://localhost"),
1281 persistent_partition_contents2
,
1282 &cookie_size
, &cookie_value
);
1283 EXPECT_EQ("persist1=true", cookie_value
);
1284 automation_util::GetCookies(GURL("http://localhost"),
1285 persistent_partition_contents3
,
1286 &cookie_size
, &cookie_value
);
1287 EXPECT_EQ("persist2=true", cookie_value
);
1291 // This test is very flaky on Win Aura, Win XP, Win 7. http://crbug.com/248873
1292 #define MAYBE_DOMStorageIsolation DISABLED_DOMStorageIsolation
1294 #define MAYBE_DOMStorageIsolation DOMStorageIsolation
1297 // This tests DOM storage isolation for packaged apps with webview tags. It
1298 // loads an app with multiple webview tags and each tag sets DOM storage
1299 // entries, which the test checks to ensure proper storage isolation is
1301 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_DOMStorageIsolation
) {
1302 ASSERT_TRUE(StartEmbeddedTestServer());
1303 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1306 std::string
get_local_storage("window.domAutomationController.send("
1307 "window.localStorage.getItem('foo') || 'badval')");
1308 std::string
get_session_storage("window.domAutomationController.send("
1309 "window.sessionStorage.getItem('bar') || 'badval')");
1311 content::WebContents
* default_tag_contents1
;
1312 content::WebContents
* default_tag_contents2
;
1313 content::WebContents
* storage_contents1
;
1314 content::WebContents
* storage_contents2
;
1316 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1317 &default_tag_contents2
, &storage_contents1
,
1318 &storage_contents2
, NULL
, NULL
, NULL
);
1320 // Initialize the storage for the first of the two tags that share a storage
1322 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1323 "initDomStorage('page1')"));
1325 // Let's test that the expected values are present in the first tag, as they
1326 // will be overwritten once we call the initDomStorage on the second tag.
1327 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1328 get_local_storage
.c_str(),
1330 EXPECT_STREQ("local-page1", output
.c_str());
1331 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1332 get_session_storage
.c_str(),
1334 EXPECT_STREQ("session-page1", output
.c_str());
1336 // Now, init the storage in the second tag in the same storage partition,
1337 // which will overwrite the shared localStorage.
1338 EXPECT_TRUE(content::ExecuteScript(storage_contents2
,
1339 "initDomStorage('page2')"));
1341 // The localStorage value now should reflect the one written through the
1343 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1344 get_local_storage
.c_str(),
1346 EXPECT_STREQ("local-page2", output
.c_str());
1347 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1348 get_local_storage
.c_str(),
1350 EXPECT_STREQ("local-page2", output
.c_str());
1352 // Session storage is not shared though, as each webview tag has separate
1353 // instance, even if they are in the same storage partition.
1354 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1355 get_session_storage
.c_str(),
1357 EXPECT_STREQ("session-page1", output
.c_str());
1358 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1359 get_session_storage
.c_str(),
1361 EXPECT_STREQ("session-page2", output
.c_str());
1363 // Also, let's check that the main browser and another tag that doesn't share
1364 // the same partition don't have those values stored.
1365 EXPECT_TRUE(ExecuteScriptAndExtractString(
1366 browser()->tab_strip_model()->GetWebContentsAt(0),
1367 get_local_storage
.c_str(),
1369 EXPECT_STREQ("badval", output
.c_str());
1370 EXPECT_TRUE(ExecuteScriptAndExtractString(
1371 browser()->tab_strip_model()->GetWebContentsAt(0),
1372 get_session_storage
.c_str(),
1374 EXPECT_STREQ("badval", output
.c_str());
1375 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1376 get_local_storage
.c_str(),
1378 EXPECT_STREQ("badval", output
.c_str());
1379 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1
,
1380 get_session_storage
.c_str(),
1382 EXPECT_STREQ("badval", output
.c_str());
1385 // See crbug.com/248500
1387 #define MAYBE_IndexedDBIsolation DISABLED_IndexedDBIsolation
1389 #define MAYBE_IndexedDBIsolation IndexedDBIsolation
1392 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1393 // an app with multiple webview tags and each tag creates an IndexedDB record,
1394 // which the test checks to ensure proper storage isolation is enforced.
1395 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_IndexedDBIsolation
) {
1396 ASSERT_TRUE(StartEmbeddedTestServer());
1397 GURL regular_url
= embedded_test_server()->GetURL("/title1.html");
1399 content::WebContents
* default_tag_contents1
;
1400 content::WebContents
* default_tag_contents2
;
1401 content::WebContents
* storage_contents1
;
1402 content::WebContents
* storage_contents2
;
1404 NavigateAndOpenAppForIsolation(regular_url
, &default_tag_contents1
,
1405 &default_tag_contents2
, &storage_contents1
,
1406 &storage_contents2
, NULL
, NULL
, NULL
);
1408 // Initialize the storage for the first of the two tags that share a storage
1410 ExecuteScriptWaitForTitle(storage_contents1
, "initIDB()", "idb created");
1411 ExecuteScriptWaitForTitle(storage_contents1
, "addItemIDB(7, 'page1')",
1412 "addItemIDB complete");
1413 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1414 "readItemIDB complete");
1417 std::string
get_value(
1418 "window.domAutomationController.send(getValueIDB() || 'badval')");
1420 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1421 get_value
.c_str(), &output
));
1422 EXPECT_STREQ("page1", output
.c_str());
1424 // Initialize the db in the second tag.
1425 ExecuteScriptWaitForTitle(storage_contents2
, "initIDB()", "idb open");
1427 // Since we share a partition, reading the value should return the existing
1429 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1430 "readItemIDB complete");
1431 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1432 get_value
.c_str(), &output
));
1433 EXPECT_STREQ("page1", output
.c_str());
1435 // Now write through the second tag and read it back.
1436 ExecuteScriptWaitForTitle(storage_contents2
, "addItemIDB(7, 'page2')",
1437 "addItemIDB complete");
1438 ExecuteScriptWaitForTitle(storage_contents2
, "readItemIDB(7)",
1439 "readItemIDB complete");
1440 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2
,
1441 get_value
.c_str(), &output
));
1442 EXPECT_STREQ("page2", output
.c_str());
1444 // Reset the document title, otherwise the next call will not see a change and
1445 // will hang waiting for it.
1446 EXPECT_TRUE(content::ExecuteScript(storage_contents1
,
1447 "document.title = 'foo'"));
1449 // Read through the first tag to ensure we have the second value.
1450 ExecuteScriptWaitForTitle(storage_contents1
, "readItemIDB(7)",
1451 "readItemIDB complete");
1452 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1
,
1453 get_value
.c_str(), &output
));
1454 EXPECT_STREQ("page2", output
.c_str());
1456 // Now, let's confirm there is no database in the main browser and another
1457 // tag that doesn't share the same partition. Due to the IndexedDB API design,
1458 // open will succeed, but the version will be 1, since it creates the database
1459 // if it is not found. The two tags use database version 3, so we avoid
1461 const char* script
=
1462 "indexedDB.open('isolation').onsuccess = function(e) {"
1463 " if (e.target.result.version == 1)"
1464 " document.title = 'db not found';"
1466 " document.title = 'error';"
1468 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1469 script
, "db not found");
1470 ExecuteScriptWaitForTitle(default_tag_contents1
, script
, "db not found");
1473 // This test ensures that closing app window on 'loadcommit' does not crash.
1474 // The test launches an app with guest and closes the window on loadcommit. It
1475 // then launches the app window again. The process is repeated 3 times.
1476 // http://crbug.com/291278
1478 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1480 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1482 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_CloseOnLoadcommit
) {
1483 ExtensionTestMessageListener
done_test_listener(
1484 "done-close-on-loadcommit", false);
1485 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit");
1486 ASSERT_TRUE(done_test_listener
.WaitUntilSatisfied());
1489 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIDeny_TestDeny
) {
1490 MediaAccessAPIDenyTestHelper("testDeny");
1493 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1494 MediaAccessAPIDeny_TestDenyThenAllowThrows
) {
1495 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1499 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1500 MediaAccessAPIDeny_TestDenyWithPreventDefault
) {
1501 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1504 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1505 MediaAccessAPIDeny_TestNoListenersImplyDeny
) {
1506 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1509 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1510 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny
) {
1511 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1514 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string
& test_name
) {
1515 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1516 ExtensionTestMessageListener
launched_listener("Launched", false);
1517 LoadAndLaunchPlatformApp("web_view/media_access/allow");
1518 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1520 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
1521 ASSERT_TRUE(embedder_web_contents
);
1522 MockWebContentsDelegate
* mock
= new MockWebContentsDelegate
;
1523 embedder_web_contents
->SetDelegate(mock
);
1525 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1526 done_listener
.AlsoListenForFailureMessage("TEST_FAILED");
1528 content::ExecuteScript(
1529 embedder_web_contents
,
1530 base::StringPrintf("startAllowTest('%s')",
1531 test_name
.c_str())));
1532 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1534 mock
->WaitForSetMediaPermission();
1537 IN_PROC_BROWSER_TEST_F(WebViewTest
, ContextMenusAPI_Basic
) {
1538 GuestContentBrowserClient new_client
;
1539 content::ContentBrowserClient
* old_client
=
1540 SetBrowserClientForTesting(&new_client
);
1542 ExtensionTestMessageListener
launched_listener("Launched", false);
1543 launched_listener
.AlsoListenForFailureMessage("TEST_FAILED");
1544 LoadAndLaunchPlatformApp("web_view/context_menus/basic");
1545 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1547 content::WebContents
* guest_web_contents
= new_client
.WaitForGuestCreated();
1548 ASSERT_TRUE(guest_web_contents
);
1549 SetBrowserClientForTesting(old_client
);
1551 content::WebContents
* embedder
= GetFirstAppWindowWebContents();
1552 ASSERT_TRUE(embedder
);
1554 // 1. Basic property test.
1555 ExecuteScriptWaitForTitle(embedder
, "checkProperties()", "ITEM_CHECKED");
1557 // 2. Create a menu item and wait for created callback to be called.
1558 ExecuteScriptWaitForTitle(embedder
, "createMenuItem()", "ITEM_CREATED");
1560 // 3. Click the created item, wait for the click handlers to fire from JS.
1561 ExtensionTestMessageListener
click_listener("ITEM_CLICKED", false);
1562 GURL
page_url("http://www.google.com");
1563 // Create and build our test context menu.
1564 scoped_ptr
<TestRenderViewContextMenu
> menu(TestRenderViewContextMenu::Create(
1565 guest_web_contents
, page_url
, GURL(), GURL()));
1567 // Look for the extension item in the menu, and execute it.
1568 int command_id
= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
;
1569 ASSERT_TRUE(menu
->IsCommandIdEnabled(command_id
));
1570 menu
->ExecuteCommand(command_id
, 0);
1572 // Wait for embedder's script to tell us its onclick fired, it does
1573 // chrome.test.sendMessage('ITEM_CLICKED')
1574 ASSERT_TRUE(click_listener
.WaitUntilSatisfied());
1576 // 4. Update the item's title and verify.
1577 ExecuteScriptWaitForTitle(embedder
, "updateMenuItem()", "ITEM_UPDATED");
1578 MenuItem::List items
= GetItems();
1579 ASSERT_EQ(1u, items
.size());
1580 MenuItem
* item
= items
.at(0);
1581 EXPECT_EQ("new_title", item
->title());
1583 // 5. Remove the item.
1584 ExecuteScriptWaitForTitle(embedder
, "removeItem()", "ITEM_REMOVED");
1585 MenuItem::List items_after_removal
= GetItems();
1586 ASSERT_EQ(0u, items_after_removal
.size());
1588 // 6. Add some more items.
1589 ExecuteScriptWaitForTitle(
1590 embedder
, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1591 MenuItem::List items_after_insertion
= GetItems();
1592 ASSERT_EQ(3u, items_after_insertion
.size());
1594 // 7. Test removeAll().
1595 ExecuteScriptWaitForTitle(embedder
, "removeAllItems()", "ITEM_ALL_REMOVED");
1596 MenuItem::List items_after_all_removal
= GetItems();
1597 ASSERT_EQ(0u, items_after_all_removal
.size());
1600 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllow
) {
1601 MediaAccessAPIAllowTestHelper("testAllow");
1604 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAndThenDeny
) {
1605 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1608 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowTwice
) {
1609 MediaAccessAPIAllowTestHelper("testAllowTwice");
1612 IN_PROC_BROWSER_TEST_F(WebViewTest
, MediaAccessAPIAllow_TestAllowAsync
) {
1613 MediaAccessAPIAllowTestHelper("testAllowAsync");
1616 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1618 IN_PROC_BROWSER_TEST_F(WebViewTest
, ScreenCoordinates
) {
1619 ASSERT_TRUE(RunPlatformAppTestWithArg(
1620 "platform_apps/web_view/common", "screen_coordinates"))
1624 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognition
) {
1625 ASSERT_TRUE(StartEmbeddedTestServer());
1626 content::WebContents
* guest_web_contents
= LoadGuest(
1627 "/extensions/platform_apps/web_view/speech/guest.html",
1629 ASSERT_TRUE(guest_web_contents
);
1631 // Click on the guest (center of the WebContents), the guest is rendered in a
1632 // way that this will trigger clicking on speech recognition input mic.
1633 SimulateMouseClick(guest_web_contents
, 0, blink::WebMouseEvent::ButtonLeft
);
1635 base::string16
expected_title(base::ASCIIToUTF16("PASSED"));
1636 base::string16
error_title(base::ASCIIToUTF16("FAILED"));
1637 content::TitleWatcher
title_watcher(guest_web_contents
, expected_title
);
1638 title_watcher
.AlsoWaitForTitle(error_title
);
1639 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
1642 #if defined(OS_CHROMEOS)
1643 IN_PROC_BROWSER_TEST_F(WebViewTest
, ChromeVoxInjection
) {
1645 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1647 ASSERT_TRUE(StartEmbeddedTestServer());
1648 content::WebContents
* guest_web_contents
= LoadGuest(
1649 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1650 "web_view/chromevox_injection");
1651 ASSERT_TRUE(guest_web_contents
);
1653 chromeos::SpeechMonitor monitor
;
1654 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1655 true, ash::A11Y_NOTIFICATION_NONE
);
1656 EXPECT_TRUE(monitor
.SkipChromeVoxEnabledMessage());
1658 EXPECT_EQ("chrome vox test title", monitor
.GetNextUtterance());
1662 // Flaky on Windows. http://crbug.com/303966
1664 #define MAYBE_TearDownTest DISABLED_TearDownTest
1666 #define MAYBE_TearDownTest TearDownTest
1668 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_TearDownTest
) {
1669 ExtensionTestMessageListener
first_loaded_listener("guest-loaded", false);
1670 const extensions::Extension
* extension
=
1671 LoadAndLaunchPlatformApp("web_view/teardown");
1672 ASSERT_TRUE(first_loaded_listener
.WaitUntilSatisfied());
1673 apps::AppWindow
* window
= NULL
;
1674 if (!GetAppWindowCount())
1675 window
= CreateAppWindow(extension
);
1677 window
= GetFirstAppWindow();
1678 CloseAppWindow(window
);
1680 // Load the app again.
1681 ExtensionTestMessageListener
second_loaded_listener("guest-loaded", false);
1682 LoadAndLaunchPlatformApp("web_view/teardown");
1683 ASSERT_TRUE(second_loaded_listener
.WaitUntilSatisfied());
1686 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1687 // platform app) does not have geolocation permission for this test.
1688 // No matter what the API does, geolocation permission would be denied.
1689 // Note that the test name prefix must be "GeolocationAPI".
1690 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessAllow
) {
1691 TestHelper("testDenyDenies",
1692 "web_view/geolocation/embedder_has_no_permission",
1696 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasNoAccessDeny
) {
1697 TestHelper("testDenyDenies",
1698 "web_view/geolocation/embedder_has_no_permission",
1702 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1703 // platform app) has geolocation permission
1705 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1706 // geolocation in this case).
1708 // Also note that these are run separately because OverrideGeolocation() doesn't
1709 // mock out geolocation for multiple navigator.geolocation calls properly and
1710 // the tests become flaky.
1711 // GeolocationAPI* test 1 of 3.
1712 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessAllow
) {
1713 TestHelper("testAllow",
1714 "web_view/geolocation/embedder_has_permission",
1718 // GeolocationAPI* test 2 of 3.
1719 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPIEmbedderHasAccessDeny
) {
1720 TestHelper("testDeny",
1721 "web_view/geolocation/embedder_has_permission",
1725 // GeolocationAPI* test 3 of 3.
1726 IN_PROC_BROWSER_TEST_F(WebViewTest
,
1727 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow
) {
1728 TestHelper("testMultipleBridgeIdAllow",
1729 "web_view/geolocation/embedder_has_permission",
1734 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
1735 // is handled correctly (and does not crash).
1736 IN_PROC_BROWSER_TEST_F(WebViewTest
, GeolocationAPICancelGeolocation
) {
1737 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1738 ASSERT_TRUE(RunPlatformAppTest(
1739 "platform_apps/web_view/geolocation/cancel_request")) << message_
;
1742 IN_PROC_BROWSER_TEST_F(WebViewTest
, DISABLED_GeolocationRequestGone
) {
1743 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1744 ASSERT_TRUE(RunPlatformAppTest(
1745 "platform_apps/web_view/geolocation/geolocation_request_gone"))
1749 IN_PROC_BROWSER_TEST_F(WebViewTest
, ClearData
) {
1751 // Flaky on XP bot http://crbug.com/282674
1752 if (base::win::GetVersion() <= base::win::VERSION_XP
)
1756 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1757 ASSERT_TRUE(RunPlatformAppTestWithArg(
1758 "platform_apps/web_view/common", "cleardata"))
1762 // This test is disabled on Win due to being flaky. http://crbug.com/294592
1764 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
1766 #define MAYBE_ConsoleMessage ConsoleMessage
1768 IN_PROC_BROWSER_TEST_F(WebViewTest
, MAYBE_ConsoleMessage
) {
1769 ASSERT_TRUE(RunPlatformAppTestWithArg(
1770 "platform_apps/web_view/common", "console_messages"))
1774 IN_PROC_BROWSER_TEST_F(WebViewTest
, DownloadPermission
) {
1775 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1776 content::WebContents
* guest_web_contents
=
1777 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
1778 "web_view/download");
1779 ASSERT_TRUE(guest_web_contents
);
1781 // Replace WebContentsDelegate with mock version so we can intercept download
1783 content::WebContentsDelegate
* delegate
= guest_web_contents
->GetDelegate();
1784 MockDownloadWebContentsDelegate
* mock_delegate
=
1785 new MockDownloadWebContentsDelegate(delegate
);
1786 guest_web_contents
->SetDelegate(mock_delegate
);
1789 // 1. Guest requests a download that its embedder denies.
1790 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
1791 "startDownload('download-link-1')"));
1792 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
1793 mock_delegate
->Reset();
1795 // 2. Guest requests a download that its embedder allows.
1796 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
1797 "startDownload('download-link-2')"));
1798 mock_delegate
->WaitForCanDownload(true); // Expect to allow.
1799 mock_delegate
->Reset();
1801 // 3. Guest requests a download that its embedder ignores, this implies deny.
1802 EXPECT_TRUE(content::ExecuteScript(guest_web_contents
,
1803 "startDownload('download-link-3')"));
1804 mock_delegate
->WaitForCanDownload(false); // Expect to not allow.
1807 // This test makes sure loading <webview> does not crash when there is an
1808 // extension which has content script whitelisted/forced.
1809 IN_PROC_BROWSER_TEST_F(WebViewTest
, WhitelistedContentScript
) {
1810 // Whitelist the extension for running content script we are going to load.
1811 extensions::ExtensionsClient::ScriptingWhitelist whitelist
;
1812 const std::string extension_id
= "imeongpbjoodlnmlakaldhlcmijmhpbb";
1813 whitelist
.push_back(extension_id
);
1814 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist
);
1816 // Load the extension.
1817 const extensions::Extension
* content_script_whitelisted_extension
=
1818 LoadExtension(test_data_dir_
.AppendASCII(
1819 "platform_apps/web_view/extension_api/content_script"));
1820 ASSERT_TRUE(content_script_whitelisted_extension
);
1821 ASSERT_EQ(extension_id
, content_script_whitelisted_extension
->id());
1823 // Now load an app with <webview>.
1824 ExtensionTestMessageListener
done_listener("TEST_PASSED", false);
1825 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted");
1826 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
1829 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentReady
) {
1830 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
1834 IN_PROC_BROWSER_TEST_F(WebViewTest
, SetPropertyOnDocumentInteractive
) {
1835 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
1839 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionAllow
) {
1841 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
1846 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_HasPermissionDeny
) {
1848 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
1853 IN_PROC_BROWSER_TEST_F(WebViewTest
, SpeechRecognitionAPI_NoPermission
) {
1855 RunPlatformAppTestWithArg("platform_apps/web_view/common",
1856 "speech_recognition_api_no_permission"))
1860 // Tests overriding user agent.
1861 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent
) {
1862 ASSERT_TRUE(RunPlatformAppTestWithArg(
1863 "platform_apps/web_view/common", "useragent")) << message_
;
1866 IN_PROC_BROWSER_TEST_F(WebViewTest
, UserAgent_NewWindow
) {
1867 ASSERT_TRUE(RunPlatformAppTestWithArg(
1868 "platform_apps/web_view/common",
1869 "useragent_newwindow")) << message_
;
1872 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoPermission
) {
1873 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
1877 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestAlertDialog
) {
1878 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER
);
1881 IN_PROC_BROWSER_TEST_F(WebViewTest
, TestConfirmDialog
) {
1882 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER
);
1885 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogCancel
) {
1886 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER
);
1889 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultCancel
) {
1890 TestHelper("testConfirmDialogDefaultCancel",
1895 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestConfirmDialogDefaultGCCancel
) {
1896 TestHelper("testConfirmDialogDefaultGCCancel",
1901 IN_PROC_BROWSER_TEST_F(WebViewTest
, Dialog_TestPromptDialog
) {
1902 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER
);
1905 IN_PROC_BROWSER_TEST_F(WebViewTest
, NoContentSettingsAPI
) {
1906 // Load the extension.
1907 const extensions::Extension
* content_settings_extension
=
1909 test_data_dir_
.AppendASCII(
1910 "platform_apps/web_view/extension_api/content_settings"));
1911 ASSERT_TRUE(content_settings_extension
);
1912 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER
);
1915 #if defined(ENABLE_PLUGINS)
1916 class WebViewPluginTest
: public WebViewTest
{
1918 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
1919 WebViewTest::SetUpCommandLine(command_line
);
1921 // Append the switch to register the pepper plugin.
1922 // library name = <out dir>/<test_name>.<library_extension>
1923 // MIME type = application/x-ppapi-<test_name>
1924 base::FilePath plugin_dir
;
1925 EXPECT_TRUE(PathService::Get(base::DIR_MODULE
, &plugin_dir
));
1927 base::FilePath plugin_lib
= plugin_dir
.Append(library_name
);
1928 EXPECT_TRUE(base::PathExists(plugin_lib
));
1929 base::FilePath::StringType pepper_plugin
= plugin_lib
.value();
1930 pepper_plugin
.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
1931 command_line
->AppendSwitchNative(switches::kRegisterPepperPlugins
,
1936 IN_PROC_BROWSER_TEST_F(WebViewPluginTest
, TestLoadPluginEvent
) {
1937 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER
);
1939 #endif // defined(ENABLE_PLUGINS)
1941 class WebViewCaptureTest
: public WebViewTest
,
1942 public testing::WithParamInterface
<std::string
> {
1944 WebViewCaptureTest() {}
1945 virtual ~WebViewCaptureTest() {}
1946 virtual void SetUp() OVERRIDE
{
1947 EnablePixelOutput();
1948 WebViewTest::SetUp();
1950 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
1951 command_line
->AppendSwitch(GetParam());
1952 // http://crbug.com/327035
1953 command_line
->AppendSwitch(switches::kDisableDelegatedRenderer
);
1954 WebViewTest::SetUpCommandLine(command_line
);
1958 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestZoomAPI
) {
1959 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER
);
1962 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI
) {
1963 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER
);
1966 IN_PROC_BROWSER_TEST_F(WebViewTest
, Shim_TestFindAPI_findupdate
) {
1967 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER
);
1970 // <webview> screenshot capture fails with ubercomp.
1971 // See http://crbug.com/327035.
1972 IN_PROC_BROWSER_TEST_P(WebViewCaptureTest
,
1973 DISABLED_Shim_ScreenshotCapture
) {
1974 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER
);
1977 // Threaded compositing is always enabled on Aura and Mac.
1978 #if !defined(USE_AURA) && !defined(OS_MACOSX)
1979 INSTANTIATE_TEST_CASE_P(WithoutThreadedCompositor
,
1981 ::testing::Values(std::string(switches::kDisableThreadedCompositing
)));
1984 #if defined(USE_AURA) || defined(OS_MACOSX)
1985 INSTANTIATE_TEST_CASE_P(WithThreadedCompositor
,
1987 ::testing::Values(std::string(switches::kEnableThreadedCompositing
)));