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