Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / apps / guest_view / web_view_browsertest.cc
blobbec47cb357e88a5a1774efada048abe70e5b2199
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/path_service.h"
6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/apps/app_browsertest_util.h"
10 #include "chrome/browser/chrome_content_browser_client.h"
11 #include "chrome/browser/prerender/prerender_link_manager.h"
12 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
15 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
16 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_dialogs.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/gpu_data_manager.h"
22 #include "content/public/browser/interstitial_page.h"
23 #include "content/public/browser/interstitial_page_delegate.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/common/content_switches.h"
28 #include "content/public/test/browser_test_utils.h"
29 #include "content/public/test/fake_speech_recognition_manager.h"
30 #include "content/public/test/test_renderer_host.h"
31 #include "extensions/browser/api/declarative/rules_registry.h"
32 #include "extensions/browser/api/declarative/rules_registry_service.h"
33 #include "extensions/browser/api/declarative/test_rules_registry.h"
34 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
35 #include "extensions/browser/app_window/native_app_window.h"
36 #include "extensions/browser/guest_view/guest_view_manager.h"
37 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
38 #include "extensions/browser/guest_view/test_guest_view_manager.h"
39 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
40 #include "extensions/common/extension.h"
41 #include "extensions/common/extensions_client.h"
42 #include "extensions/test/extension_test_message_listener.h"
43 #include "media/base/media_switches.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h"
45 #include "net/test/embedded_test_server/http_request.h"
46 #include "net/test/embedded_test_server/http_response.h"
47 #include "ui/gfx/switches.h"
48 #include "ui/gl/gl_switches.h"
50 #if defined(ENABLE_PLUGINS)
51 #include "content/public/browser/plugin_service.h"
52 #include "content/public/common/webplugininfo.h"
53 #endif
55 #if defined(OS_CHROMEOS)
56 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
57 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
58 #endif
60 // For fine-grained suppression on flaky tests.
61 #if defined(OS_WIN)
62 #include "base/win/windows_version.h"
63 #endif
65 using extensions::ContextMenuMatcher;
66 using extensions::MenuItem;
67 using prerender::PrerenderLinkManager;
68 using prerender::PrerenderLinkManagerFactory;
69 using task_manager::browsertest_util::MatchAboutBlankTab;
70 using task_manager::browsertest_util::MatchAnyApp;
71 using task_manager::browsertest_util::MatchAnyBackground;
72 using task_manager::browsertest_util::MatchAnyTab;
73 using task_manager::browsertest_util::MatchAnyWebView;
74 using task_manager::browsertest_util::MatchApp;
75 using task_manager::browsertest_util::MatchBackground;
76 using task_manager::browsertest_util::MatchWebView;
77 using task_manager::browsertest_util::WaitForTaskManagerRows;
78 using ui::MenuModel;
80 namespace {
81 const char kEmptyResponsePath[] = "/close-socket";
82 const char kRedirectResponsePath[] = "/server-redirect";
83 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent";
84 const char kRedirectResponseFullPath[] =
85 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
87 // Platform-specific filename relative to the chrome executable.
88 #if defined(OS_WIN)
89 const wchar_t library_name[] = L"ppapi_tests.dll";
90 #elif defined(OS_MACOSX)
91 const char library_name[] = "ppapi_tests.plugin";
92 #elif defined(OS_POSIX)
93 const char library_name[] = "libppapi_tests.so";
94 #endif
96 class EmptyHttpResponse : public net::test_server::HttpResponse {
97 public:
98 std::string ToResponseString() const override { return std::string(); }
101 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
102 public:
103 TestInterstitialPageDelegate() {
105 ~TestInterstitialPageDelegate() override {}
106 std::string GetHTMLContents() override { return std::string(); }
109 class WebContentsHiddenObserver : public content::WebContentsObserver {
110 public:
111 WebContentsHiddenObserver(content::WebContents* web_contents,
112 const base::Closure& hidden_callback)
113 : WebContentsObserver(web_contents),
114 hidden_callback_(hidden_callback),
115 hidden_observed_(false) {
118 // WebContentsObserver.
119 void WasHidden() override {
120 hidden_observed_ = true;
121 hidden_callback_.Run();
124 bool hidden_observed() { return hidden_observed_; }
126 private:
127 base::Closure hidden_callback_;
128 bool hidden_observed_;
130 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver);
133 class EmbedderWebContentsObserver : public content::WebContentsObserver {
134 public:
135 explicit EmbedderWebContentsObserver(content::WebContents* web_contents)
136 : WebContentsObserver(web_contents), terminated_(false) {}
138 // WebContentsObserver.
139 void RenderProcessGone(base::TerminationStatus status) override {
140 terminated_ = true;
141 if (message_loop_runner_.get())
142 message_loop_runner_->Quit();
145 void WaitForEmbedderRenderProcessTerminate() {
146 if (terminated_)
147 return;
148 message_loop_runner_ = new content::MessageLoopRunner;
149 message_loop_runner_->Run();
152 private:
153 bool terminated_;
154 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
156 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver);
159 void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
160 const char* script,
161 const char* title) {
162 base::string16 expected_title(base::ASCIIToUTF16(title));
163 base::string16 error_title(base::ASCIIToUTF16("error"));
165 content::TitleWatcher title_watcher(web_contents, expected_title);
166 title_watcher.AlsoWaitForTitle(error_title);
167 EXPECT_TRUE(content::ExecuteScript(web_contents, script));
168 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
171 } // namespace
173 // This class intercepts media access request from the embedder. The request
174 // should be triggered only if the embedder API (from tests) allows the request
175 // in Javascript.
176 // We do not issue the actual media request; the fact that the request reached
177 // embedder's WebContents is good enough for our tests. This is also to make
178 // the test run successfully on trybots.
179 class MockWebContentsDelegate : public content::WebContentsDelegate {
180 public:
181 MockWebContentsDelegate()
182 : requested_(false),
183 checked_(false) {}
184 ~MockWebContentsDelegate() override {}
186 void RequestMediaAccessPermission(
187 content::WebContents* web_contents,
188 const content::MediaStreamRequest& request,
189 const content::MediaResponseCallback& callback) override {
190 requested_ = true;
191 if (request_message_loop_runner_.get())
192 request_message_loop_runner_->Quit();
195 bool CheckMediaAccessPermission(content::WebContents* web_contents,
196 const GURL& security_origin,
197 content::MediaStreamType type) override {
198 checked_ = true;
199 if (check_message_loop_runner_.get())
200 check_message_loop_runner_->Quit();
201 return true;
204 void WaitForRequestMediaPermission() {
205 if (requested_)
206 return;
207 request_message_loop_runner_ = new content::MessageLoopRunner;
208 request_message_loop_runner_->Run();
211 void WaitForCheckMediaPermission() {
212 if (checked_)
213 return;
214 check_message_loop_runner_ = new content::MessageLoopRunner;
215 check_message_loop_runner_->Run();
218 private:
219 bool requested_;
220 bool checked_;
221 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_;
222 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_;
224 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
227 // This class intercepts download request from the guest.
228 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate {
229 public:
230 explicit MockDownloadWebContentsDelegate(
231 content::WebContentsDelegate* orig_delegate)
232 : orig_delegate_(orig_delegate),
233 waiting_for_decision_(false),
234 expect_allow_(false),
235 decision_made_(false),
236 last_download_allowed_(false) {}
237 ~MockDownloadWebContentsDelegate() override {}
239 void CanDownload(content::RenderViewHost* render_view_host,
240 const GURL& url,
241 const std::string& request_method,
242 const base::Callback<void(bool)>& callback) override {
243 orig_delegate_->CanDownload(
244 render_view_host, url, request_method,
245 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided,
246 base::Unretained(this)));
249 void WaitForCanDownload(bool expect_allow) {
250 EXPECT_FALSE(waiting_for_decision_);
251 waiting_for_decision_ = true;
253 if (decision_made_) {
254 EXPECT_EQ(expect_allow, last_download_allowed_);
255 return;
258 expect_allow_ = expect_allow;
259 message_loop_runner_ = new content::MessageLoopRunner;
260 message_loop_runner_->Run();
263 void DownloadDecided(bool allow) {
264 EXPECT_FALSE(decision_made_);
265 decision_made_ = true;
267 if (waiting_for_decision_) {
268 EXPECT_EQ(expect_allow_, allow);
269 if (message_loop_runner_.get())
270 message_loop_runner_->Quit();
271 return;
273 last_download_allowed_ = allow;
276 void Reset() {
277 waiting_for_decision_ = false;
278 decision_made_ = false;
281 private:
282 content::WebContentsDelegate* orig_delegate_;
283 bool waiting_for_decision_;
284 bool expect_allow_;
285 bool decision_made_;
286 bool last_download_allowed_;
287 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
289 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate);
292 class WebViewTest : public extensions::PlatformAppBrowserTest {
293 protected:
294 void SetUp() override {
295 if (UsesFakeSpeech()) {
296 // SpeechRecognition test specific SetUp.
297 fake_speech_recognition_manager_.reset(
298 new content::FakeSpeechRecognitionManager());
299 fake_speech_recognition_manager_->set_should_send_fake_response(true);
300 // Inject the fake manager factory so that the test result is returned to
301 // the web page.
302 content::SpeechRecognitionManager::SetManagerForTesting(
303 fake_speech_recognition_manager_.get());
305 extensions::PlatformAppBrowserTest::SetUp();
308 void TearDown() override {
309 if (UsesFakeSpeech()) {
310 // SpeechRecognition test specific TearDown.
311 content::SpeechRecognitionManager::SetManagerForTesting(NULL);
314 extensions::PlatformAppBrowserTest::TearDown();
317 void SetUpOnMainThread() override {
318 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
319 const testing::TestInfo* const test_info =
320 testing::UnitTest::GetInstance()->current_test_info();
321 // Mock out geolocation for geolocation specific tests.
322 if (!strncmp(test_info->name(), "GeolocationAPI",
323 strlen("GeolocationAPI"))) {
324 ui_test_utils::OverrideGeolocation(10, 20);
328 void SetUpCommandLine(base::CommandLine* command_line) override {
329 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
330 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
332 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
335 // This method is responsible for initializing a packaged app, which contains
336 // multiple webview tags. The tags have different partition identifiers and
337 // their WebContent objects are returned as output. The method also verifies
338 // the expected process allocation and storage partition assignment.
339 // The |navigate_to_url| parameter is used to navigate the main browser
340 // window.
342 // TODO(ajwong): This function is getting to be too large. Either refactor it
343 // so the test can specify a configuration of WebView tags that we will
344 // dynamically inject JS to generate, or move this test wholesale into
345 // something that RunPlatformAppTest() can execute purely in Javascript. This
346 // won't let us do a white-box examination of the StoragePartition equivalence
347 // directly, but we will be able to view the black box effects which is good
348 // enough. http://crbug.com/160361
349 void NavigateAndOpenAppForIsolation(
350 GURL navigate_to_url,
351 content::WebContents** default_tag_contents1,
352 content::WebContents** default_tag_contents2,
353 content::WebContents** named_partition_contents1,
354 content::WebContents** named_partition_contents2,
355 content::WebContents** persistent_partition_contents1,
356 content::WebContents** persistent_partition_contents2,
357 content::WebContents** persistent_partition_contents3) {
358 GURL::Replacements replace_host;
359 replace_host.SetHostStr("localhost");
361 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host);
363 GURL tag_url1 = embedded_test_server()->GetURL(
364 "/extensions/platform_apps/web_view/isolation/cookie.html");
365 tag_url1 = tag_url1.ReplaceComponents(replace_host);
366 GURL tag_url2 = embedded_test_server()->GetURL(
367 "/extensions/platform_apps/web_view/isolation/cookie2.html");
368 tag_url2 = tag_url2.ReplaceComponents(replace_host);
369 GURL tag_url3 = embedded_test_server()->GetURL(
370 "/extensions/platform_apps/web_view/isolation/storage1.html");
371 tag_url3 = tag_url3.ReplaceComponents(replace_host);
372 GURL tag_url4 = embedded_test_server()->GetURL(
373 "/extensions/platform_apps/web_view/isolation/storage2.html");
374 tag_url4 = tag_url4.ReplaceComponents(replace_host);
375 GURL tag_url5 = embedded_test_server()->GetURL(
376 "/extensions/platform_apps/web_view/isolation/storage1.html#p1");
377 tag_url5 = tag_url5.ReplaceComponents(replace_host);
378 GURL tag_url6 = embedded_test_server()->GetURL(
379 "/extensions/platform_apps/web_view/isolation/storage1.html#p2");
380 tag_url6 = tag_url6.ReplaceComponents(replace_host);
381 GURL tag_url7 = embedded_test_server()->GetURL(
382 "/extensions/platform_apps/web_view/isolation/storage1.html#p3");
383 tag_url7 = tag_url7.ReplaceComponents(replace_host);
385 ui_test_utils::NavigateToURL(browser(), navigate_to_url);
387 ui_test_utils::UrlLoadObserver observer1(
388 tag_url1, content::NotificationService::AllSources());
389 ui_test_utils::UrlLoadObserver observer2(
390 tag_url2, content::NotificationService::AllSources());
391 ui_test_utils::UrlLoadObserver observer3(
392 tag_url3, content::NotificationService::AllSources());
393 ui_test_utils::UrlLoadObserver observer4(
394 tag_url4, content::NotificationService::AllSources());
395 ui_test_utils::UrlLoadObserver observer5(
396 tag_url5, content::NotificationService::AllSources());
397 ui_test_utils::UrlLoadObserver observer6(
398 tag_url6, content::NotificationService::AllSources());
399 ui_test_utils::UrlLoadObserver observer7(
400 tag_url7, content::NotificationService::AllSources());
401 LoadAndLaunchPlatformApp("web_view/isolation", "Launched");
402 observer1.Wait();
403 observer2.Wait();
404 observer3.Wait();
405 observer4.Wait();
406 observer5.Wait();
407 observer6.Wait();
408 observer7.Wait();
410 content::Source<content::NavigationController> source1 = observer1.source();
411 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->
412 IsIsolatedGuest());
413 content::Source<content::NavigationController> source2 = observer2.source();
414 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->
415 IsIsolatedGuest());
416 content::Source<content::NavigationController> source3 = observer3.source();
417 EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()->
418 IsIsolatedGuest());
419 content::Source<content::NavigationController> source4 = observer4.source();
420 EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()->
421 IsIsolatedGuest());
422 content::Source<content::NavigationController> source5 = observer5.source();
423 EXPECT_TRUE(source5->GetWebContents()->GetRenderProcessHost()->
424 IsIsolatedGuest());
425 content::Source<content::NavigationController> source6 = observer6.source();
426 EXPECT_TRUE(source6->GetWebContents()->GetRenderProcessHost()->
427 IsIsolatedGuest());
428 content::Source<content::NavigationController> source7 = observer7.source();
429 EXPECT_TRUE(source7->GetWebContents()->GetRenderProcessHost()->
430 IsIsolatedGuest());
432 // Check that the first two tags use the same process and it is different
433 // than the process used by the other two.
434 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
435 source2->GetWebContents()->GetRenderProcessHost()->GetID());
436 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
437 source4->GetWebContents()->GetRenderProcessHost()->GetID());
438 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
439 source3->GetWebContents()->GetRenderProcessHost()->GetID());
441 // The two sets of tags should also be isolated from the main browser.
442 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
443 browser()->tab_strip_model()->GetWebContentsAt(0)->
444 GetRenderProcessHost()->GetID());
445 EXPECT_NE(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
446 browser()->tab_strip_model()->GetWebContentsAt(0)->
447 GetRenderProcessHost()->GetID());
449 // Check that the storage partitions of the first two tags match and are
450 // different than the other two.
451 EXPECT_EQ(
452 source1->GetWebContents()->GetRenderProcessHost()->
453 GetStoragePartition(),
454 source2->GetWebContents()->GetRenderProcessHost()->
455 GetStoragePartition());
456 EXPECT_EQ(
457 source3->GetWebContents()->GetRenderProcessHost()->
458 GetStoragePartition(),
459 source4->GetWebContents()->GetRenderProcessHost()->
460 GetStoragePartition());
461 EXPECT_NE(
462 source1->GetWebContents()->GetRenderProcessHost()->
463 GetStoragePartition(),
464 source3->GetWebContents()->GetRenderProcessHost()->
465 GetStoragePartition());
467 // Ensure the persistent storage partitions are different.
468 EXPECT_EQ(
469 source5->GetWebContents()->GetRenderProcessHost()->
470 GetStoragePartition(),
471 source6->GetWebContents()->GetRenderProcessHost()->
472 GetStoragePartition());
473 EXPECT_NE(
474 source5->GetWebContents()->GetRenderProcessHost()->
475 GetStoragePartition(),
476 source7->GetWebContents()->GetRenderProcessHost()->
477 GetStoragePartition());
478 EXPECT_NE(
479 source1->GetWebContents()->GetRenderProcessHost()->
480 GetStoragePartition(),
481 source5->GetWebContents()->GetRenderProcessHost()->
482 GetStoragePartition());
483 EXPECT_NE(
484 source1->GetWebContents()->GetRenderProcessHost()->
485 GetStoragePartition(),
486 source7->GetWebContents()->GetRenderProcessHost()->
487 GetStoragePartition());
489 *default_tag_contents1 = source1->GetWebContents();
490 *default_tag_contents2 = source2->GetWebContents();
491 *named_partition_contents1 = source3->GetWebContents();
492 *named_partition_contents2 = source4->GetWebContents();
493 if (persistent_partition_contents1) {
494 *persistent_partition_contents1 = source5->GetWebContents();
496 if (persistent_partition_contents2) {
497 *persistent_partition_contents2 = source6->GetWebContents();
499 if (persistent_partition_contents3) {
500 *persistent_partition_contents3 = source7->GetWebContents();
504 // Handles |request| by serving a redirect response if the |User-Agent| is
505 // foobar.
506 static scoped_ptr<net::test_server::HttpResponse> UserAgentResponseHandler(
507 const std::string& path,
508 const GURL& redirect_target,
509 const net::test_server::HttpRequest& request) {
510 if (!StartsWithASCII(path, request.relative_url, true))
511 return scoped_ptr<net::test_server::HttpResponse>();
513 std::map<std::string, std::string>::const_iterator it =
514 request.headers.find("User-Agent");
515 EXPECT_TRUE(it != request.headers.end());
516 if (!StartsWithASCII("foobar", it->second, true))
517 return scoped_ptr<net::test_server::HttpResponse>();
519 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
520 new net::test_server::BasicHttpResponse);
521 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
522 http_response->AddCustomHeader("Location", redirect_target.spec());
523 return http_response.Pass();
526 // Handles |request| by serving a redirect response.
527 static scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler(
528 const std::string& path,
529 const GURL& redirect_target,
530 const net::test_server::HttpRequest& request) {
531 if (!StartsWithASCII(path, request.relative_url, true))
532 return scoped_ptr<net::test_server::HttpResponse>();
534 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
535 new net::test_server::BasicHttpResponse);
536 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
537 http_response->AddCustomHeader("Location", redirect_target.spec());
538 return http_response.Pass();
541 // Handles |request| by serving an empty response.
542 static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler(
543 const std::string& path,
544 const net::test_server::HttpRequest& request) {
545 if (StartsWithASCII(path, request.relative_url, true)) {
546 return scoped_ptr<net::test_server::HttpResponse>(
547 new EmptyHttpResponse);
550 return scoped_ptr<net::test_server::HttpResponse>();
553 // Shortcut to return the current MenuManager.
554 extensions::MenuManager* menu_manager() {
555 return extensions::MenuManager::Get(browser()->profile());
558 // This gets all the items that any extension has registered for possible
559 // inclusion in context menus.
560 MenuItem::List GetItems() {
561 MenuItem::List result;
562 std::set<MenuItem::ExtensionKey> extension_ids =
563 menu_manager()->ExtensionIds();
564 std::set<MenuItem::ExtensionKey>::iterator i;
565 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) {
566 const MenuItem::List* list = menu_manager()->MenuItems(*i);
567 result.insert(result.end(), list->begin(), list->end());
569 return result;
572 enum TestServer {
573 NEEDS_TEST_SERVER,
574 NO_TEST_SERVER
577 void TestHelper(const std::string& test_name,
578 const std::string& app_location,
579 TestServer test_server) {
580 // For serving guest pages.
581 if (test_server == NEEDS_TEST_SERVER) {
582 if (!StartEmbeddedTestServer()) {
583 LOG(ERROR) << "FAILED TO START TEST SERVER.";
584 return;
586 embedded_test_server()->RegisterRequestHandler(
587 base::Bind(&WebViewTest::RedirectResponseHandler,
588 kRedirectResponsePath,
589 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
591 embedded_test_server()->RegisterRequestHandler(
592 base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath));
594 embedded_test_server()->RegisterRequestHandler(
595 base::Bind(
596 &WebViewTest::UserAgentResponseHandler,
597 kUserAgentRedirectResponsePath,
598 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
601 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
603 // Flush any pending events to make sure we start with a clean slate.
604 content::RunAllPendingInMessageLoop();
606 content::WebContents* embedder_web_contents =
607 GetFirstAppWindowWebContents();
608 if (!embedder_web_contents) {
609 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
610 return;
613 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
614 done_listener.set_failure_message("TEST_FAILED");
615 if (!content::ExecuteScript(
616 embedder_web_contents,
617 base::StringPrintf("runTest('%s')", test_name.c_str()))) {
618 LOG(ERROR) << "UNABLE TO START TEST.";
619 return;
621 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
624 content::WebContents* LoadGuest(const std::string& guest_path,
625 const std::string& app_path) {
626 GURL::Replacements replace_host;
627 replace_host.SetHostStr("localhost");
629 GURL guest_url = embedded_test_server()->GetURL(guest_path);
630 guest_url = guest_url.ReplaceComponents(replace_host);
632 ui_test_utils::UrlLoadObserver guest_observer(
633 guest_url, content::NotificationService::AllSources());
635 LoadAndLaunchPlatformApp(app_path.c_str(), "guest-loaded");
637 guest_observer.Wait();
638 content::Source<content::NavigationController> source =
639 guest_observer.source();
640 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
641 IsIsolatedGuest());
643 content::WebContents* guest_web_contents = source->GetWebContents();
644 return guest_web_contents;
647 // Runs media_access/allow tests.
648 void MediaAccessAPIAllowTestHelper(const std::string& test_name);
650 // Runs media_access/deny tests, each of them are run separately otherwise
651 // they timeout (mostly on Windows).
652 void MediaAccessAPIDenyTestHelper(const std::string& test_name) {
653 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
654 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
656 content::WebContents* embedder_web_contents =
657 GetFirstAppWindowWebContents();
658 ASSERT_TRUE(embedder_web_contents);
660 ExtensionTestMessageListener test_run_listener("PASSED", false);
661 test_run_listener.set_failure_message("FAILED");
662 EXPECT_TRUE(
663 content::ExecuteScript(
664 embedder_web_contents,
665 base::StringPrintf("startDenyTest('%s')", test_name.c_str())));
666 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied());
669 void LoadAppWithGuest(const std::string& app_path) {
670 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED",
671 false);
672 launched_listener.set_failure_message("WebViewTest.FAILURE");
673 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener);
675 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated();
678 void SendMessageToEmbedder(const std::string& message) {
679 EXPECT_TRUE(
680 content::ExecuteScript(
681 GetEmbedderWebContents(),
682 base::StringPrintf("onAppCommand('%s');", message.c_str())));
685 void SendMessageToGuestAndWait(const std::string& message,
686 const std::string& wait_message) {
687 scoped_ptr<ExtensionTestMessageListener> listener;
688 if (!wait_message.empty()) {
689 listener.reset(new ExtensionTestMessageListener(wait_message, false));
692 EXPECT_TRUE(
693 content::ExecuteScript(
694 GetGuestWebContents(),
695 base::StringPrintf("onAppCommand('%s');", message.c_str())));
697 if (listener) {
698 ASSERT_TRUE(listener->WaitUntilSatisfied());
702 content::WebContents* GetGuestWebContents() {
703 return guest_web_contents_;
706 content::WebContents* GetEmbedderWebContents() {
707 if (!embedder_web_contents_) {
708 embedder_web_contents_ = GetFirstAppWindowWebContents();
710 return embedder_web_contents_;
713 extensions::TestGuestViewManager* GetGuestViewManager() {
714 return static_cast<extensions::TestGuestViewManager*>(
715 extensions::TestGuestViewManager::FromBrowserContext(
716 browser()->profile()));
719 WebViewTest() : guest_web_contents_(NULL),
720 embedder_web_contents_(NULL) {
721 extensions::GuestViewManager::set_factory_for_testing(&factory_);
724 private:
725 bool UsesFakeSpeech() {
726 const testing::TestInfo* const test_info =
727 testing::UnitTest::GetInstance()->current_test_info();
729 // SpeechRecognition test specific SetUp.
730 return !strcmp(test_info->name(),
731 "SpeechRecognitionAPI_HasPermissionAllow");
734 scoped_ptr<content::FakeSpeechRecognitionManager>
735 fake_speech_recognition_manager_;
737 extensions::TestGuestViewManagerFactory factory_;
738 // Note that these are only set if you launch app using LoadAppWithGuest().
739 content::WebContents* guest_web_contents_;
740 content::WebContents* embedder_web_contents_;
743 class WebViewDPITest : public WebViewTest {
744 protected:
745 void SetUpCommandLine(base::CommandLine* command_line) override {
746 WebViewTest::SetUpCommandLine(command_line);
747 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
748 base::StringPrintf("%f", scale()));
751 static float scale() { return 2.0f; }
754 // This test verifies that hiding the guest triggers WebContents::WasHidden().
755 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) {
756 LoadAppWithGuest("web_view/visibility_changed");
758 scoped_refptr<content::MessageLoopRunner> loop_runner(
759 new content::MessageLoopRunner);
760 WebContentsHiddenObserver observer(GetGuestWebContents(),
761 loop_runner->QuitClosure());
763 // Handled in platform_apps/web_view/visibility_changed/main.js
764 SendMessageToEmbedder("hide-guest");
765 if (!observer.hidden_observed())
766 loop_runner->Run();
769 // This test verifies that hiding the embedder also hides the guest.
770 IN_PROC_BROWSER_TEST_F(WebViewTest, EmbedderVisibilityChanged) {
771 LoadAppWithGuest("web_view/visibility_changed");
773 scoped_refptr<content::MessageLoopRunner> loop_runner(
774 new content::MessageLoopRunner);
775 WebContentsHiddenObserver observer(GetGuestWebContents(),
776 loop_runner->QuitClosure());
778 // Handled in platform_apps/web_view/visibility_changed/main.js
779 SendMessageToEmbedder("hide-embedder");
780 if (!observer.hidden_observed())
781 loop_runner->Run();
784 // This test verifies that reloading the embedder reloads the guest (and doest
785 // not crash).
786 IN_PROC_BROWSER_TEST_F(WebViewTest, ReloadEmbedder) {
787 // Just load a guest from other test, we do not want to add a separate
788 // platform_app for this test.
789 LoadAppWithGuest("web_view/visibility_changed");
791 ExtensionTestMessageListener launched_again_listener("WebViewTest.LAUNCHED",
792 false);
793 GetEmbedderWebContents()->GetController().Reload(false);
794 ASSERT_TRUE(launched_again_listener.WaitUntilSatisfied());
797 IN_PROC_BROWSER_TEST_F(WebViewTest, AcceptTouchEvents) {
798 LoadAppWithGuest("web_view/accept_touch_events");
800 content::RenderViewHost* embedder_rvh =
801 GetEmbedderWebContents()->GetRenderViewHost();
803 bool embedder_has_touch_handler =
804 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
805 EXPECT_FALSE(embedder_has_touch_handler);
807 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
809 // Note that we need to wait for the installed/registered touch handler to
810 // appear in browser process before querying |embedder_rvh|.
811 // In practice, since we do a roundrtip from browser process to guest and
812 // back, this is sufficient.
813 embedder_has_touch_handler =
814 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
815 EXPECT_TRUE(embedder_has_touch_handler);
817 SendMessageToGuestAndWait("uninstall-touch-handler",
818 "uninstalled-touch-handler");
819 // Same as the note above about waiting.
820 embedder_has_touch_handler =
821 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
822 EXPECT_FALSE(embedder_has_touch_handler);
825 // This test ensures JavaScript errors ("Cannot redefine property") do not
826 // happen when a <webview> is removed from DOM and added back.
827 IN_PROC_BROWSER_TEST_F(WebViewTest,
828 AddRemoveWebView_AddRemoveWebView) {
829 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
830 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
831 << message_;
834 IN_PROC_BROWSER_TEST_F(WebViewTest, AutoSize) {
835 #if defined(OS_WIN)
836 // Flaky on XP bot http://crbug.com/299507
837 if (base::win::GetVersion() <= base::win::VERSION_XP)
838 return;
839 #endif
841 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
842 << message_;
845 // Test for http://crbug.com/419611.
846 IN_PROC_BROWSER_TEST_F(WebViewTest, DisplayNoneSetSrc) {
847 LoadAndLaunchPlatformApp("web_view/display_none_set_src",
848 "WebViewTest.LAUNCHED");
849 // Navigate the guest while it's in "display: none" state.
850 SendMessageToEmbedder("navigate-guest");
851 GetGuestViewManager()->WaitForSingleGuestCreated();
853 // Now attempt to navigate the guest again.
854 SendMessageToEmbedder("navigate-guest");
856 ExtensionTestMessageListener test_passed_listener("WebViewTest.PASSED",
857 false);
858 // Making the guest visible would trigger loadstop.
859 SendMessageToEmbedder("show-guest");
860 EXPECT_TRUE(test_passed_listener.WaitUntilSatisfied());
863 // Checks that {allFrames: true} injects script correctly to subframes
864 // inside <webview>.
865 IN_PROC_BROWSER_TEST_F(WebViewTest, ExecuteScript) {
866 ASSERT_TRUE(RunPlatformAppTestWithArg(
867 "platform_apps/web_view/common", "execute_script")) << message_;
870 // http://crbug.com/326332
871 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestAutosizeAfterNavigation) {
872 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER);
875 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAllowTransparencyAttribute) {
876 TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER);
879 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeHeight) {
880 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER);
883 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeHeight) {
884 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER);
887 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeBeforeNavigation) {
888 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
891 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeBeforeNavigation) {
892 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
895 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeRemoveAttributes) {
896 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
899 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeRemoveAttributes) {
900 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
903 // This test is disabled due to being flaky. http://crbug.com/282116
904 #if defined(OS_WIN) || defined(OS_MACOSX)
905 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
906 DISABLED_Shim_TestAutosizeWithPartialAttributes
907 #else
908 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
909 Shim_TestAutosizeWithPartialAttributes
910 #endif
911 IN_PROC_BROWSER_TEST_F(WebViewTest,
912 MAYBE_Shim_TestAutosizeWithPartialAttributes) {
913 TestHelper("testAutosizeWithPartialAttributes",
914 "web_view/shim",
915 NO_TEST_SERVER);
918 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) {
919 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER);
922 // Tests the existence of WebRequest API event objects on the request
923 // object, on the webview element, and hanging directly off webview.
924 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) {
925 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER);
928 // Tests the existence of DeclarativeContent API event objects on the request
929 // object, on the webview element, and hanging directly off webview.
930 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDeclarativeContentAPIExistence) {
931 TestHelper("testDeclarativeContentAPIExistence",
932 "web_view/shim",
933 NO_TEST_SERVER);
936 // http://crbug.com/315920
937 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
938 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
939 #else
940 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
941 #endif
942 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) {
943 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
946 // http://crbug.com/315920
947 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
948 #define MAYBE_Shim_TestChromeExtensionRelativePath \
949 DISABLED_Shim_TestChromeExtensionRelativePath
950 #else
951 #define MAYBE_Shim_TestChromeExtensionRelativePath \
952 Shim_TestChromeExtensionRelativePath
953 #endif
954 IN_PROC_BROWSER_TEST_F(WebViewTest,
955 MAYBE_Shim_TestChromeExtensionRelativePath) {
956 TestHelper("testChromeExtensionRelativePath",
957 "web_view/shim",
958 NO_TEST_SERVER);
961 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayNoneWebviewLoad) {
962 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER);
965 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayNoneWebviewRemoveChild) {
966 TestHelper("testDisplayNoneWebviewRemoveChild",
967 "web_view/shim", NO_TEST_SERVER);
970 IN_PROC_BROWSER_TEST_F(WebViewTest,
971 Shim_TestInlineScriptFromAccessibleResources) {
972 TestHelper("testInlineScriptFromAccessibleResources",
973 "web_view/shim",
974 NO_TEST_SERVER);
977 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestInvalidChromeExtensionURL) {
978 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
981 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestEventName) {
982 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER);
985 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestOnEventProperty) {
986 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER);
989 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadProgressEvent) {
990 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER);
993 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDestroyOnEventListener) {
994 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER);
997 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCannotMutateEventName) {
998 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER);
1001 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPartitionChangeAfterNavigation) {
1002 TestHelper("testPartitionChangeAfterNavigation",
1003 "web_view/shim",
1004 NO_TEST_SERVER);
1007 IN_PROC_BROWSER_TEST_F(WebViewTest,
1008 Shim_TestPartitionRemovalAfterNavigationFails) {
1009 TestHelper("testPartitionRemovalAfterNavigationFails",
1010 "web_view/shim",
1011 NO_TEST_SERVER);
1014 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScriptFail) {
1015 #if defined(OS_WIN)
1016 // Flaky on XP bot http://crbug.com/266185
1017 if (base::win::GetVersion() <= base::win::VERSION_XP)
1018 return;
1019 #endif
1021 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER);
1024 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScript) {
1025 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER);
1028 IN_PROC_BROWSER_TEST_F(
1029 WebViewTest,
1030 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged) {
1031 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
1032 "web_view/shim",
1033 NO_TEST_SERVER);
1036 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestTerminateAfterExit) {
1037 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER);
1040 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAssignSrcAfterCrash) {
1041 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER);
1044 IN_PROC_BROWSER_TEST_F(WebViewTest,
1045 Shim_TestNavOnConsecutiveSrcAttributeChanges) {
1046 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
1047 "web_view/shim",
1048 NO_TEST_SERVER);
1051 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavOnSrcAttributeChange) {
1052 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER);
1055 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigateAfterResize) {
1056 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER);
1059 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveSrcAttribute) {
1060 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER);
1063 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReassignSrcAttribute) {
1064 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER);
1067 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindow) {
1068 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER);
1071 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowTwoListeners) {
1072 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER);
1075 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoPreventDefault) {
1076 TestHelper("testNewWindowNoPreventDefault",
1077 "web_view/shim",
1078 NEEDS_TEST_SERVER);
1081 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoReferrerLink) {
1082 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER);
1085 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestContentLoadEvent) {
1086 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER);
1089 // TODO(fsamuel): Enable this test once <webview> can run in a detached state.
1090 IN_PROC_BROWSER_TEST_F(WebViewTest,
1091 Shim_TestContentLoadEventWithDisplayNone) {
1092 TestHelper("testContentLoadEventWithDisplayNone",
1093 "web_view/shim",
1094 NO_TEST_SERVER);
1097 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDeclarativeWebRequestAPI) {
1098 TestHelper("testDeclarativeWebRequestAPI",
1099 "web_view/shim",
1100 NEEDS_TEST_SERVER);
1103 IN_PROC_BROWSER_TEST_F(WebViewTest,
1104 Shim_TestDeclarativeWebRequestAPISendMessage) {
1105 TestHelper("testDeclarativeWebRequestAPISendMessage",
1106 "web_view/shim",
1107 NEEDS_TEST_SERVER);
1110 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPI) {
1111 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER);
1114 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIWithHeaders) {
1115 TestHelper("testWebRequestAPIWithHeaders",
1116 "web_view/shim",
1117 NEEDS_TEST_SERVER);
1120 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIGoogleProperty) {
1121 TestHelper("testWebRequestAPIGoogleProperty",
1122 "web_view/shim",
1123 NO_TEST_SERVER);
1126 // This test is disabled due to being flaky. http://crbug.com/309451
1127 #if defined(OS_WIN)
1128 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1129 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
1130 #else
1131 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
1132 Shim_TestWebRequestListenerSurvivesReparenting
1133 #endif
1134 IN_PROC_BROWSER_TEST_F(
1135 WebViewTest,
1136 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting) {
1137 TestHelper("testWebRequestListenerSurvivesReparenting",
1138 "web_view/shim",
1139 NEEDS_TEST_SERVER);
1142 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadStartLoadRedirect) {
1143 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER);
1146 IN_PROC_BROWSER_TEST_F(WebViewTest,
1147 Shim_TestLoadAbortChromeExtensionURLWrongPartition) {
1148 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1149 "web_view/shim",
1150 NO_TEST_SERVER);
1153 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortEmptyResponse) {
1154 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER);
1157 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalChromeURL) {
1158 TestHelper("testLoadAbortIllegalChromeURL",
1159 "web_view/shim",
1160 NO_TEST_SERVER);
1163 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalFileURL) {
1164 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER);
1167 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalJavaScriptURL) {
1168 TestHelper("testLoadAbortIllegalJavaScriptURL",
1169 "web_view/shim",
1170 NO_TEST_SERVER);
1173 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortInvalidNavigation) {
1174 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER);
1177 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortNonWebSafeScheme) {
1178 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER);
1181 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) {
1182 TestHelper("testReload", "web_view/shim", NO_TEST_SERVER);
1185 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReloadAfterTerminate) {
1186 TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER);
1189 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) {
1190 TestHelper("testGetProcessId", "web_view/shim", NO_TEST_SERVER);
1193 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestHiddenBeforeNavigation) {
1194 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
1197 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) {
1198 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1200 // Launch the app and wait until it's ready to load a test.
1201 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1203 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1204 ASSERT_TRUE(embedder_web_contents);
1206 GURL::Replacements replace_host;
1207 replace_host.SetHostStr("localhost");
1209 std::string guest_path(
1210 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1211 GURL guest_url = embedded_test_server()->GetURL(guest_path);
1212 guest_url = guest_url.ReplaceComponents(replace_host);
1214 ui_test_utils::UrlLoadObserver guest_observer(
1215 guest_url, content::NotificationService::AllSources());
1217 // Run the test and wait until the guest WebContents is available and has
1218 // finished loading.
1219 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
1220 EXPECT_TRUE(content::ExecuteScript(
1221 embedder_web_contents,
1222 "runTest('testRemoveWebviewOnExit')"));
1223 guest_observer.Wait();
1225 content::Source<content::NavigationController> source =
1226 guest_observer.source();
1227 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
1228 IsIsolatedGuest());
1230 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
1232 content::WebContentsDestroyedWatcher destroyed_watcher(
1233 source->GetWebContents());
1235 // Tell the embedder to kill the guest.
1236 EXPECT_TRUE(content::ExecuteScript(
1237 embedder_web_contents,
1238 "removeWebviewOnExitDoCrash();"));
1240 // Wait until the guest WebContents is destroyed.
1241 destroyed_watcher.Wait();
1244 // Remove <webview> immediately after navigating it.
1245 // This is a regression test for http://crbug.com/276023.
1246 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewAfterNavigation) {
1247 TestHelper("testRemoveWebviewAfterNavigation",
1248 "web_view/shim",
1249 NO_TEST_SERVER);
1252 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigationToExternalProtocol) {
1253 TestHelper("testNavigationToExternalProtocol",
1254 "web_view/shim",
1255 NO_TEST_SERVER);
1258 IN_PROC_BROWSER_TEST_F(WebViewTest,
1259 Shim_TestResizeWebviewWithDisplayNoneResizesContent) {
1260 TestHelper("testResizeWebviewWithDisplayNoneResizesContent",
1261 "web_view/shim",
1262 NO_TEST_SERVER);
1265 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestResizeWebviewResizesContent) {
1266 TestHelper("testResizeWebviewResizesContent",
1267 "web_view/shim",
1268 NO_TEST_SERVER);
1271 // This test makes sure we do not crash if app is closed while interstitial
1272 // page is being shown in guest.
1273 IN_PROC_BROWSER_TEST_F(WebViewTest, InterstitialTeardown) {
1274 #if defined(OS_WIN)
1275 // Flaky on XP bot http://crbug.com/297014
1276 if (base::win::GetVersion() <= base::win::VERSION_XP)
1277 return;
1278 #endif
1280 // Start a HTTPS server so we can load an interstitial page inside guest.
1281 net::SpawnedTestServer::SSLOptions ssl_options;
1282 ssl_options.server_certificate =
1283 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
1284 net::SpawnedTestServer https_server(
1285 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
1286 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1287 ASSERT_TRUE(https_server.Start());
1289 net::HostPortPair host_and_port = https_server.host_port_pair();
1291 LoadAndLaunchPlatformApp("web_view/interstitial_teardown", "EmbedderLoaded");
1293 // Now load the guest.
1294 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1295 ExtensionTestMessageListener second("GuestAddedToDom", false);
1296 EXPECT_TRUE(content::ExecuteScript(
1297 embedder_web_contents,
1298 base::StringPrintf("loadGuest(%d);\n", host_and_port.port())));
1299 ASSERT_TRUE(second.WaitUntilSatisfied());
1301 // Wait for interstitial page to be shown in guest.
1302 content::WebContents* guest_web_contents =
1303 GetGuestViewManager()->WaitForSingleGuestCreated();
1304 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest());
1305 content::WaitForInterstitialAttach(guest_web_contents);
1307 // Now close the app while interstitial page being shown in guest.
1308 extensions::AppWindow* window = GetFirstAppWindow();
1309 window->GetBaseWindow()->Close();
1312 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) {
1313 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1314 << message_;
1317 // This test verifies that prerendering has been disabled inside <webview>.
1318 // This test is here rather than in PrerenderBrowserTest for testing convenience
1319 // only. If it breaks then this is a bug in the prerenderer.
1320 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) {
1321 ASSERT_TRUE(StartEmbeddedTestServer());
1322 content::WebContents* guest_web_contents =
1323 LoadGuest(
1324 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1325 "web_view/noprerenderer");
1326 ASSERT_TRUE(guest_web_contents != NULL);
1328 PrerenderLinkManager* prerender_link_manager =
1329 PrerenderLinkManagerFactory::GetForProfile(
1330 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext()));
1331 ASSERT_TRUE(prerender_link_manager != NULL);
1332 EXPECT_TRUE(prerender_link_manager->IsEmpty());
1335 // Verify that existing <webview>'s are detected when the task manager starts
1336 // up.
1337 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerExistingWebView) {
1338 ASSERT_TRUE(StartEmbeddedTestServer());
1340 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1341 "web_view/task_manager");
1343 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1345 const char* guest_title = "WebViewed test content";
1346 const char* app_name = "<webview> task manager test";
1347 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1348 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1349 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1350 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1352 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1353 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1354 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1355 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1358 // Verify that the task manager notices the creation of new <webview>'s.
1359 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerNewWebView) {
1360 ASSERT_TRUE(StartEmbeddedTestServer());
1362 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1364 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1365 "web_view/task_manager");
1367 const char* guest_title = "WebViewed test content";
1368 const char* app_name = "<webview> task manager test";
1369 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1370 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1371 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1372 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1374 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1375 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1376 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1377 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1380 // This tests cookie isolation for packaged apps with webview tags. It navigates
1381 // the main browser window to a page that sets a cookie and loads an app with
1382 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1383 // storage isolation is enforced.
1384 // This test is flaky. See http://crbug.com/294196.
1385 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_CookieIsolation) {
1386 ASSERT_TRUE(StartEmbeddedTestServer());
1387 const std::string kExpire =
1388 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1389 std::string cookie_script1(kExpire);
1390 cookie_script1.append(
1391 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1392 std::string cookie_script2(kExpire);
1393 cookie_script2.append(
1394 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1396 GURL::Replacements replace_host;
1397 replace_host.SetHostStr("localhost");
1399 GURL set_cookie_url = embedded_test_server()->GetURL(
1400 "/extensions/platform_apps/isolation/set_cookie.html");
1401 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
1403 // The first two partitions will be used to set cookies and ensure they are
1404 // shared. The named partition is used to ensure that cookies are isolated
1405 // between partitions within the same app.
1406 content::WebContents* cookie_contents1;
1407 content::WebContents* cookie_contents2;
1408 content::WebContents* named_partition_contents1;
1409 content::WebContents* named_partition_contents2;
1411 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1,
1412 &cookie_contents2, &named_partition_contents1,
1413 &named_partition_contents2, NULL, NULL, NULL);
1415 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
1416 EXPECT_TRUE(content::ExecuteScript(cookie_contents2, cookie_script2));
1418 int cookie_size;
1419 std::string cookie_value;
1421 // Test the regular browser context to ensure we have only one cookie.
1422 ui_test_utils::GetCookies(GURL("http://localhost"),
1423 browser()->tab_strip_model()->GetWebContentsAt(0),
1424 &cookie_size, &cookie_value);
1425 EXPECT_EQ("testCookie=1", cookie_value);
1427 // The default behavior is to combine webview tags with no explicit partition
1428 // declaration into the same in-memory partition. Test the webview tags to
1429 // ensure we have properly set the cookies and we have both cookies in both
1430 // tags.
1431 ui_test_utils::GetCookies(GURL("http://localhost"),
1432 cookie_contents1,
1433 &cookie_size, &cookie_value);
1434 EXPECT_EQ("guest1=true; guest2=true", cookie_value);
1436 ui_test_utils::GetCookies(GURL("http://localhost"),
1437 cookie_contents2,
1438 &cookie_size, &cookie_value);
1439 EXPECT_EQ("guest1=true; guest2=true", cookie_value);
1441 // The third tag should not have any cookies as it is in a separate partition.
1442 ui_test_utils::GetCookies(GURL("http://localhost"),
1443 named_partition_contents1,
1444 &cookie_size, &cookie_value);
1445 EXPECT_EQ("", cookie_value);
1448 // This tests that in-memory storage partitions are reset on browser restart,
1449 // but persistent ones maintain state for cookies and HTML5 storage.
1450 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) {
1451 ASSERT_TRUE(StartEmbeddedTestServer());
1452 const std::string kExpire =
1453 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1454 std::string cookie_script1(kExpire);
1455 cookie_script1.append(
1456 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1457 std::string cookie_script2(kExpire);
1458 cookie_script2.append(
1459 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1460 std::string cookie_script3(kExpire);
1461 cookie_script3.append(
1462 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1464 // We don't care where the main browser is on this test.
1465 GURL blank_url("about:blank");
1467 // The first two partitions will be used to set cookies and ensure they are
1468 // shared. The named partition is used to ensure that cookies are isolated
1469 // between partitions within the same app.
1470 content::WebContents* cookie_contents1;
1471 content::WebContents* cookie_contents2;
1472 content::WebContents* named_partition_contents1;
1473 content::WebContents* named_partition_contents2;
1474 content::WebContents* persistent_partition_contents1;
1475 content::WebContents* persistent_partition_contents2;
1476 content::WebContents* persistent_partition_contents3;
1477 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
1478 &cookie_contents2, &named_partition_contents1,
1479 &named_partition_contents2,
1480 &persistent_partition_contents1,
1481 &persistent_partition_contents2,
1482 &persistent_partition_contents3);
1484 // Set the inmemory=true cookie for tags with inmemory partitions.
1485 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
1486 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1,
1487 cookie_script1));
1489 // For the two different persistent storage partitions, set the
1490 // two different cookies so we can check that they aren't comingled below.
1491 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1,
1492 cookie_script2));
1494 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3,
1495 cookie_script3));
1497 int cookie_size;
1498 std::string cookie_value;
1500 // Check that all in-memory partitions have a cookie set.
1501 ui_test_utils::GetCookies(GURL("http://localhost"),
1502 cookie_contents1,
1503 &cookie_size, &cookie_value);
1504 EXPECT_EQ("inmemory=true", cookie_value);
1505 ui_test_utils::GetCookies(GURL("http://localhost"),
1506 cookie_contents2,
1507 &cookie_size, &cookie_value);
1508 EXPECT_EQ("inmemory=true", cookie_value);
1509 ui_test_utils::GetCookies(GURL("http://localhost"),
1510 named_partition_contents1,
1511 &cookie_size, &cookie_value);
1512 EXPECT_EQ("inmemory=true", cookie_value);
1513 ui_test_utils::GetCookies(GURL("http://localhost"),
1514 named_partition_contents2,
1515 &cookie_size, &cookie_value);
1516 EXPECT_EQ("inmemory=true", cookie_value);
1518 // Check that all persistent partitions kept their state.
1519 ui_test_utils::GetCookies(GURL("http://localhost"),
1520 persistent_partition_contents1,
1521 &cookie_size, &cookie_value);
1522 EXPECT_EQ("persist1=true", cookie_value);
1523 ui_test_utils::GetCookies(GURL("http://localhost"),
1524 persistent_partition_contents2,
1525 &cookie_size, &cookie_value);
1526 EXPECT_EQ("persist1=true", cookie_value);
1527 ui_test_utils::GetCookies(GURL("http://localhost"),
1528 persistent_partition_contents3,
1529 &cookie_size, &cookie_value);
1530 EXPECT_EQ("persist2=true", cookie_value);
1533 // This is the post-reset portion of the StoragePersistence test. See
1534 // PRE_StoragePersistence for main comment.
1535 #if defined(OS_CHROMEOS)
1536 // http://crbug.com/223888
1537 #define MAYBE_StoragePersistence DISABLED_StoragePersistence
1538 #else
1539 #define MAYBE_StoragePersistence StoragePersistence
1540 #endif
1541 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_StoragePersistence) {
1542 ASSERT_TRUE(StartEmbeddedTestServer());
1544 // We don't care where the main browser is on this test.
1545 GURL blank_url("about:blank");
1547 // The first two partitions will be used to set cookies and ensure they are
1548 // shared. The named partition is used to ensure that cookies are isolated
1549 // between partitions within the same app.
1550 content::WebContents* cookie_contents1;
1551 content::WebContents* cookie_contents2;
1552 content::WebContents* named_partition_contents1;
1553 content::WebContents* named_partition_contents2;
1554 content::WebContents* persistent_partition_contents1;
1555 content::WebContents* persistent_partition_contents2;
1556 content::WebContents* persistent_partition_contents3;
1557 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
1558 &cookie_contents2, &named_partition_contents1,
1559 &named_partition_contents2,
1560 &persistent_partition_contents1,
1561 &persistent_partition_contents2,
1562 &persistent_partition_contents3);
1564 int cookie_size;
1565 std::string cookie_value;
1567 // Check that all in-memory partitions lost their state.
1568 ui_test_utils::GetCookies(GURL("http://localhost"),
1569 cookie_contents1,
1570 &cookie_size, &cookie_value);
1571 EXPECT_EQ("", cookie_value);
1572 ui_test_utils::GetCookies(GURL("http://localhost"),
1573 cookie_contents2,
1574 &cookie_size, &cookie_value);
1575 EXPECT_EQ("", cookie_value);
1576 ui_test_utils::GetCookies(GURL("http://localhost"),
1577 named_partition_contents1,
1578 &cookie_size, &cookie_value);
1579 EXPECT_EQ("", cookie_value);
1580 ui_test_utils::GetCookies(GURL("http://localhost"),
1581 named_partition_contents2,
1582 &cookie_size, &cookie_value);
1583 EXPECT_EQ("", cookie_value);
1585 // Check that all persistent partitions kept their state.
1586 ui_test_utils::GetCookies(GURL("http://localhost"),
1587 persistent_partition_contents1,
1588 &cookie_size, &cookie_value);
1589 EXPECT_EQ("persist1=true", cookie_value);
1590 ui_test_utils::GetCookies(GURL("http://localhost"),
1591 persistent_partition_contents2,
1592 &cookie_size, &cookie_value);
1593 EXPECT_EQ("persist1=true", cookie_value);
1594 ui_test_utils::GetCookies(GURL("http://localhost"),
1595 persistent_partition_contents3,
1596 &cookie_size, &cookie_value);
1597 EXPECT_EQ("persist2=true", cookie_value);
1600 // This tests DOM storage isolation for packaged apps with webview tags. It
1601 // loads an app with multiple webview tags and each tag sets DOM storage
1602 // entries, which the test checks to ensure proper storage isolation is
1603 // enforced.
1604 // Times out regularly on Windows. See http://crbug.com/248873.
1605 #if defined(OS_WIN)
1606 #define MAYBE_DOMStorageIsolation DISABLED_DOMStorageIsolation
1607 #else
1608 #define MAYBE_DOMStorageIsolation DOMStorageIsolation
1609 #endif
1610 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_DOMStorageIsolation) {
1611 ASSERT_TRUE(StartEmbeddedTestServer());
1612 GURL regular_url = embedded_test_server()->GetURL("/title1.html");
1614 std::string output;
1615 std::string get_local_storage("window.domAutomationController.send("
1616 "window.localStorage.getItem('foo') || 'badval')");
1617 std::string get_session_storage("window.domAutomationController.send("
1618 "window.sessionStorage.getItem('bar') || 'badval')");
1620 content::WebContents* default_tag_contents1;
1621 content::WebContents* default_tag_contents2;
1622 content::WebContents* storage_contents1;
1623 content::WebContents* storage_contents2;
1625 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
1626 &default_tag_contents2, &storage_contents1,
1627 &storage_contents2, NULL, NULL, NULL);
1629 // Initialize the storage for the first of the two tags that share a storage
1630 // partition.
1631 EXPECT_TRUE(content::ExecuteScript(storage_contents1,
1632 "initDomStorage('page1')"));
1634 // Let's test that the expected values are present in the first tag, as they
1635 // will be overwritten once we call the initDomStorage on the second tag.
1636 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1637 get_local_storage.c_str(),
1638 &output));
1639 EXPECT_STREQ("local-page1", output.c_str());
1640 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1641 get_session_storage.c_str(),
1642 &output));
1643 EXPECT_STREQ("session-page1", output.c_str());
1645 // Now, init the storage in the second tag in the same storage partition,
1646 // which will overwrite the shared localStorage.
1647 EXPECT_TRUE(content::ExecuteScript(storage_contents2,
1648 "initDomStorage('page2')"));
1650 // The localStorage value now should reflect the one written through the
1651 // second tag.
1652 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1653 get_local_storage.c_str(),
1654 &output));
1655 EXPECT_STREQ("local-page2", output.c_str());
1656 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1657 get_local_storage.c_str(),
1658 &output));
1659 EXPECT_STREQ("local-page2", output.c_str());
1661 // Session storage is not shared though, as each webview tag has separate
1662 // instance, even if they are in the same storage partition.
1663 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1664 get_session_storage.c_str(),
1665 &output));
1666 EXPECT_STREQ("session-page1", output.c_str());
1667 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1668 get_session_storage.c_str(),
1669 &output));
1670 EXPECT_STREQ("session-page2", output.c_str());
1672 // Also, let's check that the main browser and another tag that doesn't share
1673 // the same partition don't have those values stored.
1674 EXPECT_TRUE(ExecuteScriptAndExtractString(
1675 browser()->tab_strip_model()->GetWebContentsAt(0),
1676 get_local_storage.c_str(),
1677 &output));
1678 EXPECT_STREQ("badval", output.c_str());
1679 EXPECT_TRUE(ExecuteScriptAndExtractString(
1680 browser()->tab_strip_model()->GetWebContentsAt(0),
1681 get_session_storage.c_str(),
1682 &output));
1683 EXPECT_STREQ("badval", output.c_str());
1684 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
1685 get_local_storage.c_str(),
1686 &output));
1687 EXPECT_STREQ("badval", output.c_str());
1688 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
1689 get_session_storage.c_str(),
1690 &output));
1691 EXPECT_STREQ("badval", output.c_str());
1694 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1695 // an app with multiple webview tags and each tag creates an IndexedDB record,
1696 // which the test checks to ensure proper storage isolation is enforced.
1697 // This test is flaky. See http://crbug.com/248500.
1698 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_IndexedDBIsolation) {
1699 ASSERT_TRUE(StartEmbeddedTestServer());
1700 GURL regular_url = embedded_test_server()->GetURL("/title1.html");
1702 content::WebContents* default_tag_contents1;
1703 content::WebContents* default_tag_contents2;
1704 content::WebContents* storage_contents1;
1705 content::WebContents* storage_contents2;
1707 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
1708 &default_tag_contents2, &storage_contents1,
1709 &storage_contents2, NULL, NULL, NULL);
1711 // Initialize the storage for the first of the two tags that share a storage
1712 // partition.
1713 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created");
1714 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')",
1715 "addItemIDB complete");
1716 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
1717 "readItemIDB complete");
1719 std::string output;
1720 std::string get_value(
1721 "window.domAutomationController.send(getValueIDB() || 'badval')");
1723 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1724 get_value.c_str(), &output));
1725 EXPECT_STREQ("page1", output.c_str());
1727 // Initialize the db in the second tag.
1728 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open");
1730 // Since we share a partition, reading the value should return the existing
1731 // one.
1732 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
1733 "readItemIDB complete");
1734 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1735 get_value.c_str(), &output));
1736 EXPECT_STREQ("page1", output.c_str());
1738 // Now write through the second tag and read it back.
1739 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')",
1740 "addItemIDB complete");
1741 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
1742 "readItemIDB complete");
1743 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1744 get_value.c_str(), &output));
1745 EXPECT_STREQ("page2", output.c_str());
1747 // Reset the document title, otherwise the next call will not see a change and
1748 // will hang waiting for it.
1749 EXPECT_TRUE(content::ExecuteScript(storage_contents1,
1750 "document.title = 'foo'"));
1752 // Read through the first tag to ensure we have the second value.
1753 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
1754 "readItemIDB complete");
1755 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1756 get_value.c_str(), &output));
1757 EXPECT_STREQ("page2", output.c_str());
1759 // Now, let's confirm there is no database in the main browser and another
1760 // tag that doesn't share the same partition. Due to the IndexedDB API design,
1761 // open will succeed, but the version will be 1, since it creates the database
1762 // if it is not found. The two tags use database version 3, so we avoid
1763 // ambiguity.
1764 const char* script =
1765 "indexedDB.open('isolation').onsuccess = function(e) {"
1766 " if (e.target.result.version == 1)"
1767 " document.title = 'db not found';"
1768 " else "
1769 " document.title = 'error';"
1770 "}";
1771 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1772 script, "db not found");
1773 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
1776 // This test ensures that closing app window on 'loadcommit' does not crash.
1777 // The test launches an app with guest and closes the window on loadcommit. It
1778 // then launches the app window again. The process is repeated 3 times.
1779 // http://crbug.com/291278
1780 #if defined(OS_WIN)
1781 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1782 #else
1783 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1784 #endif
1785 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CloseOnLoadcommit) {
1786 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1787 "done-close-on-loadcommit");
1790 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny_TestDeny) {
1791 MediaAccessAPIDenyTestHelper("testDeny");
1794 IN_PROC_BROWSER_TEST_F(WebViewTest,
1795 MediaAccessAPIDeny_TestDenyThenAllowThrows) {
1796 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1799 IN_PROC_BROWSER_TEST_F(WebViewTest,
1800 MediaAccessAPIDeny_TestDenyWithPreventDefault) {
1801 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1804 IN_PROC_BROWSER_TEST_F(WebViewTest,
1805 MediaAccessAPIDeny_TestNoListenersImplyDeny) {
1806 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1809 IN_PROC_BROWSER_TEST_F(WebViewTest,
1810 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny) {
1811 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1814 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string& test_name) {
1815 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1816 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1818 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1819 ASSERT_TRUE(embedder_web_contents);
1820 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
1821 embedder_web_contents->SetDelegate(mock.get());
1823 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1824 done_listener.set_failure_message("TEST_FAILED");
1825 EXPECT_TRUE(
1826 content::ExecuteScript(
1827 embedder_web_contents,
1828 base::StringPrintf("startAllowTest('%s')",
1829 test_name.c_str())));
1830 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1832 mock->WaitForRequestMediaPermission();
1835 IN_PROC_BROWSER_TEST_F(WebViewTest, OpenURLFromTab_CurrentTab_Abort) {
1836 LoadAppWithGuest("web_view/simple");
1838 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will
1839 // navigate the current <webview>.
1840 ExtensionTestMessageListener load_listener("WebViewTest.LOADSTOP", false);
1842 // Navigating to a file URL is forbidden inside a <webview>.
1843 content::OpenURLParams params(GURL("file://foo"),
1844 content::Referrer(),
1845 CURRENT_TAB,
1846 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1847 true /* is_renderer_initiated */);
1848 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1849 GetGuestWebContents(), params);
1851 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
1853 // Verify that the <webview> ends up at about:blank.
1854 EXPECT_EQ(GURL(url::kAboutBlankURL),
1855 GetGuestWebContents()->GetLastCommittedURL());
1858 IN_PROC_BROWSER_TEST_F(WebViewTest, OpenURLFromTab_NewWindow_Abort) {
1859 LoadAppWithGuest("web_view/simple");
1861 // Verify that OpenURLFromTab with a window disposition of NEW_BACKGROUND_TAB
1862 // will trigger the <webview>'s New Window API.
1863 ExtensionTestMessageListener new_window_listener(
1864 "WebViewTest.NEWWINDOW", false);
1866 // Navigating to a file URL is forbidden inside a <webview>.
1867 content::OpenURLParams params(GURL("file://foo"),
1868 content::Referrer(),
1869 NEW_BACKGROUND_TAB,
1870 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1871 true /* is_renderer_initiated */);
1872 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1873 GetGuestWebContents(), params);
1875 ASSERT_TRUE(new_window_listener.WaitUntilSatisfied());
1877 // Verify that a new guest was created.
1878 content::WebContents* new_guest_web_contents =
1879 GetGuestViewManager()->GetLastGuestCreated();
1880 EXPECT_NE(GetGuestWebContents(), new_guest_web_contents);
1882 // Verify that the new <webview> guest ends up at about:blank.
1883 EXPECT_EQ(GURL(url::kAboutBlankURL),
1884 new_guest_web_contents->GetLastCommittedURL());
1887 // This test executes the context menu command 'LanguageSettings' which will
1888 // load chrome://settings/languages in a browser window. This is a browser-
1889 // initiated operation and so we expect this to succeed if the embedder is
1890 // allowed to perform the operation.
1891 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenuLanguageSettings) {
1892 LoadAppWithGuest("web_view/context_menus/basic");
1894 content::WebContents* guest_web_contents = GetGuestWebContents();
1895 content::WebContents* embedder = GetEmbedderWebContents();
1896 ASSERT_TRUE(embedder);
1898 // Create and build our test context menu.
1899 content::WebContentsAddedObserver web_contents_added_observer;
1901 GURL page_url("http://www.google.com");
1902 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1903 guest_web_contents, page_url, GURL(), GURL()));
1904 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, 0);
1906 content::WebContents* new_contents =
1907 web_contents_added_observer.GetWebContents();
1909 // Verify that a new WebContents has been created that is at the Language
1910 // Settings page.
1911 EXPECT_EQ(GURL("chrome://settings/languages"),
1912 new_contents->GetVisibleURL());
1915 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) {
1916 LoadAppWithGuest("web_view/context_menus/basic");
1918 content::WebContents* guest_web_contents = GetGuestWebContents();
1919 content::WebContents* embedder = GetEmbedderWebContents();
1920 ASSERT_TRUE(embedder);
1922 // 1. Basic property test.
1923 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED");
1925 // 2. Create a menu item and wait for created callback to be called.
1926 ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED");
1928 // 3. Click the created item, wait for the click handlers to fire from JS.
1929 ExtensionTestMessageListener click_listener("ITEM_CLICKED", false);
1930 GURL page_url("http://www.google.com");
1931 // Create and build our test context menu.
1932 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1933 guest_web_contents, page_url, GURL(), GURL()));
1935 // Look for the extension item in the menu, and execute it.
1936 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1937 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id));
1938 menu->ExecuteCommand(command_id, 0);
1940 // Wait for embedder's script to tell us its onclick fired, it does
1941 // chrome.test.sendMessage('ITEM_CLICKED')
1942 ASSERT_TRUE(click_listener.WaitUntilSatisfied());
1944 // 4. Update the item's title and verify.
1945 ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED");
1946 MenuItem::List items = GetItems();
1947 ASSERT_EQ(1u, items.size());
1948 MenuItem* item = items.at(0);
1949 EXPECT_EQ("new_title", item->title());
1951 // 5. Remove the item.
1952 ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED");
1953 MenuItem::List items_after_removal = GetItems();
1954 ASSERT_EQ(0u, items_after_removal.size());
1956 // 6. Add some more items.
1957 ExecuteScriptWaitForTitle(
1958 embedder, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1959 MenuItem::List items_after_insertion = GetItems();
1960 ASSERT_EQ(3u, items_after_insertion.size());
1962 // 7. Test removeAll().
1963 ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED");
1964 MenuItem::List items_after_all_removal = GetItems();
1965 ASSERT_EQ(0u, items_after_all_removal.size());
1968 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) {
1969 MediaAccessAPIAllowTestHelper("testAllow");
1972 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) {
1973 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1976 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) {
1977 MediaAccessAPIAllowTestHelper("testAllowTwice");
1980 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAsync) {
1981 MediaAccessAPIAllowTestHelper("testAllowAsync");
1984 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestCheck) {
1985 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1986 LoadAndLaunchPlatformApp("web_view/media_access/check", "Launched");
1988 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1989 ASSERT_TRUE(embedder_web_contents);
1990 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
1991 embedder_web_contents->SetDelegate(mock.get());
1993 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1994 done_listener.set_failure_message("TEST_FAILED");
1995 EXPECT_TRUE(
1996 content::ExecuteScript(
1997 embedder_web_contents,
1998 base::StringPrintf("startCheckTest('')")));
1999 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
2001 mock->WaitForCheckMediaPermission();
2004 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
2005 // guests.
2006 IN_PROC_BROWSER_TEST_F(WebViewTest, ScreenCoordinates) {
2007 ASSERT_TRUE(RunPlatformAppTestWithArg(
2008 "platform_apps/web_view/common", "screen_coordinates"))
2009 << message_;
2012 #if defined(OS_CHROMEOS)
2013 IN_PROC_BROWSER_TEST_F(WebViewTest, ChromeVoxInjection) {
2014 EXPECT_FALSE(
2015 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
2017 ASSERT_TRUE(StartEmbeddedTestServer());
2018 content::WebContents* guest_web_contents = LoadGuest(
2019 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
2020 "web_view/chromevox_injection");
2021 ASSERT_TRUE(guest_web_contents);
2023 chromeos::SpeechMonitor monitor;
2024 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
2025 true, ui::A11Y_NOTIFICATION_NONE);
2026 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
2028 EXPECT_EQ("chrome vox test title", monitor.GetNextUtterance());
2030 #endif
2032 // Flaky on Windows. http://crbug.com/303966
2033 #if defined(OS_WIN)
2034 #define MAYBE_TearDownTest DISABLED_TearDownTest
2035 #else
2036 #define MAYBE_TearDownTest TearDownTest
2037 #endif
2038 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) {
2039 const extensions::Extension* extension =
2040 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
2041 extensions::AppWindow* window = NULL;
2042 if (!GetAppWindowCount())
2043 window = CreateAppWindow(extension);
2044 else
2045 window = GetFirstAppWindow();
2046 CloseAppWindow(window);
2048 // Load the app again.
2049 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
2052 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
2053 // platform app) does not have geolocation permission for this test.
2054 // No matter what the API does, geolocation permission would be denied.
2055 // Note that the test name prefix must be "GeolocationAPI".
2056 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) {
2057 TestHelper("testDenyDenies",
2058 "web_view/geolocation/embedder_has_no_permission",
2059 NEEDS_TEST_SERVER);
2062 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessDeny) {
2063 TestHelper("testDenyDenies",
2064 "web_view/geolocation/embedder_has_no_permission",
2065 NEEDS_TEST_SERVER);
2068 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
2069 // platform app) has geolocation permission
2071 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
2072 // geolocation in this case).
2074 // Also note that these are run separately because OverrideGeolocation() doesn't
2075 // mock out geolocation for multiple navigator.geolocation calls properly and
2076 // the tests become flaky.
2077 // GeolocationAPI* test 1 of 3.
2078 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessAllow) {
2079 TestHelper("testAllow",
2080 "web_view/geolocation/embedder_has_permission",
2081 NEEDS_TEST_SERVER);
2084 // GeolocationAPI* test 2 of 3.
2085 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessDeny) {
2086 TestHelper("testDeny",
2087 "web_view/geolocation/embedder_has_permission",
2088 NEEDS_TEST_SERVER);
2091 // GeolocationAPI* test 3 of 3.
2092 IN_PROC_BROWSER_TEST_F(WebViewTest,
2093 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow) {
2094 TestHelper("testMultipleBridgeIdAllow",
2095 "web_view/geolocation/embedder_has_permission",
2096 NEEDS_TEST_SERVER);
2099 // Tests that
2100 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
2101 // is handled correctly (and does not crash).
2102 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPICancelGeolocation) {
2103 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2104 ASSERT_TRUE(RunPlatformAppTest(
2105 "platform_apps/web_view/geolocation/cancel_request")) << message_;
2108 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_GeolocationRequestGone) {
2109 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2110 ASSERT_TRUE(RunPlatformAppTest(
2111 "platform_apps/web_view/geolocation/geolocation_request_gone"))
2112 << message_;
2115 // In following FilesystemAPIRequestFromMainThread* tests, guest request
2116 // filesystem access from main thread of the guest.
2117 // FileSystemAPIRequestFromMainThread* test 1 of 3
2118 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromMainThreadAllow) {
2119 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER);
2122 // FileSystemAPIRequestFromMainThread* test 2 of 3.
2123 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromMainThreadDeny) {
2124 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER);
2127 // FileSystemAPIRequestFromMainThread* test 3 of 3.
2128 IN_PROC_BROWSER_TEST_F(WebViewTest,
2129 FileSystemAPIRequestFromMainThreadDefaultAllow) {
2130 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER);
2133 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
2134 // to request filesystem access from worker thread.
2135 // FileSystemAPIRequestFromWorker* test 1 of 3
2136 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromWorkerAllow) {
2137 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
2140 // FileSystemAPIRequestFromWorker* test 2 of 3.
2141 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromWorkerDeny) {
2142 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
2145 // FileSystemAPIRequestFromWorker* test 3 of 3.
2146 IN_PROC_BROWSER_TEST_F(WebViewTest,
2147 FileSystemAPIRequestFromWorkerDefaultAllow) {
2148 TestHelper(
2149 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
2152 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
2153 // embedder contains a single webview guest. The guest creates a shared worker
2154 // to request filesystem access from worker thread.
2155 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
2156 IN_PROC_BROWSER_TEST_F(
2157 WebViewTest,
2158 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow) {
2159 TestHelper("testAllow",
2160 "web_view/filesystem/shared_worker/single",
2161 NEEDS_TEST_SERVER);
2164 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
2165 IN_PROC_BROWSER_TEST_F(
2166 WebViewTest,
2167 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny) {
2168 TestHelper("testDeny",
2169 "web_view/filesystem/shared_worker/single",
2170 NEEDS_TEST_SERVER);
2173 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2174 IN_PROC_BROWSER_TEST_F(
2175 WebViewTest,
2176 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow) {
2177 TestHelper(
2178 "testDefaultAllow",
2179 "web_view/filesystem/shared_worker/single",
2180 NEEDS_TEST_SERVER);
2183 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2184 // embedder contains mutiple webview guests. Each guest creates a shared worker
2185 // to request filesystem access from worker thread.
2186 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2187 IN_PROC_BROWSER_TEST_F(
2188 WebViewTest,
2189 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow) {
2190 TestHelper("testAllow",
2191 "web_view/filesystem/shared_worker/multiple",
2192 NEEDS_TEST_SERVER);
2195 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2196 IN_PROC_BROWSER_TEST_F(
2197 WebViewTest,
2198 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny) {
2199 TestHelper("testDeny",
2200 "web_view/filesystem/shared_worker/multiple",
2201 NEEDS_TEST_SERVER);
2204 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2205 IN_PROC_BROWSER_TEST_F(
2206 WebViewTest,
2207 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow) {
2208 TestHelper(
2209 "testDefaultAllow",
2210 "web_view/filesystem/shared_worker/multiple",
2211 NEEDS_TEST_SERVER);
2214 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearData) {
2215 #if defined(OS_WIN)
2216 // Flaky on XP bot http://crbug.com/282674
2217 if (base::win::GetVersion() <= base::win::VERSION_XP)
2218 return;
2219 #endif
2221 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2222 ASSERT_TRUE(RunPlatformAppTestWithArg(
2223 "platform_apps/web_view/common", "cleardata"))
2224 << message_;
2227 // This test is disabled on Win due to being flaky. http://crbug.com/294592
2228 #if defined(OS_WIN)
2229 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
2230 #else
2231 #define MAYBE_ConsoleMessage ConsoleMessage
2232 #endif
2233 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) {
2234 ASSERT_TRUE(RunPlatformAppTestWithArg(
2235 "platform_apps/web_view/common", "console_messages"))
2236 << message_;
2239 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) {
2240 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2241 content::WebContents* guest_web_contents =
2242 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2243 "web_view/download");
2244 ASSERT_TRUE(guest_web_contents);
2246 // Replace WebContentsDelegate with mock version so we can intercept download
2247 // requests.
2248 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate();
2249 scoped_ptr<MockDownloadWebContentsDelegate>
2250 mock_delegate(new MockDownloadWebContentsDelegate(delegate));
2251 guest_web_contents->SetDelegate(mock_delegate.get());
2253 // Start test.
2254 // 1. Guest requests a download that its embedder denies.
2255 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2256 "startDownload('download-link-1')"));
2257 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
2258 mock_delegate->Reset();
2260 // 2. Guest requests a download that its embedder allows.
2261 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2262 "startDownload('download-link-2')"));
2263 mock_delegate->WaitForCanDownload(true); // Expect to allow.
2264 mock_delegate->Reset();
2266 // 3. Guest requests a download that its embedder ignores, this implies deny.
2267 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2268 "startDownload('download-link-3')"));
2269 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
2272 // This test makes sure loading <webview> does not crash when there is an
2273 // extension which has content script whitelisted/forced.
2274 IN_PROC_BROWSER_TEST_F(WebViewTest, WhitelistedContentScript) {
2275 // Whitelist the extension for running content script we are going to load.
2276 extensions::ExtensionsClient::ScriptingWhitelist whitelist;
2277 const std::string extension_id = "imeongpbjoodlnmlakaldhlcmijmhpbb";
2278 whitelist.push_back(extension_id);
2279 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
2281 // Load the extension.
2282 const extensions::Extension* content_script_whitelisted_extension =
2283 LoadExtension(test_data_dir_.AppendASCII(
2284 "platform_apps/web_view/extension_api/content_script"));
2285 ASSERT_TRUE(content_script_whitelisted_extension);
2286 ASSERT_EQ(extension_id, content_script_whitelisted_extension->id());
2288 // Now load an app with <webview>.
2289 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2290 "TEST_PASSED");
2293 IN_PROC_BROWSER_TEST_F(WebViewTest, SendMessageToExtensionFromGuest) {
2294 // Load the extension as a normal, non-component extension.
2295 const extensions::Extension* extension =
2296 LoadExtension(test_data_dir_.AppendASCII(
2297 "platform_apps/web_view/extension_api/component_extension"));
2298 ASSERT_TRUE(extension);
2300 TestHelper("testNonComponentExtension", "web_view/component_extension",
2301 NEEDS_TEST_SERVER);
2304 IN_PROC_BROWSER_TEST_F(WebViewTest, SendMessageToComponentExtensionFromGuest) {
2305 const extensions::Extension* component_extension =
2306 LoadExtensionAsComponent(test_data_dir_.AppendASCII(
2307 "platform_apps/web_view/extension_api/component_extension"));
2308 ASSERT_TRUE(component_extension);
2310 TestHelper("testComponentExtension", "web_view/component_extension",
2311 NEEDS_TEST_SERVER);
2315 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentReady) {
2316 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2317 << message_;
2320 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentInteractive) {
2321 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2322 << message_;
2325 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionAllow) {
2326 ASSERT_TRUE(
2327 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2328 "allowTest"))
2329 << message_;
2332 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionDeny) {
2333 ASSERT_TRUE(
2334 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2335 "denyTest"))
2336 << message_;
2339 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_NoPermission) {
2340 ASSERT_TRUE(
2341 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2342 "speech_recognition_api_no_permission"))
2343 << message_;
2346 // Tests overriding user agent.
2347 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent) {
2348 ASSERT_TRUE(RunPlatformAppTestWithArg(
2349 "platform_apps/web_view/common", "useragent")) << message_;
2352 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent_NewWindow) {
2353 ASSERT_TRUE(RunPlatformAppTestWithArg(
2354 "platform_apps/web_view/common",
2355 "useragent_newwindow")) << message_;
2358 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPermission) {
2359 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2360 << message_;
2363 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestAlertDialog) {
2364 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER);
2367 IN_PROC_BROWSER_TEST_F(WebViewTest, TestConfirmDialog) {
2368 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER);
2371 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogCancel) {
2372 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER);
2375 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultCancel) {
2376 TestHelper("testConfirmDialogDefaultCancel",
2377 "web_view/dialog",
2378 NO_TEST_SERVER);
2381 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultGCCancel) {
2382 TestHelper("testConfirmDialogDefaultGCCancel",
2383 "web_view/dialog",
2384 NO_TEST_SERVER);
2387 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestPromptDialog) {
2388 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER);
2391 IN_PROC_BROWSER_TEST_F(WebViewTest, NoContentSettingsAPI) {
2392 // Load the extension.
2393 const extensions::Extension* content_settings_extension =
2394 LoadExtension(
2395 test_data_dir_.AppendASCII(
2396 "platform_apps/web_view/extension_api/content_settings"));
2397 ASSERT_TRUE(content_settings_extension);
2398 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER);
2401 #if defined(ENABLE_PLUGINS)
2402 class WebViewPluginTest : public WebViewTest {
2403 protected:
2404 void SetUpCommandLine(base::CommandLine* command_line) override {
2405 WebViewTest::SetUpCommandLine(command_line);
2407 // Append the switch to register the pepper plugin.
2408 // library name = <out dir>/<test_name>.<library_extension>
2409 // MIME type = application/x-ppapi-<test_name>
2410 base::FilePath plugin_lib = GetPluginPath();
2411 EXPECT_TRUE(base::PathExists(plugin_lib));
2412 base::FilePath::StringType pepper_plugin = plugin_lib.value();
2413 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
2414 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
2415 pepper_plugin);
2418 base::FilePath GetPluginPath() const {
2419 base::FilePath plugin_dir;
2420 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
2421 return plugin_dir.Append(library_name);
2425 IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginEvent) {
2426 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER);
2429 IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginInternalResource) {
2430 const char kTestMimeType[] = "application/pdf";
2431 const char kTestFileType[] = "pdf";
2432 content::WebPluginInfo plugin_info;
2433 plugin_info.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS;
2434 plugin_info.mime_types.push_back(
2435 content::WebPluginMimeType(kTestMimeType, kTestFileType, std::string()));
2436 content::PluginService::GetInstance()->RegisterInternalPlugin(plugin_info,
2437 true);
2439 TestHelper("testPluginLoadInternalResource", "web_view/shim", NO_TEST_SERVER);
2441 #endif // defined(ENABLE_PLUGINS)
2443 class WebViewCaptureTest : public WebViewTest {
2444 public:
2445 WebViewCaptureTest() {}
2446 ~WebViewCaptureTest() override {}
2447 void SetUp() override {
2448 EnablePixelOutput();
2449 WebViewTest::SetUp();
2453 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestZoomAPI) {
2454 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER);
2457 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) {
2458 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER);
2461 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) {
2462 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER);
2465 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadDataAPI) {
2466 TestHelper("testLoadDataAPI", "web_view/shim", NEEDS_TEST_SERVER);
2469 // This test verify that the set of rules registries of a webview will be
2470 // removed from RulesRegistryService after the webview is gone.
2471 // http://crbug.com/438327
2472 IN_PROC_BROWSER_TEST_F(
2473 WebViewTest,
2474 DISABLED_Shim_TestRulesRegistryIDAreRemovedAfterWebViewIsGone) {
2475 LoadAppWithGuest("web_view/rules_registry");
2477 content::WebContents* embedder_web_contents = GetEmbedderWebContents();
2478 ASSERT_TRUE(embedder_web_contents);
2479 scoped_ptr<EmbedderWebContentsObserver> observer(
2480 new EmbedderWebContentsObserver(embedder_web_contents));
2482 content::WebContents* guest_web_contents = GetGuestWebContents();
2483 ASSERT_TRUE(guest_web_contents);
2484 extensions::WebViewGuest* guest =
2485 extensions::WebViewGuest::FromWebContents(guest_web_contents);
2486 ASSERT_TRUE(guest);
2488 // Register rule for the guest.
2489 Profile* profile = browser()->profile();
2490 int rules_registry_id =
2491 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2492 guest->owner_web_contents()->GetRenderProcessHost()->GetID(),
2493 guest->view_instance_id());
2495 extensions::RulesRegistryService* registry_service =
2496 extensions::RulesRegistryService::Get(profile);
2497 extensions::TestRulesRegistry* rules_registry =
2498 new extensions::TestRulesRegistry(
2499 content::BrowserThread::UI, "ui", rules_registry_id);
2500 registry_service->RegisterRulesRegistry(make_scoped_refptr(rules_registry));
2502 EXPECT_TRUE(registry_service->GetRulesRegistry(
2503 rules_registry_id, "ui").get());
2505 // Kill the embedder's render process, so the webview will go as well.
2506 content::RenderProcessHost* host =
2507 embedder_web_contents->GetRenderProcessHost();
2508 base::KillProcess(host->GetHandle(), 0, false);
2509 observer->WaitForEmbedderRenderProcessTerminate();
2511 EXPECT_FALSE(registry_service->GetRulesRegistry(
2512 rules_registry_id, "ui").get());
2515 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_WebViewWebRequestRegistryHasNoCache) {
2516 LoadAppWithGuest("web_view/rules_registry");
2518 content::WebContents* guest_web_contents = GetGuestWebContents();
2519 ASSERT_TRUE(guest_web_contents);
2520 extensions::WebViewGuest* guest =
2521 extensions::WebViewGuest::FromWebContents(guest_web_contents);
2522 ASSERT_TRUE(guest);
2524 Profile* profile = browser()->profile();
2525 extensions::RulesRegistryService* registry_service =
2526 extensions::RulesRegistryService::Get(profile);
2527 int rules_registry_id =
2528 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2529 guest->owner_web_contents()->GetRenderProcessHost()->GetID(),
2530 guest->view_instance_id());
2532 // Get an existing registered rule for the guest.
2533 extensions::RulesRegistry* registry =
2534 registry_service->GetRulesRegistry(
2535 rules_registry_id,
2536 extensions::declarative_webrequest_constants::kOnRequest).get();
2538 EXPECT_TRUE(registry);
2539 EXPECT_FALSE(registry->rules_cache_delegate_for_testing());
2542 // This test verifies that webview.contentWindow works inside an iframe.
2543 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebViewInsideFrame) {
2544 LoadAppWithGuest("web_view/inside_iframe");
2547 // <webview> screenshot capture fails with ubercomp.
2548 // See http://crbug.com/327035.
2549 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest,
2550 DISABLED_Shim_ScreenshotCapture) {
2551 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER);
2554 #if defined(OS_WIN)
2555 // Test is disabled on Windows because it times out often.
2556 // http://crbug.com/403325
2557 #define MAYBE_WebViewInBackgroundPage \
2558 DISABLED_WebViewInBackgroundPage
2559 #else
2560 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2561 #endif
2562 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) {
2563 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))
2564 << message_;