Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / apps / guest_view / web_view_browsertest.cc
blobc3e1c28d71c7a8465f19a8724b25ebb26ead69c7
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 <queue>
7 #include "base/location.h"
8 #include "base/path_service.h"
9 #include "base/process/process.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/apps/app_browsertest_util.h"
16 #include "chrome/browser/chrome_content_browser_client.h"
17 #include "chrome/browser/lifetime/application_lifetime.h"
18 #include "chrome/browser/pdf/pdf_extension_test_util.h"
19 #include "chrome/browser/prerender/prerender_link_manager.h"
20 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
23 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
24 #include "chrome/browser/task_management/task_management_browsertest_util.h"
25 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_dialogs.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/test/base/ui_test_utils.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/guest_view/browser/guest_view_manager.h"
32 #include "components/guest_view/browser/guest_view_manager_delegate.h"
33 #include "components/guest_view/browser/guest_view_manager_factory.h"
34 #include "components/guest_view/browser/test_guest_view_manager.h"
35 #include "content/public/browser/gpu_data_manager.h"
36 #include "content/public/browser/interstitial_page.h"
37 #include "content/public/browser/interstitial_page_delegate.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/web_contents_delegate.h"
41 #include "content/public/common/child_process_host.h"
42 #include "content/public/common/content_switches.h"
43 #include "content/public/test/browser_test_utils.h"
44 #include "content/public/test/fake_speech_recognition_manager.h"
45 #include "content/public/test/test_renderer_host.h"
46 #include "extensions/browser/api/declarative/rules_registry.h"
47 #include "extensions/browser/api/declarative/rules_registry_service.h"
48 #include "extensions/browser/api/declarative/test_rules_registry.h"
49 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
50 #include "extensions/browser/api/extensions_api_client.h"
51 #include "extensions/browser/app_window/native_app_window.h"
52 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
53 #include "extensions/common/extension.h"
54 #include "extensions/common/extensions_client.h"
55 #include "extensions/test/extension_test_message_listener.h"
56 #include "media/base/media_switches.h"
57 #include "net/test/embedded_test_server/embedded_test_server.h"
58 #include "net/test/embedded_test_server/http_request.h"
59 #include "net/test/embedded_test_server/http_response.h"
60 #include "ui/aura/window.h"
61 #include "ui/base/l10n/l10n_util.h"
62 #include "ui/compositor/compositor.h"
63 #include "ui/compositor/compositor_observer.h"
64 #include "ui/events/event_switches.h"
65 #include "ui/gfx/switches.h"
66 #include "ui/gl/gl_switches.h"
67 #include "ui/views/view.h"
68 #include "ui/views/widget/widget.h"
70 #if defined(ENABLE_PLUGINS)
71 #include "content/public/browser/plugin_service.h"
72 #include "content/public/common/webplugininfo.h"
73 #include "content/public/test/ppapi_test_utils.h"
74 #endif
76 #if defined(OS_CHROMEOS)
77 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
78 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
79 #endif
81 // For fine-grained suppression on flaky tests.
82 #if defined(OS_WIN)
83 #include "base/win/windows_version.h"
84 #endif
86 using extensions::ContextMenuMatcher;
87 using extensions::ExtensionsAPIClient;
88 using extensions::MenuItem;
89 using guest_view::GuestViewManager;
90 using guest_view::TestGuestViewManager;
91 using guest_view::TestGuestViewManagerFactory;
92 using prerender::PrerenderLinkManager;
93 using prerender::PrerenderLinkManagerFactory;
94 using task_manager::browsertest_util::MatchAboutBlankTab;
95 using task_manager::browsertest_util::MatchAnyApp;
96 using task_manager::browsertest_util::MatchAnyBackground;
97 using task_manager::browsertest_util::MatchAnyTab;
98 using task_manager::browsertest_util::MatchAnyWebView;
99 using task_manager::browsertest_util::MatchApp;
100 using task_manager::browsertest_util::MatchBackground;
101 using task_manager::browsertest_util::MatchWebView;
102 using task_manager::browsertest_util::WaitForTaskManagerRows;
103 using ui::MenuModel;
105 namespace {
106 const char kEmptyResponsePath[] = "/close-socket";
107 const char kRedirectResponsePath[] = "/server-redirect";
108 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent";
109 const char kCacheResponsePath[] = "/cache-control-response";
110 const char kRedirectResponseFullPath[] =
111 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
113 class EmptyHttpResponse : public net::test_server::HttpResponse {
114 public:
115 std::string ToResponseString() const override { return std::string(); }
118 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
119 public:
120 TestInterstitialPageDelegate() {
122 ~TestInterstitialPageDelegate() override {}
123 std::string GetHTMLContents() override { return std::string(); }
126 class WebContentsHiddenObserver : public content::WebContentsObserver {
127 public:
128 WebContentsHiddenObserver(content::WebContents* web_contents,
129 const base::Closure& hidden_callback)
130 : WebContentsObserver(web_contents),
131 hidden_callback_(hidden_callback),
132 hidden_observed_(false) {
135 // WebContentsObserver.
136 void WasHidden() override {
137 hidden_observed_ = true;
138 hidden_callback_.Run();
141 bool hidden_observed() { return hidden_observed_; }
143 private:
144 base::Closure hidden_callback_;
145 bool hidden_observed_;
147 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver);
150 // Watches for context menu to be shown, records count of how many times
151 // context menu was shown.
152 class ContextMenuCallCountObserver {
153 public:
154 ContextMenuCallCountObserver()
155 : num_times_shown_(0),
156 menu_observer_(chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
157 base::Bind(&ContextMenuCallCountObserver::OnMenuShown,
158 base::Unretained(this))) {
160 ~ContextMenuCallCountObserver() {}
162 bool OnMenuShown(const content::NotificationSource& source,
163 const content::NotificationDetails& details) {
164 ++num_times_shown_;
165 auto context_menu = content::Source<RenderViewContextMenu>(source).ptr();
166 base::ThreadTaskRunnerHandle::Get()->PostTask(
167 FROM_HERE, base::Bind(&RenderViewContextMenuBase::Cancel,
168 base::Unretained(context_menu)));
169 return true;
172 void Wait() { menu_observer_.Wait(); }
174 int num_times_shown() { return num_times_shown_; }
176 private:
177 int num_times_shown_;
178 content::WindowedNotificationObserver menu_observer_;
180 DISALLOW_COPY_AND_ASSIGN(ContextMenuCallCountObserver);
183 class EmbedderWebContentsObserver : public content::WebContentsObserver {
184 public:
185 explicit EmbedderWebContentsObserver(content::WebContents* web_contents)
186 : WebContentsObserver(web_contents), terminated_(false) {}
188 // WebContentsObserver.
189 void RenderProcessGone(base::TerminationStatus status) override {
190 terminated_ = true;
191 if (message_loop_runner_.get())
192 message_loop_runner_->Quit();
195 void WaitForEmbedderRenderProcessTerminate() {
196 if (terminated_)
197 return;
198 message_loop_runner_ = new content::MessageLoopRunner;
199 message_loop_runner_->Run();
202 private:
203 bool terminated_;
204 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
206 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver);
209 void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
210 const char* script,
211 const char* title) {
212 base::string16 expected_title(base::ASCIIToUTF16(title));
213 base::string16 error_title(base::ASCIIToUTF16("error"));
215 content::TitleWatcher title_watcher(web_contents, expected_title);
216 title_watcher.AlsoWaitForTitle(error_title);
217 EXPECT_TRUE(content::ExecuteScript(web_contents, script));
218 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
221 #if defined (USE_AURA)
222 views::View* FindWebView(views::View* view) {
223 std::queue<views::View*> queue;
224 queue.push(view);
225 while (!queue.empty()) {
226 views::View* current = queue.front();
227 queue.pop();
228 if (std::string(current->GetClassName()).find("WebView") !=
229 std::string::npos) {
230 return current;
233 for (int i = 0; i < current->child_count(); ++i)
234 queue.push(current->child_at(i));
236 return nullptr;
238 #endif
240 } // namespace
242 // This class intercepts media access request from the embedder. The request
243 // should be triggered only if the embedder API (from tests) allows the request
244 // in Javascript.
245 // We do not issue the actual media request; the fact that the request reached
246 // embedder's WebContents is good enough for our tests. This is also to make
247 // the test run successfully on trybots.
248 class MockWebContentsDelegate : public content::WebContentsDelegate {
249 public:
250 MockWebContentsDelegate()
251 : requested_(false),
252 checked_(false) {}
253 ~MockWebContentsDelegate() override {}
255 void RequestMediaAccessPermission(
256 content::WebContents* web_contents,
257 const content::MediaStreamRequest& request,
258 const content::MediaResponseCallback& callback) override {
259 requested_ = true;
260 if (request_message_loop_runner_.get())
261 request_message_loop_runner_->Quit();
264 bool CheckMediaAccessPermission(content::WebContents* web_contents,
265 const GURL& security_origin,
266 content::MediaStreamType type) override {
267 checked_ = true;
268 if (check_message_loop_runner_.get())
269 check_message_loop_runner_->Quit();
270 return true;
273 void WaitForRequestMediaPermission() {
274 if (requested_)
275 return;
276 request_message_loop_runner_ = new content::MessageLoopRunner;
277 request_message_loop_runner_->Run();
280 void WaitForCheckMediaPermission() {
281 if (checked_)
282 return;
283 check_message_loop_runner_ = new content::MessageLoopRunner;
284 check_message_loop_runner_->Run();
287 private:
288 bool requested_;
289 bool checked_;
290 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_;
291 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_;
293 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
296 // This class intercepts download request from the guest.
297 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate {
298 public:
299 explicit MockDownloadWebContentsDelegate(
300 content::WebContentsDelegate* orig_delegate)
301 : orig_delegate_(orig_delegate),
302 waiting_for_decision_(false),
303 expect_allow_(false),
304 decision_made_(false),
305 last_download_allowed_(false) {}
306 ~MockDownloadWebContentsDelegate() override {}
308 void CanDownload(const GURL& url,
309 const std::string& request_method,
310 const base::Callback<void(bool)>& callback) override {
311 orig_delegate_->CanDownload(
312 url, request_method,
313 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided,
314 base::Unretained(this)));
317 void WaitForCanDownload(bool expect_allow) {
318 EXPECT_FALSE(waiting_for_decision_);
319 waiting_for_decision_ = true;
321 if (decision_made_) {
322 EXPECT_EQ(expect_allow, last_download_allowed_);
323 return;
326 expect_allow_ = expect_allow;
327 message_loop_runner_ = new content::MessageLoopRunner;
328 message_loop_runner_->Run();
331 void DownloadDecided(bool allow) {
332 EXPECT_FALSE(decision_made_);
333 decision_made_ = true;
335 if (waiting_for_decision_) {
336 EXPECT_EQ(expect_allow_, allow);
337 if (message_loop_runner_.get())
338 message_loop_runner_->Quit();
339 return;
341 last_download_allowed_ = allow;
344 void Reset() {
345 waiting_for_decision_ = false;
346 decision_made_ = false;
349 private:
350 content::WebContentsDelegate* orig_delegate_;
351 bool waiting_for_decision_;
352 bool expect_allow_;
353 bool decision_made_;
354 bool last_download_allowed_;
355 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
357 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate);
360 // TODO(wjmaclean): Fix this test class at some point so it can be re-enabled on
361 // the site isolation bots, and then look at re-enabling WebViewFocusTest when
362 // that happens.
363 // https://crbug.com/503751
364 class WebViewTest : public extensions::PlatformAppBrowserTest {
365 protected:
366 void SetUp() override {
367 if (UsesFakeSpeech()) {
368 // SpeechRecognition test specific SetUp.
369 fake_speech_recognition_manager_.reset(
370 new content::FakeSpeechRecognitionManager());
371 fake_speech_recognition_manager_->set_should_send_fake_response(true);
372 // Inject the fake manager factory so that the test result is returned to
373 // the web page.
374 content::SpeechRecognitionManager::SetManagerForTesting(
375 fake_speech_recognition_manager_.get());
377 extensions::PlatformAppBrowserTest::SetUp();
380 void TearDown() override {
381 if (UsesFakeSpeech()) {
382 // SpeechRecognition test specific TearDown.
383 content::SpeechRecognitionManager::SetManagerForTesting(NULL);
386 extensions::PlatformAppBrowserTest::TearDown();
389 void SetUpOnMainThread() override {
390 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
391 const testing::TestInfo* const test_info =
392 testing::UnitTest::GetInstance()->current_test_info();
393 // Mock out geolocation for geolocation specific tests.
394 if (!strncmp(test_info->name(), "GeolocationAPI",
395 strlen("GeolocationAPI"))) {
396 ui_test_utils::OverrideGeolocation(10, 20);
400 void SetUpCommandLine(base::CommandLine* command_line) override {
401 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
402 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
404 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
407 // Handles |request| by serving a redirect response if the |User-Agent| is
408 // foobar.
409 static scoped_ptr<net::test_server::HttpResponse> UserAgentResponseHandler(
410 const std::string& path,
411 const GURL& redirect_target,
412 const net::test_server::HttpRequest& request) {
413 if (!base::StartsWith(path, request.relative_url,
414 base::CompareCase::SENSITIVE))
415 return scoped_ptr<net::test_server::HttpResponse>();
417 std::map<std::string, std::string>::const_iterator it =
418 request.headers.find("User-Agent");
419 EXPECT_TRUE(it != request.headers.end());
420 if (!base::StartsWith("foobar", it->second,
421 base::CompareCase::SENSITIVE))
422 return scoped_ptr<net::test_server::HttpResponse>();
424 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
425 new net::test_server::BasicHttpResponse);
426 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
427 http_response->AddCustomHeader("Location", redirect_target.spec());
428 return http_response.Pass();
431 // Handles |request| by serving a redirect response.
432 static scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler(
433 const std::string& path,
434 const GURL& redirect_target,
435 const net::test_server::HttpRequest& request) {
436 if (!base::StartsWith(path, request.relative_url,
437 base::CompareCase::SENSITIVE))
438 return scoped_ptr<net::test_server::HttpResponse>();
440 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
441 new net::test_server::BasicHttpResponse);
442 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
443 http_response->AddCustomHeader("Location", redirect_target.spec());
444 return http_response.Pass();
447 // Handles |request| by serving an empty response.
448 static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler(
449 const std::string& path,
450 const net::test_server::HttpRequest& request) {
451 if (base::StartsWith(path, request.relative_url,
452 base::CompareCase::SENSITIVE))
453 return scoped_ptr<net::test_server::HttpResponse>(new EmptyHttpResponse);
455 return scoped_ptr<net::test_server::HttpResponse>();
458 // Handles |request| by serving cache-able response.
459 static scoped_ptr<net::test_server::HttpResponse> CacheControlResponseHandler(
460 const std::string& path,
461 const net::test_server::HttpRequest& request) {
462 if (!base::StartsWith(path, request.relative_url,
463 base::CompareCase::SENSITIVE))
464 return scoped_ptr<net::test_server::HttpResponse>();
466 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
467 new net::test_server::BasicHttpResponse);
468 http_response->AddCustomHeader("Cache-control", "max-age=3600");
469 http_response->set_content_type("text/plain");
470 http_response->set_content("dummy text");
471 return http_response.Pass();
474 // Shortcut to return the current MenuManager.
475 extensions::MenuManager* menu_manager() {
476 return extensions::MenuManager::Get(browser()->profile());
479 // This gets all the items that any extension has registered for possible
480 // inclusion in context menus.
481 MenuItem::List GetItems() {
482 MenuItem::List result;
483 std::set<MenuItem::ExtensionKey> extension_ids =
484 menu_manager()->ExtensionIds();
485 std::set<MenuItem::ExtensionKey>::iterator i;
486 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) {
487 const MenuItem::List* list = menu_manager()->MenuItems(*i);
488 result.insert(result.end(), list->begin(), list->end());
490 return result;
493 enum TestServer {
494 NEEDS_TEST_SERVER,
495 NO_TEST_SERVER
498 void TestHelper(const std::string& test_name,
499 const std::string& app_location,
500 TestServer test_server) {
501 // For serving guest pages.
502 if (test_server == NEEDS_TEST_SERVER) {
503 if (!StartEmbeddedTestServer()) {
504 LOG(ERROR) << "FAILED TO START TEST SERVER.";
505 return;
507 embedded_test_server()->RegisterRequestHandler(
508 base::Bind(&WebViewTest::RedirectResponseHandler,
509 kRedirectResponsePath,
510 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
512 embedded_test_server()->RegisterRequestHandler(
513 base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath));
515 embedded_test_server()->RegisterRequestHandler(
516 base::Bind(
517 &WebViewTest::UserAgentResponseHandler,
518 kUserAgentRedirectResponsePath,
519 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
521 embedded_test_server()->RegisterRequestHandler(base::Bind(
522 &WebViewTest::CacheControlResponseHandler, kCacheResponsePath));
525 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
527 // Flush any pending events to make sure we start with a clean slate.
528 content::RunAllPendingInMessageLoop();
530 content::WebContents* embedder_web_contents =
531 GetFirstAppWindowWebContents();
532 if (!embedder_web_contents) {
533 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
534 return;
537 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
538 done_listener.set_failure_message("TEST_FAILED");
539 if (!content::ExecuteScript(
540 embedder_web_contents,
541 base::StringPrintf("runTest('%s')", test_name.c_str()))) {
542 LOG(ERROR) << "UNABLE TO START TEST.";
543 return;
545 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
548 content::WebContents* LoadGuest(const std::string& guest_path,
549 const std::string& app_path) {
550 GURL::Replacements replace_host;
551 replace_host.SetHostStr("localhost");
553 GURL guest_url = embedded_test_server()->GetURL(guest_path);
554 guest_url = guest_url.ReplaceComponents(replace_host);
556 ui_test_utils::UrlLoadObserver guest_observer(
557 guest_url, content::NotificationService::AllSources());
559 LoadAndLaunchPlatformApp(app_path.c_str(), "guest-loaded");
561 guest_observer.Wait();
562 content::Source<content::NavigationController> source =
563 guest_observer.source();
564 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
565 IsForGuestsOnly());
567 content::WebContents* guest_web_contents = source->GetWebContents();
568 return guest_web_contents;
571 // Helper to load interstitial page in a <webview>.
572 void InterstitialTeardownTestHelper() {
573 // Start a HTTPS server so we can load an interstitial page inside guest.
574 net::SpawnedTestServer::SSLOptions ssl_options;
575 ssl_options.server_certificate =
576 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
577 net::SpawnedTestServer https_server(
578 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
579 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
580 ASSERT_TRUE(https_server.Start());
582 net::HostPortPair host_and_port = https_server.host_port_pair();
584 LoadAndLaunchPlatformApp("web_view/interstitial_teardown",
585 "EmbedderLoaded");
587 // Now load the guest.
588 content::WebContents* embedder_web_contents =
589 GetFirstAppWindowWebContents();
590 ExtensionTestMessageListener second("GuestAddedToDom", false);
591 EXPECT_TRUE(content::ExecuteScript(
592 embedder_web_contents,
593 base::StringPrintf("loadGuest(%d);\n", host_and_port.port())));
594 ASSERT_TRUE(second.WaitUntilSatisfied());
596 // Wait for interstitial page to be shown in guest.
597 content::WebContents* guest_web_contents =
598 GetGuestViewManager()->WaitForSingleGuestCreated();
599 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsForGuestsOnly());
600 content::WaitForInterstitialAttach(guest_web_contents);
603 // Runs media_access/allow tests.
604 void MediaAccessAPIAllowTestHelper(const std::string& test_name);
606 // Runs media_access/deny tests, each of them are run separately otherwise
607 // they timeout (mostly on Windows).
608 void MediaAccessAPIDenyTestHelper(const std::string& test_name) {
609 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
610 LoadAndLaunchPlatformApp("web_view/media_access/deny", "loaded");
612 content::WebContents* embedder_web_contents =
613 GetFirstAppWindowWebContents();
614 ASSERT_TRUE(embedder_web_contents);
616 ExtensionTestMessageListener test_run_listener("PASSED", false);
617 test_run_listener.set_failure_message("FAILED");
618 EXPECT_TRUE(
619 content::ExecuteScript(
620 embedder_web_contents,
621 base::StringPrintf("startDenyTest('%s')", test_name.c_str())));
622 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied());
625 // Loads an app with a <webview> in it, returns once a guest is created.
626 void LoadAppWithGuest(const std::string& app_path) {
627 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED",
628 false);
629 launched_listener.set_failure_message("WebViewTest.FAILURE");
630 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener);
632 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated();
635 void SendMessageToEmbedder(const std::string& message) {
636 EXPECT_TRUE(
637 content::ExecuteScript(
638 GetEmbedderWebContents(),
639 base::StringPrintf("onAppCommand('%s');", message.c_str())));
642 void SendMessageToGuestAndWait(const std::string& message,
643 const std::string& wait_message) {
644 scoped_ptr<ExtensionTestMessageListener> listener;
645 if (!wait_message.empty()) {
646 listener.reset(new ExtensionTestMessageListener(wait_message, false));
649 EXPECT_TRUE(
650 content::ExecuteScript(
651 GetGuestWebContents(),
652 base::StringPrintf("onAppCommand('%s');", message.c_str())));
654 if (listener) {
655 ASSERT_TRUE(listener->WaitUntilSatisfied());
659 void OpenContextMenu(content::WebContents* web_contents) {
660 blink::WebMouseEvent mouse_event;
661 mouse_event.type = blink::WebInputEvent::MouseDown;
662 mouse_event.button = blink::WebMouseEvent::ButtonRight;
663 mouse_event.x = 1;
664 mouse_event.y = 1;
665 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
666 mouse_event.type = blink::WebInputEvent::MouseUp;
667 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
670 content::WebContents* GetGuestWebContents() {
671 return guest_web_contents_;
674 content::WebContents* GetEmbedderWebContents() {
675 if (!embedder_web_contents_) {
676 embedder_web_contents_ = GetFirstAppWindowWebContents();
678 return embedder_web_contents_;
681 TestGuestViewManager* GetGuestViewManager() {
682 TestGuestViewManager* manager = static_cast<TestGuestViewManager*>(
683 TestGuestViewManager::FromBrowserContext(browser()->profile()));
684 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called
685 // before a guest is created.
686 if (!manager) {
687 manager = static_cast<TestGuestViewManager*>(
688 GuestViewManager::CreateWithDelegate(
689 browser()->profile(),
690 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(
691 browser()->profile())));
693 return manager;
696 WebViewTest() : guest_web_contents_(NULL),
697 embedder_web_contents_(NULL) {
698 GuestViewManager::set_factory_for_testing(&factory_);
701 protected:
702 scoped_refptr<content::FrameWatcher> frame_watcher_;
704 private:
705 bool UsesFakeSpeech() {
706 const testing::TestInfo* const test_info =
707 testing::UnitTest::GetInstance()->current_test_info();
709 // SpeechRecognition test specific SetUp.
710 return !strcmp(test_info->name(),
711 "SpeechRecognitionAPI_HasPermissionAllow");
714 scoped_ptr<content::FakeSpeechRecognitionManager>
715 fake_speech_recognition_manager_;
717 TestGuestViewManagerFactory factory_;
718 // Note that these are only set if you launch app using LoadAppWithGuest().
719 content::WebContents* guest_web_contents_;
720 content::WebContents* embedder_web_contents_;
723 // The following test suits are created to group tests based on specific
724 // features of <webview>.
725 // These features current would not work with --site-per-process and is
726 // disabled on site isolation FYI bots.
727 class WebViewNewWindowTest : public WebViewTest {};
728 class WebViewSizeTest : public WebViewTest {};
729 class WebViewSpeechAPITest : public WebViewTest {};
730 class WebViewVisibilityTest : public WebViewTest {};
732 // Test suite that containts tests that are meant to run with and without
733 // --site-per-process.
734 class WebViewCommonTest : public extensions::PlatformAppBrowserTest {};
736 class WebViewDPITest : public WebViewTest {
737 protected:
738 void SetUpCommandLine(base::CommandLine* command_line) override {
739 WebViewTest::SetUpCommandLine(command_line);
740 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
741 base::StringPrintf("%f", scale()));
744 static float scale() { return 2.0f; }
747 // This test verifies that hiding the guest triggers WebContents::WasHidden().
748 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest, GuestVisibilityChanged) {
749 LoadAppWithGuest("web_view/visibility_changed");
751 scoped_refptr<content::MessageLoopRunner> loop_runner(
752 new content::MessageLoopRunner);
753 WebContentsHiddenObserver observer(GetGuestWebContents(),
754 loop_runner->QuitClosure());
756 // Handled in platform_apps/web_view/visibility_changed/main.js
757 SendMessageToEmbedder("hide-guest");
758 if (!observer.hidden_observed())
759 loop_runner->Run();
762 // This test verifies that hiding the embedder also hides the guest.
763 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest, EmbedderVisibilityChanged) {
764 LoadAppWithGuest("web_view/visibility_changed");
766 scoped_refptr<content::MessageLoopRunner> loop_runner(
767 new content::MessageLoopRunner);
768 WebContentsHiddenObserver observer(GetGuestWebContents(),
769 loop_runner->QuitClosure());
771 // Handled in platform_apps/web_view/visibility_changed/main.js
772 SendMessageToEmbedder("hide-embedder");
773 if (!observer.hidden_observed())
774 loop_runner->Run();
777 // This test verifies that reloading the embedder reloads the guest (and doest
778 // not crash).
779 IN_PROC_BROWSER_TEST_F(WebViewTest, ReloadEmbedder) {
780 // Just load a guest from other test, we do not want to add a separate
781 // platform_app for this test.
782 LoadAppWithGuest("web_view/visibility_changed");
784 ExtensionTestMessageListener launched_again_listener("WebViewTest.LAUNCHED",
785 false);
786 GetEmbedderWebContents()->GetController().Reload(false);
787 ASSERT_TRUE(launched_again_listener.WaitUntilSatisfied());
790 IN_PROC_BROWSER_TEST_F(WebViewTest, AcceptTouchEvents) {
791 LoadAppWithGuest("web_view/accept_touch_events");
793 content::RenderViewHost* embedder_rvh =
794 GetEmbedderWebContents()->GetRenderViewHost();
796 bool embedder_has_touch_handler =
797 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
798 EXPECT_FALSE(embedder_has_touch_handler);
800 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
802 // Note that we need to wait for the installed/registered touch handler to
803 // appear in browser process before querying |embedder_rvh|.
804 // In practice, since we do a roundrtip from browser process to guest and
805 // back, this is sufficient.
806 embedder_has_touch_handler =
807 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
808 EXPECT_TRUE(embedder_has_touch_handler);
810 SendMessageToGuestAndWait("uninstall-touch-handler",
811 "uninstalled-touch-handler");
812 // Same as the note above about waiting.
813 embedder_has_touch_handler =
814 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
815 EXPECT_FALSE(embedder_has_touch_handler);
818 // This test ensures JavaScript errors ("Cannot redefine property") do not
819 // happen when a <webview> is removed from DOM and added back.
820 IN_PROC_BROWSER_TEST_F(WebViewTest,
821 AddRemoveWebView_AddRemoveWebView) {
822 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
823 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
824 << message_;
827 IN_PROC_BROWSER_TEST_F(WebViewSizeTest, AutoSize) {
828 #if defined(OS_WIN)
829 // Flaky on XP bot http://crbug.com/299507
830 if (base::win::GetVersion() <= base::win::VERSION_XP)
831 return;
832 #endif
834 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
835 << message_;
838 // Test for http://crbug.com/419611.
839 IN_PROC_BROWSER_TEST_F(WebViewTest, DisplayNoneSetSrc) {
840 LoadAndLaunchPlatformApp("web_view/display_none_set_src",
841 "WebViewTest.LAUNCHED");
842 // Navigate the guest while it's in "display: none" state.
843 SendMessageToEmbedder("navigate-guest");
844 GetGuestViewManager()->WaitForSingleGuestCreated();
846 // Now attempt to navigate the guest again.
847 SendMessageToEmbedder("navigate-guest");
849 ExtensionTestMessageListener test_passed_listener("WebViewTest.PASSED",
850 false);
851 // Making the guest visible would trigger loadstop.
852 SendMessageToEmbedder("show-guest");
853 EXPECT_TRUE(test_passed_listener.WaitUntilSatisfied());
856 // Checks that {allFrames: true} injects script correctly to subframes
857 // inside <webview>.
858 IN_PROC_BROWSER_TEST_F(WebViewTest, ExecuteScript) {
859 ASSERT_TRUE(RunPlatformAppTestWithArg(
860 "platform_apps/web_view/common", "execute_script")) << message_;
863 // http://crbug.com/326332
864 IN_PROC_BROWSER_TEST_F(WebViewSizeTest,
865 DISABLED_Shim_TestAutosizeAfterNavigation) {
866 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER);
869 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAllowTransparencyAttribute) {
870 TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER);
873 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeHeight) {
874 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER);
877 IN_PROC_BROWSER_TEST_F(WebViewSizeTest, Shim_TestAutosizeHeight) {
878 TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER);
881 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeBeforeNavigation) {
882 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
885 IN_PROC_BROWSER_TEST_F(WebViewSizeTest, Shim_TestAutosizeBeforeNavigation) {
886 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
889 IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeRemoveAttributes) {
890 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
893 IN_PROC_BROWSER_TEST_F(WebViewSizeTest, Shim_TestAutosizeRemoveAttributes) {
894 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
897 // This test is disabled due to being flaky. http://crbug.com/282116
898 IN_PROC_BROWSER_TEST_F(WebViewSizeTest,
899 DISABLED_Shim_TestAutosizeWithPartialAttributes) {
900 TestHelper("testAutosizeWithPartialAttributes",
901 "web_view/shim",
902 NO_TEST_SERVER);
905 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) {
906 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER);
909 // Tests the existence of WebRequest API event objects on the request
910 // object, on the webview element, and hanging directly off webview.
911 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) {
912 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER);
915 // http://crbug.com/315920
916 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
917 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
918 #else
919 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
920 #endif
921 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) {
922 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
925 // http://crbug.com/315920
926 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
927 #define MAYBE_Shim_TestChromeExtensionRelativePath \
928 DISABLED_Shim_TestChromeExtensionRelativePath
929 #else
930 #define MAYBE_Shim_TestChromeExtensionRelativePath \
931 Shim_TestChromeExtensionRelativePath
932 #endif
933 IN_PROC_BROWSER_TEST_F(WebViewTest,
934 MAYBE_Shim_TestChromeExtensionRelativePath) {
935 TestHelper("testChromeExtensionRelativePath",
936 "web_view/shim",
937 NO_TEST_SERVER);
940 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayNoneWebviewLoad) {
941 TestHelper("testDisplayNoneWebviewLoad", "web_view/shim", NO_TEST_SERVER);
944 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayNoneWebviewRemoveChild) {
945 TestHelper("testDisplayNoneWebviewRemoveChild",
946 "web_view/shim", NO_TEST_SERVER);
949 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisplayBlock) {
950 TestHelper("testDisplayBlock", "web_view/shim", NO_TEST_SERVER);
953 IN_PROC_BROWSER_TEST_F(WebViewTest,
954 Shim_TestInlineScriptFromAccessibleResources) {
955 TestHelper("testInlineScriptFromAccessibleResources",
956 "web_view/shim",
957 NO_TEST_SERVER);
960 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestInvalidChromeExtensionURL) {
961 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
964 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestEventName) {
965 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER);
968 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestOnEventProperty) {
969 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER);
972 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadProgressEvent) {
973 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER);
976 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDestroyOnEventListener) {
977 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER);
980 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCannotMutateEventName) {
981 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER);
984 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPartitionChangeAfterNavigation) {
985 TestHelper("testPartitionChangeAfterNavigation",
986 "web_view/shim",
987 NO_TEST_SERVER);
990 IN_PROC_BROWSER_TEST_F(WebViewTest,
991 Shim_TestPartitionRemovalAfterNavigationFails) {
992 TestHelper("testPartitionRemovalAfterNavigationFails",
993 "web_view/shim",
994 NO_TEST_SERVER);
997 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAddContentScript) {
998 TestHelper("testAddContentScript", "web_view/shim", NEEDS_TEST_SERVER);
1001 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAddMultipleContentScripts) {
1002 TestHelper("testAddMultipleContentScripts", "web_view/shim",
1003 NEEDS_TEST_SERVER);
1006 IN_PROC_BROWSER_TEST_F(
1007 WebViewTest,
1008 Shim_TestAddContentScriptWithSameNameShouldOverwriteTheExistingOne) {
1009 TestHelper("testAddContentScriptWithSameNameShouldOverwriteTheExistingOne",
1010 "web_view/shim", NEEDS_TEST_SERVER);
1013 IN_PROC_BROWSER_TEST_F(
1014 WebViewTest,
1015 Shim_TestAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView) {
1016 TestHelper("testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView",
1017 "web_view/shim", NEEDS_TEST_SERVER);
1020 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAddAndRemoveContentScripts) {
1021 TestHelper("testAddAndRemoveContentScripts", "web_view/shim",
1022 NEEDS_TEST_SERVER);
1025 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest,
1026 Shim_TestAddContentScriptsWithNewWindowAPI) {
1027 TestHelper("testAddContentScriptsWithNewWindowAPI", "web_view/shim",
1028 NEEDS_TEST_SERVER);
1031 IN_PROC_BROWSER_TEST_F(
1032 WebViewTest,
1033 Shim_TestContentScriptIsInjectedAfterTerminateAndReloadWebView) {
1034 TestHelper("testContentScriptIsInjectedAfterTerminateAndReloadWebView",
1035 "web_view/shim", NEEDS_TEST_SERVER);
1038 IN_PROC_BROWSER_TEST_F(WebViewTest,
1039 Shim_TestContentScriptExistsAsLongAsWebViewTagExists) {
1040 TestHelper("testContentScriptExistsAsLongAsWebViewTagExists", "web_view/shim",
1041 NEEDS_TEST_SERVER);
1044 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAddContentScriptWithCode) {
1045 TestHelper("testAddContentScriptWithCode", "web_view/shim",
1046 NEEDS_TEST_SERVER);
1049 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScriptFail) {
1050 #if defined(OS_WIN)
1051 // Flaky on XP bot http://crbug.com/266185
1052 if (base::win::GetVersion() <= base::win::VERSION_XP)
1053 return;
1054 #endif
1056 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER);
1059 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScript) {
1060 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER);
1063 IN_PROC_BROWSER_TEST_F(
1064 WebViewTest,
1065 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged) {
1066 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
1067 "web_view/shim",
1068 NO_TEST_SERVER);
1071 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestTerminateAfterExit) {
1072 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER);
1075 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAssignSrcAfterCrash) {
1076 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER);
1079 IN_PROC_BROWSER_TEST_F(WebViewTest,
1080 Shim_TestNavOnConsecutiveSrcAttributeChanges) {
1081 TestHelper("testNavOnConsecutiveSrcAttributeChanges",
1082 "web_view/shim",
1083 NO_TEST_SERVER);
1086 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavOnSrcAttributeChange) {
1087 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER);
1090 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigateAfterResize) {
1091 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER);
1094 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNestedCrossOriginSubframes) {
1095 TestHelper("testNestedCrossOriginSubframes",
1096 "web_view/shim", NEEDS_TEST_SERVER);
1099 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNestedSubframes) {
1100 TestHelper("testNestedSubframes", "web_view/shim", NO_TEST_SERVER);
1103 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveSrcAttribute) {
1104 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER);
1107 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReassignSrcAttribute) {
1108 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER);
1111 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest, Shim_TestNewWindow) {
1112 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER);
1115 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest, Shim_TestNewWindowTwoListeners) {
1116 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER);
1119 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest,
1120 Shim_TestNewWindowNoPreventDefault) {
1121 TestHelper("testNewWindowNoPreventDefault",
1122 "web_view/shim",
1123 NEEDS_TEST_SERVER);
1126 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest, Shim_TestNewWindowNoReferrerLink) {
1127 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER);
1130 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestContentLoadEvent) {
1131 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER);
1134 // TODO(fsamuel): Enable this test once <webview> can run in a detached state.
1135 IN_PROC_BROWSER_TEST_F(WebViewTest,
1136 Shim_TestContentLoadEventWithDisplayNone) {
1137 TestHelper("testContentLoadEventWithDisplayNone",
1138 "web_view/shim",
1139 NO_TEST_SERVER);
1142 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDeclarativeWebRequestAPI) {
1143 TestHelper("testDeclarativeWebRequestAPI",
1144 "web_view/shim",
1145 NEEDS_TEST_SERVER);
1148 IN_PROC_BROWSER_TEST_F(WebViewTest,
1149 Shim_TestDeclarativeWebRequestAPISendMessage) {
1150 TestHelper("testDeclarativeWebRequestAPISendMessage",
1151 "web_view/shim",
1152 NEEDS_TEST_SERVER);
1155 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPI) {
1156 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER);
1159 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIWithHeaders) {
1160 TestHelper("testWebRequestAPIWithHeaders",
1161 "web_view/shim",
1162 NEEDS_TEST_SERVER);
1165 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIGoogleProperty) {
1166 TestHelper("testWebRequestAPIGoogleProperty",
1167 "web_view/shim",
1168 NO_TEST_SERVER);
1171 IN_PROC_BROWSER_TEST_F(
1172 WebViewTest, Shim_TestWebRequestListenerSurvivesReparenting) {
1173 #if defined(OS_WIN)
1174 // Flaky on XP bot http://crbug.com/309451.
1175 if (base::win::GetVersion() <= base::win::VERSION_XP)
1176 return;
1177 #endif
1179 TestHelper("testWebRequestListenerSurvivesReparenting",
1180 "web_view/shim",
1181 NEEDS_TEST_SERVER);
1184 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadStartLoadRedirect) {
1185 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER);
1188 IN_PROC_BROWSER_TEST_F(WebViewTest,
1189 Shim_TestLoadAbortChromeExtensionURLWrongPartition) {
1190 TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
1191 "web_view/shim",
1192 NO_TEST_SERVER);
1195 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortEmptyResponse) {
1196 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER);
1199 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalChromeURL) {
1200 TestHelper("testLoadAbortIllegalChromeURL",
1201 "web_view/shim",
1202 NO_TEST_SERVER);
1205 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalFileURL) {
1206 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER);
1209 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalJavaScriptURL) {
1210 TestHelper("testLoadAbortIllegalJavaScriptURL",
1211 "web_view/shim",
1212 NO_TEST_SERVER);
1215 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortInvalidNavigation) {
1216 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER);
1219 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortNonWebSafeScheme) {
1220 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER);
1223 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) {
1224 TestHelper("testReload", "web_view/shim", NO_TEST_SERVER);
1227 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReloadAfterTerminate) {
1228 TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER);
1231 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) {
1232 TestHelper("testGetProcessId", "web_view/shim", NO_TEST_SERVER);
1235 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest, Shim_TestHiddenBeforeNavigation) {
1236 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
1239 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) {
1240 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1242 // Launch the app and wait until it's ready to load a test.
1243 LoadAndLaunchPlatformApp("web_view/shim", "Launched");
1245 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1246 ASSERT_TRUE(embedder_web_contents);
1248 GURL::Replacements replace_host;
1249 replace_host.SetHostStr("localhost");
1251 std::string guest_path(
1252 "/extensions/platform_apps/web_view/shim/empty_guest.html");
1253 GURL guest_url = embedded_test_server()->GetURL(guest_path);
1254 guest_url = guest_url.ReplaceComponents(replace_host);
1256 ui_test_utils::UrlLoadObserver guest_observer(
1257 guest_url, content::NotificationService::AllSources());
1259 // Run the test and wait until the guest WebContents is available and has
1260 // finished loading.
1261 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
1262 EXPECT_TRUE(content::ExecuteScript(
1263 embedder_web_contents,
1264 "runTest('testRemoveWebviewOnExit')"));
1265 guest_observer.Wait();
1267 content::Source<content::NavigationController> source =
1268 guest_observer.source();
1269 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
1270 IsForGuestsOnly());
1272 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
1274 content::WebContentsDestroyedWatcher destroyed_watcher(
1275 source->GetWebContents());
1277 // Tell the embedder to kill the guest.
1278 EXPECT_TRUE(content::ExecuteScript(
1279 embedder_web_contents,
1280 "removeWebviewOnExitDoCrash();"));
1282 // Wait until the guest WebContents is destroyed.
1283 destroyed_watcher.Wait();
1286 // Remove <webview> immediately after navigating it.
1287 // This is a regression test for http://crbug.com/276023.
1288 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewAfterNavigation) {
1289 TestHelper("testRemoveWebviewAfterNavigation",
1290 "web_view/shim",
1291 NO_TEST_SERVER);
1294 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigationToExternalProtocol) {
1295 TestHelper("testNavigationToExternalProtocol",
1296 "web_view/shim",
1297 NO_TEST_SERVER);
1300 IN_PROC_BROWSER_TEST_F(WebViewSizeTest,
1301 Shim_TestResizeWebviewWithDisplayNoneResizesContent) {
1302 TestHelper("testResizeWebviewWithDisplayNoneResizesContent",
1303 "web_view/shim",
1304 NO_TEST_SERVER);
1307 IN_PROC_BROWSER_TEST_F(WebViewSizeTest, Shim_TestResizeWebviewResizesContent) {
1308 TestHelper("testResizeWebviewResizesContent",
1309 "web_view/shim",
1310 NO_TEST_SERVER);
1313 // This test makes sure the browser process does not crash if app is closed
1314 // while an interstitial page is being shown in guest.
1315 IN_PROC_BROWSER_TEST_F(WebViewTest, InterstitialTeardown) {
1316 #if defined(OS_WIN)
1317 // Flaky on XP bot http://crbug.com/297014
1318 if (base::win::GetVersion() <= base::win::VERSION_XP)
1319 return;
1320 #endif
1322 InterstitialTeardownTestHelper();
1324 // Now close the app while interstitial page being shown in guest.
1325 extensions::AppWindow* window = GetFirstAppWindow();
1326 window->GetBaseWindow()->Close();
1329 // This test makes sure the browser process does not crash if browser is shut
1330 // down while an interstitial page is being shown in guest.
1331 IN_PROC_BROWSER_TEST_F(WebViewTest, InterstitialTeardownOnBrowserShutdown) {
1332 #if defined(OS_WIN)
1333 // http://crbug.com/297014
1334 if (base::win::GetVersion() <= base::win::VERSION_XP)
1335 return;
1336 #endif
1338 InterstitialTeardownTestHelper();
1340 // Now close the app while interstitial page being shown in guest.
1341 extensions::AppWindow* window = GetFirstAppWindow();
1342 window->GetBaseWindow()->Close();
1344 // InterstitialPage is not destroyed immediately, so the
1345 // RenderWidgetHostViewGuest for it is still there, closing all
1346 // renderer processes will cause the RWHVGuest's RenderProcessGone()
1347 // shutdown path to be exercised.
1348 chrome::CloseAllBrowsers();
1351 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) {
1352 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1353 << message_;
1356 // This test verifies that prerendering has been disabled inside <webview>.
1357 // This test is here rather than in PrerenderBrowserTest for testing convenience
1358 // only. If it breaks then this is a bug in the prerenderer.
1359 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) {
1360 ASSERT_TRUE(StartEmbeddedTestServer());
1361 content::WebContents* guest_web_contents =
1362 LoadGuest(
1363 "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1364 "web_view/noprerenderer");
1365 ASSERT_TRUE(guest_web_contents != NULL);
1367 PrerenderLinkManager* prerender_link_manager =
1368 PrerenderLinkManagerFactory::GetForProfile(
1369 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext()));
1370 ASSERT_TRUE(prerender_link_manager != NULL);
1371 EXPECT_TRUE(prerender_link_manager->IsEmpty());
1374 // Verify that existing <webview>'s are detected when the task manager starts
1375 // up.
1376 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerExistingWebView) {
1377 ASSERT_TRUE(StartEmbeddedTestServer());
1379 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1380 "web_view/task_manager");
1382 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads.
1384 const char* guest_title = "WebViewed test content";
1385 const char* app_name = "<webview> task manager test";
1386 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1387 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1388 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1389 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1391 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1392 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1393 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1394 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1397 // Verify that the task manager notices the creation of new <webview>'s.
1398 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerNewWebView) {
1399 ASSERT_TRUE(StartEmbeddedTestServer());
1401 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads.
1403 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1404 "web_view/task_manager");
1406 const char* guest_title = "WebViewed test content";
1407 const char* app_name = "<webview> task manager test";
1408 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1409 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1410 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1411 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1413 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1414 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1415 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1416 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1419 // This tests cookie isolation for packaged apps with webview tags. It navigates
1420 // the main browser window to a page that sets a cookie and loads an app with
1421 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1422 // storage isolation is enforced.
1423 IN_PROC_BROWSER_TEST_F(WebViewTest, CookieIsolation) {
1424 ASSERT_TRUE(StartEmbeddedTestServer());
1425 // Navigate the browser to a page which writes a sample cookie
1426 // The cookie is "testCookie=1"
1427 GURL set_cookie_url = embedded_test_server()->GetURL(
1428 "/extensions/platform_apps/web_view/cookie_isolation/set_cookie.html");
1429 GURL::Replacements replace_host;
1430 replace_host.SetHostStr("localhost");
1431 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
1433 ui_test_utils::NavigateToURL(browser(), set_cookie_url);
1434 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/cookie_isolation"))
1435 << message_;
1436 // Finally, verify that the browser cookie has not changed.
1437 int cookie_size;
1438 std::string cookie_value;
1440 ui_test_utils::GetCookies(GURL("http://localhost"),
1441 browser()->tab_strip_model()->GetWebContentsAt(0),
1442 &cookie_size, &cookie_value);
1443 EXPECT_EQ("testCookie=1", cookie_value);
1446 // This tests that in-memory storage partitions are reset on browser restart,
1447 // but persistent ones maintain state for cookies and HTML5 storage.
1448 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) {
1449 ASSERT_TRUE(StartEmbeddedTestServer());
1450 // We don't care where the main browser is on this test.
1451 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1452 // Start the app for the pre-test.
1453 LoadAndLaunchPlatformApp("web_view/storage_persistence",
1454 "WebViewTest.LAUNCHED");
1456 // Send a message to run the PRE_StoragePersistence part of the test.
1457 SendMessageToEmbedder("run-pre-test");
1459 ExtensionTestMessageListener test_passed_listener("WebViewTest.PASSED",
1460 false);
1461 EXPECT_TRUE(test_passed_listener.WaitUntilSatisfied());
1464 // This is the post-reset portion of the StoragePersistence test. See
1465 // PRE_StoragePersistence for main comment.
1466 IN_PROC_BROWSER_TEST_F(WebViewTest, StoragePersistence) {
1467 ASSERT_TRUE(StartEmbeddedTestServer());
1468 // We don't care where the main browser is on this test.
1469 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1470 // Start the app for the pre-test.
1471 LoadAndLaunchPlatformApp("web_view/storage_persistence",
1472 "WebViewTest.LAUNCHED");
1474 // Send a message to run the StoragePersistence part of the test.
1475 SendMessageToEmbedder("run-test");
1477 ExtensionTestMessageListener test_passed_listener("WebViewTest.PASSED",
1478 false);
1479 EXPECT_TRUE(test_passed_listener.WaitUntilSatisfied());
1482 // This tests DOM storage isolation for packaged apps with webview tags. It
1483 // loads an app with multiple webview tags and each tag sets DOM storage
1484 // entries, which the test checks to ensure proper storage isolation is
1485 // enforced.
1486 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) {
1487 ASSERT_TRUE(StartEmbeddedTestServer());
1489 GURL navigate_to_url = embedded_test_server()->GetURL(
1490 "/extensions/platform_apps/web_view/dom_storage_isolation/page.html");
1491 GURL::Replacements replace_host;
1492 replace_host.SetHostStr("localhost");
1493 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host);
1495 ui_test_utils::NavigateToURL(browser(), navigate_to_url);
1496 ASSERT_TRUE(
1497 RunPlatformAppTest("platform_apps/web_view/dom_storage_isolation"));
1498 // Verify that the browser tab's local/session storage does not have the same
1499 // values which were stored by the webviews.
1500 std::string output;
1501 std::string get_local_storage(
1502 "window.domAutomationController.send("
1503 "window.localStorage.getItem('foo') || 'badval')");
1504 std::string get_session_storage(
1505 "window.domAutomationController.send("
1506 "window.localStorage.getItem('baz') || 'badval')");
1507 ASSERT_TRUE(ExecuteScriptAndExtractString(
1508 browser()->tab_strip_model()->GetWebContentsAt(0),
1509 get_local_storage.c_str(), &output));
1510 EXPECT_STREQ("badval", output.c_str());
1511 ASSERT_TRUE(ExecuteScriptAndExtractString(
1512 browser()->tab_strip_model()->GetWebContentsAt(0),
1513 get_session_storage.c_str(), &output));
1514 EXPECT_STREQ("badval", output.c_str());
1517 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1518 // an app with multiple webview tags and each tag creates an IndexedDB record,
1519 // which the test checks to ensure proper storage isolation is enforced.
1520 IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) {
1521 ASSERT_TRUE(StartEmbeddedTestServer());
1522 ASSERT_TRUE(RunPlatformAppTest(
1523 "platform_apps/web_view/isolation_indexeddb")) << message_;
1526 // This test ensures that closing app window on 'loadcommit' does not crash.
1527 // The test launches an app with guest and closes the window on loadcommit. It
1528 // then launches the app window again. The process is repeated 3 times.
1529 // http://crbug.com/291278
1530 #if defined(OS_WIN)
1531 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1532 #else
1533 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1534 #endif
1535 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CloseOnLoadcommit) {
1536 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit",
1537 "done-close-on-loadcommit");
1540 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny_TestDeny) {
1541 MediaAccessAPIDenyTestHelper("testDeny");
1544 IN_PROC_BROWSER_TEST_F(WebViewTest,
1545 MediaAccessAPIDeny_TestDenyThenAllowThrows) {
1546 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1549 IN_PROC_BROWSER_TEST_F(WebViewTest,
1550 MediaAccessAPIDeny_TestDenyWithPreventDefault) {
1551 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1554 IN_PROC_BROWSER_TEST_F(WebViewTest,
1555 MediaAccessAPIDeny_TestNoListenersImplyDeny) {
1556 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1559 IN_PROC_BROWSER_TEST_F(WebViewTest,
1560 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny) {
1561 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1564 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string& test_name) {
1565 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1566 LoadAndLaunchPlatformApp("web_view/media_access/allow", "Launched");
1568 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1569 ASSERT_TRUE(embedder_web_contents);
1570 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
1571 embedder_web_contents->SetDelegate(mock.get());
1573 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1574 done_listener.set_failure_message("TEST_FAILED");
1575 EXPECT_TRUE(
1576 content::ExecuteScript(
1577 embedder_web_contents,
1578 base::StringPrintf("startAllowTest('%s')",
1579 test_name.c_str())));
1580 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1582 mock->WaitForRequestMediaPermission();
1585 IN_PROC_BROWSER_TEST_F(WebViewTest, OpenURLFromTab_CurrentTab_Abort) {
1586 LoadAppWithGuest("web_view/simple");
1588 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will
1589 // navigate the current <webview>.
1590 ExtensionTestMessageListener load_listener("WebViewTest.LOADSTOP", false);
1592 // Navigating to a file URL is forbidden inside a <webview>.
1593 content::OpenURLParams params(GURL("file://foo"),
1594 content::Referrer(),
1595 CURRENT_TAB,
1596 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1597 true /* is_renderer_initiated */);
1598 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1599 GetGuestWebContents(), params);
1601 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
1603 // Verify that the <webview> ends up at about:blank.
1604 EXPECT_EQ(GURL(url::kAboutBlankURL),
1605 GetGuestWebContents()->GetLastCommittedURL());
1608 // A navigation to a web-safe URL should succeed, even if it is not renderer-
1609 // initiated, such as a navigation from the PDF viewer.
1610 IN_PROC_BROWSER_TEST_F(WebViewTest, OpenURLFromTab_CurrentTab_Succeed) {
1611 LoadAppWithGuest("web_view/simple");
1613 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will
1614 // navigate the current <webview>.
1615 ExtensionTestMessageListener load_listener("WebViewTest.LOADSTOP", false);
1617 GURL test_url("http://www.google.com");
1618 content::OpenURLParams params(test_url,
1619 content::Referrer(),
1620 CURRENT_TAB,
1621 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1622 false /* is_renderer_initiated */);
1623 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1624 GetGuestWebContents(), params);
1626 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
1628 EXPECT_EQ(test_url, GetGuestWebContents()->GetLastCommittedURL());
1631 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest, OpenURLFromTab_NewWindow_Abort) {
1632 LoadAppWithGuest("web_view/simple");
1634 // Verify that OpenURLFromTab with a window disposition of NEW_BACKGROUND_TAB
1635 // will trigger the <webview>'s New Window API.
1636 ExtensionTestMessageListener new_window_listener(
1637 "WebViewTest.NEWWINDOW", false);
1639 // Navigating to a file URL is forbidden inside a <webview>.
1640 content::OpenURLParams params(GURL("file://foo"),
1641 content::Referrer(),
1642 NEW_BACKGROUND_TAB,
1643 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1644 true /* is_renderer_initiated */);
1645 GetGuestWebContents()->GetDelegate()->OpenURLFromTab(
1646 GetGuestWebContents(), params);
1648 ASSERT_TRUE(new_window_listener.WaitUntilSatisfied());
1650 // Verify that a new guest was created.
1651 content::WebContents* new_guest_web_contents =
1652 GetGuestViewManager()->GetLastGuestCreated();
1653 EXPECT_NE(GetGuestWebContents(), new_guest_web_contents);
1655 // Verify that the new <webview> guest ends up at about:blank.
1656 EXPECT_EQ(GURL(url::kAboutBlankURL),
1657 new_guest_web_contents->GetLastCommittedURL());
1660 // This test executes the context menu command 'LanguageSettings' which will
1661 // load chrome://settings/languages in a browser window. This is a browser-
1662 // initiated operation and so we expect this to succeed if the embedder is
1663 // allowed to perform the operation.
1664 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenuLanguageSettings) {
1665 LoadAppWithGuest("web_view/context_menus/basic");
1667 content::WebContents* guest_web_contents = GetGuestWebContents();
1668 content::WebContents* embedder = GetEmbedderWebContents();
1669 ASSERT_TRUE(embedder);
1671 // Create and build our test context menu.
1672 content::WebContentsAddedObserver web_contents_added_observer;
1674 GURL page_url("http://www.google.com");
1675 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1676 guest_web_contents, page_url, GURL(), GURL()));
1677 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, 0);
1679 content::WebContents* new_contents =
1680 web_contents_added_observer.GetWebContents();
1682 // Verify that a new WebContents has been created that is at the Language
1683 // Settings page.
1684 EXPECT_EQ(GURL("chrome://settings/languages"),
1685 new_contents->GetVisibleURL());
1688 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) {
1689 LoadAppWithGuest("web_view/context_menus/basic");
1691 content::WebContents* guest_web_contents = GetGuestWebContents();
1692 content::WebContents* embedder = GetEmbedderWebContents();
1693 ASSERT_TRUE(embedder);
1695 // 1. Basic property test.
1696 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED");
1698 // 2. Create a menu item and wait for created callback to be called.
1699 ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED");
1701 // 3. Click the created item, wait for the click handlers to fire from JS.
1702 ExtensionTestMessageListener click_listener("ITEM_CLICKED", false);
1703 GURL page_url("http://www.google.com");
1704 // Create and build our test context menu.
1705 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1706 guest_web_contents, page_url, GURL(), GURL()));
1707 // Look for the extension item in the menu, and execute it.
1708 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
1709 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id));
1710 menu->ExecuteCommand(command_id, 0);
1711 // Wait for embedder's script to tell us its onclick fired, it does
1712 // chrome.test.sendMessage('ITEM_CLICKED')
1713 ASSERT_TRUE(click_listener.WaitUntilSatisfied());
1715 // 4. Update the item's title and verify.
1716 ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED");
1717 MenuItem::List items = GetItems();
1718 ASSERT_EQ(1u, items.size());
1719 MenuItem* item = items.at(0);
1720 EXPECT_EQ("new_title", item->title());
1722 // 5. Remove the item.
1723 ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED");
1724 MenuItem::List items_after_removal = GetItems();
1725 ASSERT_EQ(0u, items_after_removal.size());
1727 // 6. Add some more items.
1728 ExecuteScriptWaitForTitle(
1729 embedder, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1730 MenuItem::List items_after_insertion = GetItems();
1731 ASSERT_EQ(3u, items_after_insertion.size());
1733 // 7. Test removeAll().
1734 ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED");
1735 MenuItem::List items_after_all_removal = GetItems();
1736 ASSERT_EQ(0u, items_after_all_removal.size());
1739 // Called in the TestContextMenu test to cancel the context menu after its
1740 // shown notification is received.
1741 static bool ContextMenuNotificationCallback(
1742 const content::NotificationSource& source,
1743 const content::NotificationDetails& details) {
1744 auto context_menu = content::Source<RenderViewContextMenu>(source).ptr();
1745 base::ThreadTaskRunnerHandle::Get()->PostTask(
1746 FROM_HERE, base::Bind(&RenderViewContextMenuBase::Cancel,
1747 base::Unretained(context_menu)));
1748 return true;
1751 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_PreventDefault) {
1752 LoadAppWithGuest("web_view/context_menus/basic");
1754 content::WebContents* guest_web_contents = GetGuestWebContents();
1755 content::WebContents* embedder = GetEmbedderWebContents();
1756 ASSERT_TRUE(embedder);
1758 // Add a preventDefault() call on context menu event so context menu
1759 // does not show up.
1760 ExtensionTestMessageListener prevent_default_listener(
1761 "WebViewTest.CONTEXT_MENU_DEFAULT_PREVENTED", false);
1762 EXPECT_TRUE(content::ExecuteScript(embedder, "registerPreventDefault()"));
1763 ContextMenuCallCountObserver context_menu_shown_observer;
1765 OpenContextMenu(guest_web_contents);
1767 EXPECT_TRUE(prevent_default_listener.WaitUntilSatisfied());
1768 // Expect the menu to not show up.
1769 EXPECT_EQ(0, context_menu_shown_observer.num_times_shown());
1771 // Now remove the preventDefault() and expect context menu to be shown.
1772 ExecuteScriptWaitForTitle(
1773 embedder, "removePreventDefault()", "PREVENT_DEFAULT_LISTENER_REMOVED");
1774 OpenContextMenu(guest_web_contents);
1776 // We expect to see a context menu for the second call to |OpenContextMenu|.
1777 context_menu_shown_observer.Wait();
1778 EXPECT_EQ(1, context_menu_shown_observer.num_times_shown());
1781 // Tests that a context menu is created when right-clicking in the webview. This
1782 // also tests that the 'contextmenu' event is handled correctly.
1783 IN_PROC_BROWSER_TEST_F(WebViewTest, TestContextMenu) {
1784 LoadAppWithGuest("web_view/context_menus/basic");
1785 content::WebContents* guest_web_contents = GetGuestWebContents();
1787 // Register an observer for the context menu.
1788 content::WindowedNotificationObserver menu_observer(
1789 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
1790 base::Bind(ContextMenuNotificationCallback));
1792 OpenContextMenu(guest_web_contents);
1794 // Wait for the context menu to be visible.
1795 menu_observer.Wait();
1798 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) {
1799 MediaAccessAPIAllowTestHelper("testAllow");
1802 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) {
1803 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1806 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) {
1807 MediaAccessAPIAllowTestHelper("testAllowTwice");
1810 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAsync) {
1811 MediaAccessAPIAllowTestHelper("testAllowAsync");
1814 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestCheck) {
1815 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1816 LoadAndLaunchPlatformApp("web_view/media_access/check", "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("startCheckTest('')")));
1829 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1831 mock->WaitForCheckMediaPermission();
1834 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1835 // guests.
1836 IN_PROC_BROWSER_TEST_F(WebViewTest, ScreenCoordinates) {
1837 ASSERT_TRUE(RunPlatformAppTestWithArg(
1838 "platform_apps/web_view/common", "screen_coordinates"))
1839 << message_;
1842 #if defined(OS_CHROMEOS)
1843 IN_PROC_BROWSER_TEST_F(WebViewTest, ChromeVoxInjection) {
1844 EXPECT_FALSE(
1845 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1847 chromeos::SpeechMonitor monitor;
1848 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1849 true, ui::A11Y_NOTIFICATION_NONE);
1850 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
1852 ASSERT_TRUE(StartEmbeddedTestServer());
1853 content::WebContents* guest_web_contents = LoadGuest(
1854 "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1855 "web_view/chromevox_injection");
1856 ASSERT_TRUE(guest_web_contents);
1858 EXPECT_EQ("chrome vox test title", monitor.GetNextUtterance());
1860 #endif
1862 // Flaky on Windows. http://crbug.com/303966
1863 #if defined(OS_WIN)
1864 #define MAYBE_TearDownTest DISABLED_TearDownTest
1865 #else
1866 #define MAYBE_TearDownTest TearDownTest
1867 #endif
1868 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) {
1869 const extensions::Extension* extension =
1870 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
1871 extensions::AppWindow* window = NULL;
1872 if (!GetAppWindowCount())
1873 window = CreateAppWindow(extension);
1874 else
1875 window = GetFirstAppWindow();
1876 CloseAppWindow(window);
1878 // Load the app again.
1879 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED");
1882 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1883 // platform app) does not have geolocation permission for this test.
1884 // No matter what the API does, geolocation permission would be denied.
1885 // Note that the test name prefix must be "GeolocationAPI".
1886 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) {
1887 TestHelper("testDenyDenies",
1888 "web_view/geolocation/embedder_has_no_permission",
1889 NEEDS_TEST_SERVER);
1892 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessDeny) {
1893 TestHelper("testDenyDenies",
1894 "web_view/geolocation/embedder_has_no_permission",
1895 NEEDS_TEST_SERVER);
1898 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1899 // platform app) has geolocation permission
1901 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1902 // geolocation in this case).
1904 // Also note that these are run separately because OverrideGeolocation() doesn't
1905 // mock out geolocation for multiple navigator.geolocation calls properly and
1906 // the tests become flaky.
1907 // GeolocationAPI* test 1 of 3.
1908 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessAllow) {
1909 TestHelper("testAllow",
1910 "web_view/geolocation/embedder_has_permission",
1911 NEEDS_TEST_SERVER);
1914 // GeolocationAPI* test 2 of 3.
1915 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessDeny) {
1916 TestHelper("testDeny",
1917 "web_view/geolocation/embedder_has_permission",
1918 NEEDS_TEST_SERVER);
1921 // GeolocationAPI* test 3 of 3.
1922 IN_PROC_BROWSER_TEST_F(WebViewTest,
1923 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow) {
1924 TestHelper("testMultipleBridgeIdAllow",
1925 "web_view/geolocation/embedder_has_permission",
1926 NEEDS_TEST_SERVER);
1929 // Tests that
1930 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
1931 // is handled correctly (and does not crash).
1932 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPICancelGeolocation) {
1933 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1934 ASSERT_TRUE(RunPlatformAppTest(
1935 "platform_apps/web_view/geolocation/cancel_request")) << message_;
1938 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_GeolocationRequestGone) {
1939 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1940 ASSERT_TRUE(RunPlatformAppTest(
1941 "platform_apps/web_view/geolocation/geolocation_request_gone"))
1942 << message_;
1945 // In following FilesystemAPIRequestFromMainThread* tests, guest request
1946 // filesystem access from main thread of the guest.
1947 // FileSystemAPIRequestFromMainThread* test 1 of 3
1948 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromMainThreadAllow) {
1949 TestHelper("testAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER);
1952 // FileSystemAPIRequestFromMainThread* test 2 of 3.
1953 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromMainThreadDeny) {
1954 TestHelper("testDeny", "web_view/filesystem/main", NEEDS_TEST_SERVER);
1957 // FileSystemAPIRequestFromMainThread* test 3 of 3.
1958 IN_PROC_BROWSER_TEST_F(WebViewTest,
1959 FileSystemAPIRequestFromMainThreadDefaultAllow) {
1960 TestHelper("testDefaultAllow", "web_view/filesystem/main", NEEDS_TEST_SERVER);
1963 // In following FilesystemAPIRequestFromWorker* tests, guest create a worker
1964 // to request filesystem access from worker thread.
1965 // FileSystemAPIRequestFromWorker* test 1 of 3
1966 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromWorkerAllow) {
1967 TestHelper("testAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
1970 // FileSystemAPIRequestFromWorker* test 2 of 3.
1971 IN_PROC_BROWSER_TEST_F(WebViewTest, FileSystemAPIRequestFromWorkerDeny) {
1972 TestHelper("testDeny", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
1975 // FileSystemAPIRequestFromWorker* test 3 of 3.
1976 IN_PROC_BROWSER_TEST_F(WebViewTest,
1977 FileSystemAPIRequestFromWorkerDefaultAllow) {
1978 TestHelper(
1979 "testDefaultAllow", "web_view/filesystem/worker", NEEDS_TEST_SERVER);
1982 // In following FilesystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* tests,
1983 // embedder contains a single webview guest. The guest creates a shared worker
1984 // to request filesystem access from worker thread.
1985 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 1 of 3
1986 IN_PROC_BROWSER_TEST_F(
1987 WebViewTest,
1988 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestAllow) {
1989 TestHelper("testAllow",
1990 "web_view/filesystem/shared_worker/single",
1991 NEEDS_TEST_SERVER);
1994 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 2 of 3.
1995 IN_PROC_BROWSER_TEST_F(
1996 WebViewTest,
1997 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDeny) {
1998 TestHelper("testDeny",
1999 "web_view/filesystem/shared_worker/single",
2000 NEEDS_TEST_SERVER);
2003 // FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuest* test 3 of 3.
2004 IN_PROC_BROWSER_TEST_F(
2005 WebViewTest,
2006 FileSystemAPIRequestFromSharedWorkerOfSingleWebViewGuestDefaultAllow) {
2007 TestHelper(
2008 "testDefaultAllow",
2009 "web_view/filesystem/shared_worker/single",
2010 NEEDS_TEST_SERVER);
2013 // In following FilesystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* tests,
2014 // embedder contains mutiple webview guests. Each guest creates a shared worker
2015 // to request filesystem access from worker thread.
2016 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 1 of 3
2017 IN_PROC_BROWSER_TEST_F(
2018 WebViewTest,
2019 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsAllow) {
2020 TestHelper("testAllow",
2021 "web_view/filesystem/shared_worker/multiple",
2022 NEEDS_TEST_SERVER);
2025 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 2 of 3.
2026 IN_PROC_BROWSER_TEST_F(
2027 WebViewTest,
2028 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDeny) {
2029 TestHelper("testDeny",
2030 "web_view/filesystem/shared_worker/multiple",
2031 NEEDS_TEST_SERVER);
2034 // FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuests* test 3 of 3.
2035 IN_PROC_BROWSER_TEST_F(
2036 WebViewTest,
2037 FileSystemAPIRequestFromSharedWorkerOfMultiWebViewGuestsDefaultAllow) {
2038 TestHelper(
2039 "testDefaultAllow",
2040 "web_view/filesystem/shared_worker/multiple",
2041 NEEDS_TEST_SERVER);
2044 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearData) {
2045 #if defined(OS_WIN)
2046 // Flaky on XP bot http://crbug.com/282674
2047 if (base::win::GetVersion() <= base::win::VERSION_XP)
2048 return;
2049 #endif
2051 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2052 ASSERT_TRUE(RunPlatformAppTestWithArg(
2053 "platform_apps/web_view/common", "cleardata"))
2054 << message_;
2057 #if defined(OS_WIN)
2058 // Test is disabled on Windows because it fails often (~9% time)
2059 // http://crbug.com/489088
2060 #define MAYBE_ClearDataCache DISABLED_ClearDataCache
2061 #else
2062 #define MAYBE_ClearDataCache ClearDataCache
2063 #endif
2064 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ClearDataCache) {
2065 TestHelper("testClearCache", "web_view/clear_data_cache", NEEDS_TEST_SERVER);
2068 IN_PROC_BROWSER_TEST_F(WebViewTest, ConsoleMessage) {
2069 ASSERT_TRUE(RunPlatformAppTestWithArg(
2070 "platform_apps/web_view/common", "console_messages"))
2071 << message_;
2074 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) {
2075 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2076 content::WebContents* guest_web_contents =
2077 LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
2078 "web_view/download");
2079 ASSERT_TRUE(guest_web_contents);
2081 // Replace WebContentsDelegate with mock version so we can intercept download
2082 // requests.
2083 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate();
2084 scoped_ptr<MockDownloadWebContentsDelegate>
2085 mock_delegate(new MockDownloadWebContentsDelegate(delegate));
2086 guest_web_contents->SetDelegate(mock_delegate.get());
2088 // Start test.
2089 // 1. Guest requests a download that its embedder denies.
2090 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2091 "startDownload('download-link-1')"));
2092 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
2093 mock_delegate->Reset();
2095 // 2. Guest requests a download that its embedder allows.
2096 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2097 "startDownload('download-link-2')"));
2098 mock_delegate->WaitForCanDownload(true); // Expect to allow.
2099 mock_delegate->Reset();
2101 // 3. Guest requests a download that its embedder ignores, this implies deny.
2102 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
2103 "startDownload('download-link-3')"));
2104 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
2107 // This test makes sure loading <webview> does not crash when there is an
2108 // extension which has content script whitelisted/forced.
2109 IN_PROC_BROWSER_TEST_F(WebViewTest, WhitelistedContentScript) {
2110 // Whitelist the extension for running content script we are going to load.
2111 extensions::ExtensionsClient::ScriptingWhitelist whitelist;
2112 const std::string extension_id = "imeongpbjoodlnmlakaldhlcmijmhpbb";
2113 whitelist.push_back(extension_id);
2114 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
2116 // Load the extension.
2117 const extensions::Extension* content_script_whitelisted_extension =
2118 LoadExtension(test_data_dir_.AppendASCII(
2119 "platform_apps/web_view/extension_api/content_script"));
2120 ASSERT_TRUE(content_script_whitelisted_extension);
2121 ASSERT_EQ(extension_id, content_script_whitelisted_extension->id());
2123 // Now load an app with <webview>.
2124 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted",
2125 "TEST_PASSED");
2128 IN_PROC_BROWSER_TEST_F(WebViewTest, SendMessageToExtensionFromGuest) {
2129 // Load the extension as a normal, non-component extension.
2130 const extensions::Extension* extension =
2131 LoadExtension(test_data_dir_.AppendASCII(
2132 "platform_apps/web_view/extension_api/component_extension"));
2133 ASSERT_TRUE(extension);
2135 TestHelper("testNonComponentExtension", "web_view/component_extension",
2136 NEEDS_TEST_SERVER);
2139 IN_PROC_BROWSER_TEST_F(WebViewTest, SendMessageToComponentExtensionFromGuest) {
2140 const extensions::Extension* component_extension =
2141 LoadExtensionAsComponent(test_data_dir_.AppendASCII(
2142 "platform_apps/web_view/extension_api/component_extension"));
2143 ASSERT_TRUE(component_extension);
2145 TestHelper("testComponentExtension", "web_view/component_extension",
2146 NEEDS_TEST_SERVER);
2148 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
2149 ASSERT_TRUE(embedder_web_contents);
2151 // Retrive the guestProcessId and guestRenderFrameRoutingId from the
2152 // extension.
2153 int guest_process_id = content::ChildProcessHost::kInvalidUniqueID;
2154 content::ExecuteScriptAndGetValue(embedder_web_contents->GetMainFrame(),
2155 "window.guestProcessId")
2156 ->GetAsInteger(&guest_process_id);
2157 int guest_render_frame_routing_id = MSG_ROUTING_NONE;
2158 content::ExecuteScriptAndGetValue(embedder_web_contents->GetMainFrame(),
2159 "window.guestRenderFrameRoutingId")
2160 ->GetAsInteger(&guest_render_frame_routing_id);
2162 auto* guest_rfh = content::RenderFrameHost::FromID(
2163 guest_process_id, guest_render_frame_routing_id);
2164 // Verify that the guest related info (guest_process_id and
2165 // guest_render_frame_routing_id) actually points to a WebViewGuest.
2166 ASSERT_TRUE(extensions::WebViewGuest::FromWebContents(
2167 content::WebContents::FromRenderFrameHost(guest_rfh)));
2170 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentReady) {
2171 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
2172 << message_;
2175 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentInteractive) {
2176 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
2177 << message_;
2180 IN_PROC_BROWSER_TEST_F(WebViewSpeechAPITest,
2181 SpeechRecognitionAPI_HasPermissionAllow) {
2182 ASSERT_TRUE(
2183 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2184 "allowTest"))
2185 << message_;
2188 IN_PROC_BROWSER_TEST_F(WebViewSpeechAPITest,
2189 SpeechRecognitionAPI_HasPermissionDeny) {
2190 ASSERT_TRUE(
2191 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
2192 "denyTest"))
2193 << message_;
2196 IN_PROC_BROWSER_TEST_F(WebViewSpeechAPITest,
2197 SpeechRecognitionAPI_NoPermission) {
2198 ASSERT_TRUE(
2199 RunPlatformAppTestWithArg("platform_apps/web_view/common",
2200 "speech_recognition_api_no_permission"))
2201 << message_;
2204 // Tests overriding user agent.
2205 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent) {
2206 ASSERT_TRUE(RunPlatformAppTestWithArg(
2207 "platform_apps/web_view/common", "useragent")) << message_;
2210 IN_PROC_BROWSER_TEST_F(WebViewNewWindowTest, UserAgent_NewWindow) {
2211 ASSERT_TRUE(RunPlatformAppTestWithArg(
2212 "platform_apps/web_view/common",
2213 "useragent_newwindow")) << message_;
2216 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPermission) {
2217 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
2218 << message_;
2221 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestAlertDialog) {
2222 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER);
2225 IN_PROC_BROWSER_TEST_F(WebViewTest, TestConfirmDialog) {
2226 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER);
2229 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogCancel) {
2230 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER);
2233 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultCancel) {
2234 TestHelper("testConfirmDialogDefaultCancel",
2235 "web_view/dialog",
2236 NO_TEST_SERVER);
2239 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultGCCancel) {
2240 TestHelper("testConfirmDialogDefaultGCCancel",
2241 "web_view/dialog",
2242 NO_TEST_SERVER);
2245 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestPromptDialog) {
2246 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER);
2249 IN_PROC_BROWSER_TEST_F(WebViewTest, NoContentSettingsAPI) {
2250 // Load the extension.
2251 const extensions::Extension* content_settings_extension =
2252 LoadExtension(
2253 test_data_dir_.AppendASCII(
2254 "platform_apps/web_view/extension_api/content_settings"));
2255 ASSERT_TRUE(content_settings_extension);
2256 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER);
2259 #if defined(ENABLE_PLUGINS)
2260 class WebViewPluginTest : public WebViewTest {
2261 protected:
2262 void SetUpCommandLine(base::CommandLine* command_line) override {
2263 WebViewTest::SetUpCommandLine(command_line);
2264 ASSERT_TRUE(ppapi::RegisterTestPlugin(command_line));
2268 IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginEvent) {
2269 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER);
2272 IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginInternalResource) {
2273 const char kTestMimeType[] = "application/pdf";
2274 const char kTestFileType[] = "pdf";
2275 content::WebPluginInfo plugin_info;
2276 plugin_info.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS;
2277 plugin_info.mime_types.push_back(
2278 content::WebPluginMimeType(kTestMimeType, kTestFileType, std::string()));
2279 content::PluginService::GetInstance()->RegisterInternalPlugin(plugin_info,
2280 true);
2282 TestHelper("testPluginLoadInternalResource", "web_view/shim", NO_TEST_SERVER);
2284 #endif // defined(ENABLE_PLUGINS)
2286 class WebViewCaptureTest : public WebViewTest {
2287 public:
2288 WebViewCaptureTest() {}
2289 ~WebViewCaptureTest() override {}
2290 void SetUp() override {
2291 EnablePixelOutput();
2292 WebViewTest::SetUp();
2296 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestZoomAPI) {
2297 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER);
2300 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) {
2301 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER);
2304 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) {
2305 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER);
2308 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadDataAPI) {
2309 TestHelper("testLoadDataAPI", "web_view/shim", NEEDS_TEST_SERVER);
2312 // This test verifies that the resize and contentResize events work correctly.
2313 IN_PROC_BROWSER_TEST_F(WebViewSizeTest, Shim_TestResizeEvents) {
2314 TestHelper("testResizeEvents", "web_view/shim", NO_TEST_SERVER);
2317 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPerOriginZoomMode) {
2318 TestHelper("testPerOriginZoomMode", "web_view/shim", NO_TEST_SERVER);
2321 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPerViewZoomMode) {
2322 TestHelper("testPerViewZoomMode", "web_view/shim", NO_TEST_SERVER);
2325 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDisabledZoomMode) {
2326 TestHelper("testDisabledZoomMode", "web_view/shim", NO_TEST_SERVER);
2329 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestZoomBeforeNavigation) {
2330 TestHelper("testZoomBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
2333 // This test verify that the set of rules registries of a webview will be
2334 // removed from RulesRegistryService after the webview is gone.
2335 // http://crbug.com/438327
2336 IN_PROC_BROWSER_TEST_F(
2337 WebViewTest,
2338 DISABLED_Shim_TestRulesRegistryIDAreRemovedAfterWebViewIsGone) {
2339 LoadAppWithGuest("web_view/rules_registry");
2341 content::WebContents* embedder_web_contents = GetEmbedderWebContents();
2342 ASSERT_TRUE(embedder_web_contents);
2343 scoped_ptr<EmbedderWebContentsObserver> observer(
2344 new EmbedderWebContentsObserver(embedder_web_contents));
2346 content::WebContents* guest_web_contents = GetGuestWebContents();
2347 ASSERT_TRUE(guest_web_contents);
2348 extensions::WebViewGuest* guest =
2349 extensions::WebViewGuest::FromWebContents(guest_web_contents);
2350 ASSERT_TRUE(guest);
2352 // Register rule for the guest.
2353 Profile* profile = browser()->profile();
2354 int rules_registry_id =
2355 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2356 guest->owner_web_contents()->GetRenderProcessHost()->GetID(),
2357 guest->view_instance_id());
2359 extensions::RulesRegistryService* registry_service =
2360 extensions::RulesRegistryService::Get(profile);
2361 extensions::TestRulesRegistry* rules_registry =
2362 new extensions::TestRulesRegistry(
2363 content::BrowserThread::UI, "ui", rules_registry_id);
2364 registry_service->RegisterRulesRegistry(make_scoped_refptr(rules_registry));
2366 EXPECT_TRUE(registry_service->GetRulesRegistry(
2367 rules_registry_id, "ui").get());
2369 // Kill the embedder's render process, so the webview will go as well.
2370 base::Process process = base::Process::DeprecatedGetProcessFromHandle(
2371 embedder_web_contents->GetRenderProcessHost()->GetHandle());
2372 process.Terminate(0, false);
2373 observer->WaitForEmbedderRenderProcessTerminate();
2375 EXPECT_FALSE(registry_service->GetRulesRegistry(
2376 rules_registry_id, "ui").get());
2379 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_WebViewWebRequestRegistryHasNoCache) {
2380 LoadAppWithGuest("web_view/rules_registry");
2382 content::WebContents* guest_web_contents = GetGuestWebContents();
2383 ASSERT_TRUE(guest_web_contents);
2384 extensions::WebViewGuest* guest =
2385 extensions::WebViewGuest::FromWebContents(guest_web_contents);
2386 ASSERT_TRUE(guest);
2388 Profile* profile = browser()->profile();
2389 extensions::RulesRegistryService* registry_service =
2390 extensions::RulesRegistryService::Get(profile);
2391 int rules_registry_id =
2392 extensions::WebViewGuest::GetOrGenerateRulesRegistryID(
2393 guest->owner_web_contents()->GetRenderProcessHost()->GetID(),
2394 guest->view_instance_id());
2396 // Get an existing registered rule for the guest.
2397 extensions::RulesRegistry* registry =
2398 registry_service->GetRulesRegistry(
2399 rules_registry_id,
2400 extensions::declarative_webrequest_constants::kOnRequest).get();
2402 EXPECT_TRUE(registry);
2403 EXPECT_FALSE(registry->rules_cache_delegate_for_testing());
2406 // This test verifies that webview.contentWindow works inside an iframe.
2407 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebViewInsideFrame) {
2408 LoadAppWithGuest("web_view/inside_iframe");
2411 // <webview> screenshot capture fails with ubercomp.
2412 // See http://crbug.com/327035.
2413 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest,
2414 DISABLED_Shim_ScreenshotCapture) {
2415 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER);
2418 // Tests that browser process does not crash when loading plugin inside
2419 // <webview> with content settings set to CONTENT_SETTING_BLOCK.
2420 IN_PROC_BROWSER_TEST_F(WebViewTest, TestPlugin) {
2421 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
2422 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
2423 TestHelper("testPlugin", "web_view/shim", NEEDS_TEST_SERVER);
2426 #if defined(OS_WIN)
2427 // Test is disabled on Windows because it times out often.
2428 // http://crbug.com/403325
2429 #define MAYBE_WebViewInBackgroundPage \
2430 DISABLED_WebViewInBackgroundPage
2431 #else
2432 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage
2433 #endif
2434 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) {
2435 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))
2436 << message_;
2439 // This test verifies that the allowtransparency attribute properly propagates.
2440 IN_PROC_BROWSER_TEST_F(WebViewTest, AllowTransparencyAndAllowScalingPropagate) {
2441 LoadAppWithGuest("web_view/simple");
2443 ASSERT_TRUE(GetGuestWebContents());
2444 extensions::WebViewGuest* guest =
2445 extensions::WebViewGuest::FromWebContents(GetGuestWebContents());
2446 ASSERT_TRUE(guest->allow_transparency());
2447 ASSERT_TRUE(guest->allow_scaling());
2450 IN_PROC_BROWSER_TEST_F(WebViewCommonTest, BasicPostMessage) {
2451 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2452 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/post_message/basic"))
2453 << message_;
2456 // Tests that webviews do get garbage collected.
2457 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGarbageCollect) {
2458 TestHelper("testGarbageCollect", "web_view/shim", NO_TEST_SERVER);
2459 GetGuestViewManager()->WaitForSingleViewGarbageCollected();
2462 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCloseNewWindowCleanup) {
2463 TestHelper("testCloseNewWindowCleanup", "web_view/shim", NEEDS_TEST_SERVER);
2464 auto gvm = GetGuestViewManager();
2465 gvm->WaitForLastGuestDeleted();
2466 ASSERT_EQ(gvm->num_embedder_processes_destroyed(), 0);
2469 // Ensure that focusing a WebView while it is already focused does not blur the
2470 // guest content.
2471 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFocusWhileFocused) {
2472 TestHelper("testFocusWhileFocused", "web_view/shim", NO_TEST_SERVER);
2475 IN_PROC_BROWSER_TEST_F(WebViewTest, NestedGuestContainerBounds) {
2476 TestHelper("testPDFInWebview", "web_view/shim", NO_TEST_SERVER);
2478 std::vector<content::WebContents*> guest_web_contents_list;
2479 GetGuestViewManager()->WaitForNumGuestsCreated(2u);
2480 GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
2481 ASSERT_EQ(2u, guest_web_contents_list.size());
2483 content::WebContents* web_view_contents = guest_web_contents_list[0];
2484 content::WebContents* mime_handler_view_contents = guest_web_contents_list[1];
2486 // Make sure we've completed loading |mime_handler_view_guest|.
2487 bool load_success = pdf_extension_test_util::EnsurePDFHasLoaded(
2488 web_view_contents);
2489 EXPECT_TRUE(load_success);
2491 gfx::Rect web_view_container_bounds = web_view_contents->GetContainerBounds();
2492 gfx::Rect mime_handler_view_container_bounds =
2493 mime_handler_view_contents->GetContainerBounds();
2494 EXPECT_EQ(web_view_container_bounds.origin(),
2495 mime_handler_view_container_bounds.origin());
2498 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestMailtoLink) {
2499 TestHelper("testMailtoLink", "web_view/shim", NEEDS_TEST_SERVER);
2502 // Tests that a renderer navigation from an unattached guest that results in a
2503 // server redirect works properly.
2504 IN_PROC_BROWSER_TEST_F(WebViewTest,
2505 Shim_TestRendererNavigationRedirectWhileUnattached) {
2506 TestHelper("testRendererNavigationRedirectWhileUnattached",
2507 "web_view/shim", NEEDS_TEST_SERVER);
2510 #if defined(USE_AURA)
2511 // TODO(wjmaclean): when WebViewTest is re-enabled on the site-isolation
2512 // bots, then re-enable this test class as well.
2513 // https://crbug.com/503751
2514 class WebViewFocusTest : public WebViewTest {
2515 public:
2516 ~WebViewFocusTest() override {}
2518 void SetUpCommandLine(base::CommandLine* command_line) override {
2519 WebViewTest::SetUpCommandLine(command_line);
2521 command_line->AppendSwitchASCII(switches::kTouchEvents,
2522 switches::kTouchEventsEnabled);
2525 void ForceCompositorFrame() {
2526 if (!frame_watcher_) {
2527 frame_watcher_ = new content::FrameWatcher();
2528 frame_watcher_->AttachTo(GetEmbedderWebContents());
2531 while (!RequestFrame(GetEmbedderWebContents())) {
2532 // RequestFrame failed because we were waiting on an ack ... wait a short
2533 // time and retry.
2534 base::RunLoop run_loop;
2535 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2536 FROM_HERE, run_loop.QuitClosure(),
2537 base::TimeDelta::FromMilliseconds(10));
2538 run_loop.Run();
2540 frame_watcher_->WaitFrames(1);
2543 private:
2544 scoped_refptr<content::FrameWatcher> frame_watcher_;
2547 class FocusWaiter : public views::FocusChangeListener {
2548 public:
2549 explicit FocusWaiter(views::View* view_to_wait_for)
2550 : view_to_wait_for_(view_to_wait_for) {
2551 view_to_wait_for_->GetFocusManager()->AddFocusChangeListener(this);
2553 ~FocusWaiter() override {
2554 view_to_wait_for_->GetFocusManager()->RemoveFocusChangeListener(this);
2557 void Wait() {
2558 if (view_to_wait_for_->HasFocus())
2559 return;
2561 base::MessageLoop::current()->Run();
2564 // FocusChangeListener implementation.
2565 void OnWillChangeFocus(views::View* focused_before,
2566 views::View* focused_now) override {}
2567 void OnDidChangeFocus(views::View* focused_before,
2568 views::View* focused_now) override {
2569 if (view_to_wait_for_ == focused_now)
2570 base::MessageLoop::current()->QuitWhenIdle();
2573 private:
2574 views::View* view_to_wait_for_;
2576 DISALLOW_COPY_AND_ASSIGN(FocusWaiter);
2579 // The following test verifies that a views::WebView hosting an embedder
2580 // gains focus on touchstart.
2581 IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) {
2582 LoadAppWithGuest("web_view/accept_touch_events");
2584 content::WebContents* web_contents = GetEmbedderWebContents();
2585 content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost();
2587 bool embedder_has_touch_handler =
2588 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
2589 EXPECT_FALSE(embedder_has_touch_handler);
2591 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler");
2593 // Note that we need to wait for the installed/registered touch handler to
2594 // appear in browser process before querying |embedder_rvh|.
2595 // In practice, since we do a roundrtip from browser process to guest and
2596 // back, this is sufficient.
2597 embedder_has_touch_handler =
2598 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh);
2599 EXPECT_TRUE(embedder_has_touch_handler);
2601 extensions::AppWindow* app_window = GetFirstAppWindowForBrowser(browser());
2602 aura::Window* window = app_window->GetNativeWindow();
2603 EXPECT_TRUE(app_window);
2604 EXPECT_TRUE(window);
2605 views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
2606 EXPECT_TRUE(widget->GetRootView());
2607 // We only expect a single views::webview in the view hierarchy.
2608 views::View* aura_webview = FindWebView(widget->GetRootView());
2609 ASSERT_TRUE(aura_webview);
2610 gfx::Rect bounds(aura_webview->bounds());
2611 EXPECT_TRUE(aura_webview->IsFocusable());
2613 views::View* other_focusable_view = new views::View();
2614 other_focusable_view->SetBounds(bounds.x() + bounds.width(), bounds.y(), 100,
2615 100);
2616 other_focusable_view->SetFocusable(true);
2617 aura_webview->parent()->AddChildView(other_focusable_view);
2618 other_focusable_view->SetPosition(gfx::Point(bounds.x() + bounds.width(), 0));
2620 // Sync changes to compositor.
2621 ForceCompositorFrame();
2623 aura_webview->RequestFocus();
2624 // Verify that other_focusable_view can steal focus from aura_webview.
2625 EXPECT_TRUE(aura_webview->HasFocus());
2626 other_focusable_view->RequestFocus();
2627 EXPECT_TRUE(other_focusable_view->HasFocus());
2628 EXPECT_FALSE(aura_webview->HasFocus());
2630 // Compute location of guest within embedder so we can more accurately
2631 // target our touch event.
2632 gfx::Rect guest_rect = GetGuestWebContents()->GetContainerBounds();
2633 gfx::Point embedder_origin =
2634 GetEmbedderWebContents()->GetContainerBounds().origin();
2635 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y());
2637 // Generate and send synthetic touch event.
2638 FocusWaiter waiter(aura_webview);
2639 content::SimulateTouchPressAt(GetEmbedderWebContents(),
2640 guest_rect.CenterPoint());
2642 // Wait for the TouchStart to propagate and restore focus. Test times out
2643 // on failure.
2644 waiter.Wait();
2646 #endif
2648 #if defined(ENABLE_TASK_MANAGER)
2650 namespace {
2652 base::string16 GetExpectedPrefix(content::WebContents* web_contents) {
2653 DCHECK(web_contents);
2654 guest_view::GuestViewBase* guest =
2655 guest_view::GuestViewBase::FromWebContents(web_contents);
2656 DCHECK(guest);
2658 return l10n_util::GetStringFUTF16(guest->GetTaskPrefix(), base::string16());
2661 const std::vector<task_management::WebContentsTag*>& GetTrackedTags() {
2662 return task_management::WebContentsTagsManager::GetInstance()->
2663 tracked_tags();
2666 } // namespace
2668 // Tests that the pre-existing WebViews are provided to the task manager.
2669 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagementPreExistingWebViews) {
2670 ASSERT_TRUE(StartEmbeddedTestServer());
2672 // Browser tests start with a single tab.
2673 EXPECT_EQ(1U, GetTrackedTags().size());
2675 content::WebContents* guest_contents =
2676 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
2677 "web_view/task_manager");
2679 task_management::MockWebContentsTaskManager task_manager;
2680 task_manager.StartObserving();
2682 // The pre-existing tab and guest tasks are provided.
2683 // TODO(afakhry): This will have to change once we start tracking extensions.
2684 EXPECT_EQ(2U, task_manager.tasks().size());
2686 const task_management::Task* task = task_manager.tasks().back();
2687 EXPECT_EQ(task_management::Task::GUEST, task->GetType());
2688 const base::string16 title = task->title();
2689 const base::string16 expected_prefix = GetExpectedPrefix(guest_contents);
2690 EXPECT_TRUE(base::StartsWith(title,
2691 expected_prefix,
2692 base::CompareCase::INSENSITIVE_ASCII));
2695 // Tests that the post-existing WebViews are provided to the task manager.
2696 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagementPostExistingWebViews) {
2697 ASSERT_TRUE(StartEmbeddedTestServer());
2699 // Browser tests start with a single tab.
2700 EXPECT_EQ(1U, GetTrackedTags().size());
2702 task_management::MockWebContentsTaskManager task_manager;
2703 task_manager.StartObserving();
2705 // Only the "about:blank" tab shows at the moment.
2706 EXPECT_EQ(1U, task_manager.tasks().size());
2707 const task_management::Task* about_blank_task = task_manager.tasks().back();
2708 EXPECT_EQ(task_management::Task::RENDERER, about_blank_task->GetType());
2709 EXPECT_EQ(base::UTF8ToUTF16("Tab: about:blank"), about_blank_task->title());
2711 // Now load a guest web view.
2712 content::WebContents* guest_contents =
2713 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
2714 "web_view/task_manager");
2715 // TODO(afakhry): This will have to change once we start tracking extensions.
2716 EXPECT_EQ(2U, task_manager.tasks().size());
2718 const task_management::Task* task = task_manager.tasks().back();
2719 EXPECT_EQ(task_management::Task::GUEST, task->GetType());
2720 const base::string16 title = task->title();
2721 const base::string16 expected_prefix = GetExpectedPrefix(guest_contents);
2722 EXPECT_TRUE(base::StartsWith(title,
2723 expected_prefix,
2724 base::CompareCase::INSENSITIVE_ASCII));
2727 #endif // defined(ENABLE_TASK_MANAGER)