Make chrome/browser/chromeos/accessibility compile on Athena with use_ash=0
[chromium-blink-merge.git] / chrome / browser / apps / web_view_browsertest.cc
blobead6ef930ec36e85db54c3e5c49dee4e890c9aeb
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/app_window/native_app_window.h"
31 #include "extensions/browser/guest_view/guest_view_manager.h"
32 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
33 #include "extensions/browser/guest_view/test_guest_view_manager.h"
34 #include "extensions/common/extension.h"
35 #include "extensions/common/extensions_client.h"
36 #include "extensions/test/extension_test_message_listener.h"
37 #include "media/base/media_switches.h"
38 #include "net/test/embedded_test_server/embedded_test_server.h"
39 #include "net/test/embedded_test_server/http_request.h"
40 #include "net/test/embedded_test_server/http_response.h"
41 #include "ui/gfx/switches.h"
42 #include "ui/gl/gl_switches.h"
44 #if defined(OS_CHROMEOS)
45 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
46 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
47 #endif
49 // For fine-grained suppression on flaky tests.
50 #if defined(OS_WIN)
51 #include "base/win/windows_version.h"
52 #endif
54 using extensions::ContextMenuMatcher;
55 using extensions::MenuItem;
56 using prerender::PrerenderLinkManager;
57 using prerender::PrerenderLinkManagerFactory;
58 using task_manager::browsertest_util::MatchAboutBlankTab;
59 using task_manager::browsertest_util::MatchAnyApp;
60 using task_manager::browsertest_util::MatchAnyBackground;
61 using task_manager::browsertest_util::MatchAnyTab;
62 using task_manager::browsertest_util::MatchAnyWebView;
63 using task_manager::browsertest_util::MatchApp;
64 using task_manager::browsertest_util::MatchBackground;
65 using task_manager::browsertest_util::MatchWebView;
66 using task_manager::browsertest_util::WaitForTaskManagerRows;
67 using ui::MenuModel;
69 namespace {
70 const char kEmptyResponsePath[] = "/close-socket";
71 const char kRedirectResponsePath[] = "/server-redirect";
72 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent";
73 const char kRedirectResponseFullPath[] =
74 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
76 // Platform-specific filename relative to the chrome executable.
77 #if defined(OS_WIN)
78 const wchar_t library_name[] = L"ppapi_tests.dll";
79 #elif defined(OS_MACOSX)
80 const char library_name[] = "ppapi_tests.plugin";
81 #elif defined(OS_POSIX)
82 const char library_name[] = "libppapi_tests.so";
83 #endif
85 class EmptyHttpResponse : public net::test_server::HttpResponse {
86 public:
87 std::string ToResponseString() const override { return std::string(); }
90 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
91 public:
92 TestInterstitialPageDelegate() {
94 ~TestInterstitialPageDelegate() override {}
95 std::string GetHTMLContents() override { return std::string(); }
98 class WebContentsHiddenObserver : public content::WebContentsObserver {
99 public:
100 WebContentsHiddenObserver(content::WebContents* web_contents,
101 const base::Closure& hidden_callback)
102 : WebContentsObserver(web_contents),
103 hidden_callback_(hidden_callback),
104 hidden_observed_(false) {
107 // WebContentsObserver.
108 void WasHidden() override {
109 hidden_observed_ = true;
110 hidden_callback_.Run();
113 bool hidden_observed() { return hidden_observed_; }
115 private:
116 base::Closure hidden_callback_;
117 bool hidden_observed_;
119 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver);
122 void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
123 const char* script,
124 const char* title) {
125 base::string16 expected_title(base::ASCIIToUTF16(title));
126 base::string16 error_title(base::ASCIIToUTF16("error"));
128 content::TitleWatcher title_watcher(web_contents, expected_title);
129 title_watcher.AlsoWaitForTitle(error_title);
130 EXPECT_TRUE(content::ExecuteScript(web_contents, script));
131 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
134 } // namespace
136 // This class intercepts media access request from the embedder. The request
137 // should be triggered only if the embedder API (from tests) allows the request
138 // in Javascript.
139 // We do not issue the actual media request; the fact that the request reached
140 // embedder's WebContents is good enough for our tests. This is also to make
141 // the test run successfully on trybots.
142 class MockWebContentsDelegate : public content::WebContentsDelegate {
143 public:
144 MockWebContentsDelegate()
145 : requested_(false),
146 checked_(false) {}
147 ~MockWebContentsDelegate() override {}
149 void RequestMediaAccessPermission(
150 content::WebContents* web_contents,
151 const content::MediaStreamRequest& request,
152 const content::MediaResponseCallback& callback) override {
153 requested_ = true;
154 if (request_message_loop_runner_.get())
155 request_message_loop_runner_->Quit();
158 bool CheckMediaAccessPermission(content::WebContents* web_contents,
159 const GURL& security_origin,
160 content::MediaStreamType type) override {
161 checked_ = true;
162 if (check_message_loop_runner_.get())
163 check_message_loop_runner_->Quit();
164 return true;
167 void WaitForRequestMediaPermission() {
168 if (requested_)
169 return;
170 request_message_loop_runner_ = new content::MessageLoopRunner;
171 request_message_loop_runner_->Run();
174 void WaitForCheckMediaPermission() {
175 if (checked_)
176 return;
177 check_message_loop_runner_ = new content::MessageLoopRunner;
178 check_message_loop_runner_->Run();
181 private:
182 bool requested_;
183 bool checked_;
184 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_;
185 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_;
187 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
190 // This class intercepts download request from the guest.
191 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate {
192 public:
193 explicit MockDownloadWebContentsDelegate(
194 content::WebContentsDelegate* orig_delegate)
195 : orig_delegate_(orig_delegate),
196 waiting_for_decision_(false),
197 expect_allow_(false),
198 decision_made_(false),
199 last_download_allowed_(false) {}
200 ~MockDownloadWebContentsDelegate() override {}
202 void CanDownload(content::RenderViewHost* render_view_host,
203 const GURL& url,
204 const std::string& request_method,
205 const base::Callback<void(bool)>& callback) override {
206 orig_delegate_->CanDownload(
207 render_view_host, url, request_method,
208 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided,
209 base::Unretained(this)));
212 void WaitForCanDownload(bool expect_allow) {
213 EXPECT_FALSE(waiting_for_decision_);
214 waiting_for_decision_ = true;
216 if (decision_made_) {
217 EXPECT_EQ(expect_allow, last_download_allowed_);
218 return;
221 expect_allow_ = expect_allow;
222 message_loop_runner_ = new content::MessageLoopRunner;
223 message_loop_runner_->Run();
226 void DownloadDecided(bool allow) {
227 EXPECT_FALSE(decision_made_);
228 decision_made_ = true;
230 if (waiting_for_decision_) {
231 EXPECT_EQ(expect_allow_, allow);
232 if (message_loop_runner_.get())
233 message_loop_runner_->Quit();
234 return;
236 last_download_allowed_ = allow;
239 void Reset() {
240 waiting_for_decision_ = false;
241 decision_made_ = false;
244 private:
245 content::WebContentsDelegate* orig_delegate_;
246 bool waiting_for_decision_;
247 bool expect_allow_;
248 bool decision_made_;
249 bool last_download_allowed_;
250 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
252 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate);
255 class WebViewTest : public extensions::PlatformAppBrowserTest {
256 protected:
257 void SetUp() override {
258 if (UsesFakeSpeech()) {
259 // SpeechRecognition test specific SetUp.
260 fake_speech_recognition_manager_.reset(
261 new content::FakeSpeechRecognitionManager());
262 fake_speech_recognition_manager_->set_should_send_fake_response(true);
263 // Inject the fake manager factory so that the test result is returned to
264 // the web page.
265 content::SpeechRecognitionManager::SetManagerForTesting(
266 fake_speech_recognition_manager_.get());
268 extensions::PlatformAppBrowserTest::SetUp();
271 void TearDown() override {
272 if (UsesFakeSpeech()) {
273 // SpeechRecognition test specific TearDown.
274 content::SpeechRecognitionManager::SetManagerForTesting(NULL);
277 extensions::PlatformAppBrowserTest::TearDown();
280 void SetUpOnMainThread() override {
281 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
282 const testing::TestInfo* const test_info =
283 testing::UnitTest::GetInstance()->current_test_info();
284 // Mock out geolocation for geolocation specific tests.
285 if (!strncmp(test_info->name(), "GeolocationAPI",
286 strlen("GeolocationAPI"))) {
287 ui_test_utils::OverrideGeolocation(10, 20);
291 void SetUpCommandLine(CommandLine* command_line) override {
292 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
293 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
295 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
298 // This method is responsible for initializing a packaged app, which contains
299 // multiple webview tags. The tags have different partition identifiers and
300 // their WebContent objects are returned as output. The method also verifies
301 // the expected process allocation and storage partition assignment.
302 // The |navigate_to_url| parameter is used to navigate the main browser
303 // window.
305 // TODO(ajwong): This function is getting to be too large. Either refactor it
306 // so the test can specify a configuration of WebView tags that we will
307 // dynamically inject JS to generate, or move this test wholesale into
308 // something that RunPlatformAppTest() can execute purely in Javascript. This
309 // won't let us do a white-box examination of the StoragePartition equivalence
310 // directly, but we will be able to view the black box effects which is good
311 // enough. http://crbug.com/160361
312 void NavigateAndOpenAppForIsolation(
313 GURL navigate_to_url,
314 content::WebContents** default_tag_contents1,
315 content::WebContents** default_tag_contents2,
316 content::WebContents** named_partition_contents1,
317 content::WebContents** named_partition_contents2,
318 content::WebContents** persistent_partition_contents1,
319 content::WebContents** persistent_partition_contents2,
320 content::WebContents** persistent_partition_contents3) {
321 GURL::Replacements replace_host;
322 std::string host_str("localhost"); // Must stay in scope with replace_host.
323 replace_host.SetHostStr(host_str);
325 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host);
327 GURL tag_url1 = embedded_test_server()->GetURL(
328 "/extensions/platform_apps/web_view/isolation/cookie.html");
329 tag_url1 = tag_url1.ReplaceComponents(replace_host);
330 GURL tag_url2 = embedded_test_server()->GetURL(
331 "/extensions/platform_apps/web_view/isolation/cookie2.html");
332 tag_url2 = tag_url2.ReplaceComponents(replace_host);
333 GURL tag_url3 = embedded_test_server()->GetURL(
334 "/extensions/platform_apps/web_view/isolation/storage1.html");
335 tag_url3 = tag_url3.ReplaceComponents(replace_host);
336 GURL tag_url4 = embedded_test_server()->GetURL(
337 "/extensions/platform_apps/web_view/isolation/storage2.html");
338 tag_url4 = tag_url4.ReplaceComponents(replace_host);
339 GURL tag_url5 = embedded_test_server()->GetURL(
340 "/extensions/platform_apps/web_view/isolation/storage1.html#p1");
341 tag_url5 = tag_url5.ReplaceComponents(replace_host);
342 GURL tag_url6 = embedded_test_server()->GetURL(
343 "/extensions/platform_apps/web_view/isolation/storage1.html#p2");
344 tag_url6 = tag_url6.ReplaceComponents(replace_host);
345 GURL tag_url7 = embedded_test_server()->GetURL(
346 "/extensions/platform_apps/web_view/isolation/storage1.html#p3");
347 tag_url7 = tag_url7.ReplaceComponents(replace_host);
349 ui_test_utils::NavigateToURLWithDisposition(
350 browser(), navigate_to_url, CURRENT_TAB,
351 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
353 ui_test_utils::UrlLoadObserver observer1(
354 tag_url1, content::NotificationService::AllSources());
355 ui_test_utils::UrlLoadObserver observer2(
356 tag_url2, content::NotificationService::AllSources());
357 ui_test_utils::UrlLoadObserver observer3(
358 tag_url3, content::NotificationService::AllSources());
359 ui_test_utils::UrlLoadObserver observer4(
360 tag_url4, content::NotificationService::AllSources());
361 ui_test_utils::UrlLoadObserver observer5(
362 tag_url5, content::NotificationService::AllSources());
363 ui_test_utils::UrlLoadObserver observer6(
364 tag_url6, content::NotificationService::AllSources());
365 ui_test_utils::UrlLoadObserver observer7(
366 tag_url7, content::NotificationService::AllSources());
367 LoadAndLaunchPlatformApp("web_view/isolation", "Launched");
368 observer1.Wait();
369 observer2.Wait();
370 observer3.Wait();
371 observer4.Wait();
372 observer5.Wait();
373 observer6.Wait();
374 observer7.Wait();
376 content::Source<content::NavigationController> source1 = observer1.source();
377 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->
378 IsIsolatedGuest());
379 content::Source<content::NavigationController> source2 = observer2.source();
380 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->
381 IsIsolatedGuest());
382 content::Source<content::NavigationController> source3 = observer3.source();
383 EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()->
384 IsIsolatedGuest());
385 content::Source<content::NavigationController> source4 = observer4.source();
386 EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()->
387 IsIsolatedGuest());
388 content::Source<content::NavigationController> source5 = observer5.source();
389 EXPECT_TRUE(source5->GetWebContents()->GetRenderProcessHost()->
390 IsIsolatedGuest());
391 content::Source<content::NavigationController> source6 = observer6.source();
392 EXPECT_TRUE(source6->GetWebContents()->GetRenderProcessHost()->
393 IsIsolatedGuest());
394 content::Source<content::NavigationController> source7 = observer7.source();
395 EXPECT_TRUE(source7->GetWebContents()->GetRenderProcessHost()->
396 IsIsolatedGuest());
398 // Check that the first two tags use the same process and it is different
399 // than the process used by the other two.
400 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
401 source2->GetWebContents()->GetRenderProcessHost()->GetID());
402 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
403 source4->GetWebContents()->GetRenderProcessHost()->GetID());
404 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
405 source3->GetWebContents()->GetRenderProcessHost()->GetID());
407 // The two sets of tags should also be isolated from the main browser.
408 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
409 browser()->tab_strip_model()->GetWebContentsAt(0)->
410 GetRenderProcessHost()->GetID());
411 EXPECT_NE(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
412 browser()->tab_strip_model()->GetWebContentsAt(0)->
413 GetRenderProcessHost()->GetID());
415 // Check that the storage partitions of the first two tags match and are
416 // different than the other two.
417 EXPECT_EQ(
418 source1->GetWebContents()->GetRenderProcessHost()->
419 GetStoragePartition(),
420 source2->GetWebContents()->GetRenderProcessHost()->
421 GetStoragePartition());
422 EXPECT_EQ(
423 source3->GetWebContents()->GetRenderProcessHost()->
424 GetStoragePartition(),
425 source4->GetWebContents()->GetRenderProcessHost()->
426 GetStoragePartition());
427 EXPECT_NE(
428 source1->GetWebContents()->GetRenderProcessHost()->
429 GetStoragePartition(),
430 source3->GetWebContents()->GetRenderProcessHost()->
431 GetStoragePartition());
433 // Ensure the persistent storage partitions are different.
434 EXPECT_EQ(
435 source5->GetWebContents()->GetRenderProcessHost()->
436 GetStoragePartition(),
437 source6->GetWebContents()->GetRenderProcessHost()->
438 GetStoragePartition());
439 EXPECT_NE(
440 source5->GetWebContents()->GetRenderProcessHost()->
441 GetStoragePartition(),
442 source7->GetWebContents()->GetRenderProcessHost()->
443 GetStoragePartition());
444 EXPECT_NE(
445 source1->GetWebContents()->GetRenderProcessHost()->
446 GetStoragePartition(),
447 source5->GetWebContents()->GetRenderProcessHost()->
448 GetStoragePartition());
449 EXPECT_NE(
450 source1->GetWebContents()->GetRenderProcessHost()->
451 GetStoragePartition(),
452 source7->GetWebContents()->GetRenderProcessHost()->
453 GetStoragePartition());
455 *default_tag_contents1 = source1->GetWebContents();
456 *default_tag_contents2 = source2->GetWebContents();
457 *named_partition_contents1 = source3->GetWebContents();
458 *named_partition_contents2 = source4->GetWebContents();
459 if (persistent_partition_contents1) {
460 *persistent_partition_contents1 = source5->GetWebContents();
462 if (persistent_partition_contents2) {
463 *persistent_partition_contents2 = source6->GetWebContents();
465 if (persistent_partition_contents3) {
466 *persistent_partition_contents3 = source7->GetWebContents();
470 // Handles |request| by serving a redirect response if the |User-Agent| is
471 // foobar.
472 static scoped_ptr<net::test_server::HttpResponse> UserAgentResponseHandler(
473 const std::string& path,
474 const GURL& redirect_target,
475 const net::test_server::HttpRequest& request) {
476 if (!StartsWithASCII(path, request.relative_url, true))
477 return scoped_ptr<net::test_server::HttpResponse>();
479 std::map<std::string, std::string>::const_iterator it =
480 request.headers.find("User-Agent");
481 EXPECT_TRUE(it != request.headers.end());
482 if (!StartsWithASCII("foobar", it->second, true))
483 return scoped_ptr<net::test_server::HttpResponse>();
485 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
486 new net::test_server::BasicHttpResponse);
487 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
488 http_response->AddCustomHeader("Location", redirect_target.spec());
489 return http_response.Pass();
492 // Handles |request| by serving a redirect response.
493 static scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler(
494 const std::string& path,
495 const GURL& redirect_target,
496 const net::test_server::HttpRequest& request) {
497 if (!StartsWithASCII(path, request.relative_url, true))
498 return scoped_ptr<net::test_server::HttpResponse>();
500 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
501 new net::test_server::BasicHttpResponse);
502 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
503 http_response->AddCustomHeader("Location", redirect_target.spec());
504 return http_response.Pass();
507 // Handles |request| by serving an empty response.
508 static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler(
509 const std::string& path,
510 const net::test_server::HttpRequest& request) {
511 if (StartsWithASCII(path, request.relative_url, true)) {
512 return scoped_ptr<net::test_server::HttpResponse>(
513 new EmptyHttpResponse);
516 return scoped_ptr<net::test_server::HttpResponse>();
519 // Shortcut to return the current MenuManager.
520 extensions::MenuManager* menu_manager() {
521 return extensions::MenuManager::Get(browser()->profile());
524 // This gets all the items that any extension has registered for possible
525 // inclusion in context menus.
526 MenuItem::List GetItems() {
527 MenuItem::List result;
528 std::set<MenuItem::ExtensionKey> extension_ids =
529 menu_manager()->ExtensionIds();
530 std::set<MenuItem::ExtensionKey>::iterator i;
531 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) {
532 const MenuItem::List* list = menu_manager()->MenuItems(*i);
533 result.insert(result.end(), list->begin(), list->end());
535 return result;
538 enum TestServer {
539 NEEDS_TEST_SERVER,
540 NO_TEST_SERVER
543 void TestHelper(const std::string& test_name,
544 const std::string& app_location,
545 TestServer test_server) {
546 // For serving guest pages.
547 if (test_server == NEEDS_TEST_SERVER) {
548 if (!StartEmbeddedTestServer()) {
549 LOG(ERROR) << "FAILED TO START TEST SERVER.";
550 return;
552 embedded_test_server()->RegisterRequestHandler(
553 base::Bind(&WebViewTest::RedirectResponseHandler,
554 kRedirectResponsePath,
555 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
557 embedded_test_server()->RegisterRequestHandler(
558 base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath));
560 embedded_test_server()->RegisterRequestHandler(
561 base::Bind(
562 &WebViewTest::UserAgentResponseHandler,
563 kUserAgentRedirectResponsePath,
564 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
567 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
569 // Flush any pending events to make sure we start with a clean slate.
570 content::RunAllPendingInMessageLoop();
572 content::WebContents* embedder_web_contents =
573 GetFirstAppWindowWebContents();
574 if (!embedder_web_contents) {
575 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
576 return;
579 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
580 done_listener.set_failure_message("TEST_FAILED");
581 if (!content::ExecuteScript(
582 embedder_web_contents,
583 base::StringPrintf("runTest('%s')", test_name.c_str()))) {
584 LOG(ERROR) << "UNABLE TO START TEST.";
585 return;
587 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
590 content::WebContents* LoadGuest(const std::string& guest_path,
591 const std::string& app_path) {
592 GURL::Replacements replace_host;
593 std::string host_str("localhost"); // Must stay in scope with replace_host.
594 replace_host.SetHostStr(host_str);
596 GURL guest_url = embedded_test_server()->GetURL(guest_path);
597 guest_url = guest_url.ReplaceComponents(replace_host);
599 ui_test_utils::UrlLoadObserver guest_observer(
600 guest_url, content::NotificationService::AllSources());
602 LoadAndLaunchPlatformApp(app_path.c_str(), "guest-loaded");
604 guest_observer.Wait();
605 content::Source<content::NavigationController> source =
606 guest_observer.source();
607 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
608 IsIsolatedGuest());
610 content::WebContents* guest_web_contents = source->GetWebContents();
611 return guest_web_contents;
614 // Runs media_access/allow tests.
615 void MediaAccessAPIAllowTestHelper(const std::string& test_name);
617 // Runs media_access/deny tests, each of them are run separately otherwise
618 // they timeout (mostly on Windows).
619 void MediaAccessAPIDenyTestHelper(const std::string& test_name) {
620 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
621 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
623 content::WebContents* embedder_web_contents =
624 GetFirstAppWindowWebContents();
625 ASSERT_TRUE(embedder_web_contents);
627 ExtensionTestMessageListener test_run_listener("PASSED", false);
628 test_run_listener.set_failure_message("FAILED");
629 EXPECT_TRUE(
630 content::ExecuteScript(
631 embedder_web_contents,
632 base::StringPrintf("startDenyTest('%s')", test_name.c_str())));
633 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied());
636 void LoadAppWithGuest(const std::string& app_path) {
637 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED",
638 false);
639 launched_listener.set_failure_message("WebViewTest.FAILURE");
640 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener);
642 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated();
645 void SendMessageToEmbedder(const std::string& message) {
646 EXPECT_TRUE(
647 content::ExecuteScript(
648 GetEmbedderWebContents(),
649 base::StringPrintf("onAppCommand('%s');", message.c_str())));
652 void SendMessageToGuestAndWait(const std::string& message,
653 const std::string& wait_message) {
654 scoped_ptr<ExtensionTestMessageListener> listener;
655 if (!wait_message.empty()) {
656 listener.reset(new ExtensionTestMessageListener(wait_message, false));
659 EXPECT_TRUE(
660 content::ExecuteScript(
661 GetGuestWebContents(),
662 base::StringPrintf("onAppCommand('%s');", message.c_str())));
664 if (listener) {
665 ASSERT_TRUE(listener->WaitUntilSatisfied());
669 content::WebContents* GetGuestWebContents() {
670 return guest_web_contents_;
673 content::WebContents* GetEmbedderWebContents() {
674 if (!embedder_web_contents_) {
675 embedder_web_contents_ = GetFirstAppWindowWebContents();
677 return embedder_web_contents_;
680 extensions::TestGuestViewManager* GetGuestViewManager() {
681 return static_cast<extensions::TestGuestViewManager*>(
682 extensions::TestGuestViewManager::FromBrowserContext(
683 browser()->profile()));
686 WebViewTest() : guest_web_contents_(NULL),
687 embedder_web_contents_(NULL) {
688 extensions::GuestViewManager::set_factory_for_testing(&factory_);
691 private:
692 bool UsesFakeSpeech() {
693 const testing::TestInfo* const test_info =
694 testing::UnitTest::GetInstance()->current_test_info();
696 // SpeechRecognition test specific SetUp.
697 return !strcmp(test_info->name(),
698 "SpeechRecognitionAPI_HasPermissionAllow");
701 scoped_ptr<content::FakeSpeechRecognitionManager>
702 fake_speech_recognition_manager_;
704 extensions::TestGuestViewManagerFactory factory_;
705 // Note that these are only set if you launch app using LoadAppWithGuest().
706 content::WebContents* guest_web_contents_;
707 content::WebContents* embedder_web_contents_;
710 class WebViewDPITest : public WebViewTest {
711 protected:
712 void SetUpCommandLine(CommandLine* command_line) override {
713 WebViewTest::SetUpCommandLine(command_line);
714 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
715 base::StringPrintf("%f", scale()));
718 static float scale() { return 2.0f; }
721 // This test verifies that hiding the guest triggers WebContents::WasHidden().
722 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) {
723 LoadAppWithGuest("web_view/visibility_changed");
725 scoped_refptr<content::MessageLoopRunner> loop_runner(
726 new content::MessageLoopRunner);
727 WebContentsHiddenObserver observer(GetGuestWebContents(),
728 loop_runner->QuitClosure());
730 // Handled in platform_apps/web_view/visibility_changed/main.js
731 SendMessageToEmbedder("hide-guest");
732 if (!observer.hidden_observed())
733 loop_runner->Run();
736 // This test verifies that hiding the embedder also hides the guest.
737 IN_PROC_BROWSER_TEST_F(WebViewTest, EmbedderVisibilityChanged) {
738 LoadAppWithGuest("web_view/visibility_changed");
740 scoped_refptr<content::MessageLoopRunner> loop_runner(
741 new content::MessageLoopRunner);
742 WebContentsHiddenObserver observer(GetGuestWebContents(),
743 loop_runner->QuitClosure());
745 // Handled in platform_apps/web_view/visibility_changed/main.js
746 SendMessageToEmbedder("hide-embedder");
747 if (!observer.hidden_observed())
748 loop_runner->Run();
751 // This test verifies that reloading the embedder reloads the guest (and doest
752 // not crash).
753 IN_PROC_BROWSER_TEST_F(WebViewTest, ReloadEmbedder) {
754 // Just load a guest from other test, we do not want to add a separate
755 // platform_app for this test.
756 LoadAppWithGuest("web_view/visibility_changed");
758 ExtensionTestMessageListener launched_again_listener("WebViewTest.LAUNCHED",
759 false);
760 GetEmbedderWebContents()->GetController().Reload(false);
761 ASSERT_TRUE(launched_again_listener.WaitUntilSatisfied());
764 IN_PROC_BROWSER_TEST_F(WebViewTest, AcceptTouchEvents) {
765 LoadAppWithGuest("web_view/accept_touch_events");
767 content::RenderViewHost* embedder_rvh =
768 GetEmbedderWebContents()->GetRenderViewHost();
770 bool embedder_has_touch_handler =
771 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
772 EXPECT_FALSE(embedder_has_touch_handler);
774 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
776 // Note that we need to wait for the installed/registered touch handler to
777 // appear in browser process before querying |embedder_rvh|.
778 // In practice, since we do a roundrtip from browser process to guest and
779 // back, this is sufficient.
780 embedder_has_touch_handler =
781 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
782 EXPECT_TRUE(embedder_has_touch_handler);
784 SendMessageToGuestAndWait("uninstall-touch-handler",
785 "uninstalled-touch-handler");
786 // Same as the note above about waiting.
787 embedder_has_touch_handler =
788 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
789 EXPECT_FALSE(embedder_has_touch_handler);
792 // This test ensures JavaScript errors ("Cannot redefine property") do not
793 // happen when a <webview> is removed from DOM and added back.
794 IN_PROC_BROWSER_TEST_F(WebViewTest,
795 AddRemoveWebView_AddRemoveWebView) {
796 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
797 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
798 << message_;
801 IN_PROC_BROWSER_TEST_F(WebViewTest, AutoSize) {
802 #if defined(OS_WIN)
803 // Flaky on XP bot http://crbug.com/299507
804 if (base::win::GetVersion() <= base::win::VERSION_XP)
805 return;
806 #endif
808 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
809 << message_;
812 // Test for http://crbug.com/419611.
813 IN_PROC_BROWSER_TEST_F(WebViewTest, DisplayNoneSetSrc) {
814 LoadAndLaunchPlatformApp("web_view/display_none_set_src",
815 "WebViewTest.LAUNCHED");
816 // Navigate the guest while it's in "display: none" state.
817 SendMessageToEmbedder("navigate-guest");
818 GetGuestViewManager()->WaitForSingleGuestCreated();
820 // Now attempt to navigate the guest again.
821 SendMessageToEmbedder("navigate-guest");
823 ExtensionTestMessageListener test_passed_listener("WebViewTest.PASSED",
824 false);
825 // Making the guest visible would trigger loadstop.
826 SendMessageToEmbedder("show-guest");
827 EXPECT_TRUE(test_passed_listener.WaitUntilSatisfied());
830 // http://crbug.com/326332
831 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestAutosizeAfterNavigation) {
832 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER);
835 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAllowTransparencyAttribute) {
836 TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER);
839 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeHeight) {
840 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER);
843 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeHeight) {
844 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER);
847 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeBeforeNavigation) {
848 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
851 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeBeforeNavigation) {
852 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
855 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeRemoveAttributes) {
856 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
859 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeRemoveAttributes) {
860 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
863 // This test is disabled due to being flaky. http://crbug.com/282116
864 #if defined(OS_WIN) || defined(OS_MACOSX)
865 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
866 DISABLED_Shim_TestAutosizeWithPartialAttributes
867 #else
868 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
869 Shim_TestAutosizeWithPartialAttributes
870 #endif
871 IN_PROC_BROWSER_TEST_F(WebViewTest,
872 MAYBE_Shim_TestAutosizeWithPartialAttributes) {
873 TestHelper("testAutosizeWithPartialAttributes",
874 "web_view/shim",
875 NO_TEST_SERVER);
878 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) {
879 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER);
882 // Tests the existence of WebRequest API event objects on the request
883 // object, on the webview element, and hanging directly off webview.
884 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) {
885 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER);
888 // http://crbug.com/315920
889 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
890 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
891 #else
892 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
893 #endif
894 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) {
895 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
898 // http://crbug.com/315920
899 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
900 #define MAYBE_Shim_TestChromeExtensionRelativePath \
901 DISABLED_Shim_TestChromeExtensionRelativePath
902 #else
903 #define MAYBE_Shim_TestChromeExtensionRelativePath \
904 Shim_TestChromeExtensionRelativePath
905 #endif
906 IN_PROC_BROWSER_TEST_F(WebViewTest,
907 MAYBE_Shim_TestChromeExtensionRelativePath) {
908 TestHelper("testChromeExtensionRelativePath",
909 "web_view/shim",
910 NO_TEST_SERVER);
913 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayNoneWebviewLoad) {
914 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER);
917 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayNoneWebviewRemoveChild) {
918 TestHelper("testDisplayNoneWebviewRemoveChild",
919 "web_view/shim", NO_TEST_SERVER);
922 IN_PROC_BROWSER_TEST_F(WebViewTest,
923 Shim_TestInlineScriptFromAccessibleResources) {
924 TestHelper("testInlineScriptFromAccessibleResources",
925 "web_view/shim",
926 NO_TEST_SERVER);
929 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestInvalidChromeExtensionURL) {
930 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
933 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestEventName) {
934 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER);
937 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestOnEventProperty) {
938 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER);
941 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadProgressEvent) {
942 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER);
945 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDestroyOnEventListener) {
946 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER);
949 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCannotMutateEventName) {
950 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER);
953 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPartitionRaisesException) {
954 TestHelper("testPartitionRaisesException", "web_view/shim", NO_TEST_SERVER);
957 IN_PROC_BROWSER_TEST_F(WebViewTest,
958 Shim_TestPartitionRemovalAfterNavigationFails) {
959 TestHelper("testPartitionRemovalAfterNavigationFails",
960 "web_view/shim",
961 NO_TEST_SERVER);
964 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScriptFail) {
965 #if defined(OS_WIN)
966 // Flaky on XP bot http://crbug.com/266185
967 if (base::win::GetVersion() <= base::win::VERSION_XP)
968 return;
969 #endif
971 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER);
974 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScript) {
975 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER);
978 IN_PROC_BROWSER_TEST_F(
979 WebViewTest,
980 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged) {
981 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
982 "web_view/shim",
983 NO_TEST_SERVER);
986 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestTerminateAfterExit) {
987 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER);
990 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAssignSrcAfterCrash) {
991 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER);
994 IN_PROC_BROWSER_TEST_F(WebViewTest,
995 Shim_TestNavOnConsecutiveSrcAttributeChanges) {
996 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
997 "web_view/shim",
998 NO_TEST_SERVER);
1001 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavOnSrcAttributeChange) {
1002 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER);
1005 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigateAfterResize) {
1006 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER);
1009 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveSrcAttribute) {
1010 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER);
1013 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReassignSrcAttribute) {
1014 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER);
1017 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindow) {
1018 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER);
1021 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowTwoListeners) {
1022 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER);
1025 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoPreventDefault) {
1026 TestHelper("testNewWindowNoPreventDefault",
1027 "web_view/shim",
1028 NEEDS_TEST_SERVER);
1031 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoReferrerLink) {
1032 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER);
1035 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestContentLoadEvent) {
1036 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER);
1039 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDeclarativeWebRequestAPI) {
1040 TestHelper("testDeclarativeWebRequestAPI",
1041 "web_view/shim",
1042 NEEDS_TEST_SERVER);
1045 IN_PROC_BROWSER_TEST_F(WebViewTest,
1046 Shim_TestDeclarativeWebRequestAPISendMessage) {
1047 TestHelper("testDeclarativeWebRequestAPISendMessage",
1048 "web_view/shim",
1049 NEEDS_TEST_SERVER);
1052 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPI) {
1053 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER);
1056 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIWithHeaders) {
1057 TestHelper("testWebRequestAPIWithHeaders",
1058 "web_view/shim",
1059 NEEDS_TEST_SERVER);
1062 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIGoogleProperty) {
1063 TestHelper("testWebRequestAPIGoogleProperty",
1064 "web_view/shim",
1065 NO_TEST_SERVER);
1068 // This test is disabled due to being flaky. http://crbug.com/309451
1069 #if defined(OS_WIN)
1070 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1071 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
1072 #else
1073 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1074 Shim_TestWebRequestListenerSurvivesReparenting
1075 #endif
1076 IN_PROC_BROWSER_TEST_F(
1077 WebViewTest,
1078 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting) {
1079 TestHelper("testWebRequestListenerSurvivesReparenting",
1080 "web_view/shim",
1081 NEEDS_TEST_SERVER);
1084 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadStartLoadRedirect) {
1085 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER);
1088 IN_PROC_BROWSER_TEST_F(WebViewTest,
1089 Shim_TestLoadAbortChromeExtensionURLWrongPartition) {
1090 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1091 "web_view/shim",
1092 NO_TEST_SERVER);
1095 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortEmptyResponse) {
1096 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER);
1099 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalChromeURL) {
1100 TestHelper("testLoadAbortIllegalChromeURL",
1101 "web_view/shim",
1102 NO_TEST_SERVER);
1105 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalFileURL) {
1106 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER);
1109 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalJavaScriptURL) {
1110 TestHelper("testLoadAbortIllegalJavaScriptURL",
1111 "web_view/shim",
1112 NO_TEST_SERVER);
1115 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortInvalidNavigation) {
1116 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER);
1119 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortNonWebSafeScheme) {
1120 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER);
1123 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) {
1124 TestHelper("testReload", "web_view/shim", NO_TEST_SERVER);
1127 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReloadAfterTerminate) {
1128 TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER);
1131 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) {
1132 TestHelper("testGetProcessId", "web_view/shim", NO_TEST_SERVER);
1135 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestHiddenBeforeNavigation) {
1136 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
1139 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) {
1140 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1142 // Launch the app and wait until it's ready to load a test.
1143 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1145 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1146 ASSERT_TRUE(embedder_web_contents);
1148 GURL::Replacements replace_host;
1149 std::string host_str("localhost"); // Must stay in scope with replace_host.
1150 replace_host.SetHostStr(host_str);
1152 std::string guest_path(
1153 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1154 GURL guest_url = embedded_test_server()->GetURL(guest_path);
1155 guest_url = guest_url.ReplaceComponents(replace_host);
1157 ui_test_utils::UrlLoadObserver guest_observer(
1158 guest_url, content::NotificationService::AllSources());
1160 // Run the test and wait until the guest WebContents is available and has
1161 // finished loading.
1162 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
1163 EXPECT_TRUE(content::ExecuteScript(
1164 embedder_web_contents,
1165 "runTest('testRemoveWebviewOnExit')"));
1166 guest_observer.Wait();
1168 content::Source<content::NavigationController> source =
1169 guest_observer.source();
1170 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
1171 IsIsolatedGuest());
1173 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
1175 content::WebContentsDestroyedWatcher destroyed_watcher(
1176 source->GetWebContents());
1178 // Tell the embedder to kill the guest.
1179 EXPECT_TRUE(content::ExecuteScript(
1180 embedder_web_contents,
1181 "removeWebviewOnExitDoCrash();"));
1183 // Wait until the guest WebContents is destroyed.
1184 destroyed_watcher.Wait();
1187 // Remove <webview> immediately after navigating it.
1188 // This is a regression test for http://crbug.com/276023.
1189 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewAfterNavigation) {
1190 TestHelper("testRemoveWebviewAfterNavigation",
1191 "web_view/shim",
1192 NO_TEST_SERVER);
1195 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigationToExternalProtocol) {
1196 TestHelper("testNavigationToExternalProtocol",
1197 "web_view/shim",
1198 NO_TEST_SERVER);
1201 IN_PROC_BROWSER_TEST_F(WebViewTest,
1202 Shim_TestResizeWebviewWithDisplayNoneResizesContent) {
1203 TestHelper("testResizeWebviewWithDisplayNoneResizesContent",
1204 "web_view/shim",
1205 NO_TEST_SERVER);
1208 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestResizeWebviewResizesContent) {
1209 TestHelper("testResizeWebviewResizesContent",
1210 "web_view/shim",
1211 NO_TEST_SERVER);
1214 // This test makes sure we do not crash if app is closed while interstitial
1215 // page is being shown in guest.
1216 IN_PROC_BROWSER_TEST_F(WebViewTest, InterstitialTeardown) {
1217 #if defined(OS_WIN)
1218 // Flaky on XP bot http://crbug.com/297014
1219 if (base::win::GetVersion() <= base::win::VERSION_XP)
1220 return;
1221 #endif
1223 // Start a HTTPS server so we can load an interstitial page inside guest.
1224 net::SpawnedTestServer::SSLOptions ssl_options;
1225 ssl_options.server_certificate =
1226 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
1227 net::SpawnedTestServer https_server(
1228 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
1229 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1230 ASSERT_TRUE(https_server.Start());
1232 net::HostPortPair host_and_port = https_server.host_port_pair();
1234 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded");
1236 // Now load the guest.
1237 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1238 ExtensionTestMessageListener second("GuestAddedToDom", false);
1239 EXPECT_TRUE(content::ExecuteScript(
1240 embedder_web_contents,
1241 base::StringPrintf("loadGuest(%d);\n", host_and_port.port())));
1242 ASSERT_TRUE(second.WaitUntilSatisfied());
1244 // Wait for interstitial page to be shown in guest.
1245 content::WebContents* guest_web_contents =
1246 GetGuestViewManager()->WaitForSingleGuestCreated();
1247 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest());
1248 content::WaitForInterstitialAttach(guest_web_contents);
1250 // Now close the app while interstitial page being shown in guest.
1251 extensions::AppWindow* window = GetFirstAppWindow();
1252 window->GetBaseWindow()->Close();
1255 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) {
1256 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1257 << message_;
1260 // This test verifies that prerendering has been disabled inside <webview>.
1261 // This test is here rather than in PrerenderBrowserTest for testing convenience
1262 // only. If it breaks then this is a bug in the prerenderer.
1263 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) {
1264 ASSERT_TRUE(StartEmbeddedTestServer());
1265 content::WebContents* guest_web_contents =
1266 LoadGuest(
1267 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1268 "web_view/noprerenderer");
1269 ASSERT_TRUE(guest_web_contents != NULL);
1271 PrerenderLinkManager* prerender_link_manager =
1272 PrerenderLinkManagerFactory::GetForProfile(
1273 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext()));
1274 ASSERT_TRUE(prerender_link_manager != NULL);
1275 EXPECT_TRUE(prerender_link_manager->IsEmpty());
1278 // Verify that existing <webview>'s are detected when the task manager starts
1279 // up.
1280 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerExistingWebView) {
1281 ASSERT_TRUE(StartEmbeddedTestServer());
1283 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1284 "web_view/task_manager");
1286 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1288 const char* guest_title = "WebViewed test content";
1289 const char* app_name = "<webview> task manager test";
1290 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1291 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1292 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1293 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1295 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1296 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1297 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1298 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1301 // Verify that the task manager notices the creation of new <webview>'s.
1302 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerNewWebView) {
1303 ASSERT_TRUE(StartEmbeddedTestServer());
1305 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1307 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1308 "web_view/task_manager");
1310 const char* guest_title = "WebViewed test content";
1311 const char* app_name = "<webview> task manager test";
1312 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1313 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1314 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1315 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1317 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1318 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1319 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1320 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1323 // This tests cookie isolation for packaged apps with webview tags. It navigates
1324 // the main browser window to a page that sets a cookie and loads an app with
1325 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1326 // storage isolation is enforced.
1327 // This test is flaky. See http://crbug.com/294196.
1328 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_CookieIsolation) {
1329 ASSERT_TRUE(StartEmbeddedTestServer());
1330 const std::string kExpire =
1331 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1332 std::string cookie_script1(kExpire);
1333 cookie_script1.append(
1334 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1335 std::string cookie_script2(kExpire);
1336 cookie_script2.append(
1337 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1339 GURL::Replacements replace_host;
1340 std::string host_str("localhost"); // Must stay in scope with replace_host.
1341 replace_host.SetHostStr(host_str);
1343 GURL set_cookie_url = embedded_test_server()->GetURL(
1344 "/extensions/platform_apps/isolation/set_cookie.html");
1345 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
1347 // The first two partitions will be used to set cookies and ensure they are
1348 // shared. The named partition is used to ensure that cookies are isolated
1349 // between partitions within the same app.
1350 content::WebContents* cookie_contents1;
1351 content::WebContents* cookie_contents2;
1352 content::WebContents* named_partition_contents1;
1353 content::WebContents* named_partition_contents2;
1355 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1,
1356 &cookie_contents2, &named_partition_contents1,
1357 &named_partition_contents2, NULL, NULL, NULL);
1359 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
1360 EXPECT_TRUE(content::ExecuteScript(cookie_contents2, cookie_script2));
1362 int cookie_size;
1363 std::string cookie_value;
1365 // Test the regular browser context to ensure we have only one cookie.
1366 ui_test_utils::GetCookies(GURL("http://localhost"),
1367 browser()->tab_strip_model()->GetWebContentsAt(0),
1368 &cookie_size, &cookie_value);
1369 EXPECT_EQ("testCookie=1", cookie_value);
1371 // The default behavior is to combine webview tags with no explicit partition
1372 // declaration into the same in-memory partition. Test the webview tags to
1373 // ensure we have properly set the cookies and we have both cookies in both
1374 // tags.
1375 ui_test_utils::GetCookies(GURL("http://localhost"),
1376 cookie_contents1,
1377 &cookie_size, &cookie_value);
1378 EXPECT_EQ("guest1=true; guest2=true", cookie_value);
1380 ui_test_utils::GetCookies(GURL("http://localhost"),
1381 cookie_contents2,
1382 &cookie_size, &cookie_value);
1383 EXPECT_EQ("guest1=true; guest2=true", cookie_value);
1385 // The third tag should not have any cookies as it is in a separate partition.
1386 ui_test_utils::GetCookies(GURL("http://localhost"),
1387 named_partition_contents1,
1388 &cookie_size, &cookie_value);
1389 EXPECT_EQ("", cookie_value);
1392 // This tests that in-memory storage partitions are reset on browser restart,
1393 // but persistent ones maintain state for cookies and HTML5 storage.
1394 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) {
1395 ASSERT_TRUE(StartEmbeddedTestServer());
1396 const std::string kExpire =
1397 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1398 std::string cookie_script1(kExpire);
1399 cookie_script1.append(
1400 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1401 std::string cookie_script2(kExpire);
1402 cookie_script2.append(
1403 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1404 std::string cookie_script3(kExpire);
1405 cookie_script3.append(
1406 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1408 // We don't care where the main browser is on this test.
1409 GURL blank_url("about:blank");
1411 // The first two partitions will be used to set cookies and ensure they are
1412 // shared. The named partition is used to ensure that cookies are isolated
1413 // between partitions within the same app.
1414 content::WebContents* cookie_contents1;
1415 content::WebContents* cookie_contents2;
1416 content::WebContents* named_partition_contents1;
1417 content::WebContents* named_partition_contents2;
1418 content::WebContents* persistent_partition_contents1;
1419 content::WebContents* persistent_partition_contents2;
1420 content::WebContents* persistent_partition_contents3;
1421 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
1422 &cookie_contents2, &named_partition_contents1,
1423 &named_partition_contents2,
1424 &persistent_partition_contents1,
1425 &persistent_partition_contents2,
1426 &persistent_partition_contents3);
1428 // Set the inmemory=true cookie for tags with inmemory partitions.
1429 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
1430 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1,
1431 cookie_script1));
1433 // For the two different persistent storage partitions, set the
1434 // two different cookies so we can check that they aren't comingled below.
1435 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1,
1436 cookie_script2));
1438 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3,
1439 cookie_script3));
1441 int cookie_size;
1442 std::string cookie_value;
1444 // Check that all in-memory partitions have a cookie set.
1445 ui_test_utils::GetCookies(GURL("http://localhost"),
1446 cookie_contents1,
1447 &cookie_size, &cookie_value);
1448 EXPECT_EQ("inmemory=true", cookie_value);
1449 ui_test_utils::GetCookies(GURL("http://localhost"),
1450 cookie_contents2,
1451 &cookie_size, &cookie_value);
1452 EXPECT_EQ("inmemory=true", cookie_value);
1453 ui_test_utils::GetCookies(GURL("http://localhost"),
1454 named_partition_contents1,
1455 &cookie_size, &cookie_value);
1456 EXPECT_EQ("inmemory=true", cookie_value);
1457 ui_test_utils::GetCookies(GURL("http://localhost"),
1458 named_partition_contents2,
1459 &cookie_size, &cookie_value);
1460 EXPECT_EQ("inmemory=true", cookie_value);
1462 // Check that all persistent partitions kept their state.
1463 ui_test_utils::GetCookies(GURL("http://localhost"),
1464 persistent_partition_contents1,
1465 &cookie_size, &cookie_value);
1466 EXPECT_EQ("persist1=true", cookie_value);
1467 ui_test_utils::GetCookies(GURL("http://localhost"),
1468 persistent_partition_contents2,
1469 &cookie_size, &cookie_value);
1470 EXPECT_EQ("persist1=true", cookie_value);
1471 ui_test_utils::GetCookies(GURL("http://localhost"),
1472 persistent_partition_contents3,
1473 &cookie_size, &cookie_value);
1474 EXPECT_EQ("persist2=true", cookie_value);
1477 // This is the post-reset portion of the StoragePersistence test. See
1478 // PRE_StoragePersistence for main comment.
1479 #if defined(OS_CHROMEOS)
1480 // http://crbug.com/223888
1481 #define MAYBE_StoragePersistence DISABLED_StoragePersistence
1482 #else
1483 #define MAYBE_StoragePersistence StoragePersistence
1484 #endif
1485 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_StoragePersistence) {
1486 ASSERT_TRUE(StartEmbeddedTestServer());
1488 // We don't care where the main browser is on this test.
1489 GURL blank_url("about:blank");
1491 // The first two partitions will be used to set cookies and ensure they are
1492 // shared. The named partition is used to ensure that cookies are isolated
1493 // between partitions within the same app.
1494 content::WebContents* cookie_contents1;
1495 content::WebContents* cookie_contents2;
1496 content::WebContents* named_partition_contents1;
1497 content::WebContents* named_partition_contents2;
1498 content::WebContents* persistent_partition_contents1;
1499 content::WebContents* persistent_partition_contents2;
1500 content::WebContents* persistent_partition_contents3;
1501 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
1502 &cookie_contents2, &named_partition_contents1,
1503 &named_partition_contents2,
1504 &persistent_partition_contents1,
1505 &persistent_partition_contents2,
1506 &persistent_partition_contents3);
1508 int cookie_size;
1509 std::string cookie_value;
1511 // Check that all in-memory partitions lost their state.
1512 ui_test_utils::GetCookies(GURL("http://localhost"),
1513 cookie_contents1,
1514 &cookie_size, &cookie_value);
1515 EXPECT_EQ("", cookie_value);
1516 ui_test_utils::GetCookies(GURL("http://localhost"),
1517 cookie_contents2,
1518 &cookie_size, &cookie_value);
1519 EXPECT_EQ("", cookie_value);
1520 ui_test_utils::GetCookies(GURL("http://localhost"),
1521 named_partition_contents1,
1522 &cookie_size, &cookie_value);
1523 EXPECT_EQ("", cookie_value);
1524 ui_test_utils::GetCookies(GURL("http://localhost"),
1525 named_partition_contents2,
1526 &cookie_size, &cookie_value);
1527 EXPECT_EQ("", cookie_value);
1529 // Check that all persistent partitions kept their state.
1530 ui_test_utils::GetCookies(GURL("http://localhost"),
1531 persistent_partition_contents1,
1532 &cookie_size, &cookie_value);
1533 EXPECT_EQ("persist1=true", cookie_value);
1534 ui_test_utils::GetCookies(GURL("http://localhost"),
1535 persistent_partition_contents2,
1536 &cookie_size, &cookie_value);
1537 EXPECT_EQ("persist1=true", cookie_value);
1538 ui_test_utils::GetCookies(GURL("http://localhost"),
1539 persistent_partition_contents3,
1540 &cookie_size, &cookie_value);
1541 EXPECT_EQ("persist2=true", cookie_value);
1544 // This tests DOM storage isolation for packaged apps with webview tags. It
1545 // loads an app with multiple webview tags and each tag sets DOM storage
1546 // entries, which the test checks to ensure proper storage isolation is
1547 // enforced.
1548 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) {
1549 ASSERT_TRUE(StartEmbeddedTestServer());
1550 GURL regular_url = embedded_test_server()->GetURL("/title1.html");
1552 std::string output;
1553 std::string get_local_storage("window.domAutomationController.send("
1554 "window.localStorage.getItem('foo') || 'badval')");
1555 std::string get_session_storage("window.domAutomationController.send("
1556 "window.sessionStorage.getItem('bar') || 'badval')");
1558 content::WebContents* default_tag_contents1;
1559 content::WebContents* default_tag_contents2;
1560 content::WebContents* storage_contents1;
1561 content::WebContents* storage_contents2;
1563 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
1564 &default_tag_contents2, &storage_contents1,
1565 &storage_contents2, NULL, NULL, NULL);
1567 // Initialize the storage for the first of the two tags that share a storage
1568 // partition.
1569 EXPECT_TRUE(content::ExecuteScript(storage_contents1,
1570 "initDomStorage('page1')"));
1572 // Let's test that the expected values are present in the first tag, as they
1573 // will be overwritten once we call the initDomStorage on the second tag.
1574 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1575 get_local_storage.c_str(),
1576 &output));
1577 EXPECT_STREQ("local-page1", output.c_str());
1578 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1579 get_session_storage.c_str(),
1580 &output));
1581 EXPECT_STREQ("session-page1", output.c_str());
1583 // Now, init the storage in the second tag in the same storage partition,
1584 // which will overwrite the shared localStorage.
1585 EXPECT_TRUE(content::ExecuteScript(storage_contents2,
1586 "initDomStorage('page2')"));
1588 // The localStorage value now should reflect the one written through the
1589 // second tag.
1590 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1591 get_local_storage.c_str(),
1592 &output));
1593 EXPECT_STREQ("local-page2", output.c_str());
1594 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1595 get_local_storage.c_str(),
1596 &output));
1597 EXPECT_STREQ("local-page2", output.c_str());
1599 // Session storage is not shared though, as each webview tag has separate
1600 // instance, even if they are in the same storage partition.
1601 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1602 get_session_storage.c_str(),
1603 &output));
1604 EXPECT_STREQ("session-page1", output.c_str());
1605 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1606 get_session_storage.c_str(),
1607 &output));
1608 EXPECT_STREQ("session-page2", output.c_str());
1610 // Also, let's check that the main browser and another tag that doesn't share
1611 // the same partition don't have those values stored.
1612 EXPECT_TRUE(ExecuteScriptAndExtractString(
1613 browser()->tab_strip_model()->GetWebContentsAt(0),
1614 get_local_storage.c_str(),
1615 &output));
1616 EXPECT_STREQ("badval", output.c_str());
1617 EXPECT_TRUE(ExecuteScriptAndExtractString(
1618 browser()->tab_strip_model()->GetWebContentsAt(0),
1619 get_session_storage.c_str(),
1620 &output));
1621 EXPECT_STREQ("badval", output.c_str());
1622 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
1623 get_local_storage.c_str(),
1624 &output));
1625 EXPECT_STREQ("badval", output.c_str());
1626 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
1627 get_session_storage.c_str(),
1628 &output));
1629 EXPECT_STREQ("badval", output.c_str());
1632 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1633 // an app with multiple webview tags and each tag creates an IndexedDB record,
1634 // which the test checks to ensure proper storage isolation is enforced.
1635 // This test is flaky. See http://crbug.com/248500.
1636 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_IndexedDBIsolation) {
1637 ASSERT_TRUE(StartEmbeddedTestServer());
1638 GURL regular_url = embedded_test_server()->GetURL("/title1.html");
1640 content::WebContents* default_tag_contents1;
1641 content::WebContents* default_tag_contents2;
1642 content::WebContents* storage_contents1;
1643 content::WebContents* storage_contents2;
1645 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
1646 &default_tag_contents2, &storage_contents1,
1647 &storage_contents2, NULL, NULL, NULL);
1649 // Initialize the storage for the first of the two tags that share a storage
1650 // partition.
1651 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created");
1652 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')",
1653 "addItemIDB complete");
1654 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
1655 "readItemIDB complete");
1657 std::string output;
1658 std::string get_value(
1659 "window.domAutomationController.send(getValueIDB() || 'badval')");
1661 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1662 get_value.c_str(), &output));
1663 EXPECT_STREQ("page1", output.c_str());
1665 // Initialize the db in the second tag.
1666 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open");
1668 // Since we share a partition, reading the value should return the existing
1669 // one.
1670 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
1671 "readItemIDB complete");
1672 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1673 get_value.c_str(), &output));
1674 EXPECT_STREQ("page1", output.c_str());
1676 // Now write through the second tag and read it back.
1677 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')",
1678 "addItemIDB complete");
1679 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
1680 "readItemIDB complete");
1681 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1682 get_value.c_str(), &output));
1683 EXPECT_STREQ("page2", output.c_str());
1685 // Reset the document title, otherwise the next call will not see a change and
1686 // will hang waiting for it.
1687 EXPECT_TRUE(content::ExecuteScript(storage_contents1,
1688 "document.title = 'foo'"));
1690 // Read through the first tag to ensure we have the second value.
1691 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
1692 "readItemIDB complete");
1693 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1694 get_value.c_str(), &output));
1695 EXPECT_STREQ("page2", output.c_str());
1697 // Now, let's confirm there is no database in the main browser and another
1698 // tag that doesn't share the same partition. Due to the IndexedDB API design,
1699 // open will succeed, but the version will be 1, since it creates the database
1700 // if it is not found. The two tags use database version 3, so we avoid
1701 // ambiguity.
1702 const char* script =
1703 "indexedDB.open('isolation').onsuccess = function(e) {"
1704 " if (e.target.result.version == 1)"
1705 " document.title = 'db not found';"
1706 " else "
1707 " document.title = 'error';"
1708 "}";
1709 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1710 script, "db not found");
1711 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
1714 // This test ensures that closing app window on 'loadcommit' does not crash.
1715 // The test launches an app with guest and closes the window on loadcommit. It
1716 // then launches the app window again. The process is repeated 3 times.
1717 // http://crbug.com/291278
1718 #if defined(OS_WIN)
1719 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1720 #else
1721 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1722 #endif
1723 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CloseOnLoadcommit) {
1724 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1725 "done-close-on-loadcommit");
1728 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny_TestDeny) {
1729 MediaAccessAPIDenyTestHelper("testDeny");
1732 IN_PROC_BROWSER_TEST_F(WebViewTest,
1733 MediaAccessAPIDeny_TestDenyThenAllowThrows) {
1734 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1738 IN_PROC_BROWSER_TEST_F(WebViewTest,
1739 MediaAccessAPIDeny_TestDenyWithPreventDefault) {
1740 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1743 IN_PROC_BROWSER_TEST_F(WebViewTest,
1744 MediaAccessAPIDeny_TestNoListenersImplyDeny) {
1745 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1748 IN_PROC_BROWSER_TEST_F(WebViewTest,
1749 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny) {
1750 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1753 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string& test_name) {
1754 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1755 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1757 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1758 ASSERT_TRUE(embedder_web_contents);
1759 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
1760 embedder_web_contents->SetDelegate(mock.get());
1762 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1763 done_listener.set_failure_message("TEST_FAILED");
1764 EXPECT_TRUE(
1765 content::ExecuteScript(
1766 embedder_web_contents,
1767 base::StringPrintf("startAllowTest('%s')",
1768 test_name.c_str())));
1769 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1771 mock->WaitForRequestMediaPermission();
1774 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) {
1775 LoadAppWithGuest("web_view/context_menus/basic");
1777 content::WebContents* guest_web_contents = GetGuestWebContents();
1778 content::WebContents* embedder = GetEmbedderWebContents();
1779 ASSERT_TRUE(embedder);
1781 // 1. Basic property test.
1782 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED");
1784 // 2. Create a menu item and wait for created callback to be called.
1785 ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED");
1787 // 3. Click the created item, wait for the click handlers to fire from JS.
1788 ExtensionTestMessageListener click_listener("ITEM_CLICKED", false);
1789 GURL page_url("http://www.google.com");
1790 // Create and build our test context menu.
1791 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1792 guest_web_contents, page_url, GURL(), GURL()));
1794 // Look for the extension item in the menu, and execute it.
1795 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1796 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id));
1797 menu->ExecuteCommand(command_id, 0);
1799 // Wait for embedder's script to tell us its onclick fired, it does
1800 // chrome.test.sendMessage('ITEM_CLICKED')
1801 ASSERT_TRUE(click_listener.WaitUntilSatisfied());
1803 // 4. Update the item's title and verify.
1804 ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED");
1805 MenuItem::List items = GetItems();
1806 ASSERT_EQ(1u, items.size());
1807 MenuItem* item = items.at(0);
1808 EXPECT_EQ("new_title", item->title());
1810 // 5. Remove the item.
1811 ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED");
1812 MenuItem::List items_after_removal = GetItems();
1813 ASSERT_EQ(0u, items_after_removal.size());
1815 // 6. Add some more items.
1816 ExecuteScriptWaitForTitle(
1817 embedder, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1818 MenuItem::List items_after_insertion = GetItems();
1819 ASSERT_EQ(3u, items_after_insertion.size());
1821 // 7. Test removeAll().
1822 ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED");
1823 MenuItem::List items_after_all_removal = GetItems();
1824 ASSERT_EQ(0u, items_after_all_removal.size());
1827 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) {
1828 MediaAccessAPIAllowTestHelper("testAllow");
1831 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) {
1832 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1835 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) {
1836 MediaAccessAPIAllowTestHelper("testAllowTwice");
1839 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAsync) {
1840 MediaAccessAPIAllowTestHelper("testAllowAsync");
1843 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestCheck) {
1844 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1845 LoadAndLaunchPlatformApp("web_view/media_access/check", "Launched");
1847 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1848 ASSERT_TRUE(embedder_web_contents);
1849 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
1850 embedder_web_contents->SetDelegate(mock.get());
1852 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1853 done_listener.set_failure_message("TEST_FAILED");
1854 EXPECT_TRUE(
1855 content::ExecuteScript(
1856 embedder_web_contents,
1857 base::StringPrintf("startCheckTest('')")));
1858 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1860 mock->WaitForCheckMediaPermission();
1863 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1864 // guests.
1865 IN_PROC_BROWSER_TEST_F(WebViewTest, ScreenCoordinates) {
1866 ASSERT_TRUE(RunPlatformAppTestWithArg(
1867 "platform_apps/web_view/common", "screen_coordinates"))
1868 << message_;
1871 #if defined(OS_CHROMEOS)
1872 IN_PROC_BROWSER_TEST_F(WebViewTest, ChromeVoxInjection) {
1873 EXPECT_FALSE(
1874 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1876 ASSERT_TRUE(StartEmbeddedTestServer());
1877 content::WebContents* guest_web_contents = LoadGuest(
1878 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1879 "web_view/chromevox_injection");
1880 ASSERT_TRUE(guest_web_contents);
1882 chromeos::SpeechMonitor monitor;
1883 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1884 true, ui::A11Y_NOTIFICATION_NONE);
1885 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
1887 EXPECT_EQ("chrome vox test title", monitor.GetNextUtterance());
1889 #endif
1891 // Flaky on Windows. http://crbug.com/303966
1892 #if defined(OS_WIN)
1893 #define MAYBE_TearDownTest DISABLED_TearDownTest
1894 #else
1895 #define MAYBE_TearDownTest TearDownTest
1896 #endif
1897 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) {
1898 const extensions::Extension* extension =
1899 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded");
1900 extensions::AppWindow* window = NULL;
1901 if (!GetAppWindowCount())
1902 window = CreateAppWindow(extension);
1903 else
1904 window = GetFirstAppWindow();
1905 CloseAppWindow(window);
1907 // Load the app again.
1908 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded");
1911 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1912 // platform app) does not have geolocation permission for this test.
1913 // No matter what the API does, geolocation permission would be denied.
1914 // Note that the test name prefix must be "GeolocationAPI".
1915 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) {
1916 TestHelper("testDenyDenies",
1917 "web_view/geolocation/embedder_has_no_permission",
1918 NEEDS_TEST_SERVER);
1921 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessDeny) {
1922 TestHelper("testDenyDenies",
1923 "web_view/geolocation/embedder_has_no_permission",
1924 NEEDS_TEST_SERVER);
1927 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1928 // platform app) has geolocation permission
1930 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1931 // geolocation in this case).
1933 // Also note that these are run separately because OverrideGeolocation() doesn't
1934 // mock out geolocation for multiple navigator.geolocation calls properly and
1935 // the tests become flaky.
1936 // GeolocationAPI* test 1 of 3.
1937 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessAllow) {
1938 TestHelper("testAllow",
1939 "web_view/geolocation/embedder_has_permission",
1940 NEEDS_TEST_SERVER);
1943 // GeolocationAPI* test 2 of 3.
1944 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessDeny) {
1945 TestHelper("testDeny",
1946 "web_view/geolocation/embedder_has_permission",
1947 NEEDS_TEST_SERVER);
1950 // GeolocationAPI* test 3 of 3.
1951 IN_PROC_BROWSER_TEST_F(WebViewTest,
1952 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow) {
1953 TestHelper("testMultipleBridgeIdAllow",
1954 "web_view/geolocation/embedder_has_permission",
1955 NEEDS_TEST_SERVER);
1958 // Tests that
1959 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
1960 // is handled correctly (and does not crash).
1961 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPICancelGeolocation) {
1962 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1963 ASSERT_TRUE(RunPlatformAppTest(
1964 "platform_apps/web_view/geolocation/cancel_request")) << message_;
1967 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_GeolocationRequestGone) {
1968 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1969 ASSERT_TRUE(RunPlatformAppTest(
1970 "platform_apps/web_view/geolocation/geolocation_request_gone"))
1971 << message_;
1974 // In following FilesystemAPIRequestFromMainThread* tests, guest request
1975 // filesystem access from main thread of the guest.
1976 // FileSystemAPIRequestFromMainThread* test 1 of 3
1977 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromMainThreadAllow) {
1978 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER);
1981 // FileSystemAPIRequestFromMainThread* test 2 of 3.
1982 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromMainThreadDeny) {
1983 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER);
1986 // FileSystemAPIRequestFromMainThread* test 3 of 3.
1987 IN_PROC_BROWSER_TEST_F(WebViewTest,
1988 FileSystemAPIRequestFromMainThreadDefaultAllow) {
1989 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER);
1992 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
1993 // to request filesystem access from worker thread.
1994 // FileSystemAPIRequestFromWorker* test 1 of 3
1995 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromWorkerAllow) {
1996 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
1999 // FileSystemAPIRequestFromWorker* test 2 of 3.
2000 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromWorkerDeny) {
2001 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
2004 // FileSystemAPIRequestFromWorker* test 3 of 3.
2005 IN_PROC_BROWSER_TEST_F(WebViewTest,
2006 FileSystemAPIRequestFromWorkerDefaultAllow) {
2007 TestHelper(
2008 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
2011 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
2012 // embedder contains a single webview guest. The guest creates a shared worker
2013 // to request filesystem access from worker thread.
2014 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
2015 IN_PROC_BROWSER_TEST_F(
2016 WebViewTest,
2017 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow) {
2018 TestHelper("testAllow",
2019 "web_view/filesystem/shared_worker/single",
2020 NEEDS_TEST_SERVER);
2023 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
2024 IN_PROC_BROWSER_TEST_F(
2025 WebViewTest,
2026 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny) {
2027 TestHelper("testDeny",
2028 "web_view/filesystem/shared_worker/single",
2029 NEEDS_TEST_SERVER);
2032 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2033 IN_PROC_BROWSER_TEST_F(
2034 WebViewTest,
2035 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow) {
2036 TestHelper(
2037 "testDefaultAllow",
2038 "web_view/filesystem/shared_worker/single",
2039 NEEDS_TEST_SERVER);
2042 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2043 // embedder contains mutiple webview guests. Each guest creates a shared worker
2044 // to request filesystem access from worker thread.
2045 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2046 IN_PROC_BROWSER_TEST_F(
2047 WebViewTest,
2048 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow) {
2049 TestHelper("testAllow",
2050 "web_view/filesystem/shared_worker/multiple",
2051 NEEDS_TEST_SERVER);
2054 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2055 IN_PROC_BROWSER_TEST_F(
2056 WebViewTest,
2057 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny) {
2058 TestHelper("testDeny",
2059 "web_view/filesystem/shared_worker/multiple",
2060 NEEDS_TEST_SERVER);
2063 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2064 IN_PROC_BROWSER_TEST_F(
2065 WebViewTest,
2066 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow) {
2067 TestHelper(
2068 "testDefaultAllow",
2069 "web_view/filesystem/shared_worker/multiple",
2070 NEEDS_TEST_SERVER);
2073 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearData) {
2074 #if defined(OS_WIN)
2075 // Flaky on XP bot http://crbug.com/282674
2076 if (base::win::GetVersion() <= base::win::VERSION_XP)
2077 return;
2078 #endif
2080 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2081 ASSERT_TRUE(RunPlatformAppTestWithArg(
2082 "platform_apps/web_view/common", "cleardata"))
2083 << message_;
2086 // This test is disabled on Win due to being flaky. http://crbug.com/294592
2087 #if defined(OS_WIN)
2088 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
2089 #else
2090 #define MAYBE_ConsoleMessage ConsoleMessage
2091 #endif
2092 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) {
2093 ASSERT_TRUE(RunPlatformAppTestWithArg(
2094 "platform_apps/web_view/common", "console_messages"))
2095 << message_;
2098 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) {
2099 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2100 content::WebContents* guest_web_contents =
2101 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2102 "web_view/download");
2103 ASSERT_TRUE(guest_web_contents);
2105 // Replace WebContentsDelegate with mock version so we can intercept download
2106 // requests.
2107 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate();
2108 scoped_ptr<MockDownloadWebContentsDelegate>
2109 mock_delegate(new MockDownloadWebContentsDelegate(delegate));
2110 guest_web_contents->SetDelegate(mock_delegate.get());
2112 // Start test.
2113 // 1. Guest requests a download that its embedder denies.
2114 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2115 "startDownload('download-link-1')"));
2116 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
2117 mock_delegate->Reset();
2119 // 2. Guest requests a download that its embedder allows.
2120 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2121 "startDownload('download-link-2')"));
2122 mock_delegate->WaitForCanDownload(true); // Expect to allow.
2123 mock_delegate->Reset();
2125 // 3. Guest requests a download that its embedder ignores, this implies deny.
2126 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2127 "startDownload('download-link-3')"));
2128 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
2131 // This test makes sure loading <webview> does not crash when there is an
2132 // extension which has content script whitelisted/forced.
2133 IN_PROC_BROWSER_TEST_F(WebViewTest, WhitelistedContentScript) {
2134 // Whitelist the extension for running content script we are going to load.
2135 extensions::ExtensionsClient::ScriptingWhitelist whitelist;
2136 const std::string extension_id = "imeongpbjoodlnmlakaldhlcmijmhpbb";
2137 whitelist.push_back(extension_id);
2138 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
2140 // Load the extension.
2141 const extensions::Extension* content_script_whitelisted_extension =
2142 LoadExtension(test_data_dir_.AppendASCII(
2143 "platform_apps/web_view/extension_api/content_script"));
2144 ASSERT_TRUE(content_script_whitelisted_extension);
2145 ASSERT_EQ(extension_id, content_script_whitelisted_extension->id());
2147 // Now load an app with <webview>.
2148 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2149 "TEST_PASSED");
2152 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentReady) {
2153 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2154 << message_;
2157 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentInteractive) {
2158 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2159 << message_;
2162 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionAllow) {
2163 ASSERT_TRUE(
2164 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2165 "allowTest"))
2166 << message_;
2169 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionDeny) {
2170 ASSERT_TRUE(
2171 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2172 "denyTest"))
2173 << message_;
2176 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_NoPermission) {
2177 ASSERT_TRUE(
2178 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2179 "speech_recognition_api_no_permission"))
2180 << message_;
2183 // Tests overriding user agent.
2184 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent) {
2185 ASSERT_TRUE(RunPlatformAppTestWithArg(
2186 "platform_apps/web_view/common", "useragent")) << message_;
2189 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent_NewWindow) {
2190 ASSERT_TRUE(RunPlatformAppTestWithArg(
2191 "platform_apps/web_view/common",
2192 "useragent_newwindow")) << message_;
2195 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPermission) {
2196 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2197 << message_;
2200 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestAlertDialog) {
2201 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER);
2204 IN_PROC_BROWSER_TEST_F(WebViewTest, TestConfirmDialog) {
2205 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER);
2208 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogCancel) {
2209 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER);
2212 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultCancel) {
2213 TestHelper("testConfirmDialogDefaultCancel",
2214 "web_view/dialog",
2215 NO_TEST_SERVER);
2218 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultGCCancel) {
2219 TestHelper("testConfirmDialogDefaultGCCancel",
2220 "web_view/dialog",
2221 NO_TEST_SERVER);
2224 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestPromptDialog) {
2225 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER);
2228 IN_PROC_BROWSER_TEST_F(WebViewTest, NoContentSettingsAPI) {
2229 // Load the extension.
2230 const extensions::Extension* content_settings_extension =
2231 LoadExtension(
2232 test_data_dir_.AppendASCII(
2233 "platform_apps/web_view/extension_api/content_settings"));
2234 ASSERT_TRUE(content_settings_extension);
2235 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER);
2238 #if defined(ENABLE_PLUGINS)
2239 class WebViewPluginTest : public WebViewTest {
2240 protected:
2241 void SetUpCommandLine(CommandLine* command_line) override {
2242 WebViewTest::SetUpCommandLine(command_line);
2244 // Append the switch to register the pepper plugin.
2245 // library name = <out dir>/<test_name>.<library_extension>
2246 // MIME type = application/x-ppapi-<test_name>
2247 base::FilePath plugin_dir;
2248 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
2250 base::FilePath plugin_lib = plugin_dir.Append(library_name);
2251 EXPECT_TRUE(base::PathExists(plugin_lib));
2252 base::FilePath::StringType pepper_plugin = plugin_lib.value();
2253 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
2254 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
2255 pepper_plugin);
2259 IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginEvent) {
2260 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER);
2262 #endif // defined(ENABLE_PLUGINS)
2264 class WebViewCaptureTest : public WebViewTest {
2265 public:
2266 WebViewCaptureTest() {}
2267 ~WebViewCaptureTest() override {}
2268 void SetUp() override {
2269 EnablePixelOutput();
2270 WebViewTest::SetUp();
2274 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestZoomAPI) {
2275 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER);
2278 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) {
2279 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER);
2282 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) {
2283 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER);
2286 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadDataAPI) {
2287 TestHelper("testLoadDataAPI", "web_view/shim", NEEDS_TEST_SERVER);
2290 // <webview> screenshot capture fails with ubercomp.
2291 // See http://crbug.com/327035.
2292 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest,
2293 DISABLED_Shim_ScreenshotCapture) {
2294 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER);
2297 #if defined(OS_WIN)
2298 // Test is disabled on Windows because it times out often.
2299 // http://crbug.com/403325
2300 #define MAYBE_WebViewInBackgroundPage \
2301 DISABLED_WebViewInBackgroundPage
2302 #else
2303 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2304 #endif
2305 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) {
2306 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))
2307 << message_;