web_view_browsertest.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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. 4 5#include "apps/ui/native_app_window.h" 6#include "base/path_service.h" 7#include "base/strings/stringprintf.h" 8#include "base/strings/utf_string_conversions.h" 9#include "chrome/app/chrome_command_ids.h" 10#include "chrome/browser/apps/app_browsertest_util.h" 11#include "chrome/browser/chrome_content_browser_client.h" 12#include "chrome/browser/extensions/extension_test_message_listener.h" 13#include "chrome/browser/prerender/prerender_link_manager.h" 14#include "chrome/browser/prerender/prerender_link_manager_factory.h" 15#include "chrome/browser/profiles/profile.h" 16#include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 17#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" 18#include "chrome/browser/task_manager/task_manager_browsertest_util.h" 19#include "chrome/browser/ui/browser.h" 20#include "chrome/browser/ui/browser_dialogs.h" 21#include "chrome/browser/ui/tabs/tab_strip_model.h" 22#include "chrome/test/base/ui_test_utils.h" 23#include "content/public/browser/gpu_data_manager.h" 24#include "content/public/browser/interstitial_page.h" 25#include "content/public/browser/interstitial_page_delegate.h" 26#include "content/public/browser/notification_service.h" 27#include "content/public/browser/render_process_host.h" 28#include "content/public/browser/web_contents_delegate.h" 29#include "content/public/common/content_switches.h" 30#include "content/public/test/browser_test_utils.h" 31#include "content/public/test/fake_speech_recognition_manager.h" 32#include "content/public/test/test_renderer_host.h" 33#include "extensions/common/extension.h" 34#include "extensions/common/extensions_client.h" 35#include "media/base/media_switches.h" 36#include "net/test/embedded_test_server/embedded_test_server.h" 37#include "net/test/embedded_test_server/http_request.h" 38#include "net/test/embedded_test_server/http_response.h" 39#include "ui/gl/gl_switches.h" 40 41#if defined(OS_CHROMEOS) 42#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 43#include "chrome/browser/chromeos/accessibility/speech_monitor.h" 44#endif 45 46// For fine-grained suppression on flaky tests. 47#if defined(OS_WIN) 48#include "base/win/windows_version.h" 49#endif 50 51using extensions::MenuItem; 52using prerender::PrerenderLinkManager; 53using prerender::PrerenderLinkManagerFactory; 54using task_manager::browsertest_util::MatchAboutBlankTab; 55using task_manager::browsertest_util::MatchAnyApp; 56using task_manager::browsertest_util::MatchAnyBackground; 57using task_manager::browsertest_util::MatchAnyTab; 58using task_manager::browsertest_util::MatchAnyWebView; 59using task_manager::browsertest_util::MatchApp; 60using task_manager::browsertest_util::MatchBackground; 61using task_manager::browsertest_util::MatchWebView; 62using task_manager::browsertest_util::WaitForTaskManagerRows; 63using ui::MenuModel; 64 65namespace { 66const char kEmptyResponsePath[] = "/close-socket"; 67const char kRedirectResponsePath[] = "/server-redirect"; 68const char kRedirectResponseFullPath[] = 69 "/extensions/platform_apps/web_view/shim/guest_redirect.html"; 70 71// Platform-specific filename relative to the chrome executable. 72#if defined(OS_WIN) 73const wchar_t library_name[] = L"ppapi_tests.dll"; 74#elif defined(OS_MACOSX) 75const char library_name[] = "ppapi_tests.plugin"; 76#elif defined(OS_POSIX) 77const char library_name[] = "libppapi_tests.so"; 78#endif 79 80class EmptyHttpResponse : public net::test_server::HttpResponse { 81 public: 82 virtual std::string ToResponseString() const OVERRIDE { 83 return std::string(); 84 } 85}; 86 87class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { 88 public: 89 TestInterstitialPageDelegate() { 90 } 91 virtual ~TestInterstitialPageDelegate() {} 92 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } 93}; 94 95// Used to get notified when a guest is created. 96class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient { 97 public: 98 GuestContentBrowserClient() : web_contents_(NULL) {} 99 100 content::WebContents* WaitForGuestCreated() { 101 if (web_contents_) 102 return web_contents_; 103 104 message_loop_runner_ = new content::MessageLoopRunner; 105 message_loop_runner_->Run(); 106 return web_contents_; 107 } 108 109 private: 110 // ChromeContentBrowserClient implementation: 111 virtual void GuestWebContentsAttached( 112 content::WebContents* guest_web_contents, 113 content::WebContents* embedder_web_contents, 114 const base::DictionaryValue& extra_params) OVERRIDE { 115 ChromeContentBrowserClient::GuestWebContentsAttached( 116 guest_web_contents, embedder_web_contents, extra_params); 117 web_contents_ = guest_web_contents; 118 119 if (message_loop_runner_) 120 message_loop_runner_->Quit(); 121 } 122 123 content::WebContents* web_contents_; 124 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 125}; 126 127class WebContentsHiddenObserver : public content::WebContentsObserver { 128 public: 129 WebContentsHiddenObserver(content::WebContents* web_contents, 130 const base::Closure& hidden_callback) 131 : WebContentsObserver(web_contents), 132 hidden_callback_(hidden_callback), 133 hidden_observed_(false) { 134 } 135 136 // WebContentsObserver. 137 virtual void WasHidden() OVERRIDE { 138 hidden_observed_ = true; 139 hidden_callback_.Run(); 140 } 141 142 bool hidden_observed() { return hidden_observed_; } 143 144 private: 145 base::Closure hidden_callback_; 146 bool hidden_observed_; 147 148 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver); 149}; 150 151class InterstitialObserver : public content::WebContentsObserver { 152 public: 153 InterstitialObserver(content::WebContents* web_contents, 154 const base::Closure& attach_callback, 155 const base::Closure& detach_callback) 156 : WebContentsObserver(web_contents), 157 attach_callback_(attach_callback), 158 detach_callback_(detach_callback) { 159 } 160 161 virtual void DidAttachInterstitialPage() OVERRIDE { 162 attach_callback_.Run(); 163 } 164 165 virtual void DidDetachInterstitialPage() OVERRIDE { 166 detach_callback_.Run(); 167 } 168 169 private: 170 base::Closure attach_callback_; 171 base::Closure detach_callback_; 172 173 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); 174}; 175 176void ExecuteScriptWaitForTitle(content::WebContents* web_contents, 177 const char* script, 178 const char* title) { 179 base::string16 expected_title(base::ASCIIToUTF16(title)); 180 base::string16 error_title(base::ASCIIToUTF16("error")); 181 182 content::TitleWatcher title_watcher(web_contents, expected_title); 183 title_watcher.AlsoWaitForTitle(error_title); 184 EXPECT_TRUE(content::ExecuteScript(web_contents, script)); 185 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 186} 187 188} // namespace 189 190// This class intercepts media access request from the embedder. The request 191// should be triggered only if the embedder API (from tests) allows the request 192// in Javascript. 193// We do not issue the actual media request; the fact that the request reached 194// embedder's WebContents is good enough for our tests. This is also to make 195// the test run successfully on trybots. 196class MockWebContentsDelegate : public content::WebContentsDelegate { 197 public: 198 MockWebContentsDelegate() : requested_(false) {} 199 virtual ~MockWebContentsDelegate() {} 200 201 virtual void RequestMediaAccessPermission( 202 content::WebContents* web_contents, 203 const content::MediaStreamRequest& request, 204 const content::MediaResponseCallback& callback) OVERRIDE { 205 requested_ = true; 206 if (message_loop_runner_.get()) 207 message_loop_runner_->Quit(); 208 } 209 210 void WaitForSetMediaPermission() { 211 if (requested_) 212 return; 213 message_loop_runner_ = new content::MessageLoopRunner; 214 message_loop_runner_->Run(); 215 } 216 217 private: 218 bool requested_; 219 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 220 221 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate); 222}; 223 224// This class intercepts download request from the guest. 225class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { 226 public: 227 explicit MockDownloadWebContentsDelegate( 228 content::WebContentsDelegate* orig_delegate) 229 : orig_delegate_(orig_delegate), 230 waiting_for_decision_(false), 231 expect_allow_(false), 232 decision_made_(false), 233 last_download_allowed_(false) {} 234 virtual ~MockDownloadWebContentsDelegate() {} 235 236 virtual void CanDownload( 237 content::RenderViewHost* render_view_host, 238 const GURL& url, 239 const std::string& request_method, 240 const base::Callback<void(bool)>& callback) OVERRIDE { 241 orig_delegate_->CanDownload( 242 render_view_host, url, request_method, 243 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided, 244 base::Unretained(this))); 245 } 246 247 void WaitForCanDownload(bool expect_allow) { 248 EXPECT_FALSE(waiting_for_decision_); 249 waiting_for_decision_ = true; 250 251 if (decision_made_) { 252 EXPECT_EQ(expect_allow, last_download_allowed_); 253 return; 254 } 255 256 expect_allow_ = expect_allow; 257 message_loop_runner_ = new content::MessageLoopRunner; 258 message_loop_runner_->Run(); 259 } 260 261 void DownloadDecided(bool allow) { 262 EXPECT_FALSE(decision_made_); 263 decision_made_ = true; 264 265 if (waiting_for_decision_) { 266 EXPECT_EQ(expect_allow_, allow); 267 if (message_loop_runner_.get()) 268 message_loop_runner_->Quit(); 269 return; 270 } 271 last_download_allowed_ = allow; 272 } 273 274 void Reset() { 275 waiting_for_decision_ = false; 276 decision_made_ = false; 277 } 278 279 private: 280 content::WebContentsDelegate* orig_delegate_; 281 bool waiting_for_decision_; 282 bool expect_allow_; 283 bool decision_made_; 284 bool last_download_allowed_; 285 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 286 287 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate); 288}; 289 290class WebViewTest : public extensions::PlatformAppBrowserTest { 291 protected: 292 virtual void SetUp() OVERRIDE { 293 if (UsesFakeSpeech()) { 294 // SpeechRecognition test specific SetUp. 295 fake_speech_recognition_manager_.reset( 296 new content::FakeSpeechRecognitionManager()); 297 fake_speech_recognition_manager_->set_should_send_fake_response(true); 298 // Inject the fake manager factory so that the test result is returned to 299 // the web page. 300 content::SpeechRecognitionManager::SetManagerForTesting( 301 fake_speech_recognition_manager_.get()); 302 } 303 extensions::PlatformAppBrowserTest::SetUp(); 304 } 305 306 virtual void TearDown() OVERRIDE { 307 if (UsesFakeSpeech()) { 308 // SpeechRecognition test specific TearDown. 309 content::SpeechRecognitionManager::SetManagerForTesting(NULL); 310 } 311 312 extensions::PlatformAppBrowserTest::TearDown(); 313 } 314 315 virtual void SetUpOnMainThread() OVERRIDE { 316 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); 317 const testing::TestInfo* const test_info = 318 testing::UnitTest::GetInstance()->current_test_info(); 319 // Mock out geolocation for geolocation specific tests. 320 if (!strncmp(test_info->name(), "GeolocationAPI", 321 strlen("GeolocationAPI"))) { 322 ui_test_utils::OverrideGeolocation(10, 20); 323 } 324 } 325 326 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 327 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); 328 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 329 330 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); 331 } 332 333 // This method is responsible for initializing a packaged app, which contains 334 // multiple webview tags. The tags have different partition identifiers and 335 // their WebContent objects are returned as output. The method also verifies 336 // the expected process allocation and storage partition assignment. 337 // The |navigate_to_url| parameter is used to navigate the main browser 338 // window. 339 // 340 // TODO(ajwong): This function is getting to be too large. Either refactor it 341 // so the test can specify a configuration of WebView tags that we will 342 // dynamically inject JS to generate, or move this test wholesale into 343 // something that RunPlatformAppTest() can execute purely in Javascript. This 344 // won't let us do a white-box examination of the StoragePartition equivalence 345 // directly, but we will be able to view the black box effects which is good 346 // enough. http://crbug.com/160361 347 void NavigateAndOpenAppForIsolation( 348 GURL navigate_to_url, 349 content::WebContents** default_tag_contents1, 350 content::WebContents** default_tag_contents2, 351 content::WebContents** named_partition_contents1, 352 content::WebContents** named_partition_contents2, 353 content::WebContents** persistent_partition_contents1, 354 content::WebContents** persistent_partition_contents2, 355 content::WebContents** persistent_partition_contents3) { 356 GURL::Replacements replace_host; 357 std::string host_str("localhost"); // Must stay in scope with replace_host. 358 replace_host.SetHostStr(host_str); 359 360 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host); 361 362 GURL tag_url1 = embedded_test_server()->GetURL( 363 "/extensions/platform_apps/web_view/isolation/cookie.html"); 364 tag_url1 = tag_url1.ReplaceComponents(replace_host); 365 GURL tag_url2 = embedded_test_server()->GetURL( 366 "/extensions/platform_apps/web_view/isolation/cookie2.html"); 367 tag_url2 = tag_url2.ReplaceComponents(replace_host); 368 GURL tag_url3 = embedded_test_server()->GetURL( 369 "/extensions/platform_apps/web_view/isolation/storage1.html"); 370 tag_url3 = tag_url3.ReplaceComponents(replace_host); 371 GURL tag_url4 = embedded_test_server()->GetURL( 372 "/extensions/platform_apps/web_view/isolation/storage2.html"); 373 tag_url4 = tag_url4.ReplaceComponents(replace_host); 374 GURL tag_url5 = embedded_test_server()->GetURL( 375 "/extensions/platform_apps/web_view/isolation/storage1.html#p1"); 376 tag_url5 = tag_url5.ReplaceComponents(replace_host); 377 GURL tag_url6 = embedded_test_server()->GetURL( 378 "/extensions/platform_apps/web_view/isolation/storage1.html#p2"); 379 tag_url6 = tag_url6.ReplaceComponents(replace_host); 380 GURL tag_url7 = embedded_test_server()->GetURL( 381 "/extensions/platform_apps/web_view/isolation/storage1.html#p3"); 382 tag_url7 = tag_url7.ReplaceComponents(replace_host); 383 384 ui_test_utils::NavigateToURLWithDisposition( 385 browser(), navigate_to_url, CURRENT_TAB, 386 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 387 388 ui_test_utils::UrlLoadObserver observer1( 389 tag_url1, content::NotificationService::AllSources()); 390 ui_test_utils::UrlLoadObserver observer2( 391 tag_url2, content::NotificationService::AllSources()); 392 ui_test_utils::UrlLoadObserver observer3( 393 tag_url3, content::NotificationService::AllSources()); 394 ui_test_utils::UrlLoadObserver observer4( 395 tag_url4, content::NotificationService::AllSources()); 396 ui_test_utils::UrlLoadObserver observer5( 397 tag_url5, content::NotificationService::AllSources()); 398 ui_test_utils::UrlLoadObserver observer6( 399 tag_url6, content::NotificationService::AllSources()); 400 ui_test_utils::UrlLoadObserver observer7( 401 tag_url7, content::NotificationService::AllSources()); 402 LoadAndLaunchPlatformApp("web_view/isolation"); 403 observer1.Wait(); 404 observer2.Wait(); 405 observer3.Wait(); 406 observer4.Wait(); 407 observer5.Wait(); 408 observer6.Wait(); 409 observer7.Wait(); 410 411 content::Source<content::NavigationController> source1 = observer1.source(); 412 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()-> 413 IsIsolatedGuest()); 414 content::Source<content::NavigationController> source2 = observer2.source(); 415 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()-> 416 IsIsolatedGuest()); 417 content::Source<content::NavigationController> source3 = observer3.source(); 418 EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()-> 419 IsIsolatedGuest()); 420 content::Source<content::NavigationController> source4 = observer4.source(); 421 EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()-> 422 IsIsolatedGuest()); 423 content::Source<content::NavigationController> source5 = observer5.source(); 424 EXPECT_TRUE(source5->GetWebContents()->GetRenderProcessHost()-> 425 IsIsolatedGuest()); 426 content::Source<content::NavigationController> source6 = observer6.source(); 427 EXPECT_TRUE(source6->GetWebContents()->GetRenderProcessHost()-> 428 IsIsolatedGuest()); 429 content::Source<content::NavigationController> source7 = observer7.source(); 430 EXPECT_TRUE(source7->GetWebContents()->GetRenderProcessHost()-> 431 IsIsolatedGuest()); 432 433 // Check that the first two tags use the same process and it is different 434 // than the process used by the other two. 435 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(), 436 source2->GetWebContents()->GetRenderProcessHost()->GetID()); 437 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(), 438 source4->GetWebContents()->GetRenderProcessHost()->GetID()); 439 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), 440 source3->GetWebContents()->GetRenderProcessHost()->GetID()); 441 442 // The two sets of tags should also be isolated from the main browser. 443 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), 444 browser()->tab_strip_model()->GetWebContentsAt(0)-> 445 GetRenderProcessHost()->GetID()); 446 EXPECT_NE(source3->GetWebContents()->GetRenderProcessHost()->GetID(), 447 browser()->tab_strip_model()->GetWebContentsAt(0)-> 448 GetRenderProcessHost()->GetID()); 449 450 // Check that the storage partitions of the first two tags match and are 451 // different than the other two. 452 EXPECT_EQ( 453 source1->GetWebContents()->GetRenderProcessHost()-> 454 GetStoragePartition(), 455 source2->GetWebContents()->GetRenderProcessHost()-> 456 GetStoragePartition()); 457 EXPECT_EQ( 458 source3->GetWebContents()->GetRenderProcessHost()-> 459 GetStoragePartition(), 460 source4->GetWebContents()->GetRenderProcessHost()-> 461 GetStoragePartition()); 462 EXPECT_NE( 463 source1->GetWebContents()->GetRenderProcessHost()-> 464 GetStoragePartition(), 465 source3->GetWebContents()->GetRenderProcessHost()-> 466 GetStoragePartition()); 467 468 // Ensure the persistent storage partitions are different. 469 EXPECT_EQ( 470 source5->GetWebContents()->GetRenderProcessHost()-> 471 GetStoragePartition(), 472 source6->GetWebContents()->GetRenderProcessHost()-> 473 GetStoragePartition()); 474 EXPECT_NE( 475 source5->GetWebContents()->GetRenderProcessHost()-> 476 GetStoragePartition(), 477 source7->GetWebContents()->GetRenderProcessHost()-> 478 GetStoragePartition()); 479 EXPECT_NE( 480 source1->GetWebContents()->GetRenderProcessHost()-> 481 GetStoragePartition(), 482 source5->GetWebContents()->GetRenderProcessHost()-> 483 GetStoragePartition()); 484 EXPECT_NE( 485 source1->GetWebContents()->GetRenderProcessHost()-> 486 GetStoragePartition(), 487 source7->GetWebContents()->GetRenderProcessHost()-> 488 GetStoragePartition()); 489 490 *default_tag_contents1 = source1->GetWebContents(); 491 *default_tag_contents2 = source2->GetWebContents(); 492 *named_partition_contents1 = source3->GetWebContents(); 493 *named_partition_contents2 = source4->GetWebContents(); 494 if (persistent_partition_contents1) { 495 *persistent_partition_contents1 = source5->GetWebContents(); 496 } 497 if (persistent_partition_contents2) { 498 *persistent_partition_contents2 = source6->GetWebContents(); 499 } 500 if (persistent_partition_contents3) { 501 *persistent_partition_contents3 = source7->GetWebContents(); 502 } 503 } 504 505 // Handles |request| by serving a redirect response. 506 static scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler( 507 const std::string& path, 508 const GURL& redirect_target, 509 const net::test_server::HttpRequest& request) { 510 if (!StartsWithASCII(path, request.relative_url, true)) 511 return scoped_ptr<net::test_server::HttpResponse>(); 512 513 scoped_ptr<net::test_server::BasicHttpResponse> http_response( 514 new net::test_server::BasicHttpResponse); 515 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); 516 http_response->AddCustomHeader("Location", redirect_target.spec()); 517 return http_response.PassAs<net::test_server::HttpResponse>(); 518 } 519 520 // Handles |request| by serving an empty response. 521 static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler( 522 const std::string& path, 523 const net::test_server::HttpRequest& request) { 524 if (StartsWithASCII(path, request.relative_url, true)) { 525 return scoped_ptr<net::test_server::HttpResponse>( 526 new EmptyHttpResponse); 527 } 528 529 return scoped_ptr<net::test_server::HttpResponse>(); 530 } 531 532 // Shortcut to return the current MenuManager. 533 extensions::MenuManager* menu_manager() { 534 return extensions::MenuManager::Get(browser()->profile()); 535 } 536 537 // This gets all the items that any extension has registered for possible 538 // inclusion in context menus. 539 MenuItem::List GetItems() { 540 MenuItem::List result; 541 std::set<MenuItem::ExtensionKey> extension_ids = 542 menu_manager()->ExtensionIds(); 543 std::set<MenuItem::ExtensionKey>::iterator i; 544 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) { 545 const MenuItem::List* list = menu_manager()->MenuItems(*i); 546 result.insert(result.end(), list->begin(), list->end()); 547 } 548 return result; 549 } 550 551 enum TestServer { 552 NEEDS_TEST_SERVER, 553 NO_TEST_SERVER 554 }; 555 556 void TestHelper(const std::string& test_name, 557 const std::string& app_location, 558 TestServer test_server) { 559 // For serving guest pages. 560 if (test_server == NEEDS_TEST_SERVER) { 561 if (!StartEmbeddedTestServer()) { 562 LOG(ERROR) << "FAILED TO START TEST SERVER."; 563 return; 564 } 565 embedded_test_server()->RegisterRequestHandler( 566 base::Bind(&WebViewTest::RedirectResponseHandler, 567 kRedirectResponsePath, 568 embedded_test_server()->GetURL(kRedirectResponseFullPath))); 569 570 embedded_test_server()->RegisterRequestHandler( 571 base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath)); 572 } 573 574 ExtensionTestMessageListener launched_listener("Launched", false); 575 LoadAndLaunchPlatformApp(app_location.c_str()); 576 if (!launched_listener.WaitUntilSatisfied()) { 577 LOG(ERROR) << "TEST DID NOT LAUNCH."; 578 return; 579 } 580 581 // Flush any pending events to make sure we start with a clean slate. 582 content::RunAllPendingInMessageLoop(); 583 584 content::WebContents* embedder_web_contents = 585 GetFirstAppWindowWebContents(); 586 if (!embedder_web_contents) { 587 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS."; 588 return; 589 } 590 591 ExtensionTestMessageListener done_listener("TEST_PASSED", false); 592 done_listener.set_failure_message("TEST_FAILED"); 593 if (!content::ExecuteScript( 594 embedder_web_contents, 595 base::StringPrintf("runTest('%s')", test_name.c_str()))) { 596 LOG(ERROR) << "UNABLE TO START TEST."; 597 return; 598 } 599 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 600 } 601 602 content::WebContents* LoadGuest(const std::string& guest_path, 603 const std::string& app_path) { 604 GURL::Replacements replace_host; 605 std::string host_str("localhost"); // Must stay in scope with replace_host. 606 replace_host.SetHostStr(host_str); 607 608 GURL guest_url = embedded_test_server()->GetURL(guest_path); 609 guest_url = guest_url.ReplaceComponents(replace_host); 610 611 ui_test_utils::UrlLoadObserver guest_observer( 612 guest_url, content::NotificationService::AllSources()); 613 614 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false); 615 LoadAndLaunchPlatformApp(app_path.c_str()); 616 guest_observer.Wait(); 617 618 content::Source<content::NavigationController> source = 619 guest_observer.source(); 620 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()-> 621 IsIsolatedGuest()); 622 623 bool satisfied = guest_loaded_listener.WaitUntilSatisfied(); 624 if (!satisfied) 625 return NULL; 626 627 content::WebContents* guest_web_contents = source->GetWebContents(); 628 return guest_web_contents; 629 } 630 631 // Runs media_access/allow tests. 632 void MediaAccessAPIAllowTestHelper(const std::string& test_name); 633 634 // Runs media_access/deny tests, each of them are run separately otherwise 635 // they timeout (mostly on Windows). 636 void MediaAccessAPIDenyTestHelper(const std::string& test_name) { 637 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 638 ExtensionTestMessageListener loaded_listener("loaded", false); 639 LoadAndLaunchPlatformApp("web_view/media_access/deny"); 640 ASSERT_TRUE(loaded_listener.WaitUntilSatisfied()); 641 642 content::WebContents* embedder_web_contents = 643 GetFirstAppWindowWebContents(); 644 ASSERT_TRUE(embedder_web_contents); 645 646 ExtensionTestMessageListener test_run_listener("PASSED", false); 647 test_run_listener.set_failure_message("FAILED"); 648 EXPECT_TRUE( 649 content::ExecuteScript( 650 embedder_web_contents, 651 base::StringPrintf("startDenyTest('%s')", test_name.c_str()))); 652 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied()); 653 } 654 655 void WaitForInterstitial(content::WebContents* web_contents) { 656 scoped_refptr<content::MessageLoopRunner> loop_runner( 657 new content::MessageLoopRunner); 658 InterstitialObserver observer(web_contents, 659 loop_runner->QuitClosure(), 660 base::Closure()); 661 if (!content::InterstitialPage::GetInterstitialPage(web_contents)) 662 loop_runner->Run(); 663 } 664 665 void LoadAppWithGuest(const std::string& app_path) { 666 GuestContentBrowserClient new_client; 667 content::ContentBrowserClient* old_client = 668 SetBrowserClientForTesting(&new_client); 669 670 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", 671 false); 672 launched_listener.set_failure_message("WebViewTest.FAILURE"); 673 LoadAndLaunchPlatformApp(app_path.c_str()); 674 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 675 676 guest_web_contents_ = new_client.WaitForGuestCreated(); 677 SetBrowserClientForTesting(old_client); 678 } 679 680 void SendMessageToEmbedder(const std::string& message) { 681 EXPECT_TRUE( 682 content::ExecuteScript( 683 GetEmbedderWebContents(), 684 base::StringPrintf("onAppCommand('%s');", message.c_str()))); 685 } 686 687 void SendMessageToGuestAndWait(const std::string& message, 688 const std::string& wait_message) { 689 scoped_ptr<ExtensionTestMessageListener> listener; 690 if (!wait_message.empty()) { 691 listener.reset(new ExtensionTestMessageListener(wait_message, false)); 692 } 693 694 EXPECT_TRUE( 695 content::ExecuteScript( 696 GetGuestWebContents(), 697 base::StringPrintf("onAppCommand('%s');", message.c_str()))); 698 699 if (listener) { 700 ASSERT_TRUE(listener->WaitUntilSatisfied()); 701 } 702 } 703 704 content::WebContents* GetGuestWebContents() { 705 return guest_web_contents_; 706 } 707 708 content::WebContents* GetEmbedderWebContents() { 709 if (!embedder_web_contents_) { 710 embedder_web_contents_ = GetFirstAppWindowWebContents(); 711 } 712 return embedder_web_contents_; 713 } 714 715 WebViewTest() : guest_web_contents_(NULL), 716 embedder_web_contents_(NULL) { 717 } 718 719 private: 720 bool UsesFakeSpeech() { 721 const testing::TestInfo* const test_info = 722 testing::UnitTest::GetInstance()->current_test_info(); 723 724 // SpeechRecognition test specific SetUp. 725 return !strcmp(test_info->name(), 726 "SpeechRecognitionAPI_HasPermissionAllow"); 727 } 728 729 scoped_ptr<content::FakeSpeechRecognitionManager> 730 fake_speech_recognition_manager_; 731 732 // Note that these are only set if you launch app using LoadAppWithGuest(). 733 content::WebContents* guest_web_contents_; 734 content::WebContents* embedder_web_contents_; 735}; 736 737// This test verifies that hiding the guest triggers WebContents::WasHidden(). 738IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) { 739 LoadAppWithGuest("web_view/visibility_changed"); 740 741 scoped_refptr<content::MessageLoopRunner> loop_runner( 742 new content::MessageLoopRunner); 743 WebContentsHiddenObserver observer(GetGuestWebContents(), 744 loop_runner->QuitClosure()); 745 746 // Handled in platform_apps/web_view/visibility_changed/main.js 747 SendMessageToEmbedder("hide-guest"); 748 if (!observer.hidden_observed()) 749 loop_runner->Run(); 750} 751 752// This test verifies that hiding the embedder also hides the guest. 753IN_PROC_BROWSER_TEST_F(WebViewTest, EmbedderVisibilityChanged) { 754 LoadAppWithGuest("web_view/visibility_changed"); 755 756 scoped_refptr<content::MessageLoopRunner> loop_runner( 757 new content::MessageLoopRunner); 758 WebContentsHiddenObserver observer(GetGuestWebContents(), 759 loop_runner->QuitClosure()); 760 761 // Handled in platform_apps/web_view/visibility_changed/main.js 762 SendMessageToEmbedder("hide-embedder"); 763 if (!observer.hidden_observed()) 764 loop_runner->Run(); 765} 766 767// This test verifies that reloading the embedder reloads the guest (and doest 768// not crash). 769IN_PROC_BROWSER_TEST_F(WebViewTest, ReloadEmbedder) { 770 // Just load a guest from other test, we do not want to add a separate 771 // platform_app for this test. 772 LoadAppWithGuest("web_view/visibility_changed"); 773 774 ExtensionTestMessageListener launched_again_listener("WebViewTest.LAUNCHED", 775 false); 776 GetEmbedderWebContents()->GetController().Reload(false); 777 ASSERT_TRUE(launched_again_listener.WaitUntilSatisfied()); 778} 779 780IN_PROC_BROWSER_TEST_F(WebViewTest, AcceptTouchEvents) { 781 LoadAppWithGuest("web_view/accept_touch_events"); 782 783 content::RenderViewHost* embedder_rvh = 784 GetEmbedderWebContents()->GetRenderViewHost(); 785 786 bool embedder_has_touch_handler = 787 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); 788 EXPECT_FALSE(embedder_has_touch_handler); 789 790 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler"); 791 792 // Note that we need to wait for the installed/registered touch handler to 793 // appear in browser process before querying |embedder_rvh|. 794 // In practice, since we do a roundrtip from browser process to guest and 795 // back, this is sufficient. 796 embedder_has_touch_handler = 797 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); 798 EXPECT_TRUE(embedder_has_touch_handler); 799 800 SendMessageToGuestAndWait("uninstall-touch-handler", 801 "uninstalled-touch-handler"); 802 // Same as the note above about waiting. 803 embedder_has_touch_handler = 804 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); 805 EXPECT_FALSE(embedder_has_touch_handler); 806} 807 808// This test ensures JavaScript errors ("Cannot redefine property") do not 809// happen when a <webview> is removed from DOM and added back. 810IN_PROC_BROWSER_TEST_F(WebViewTest, 811 AddRemoveWebView_AddRemoveWebView) { 812 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 813 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove")) 814 << message_; 815} 816 817IN_PROC_BROWSER_TEST_F(WebViewTest, AutoSize) { 818#if defined(OS_WIN) 819 // Flaky on XP bot http://crbug.com/299507 820 if (base::win::GetVersion() <= base::win::VERSION_XP) 821 return; 822#endif 823 824 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize")) 825 << message_; 826} 827 828// http://crbug.com/326332 829IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestAutosizeAfterNavigation) { 830 TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER); 831} 832 833IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeBeforeNavigation) { 834 TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER); 835} 836IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeRemoveAttributes) { 837 TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER); 838} 839 840// This test is disabled due to being flaky. http://crbug.com/282116 841#if defined(OS_WIN) 842#define MAYBE_Shim_TestAutosizeWithPartialAttributes \ 843 DISABLED_Shim_TestAutosizeWithPartialAttributes 844#else 845#define MAYBE_Shim_TestAutosizeWithPartialAttributes \ 846 Shim_TestAutosizeWithPartialAttributes 847#endif 848IN_PROC_BROWSER_TEST_F(WebViewTest, 849 MAYBE_Shim_TestAutosizeWithPartialAttributes) { 850 TestHelper("testAutosizeWithPartialAttributes", 851 "web_view/shim", 852 NO_TEST_SERVER); 853} 854 855IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) { 856 TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER); 857} 858 859// Tests the existence of WebRequest API event objects on the request 860// object, on the webview element, and hanging directly off webview. 861IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) { 862 TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER); 863} 864 865// http://crbug.com/315920 866#if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)) 867#define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL 868#else 869#define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL 870#endif 871IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) { 872 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER); 873} 874 875// http://crbug.com/315920 876#if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)) 877#define MAYBE_Shim_TestChromeExtensionRelativePath \ 878 DISABLED_Shim_TestChromeExtensionRelativePath 879#else 880#define MAYBE_Shim_TestChromeExtensionRelativePath \ 881 Shim_TestChromeExtensionRelativePath 882#endif 883IN_PROC_BROWSER_TEST_F(WebViewTest, 884 MAYBE_Shim_TestChromeExtensionRelativePath) { 885 TestHelper("testChromeExtensionRelativePath", 886 "web_view/shim", 887 NO_TEST_SERVER); 888} 889 890IN_PROC_BROWSER_TEST_F(WebViewTest, 891 Shim_TestInlineScriptFromAccessibleResources) { 892 TestHelper("testInlineScriptFromAccessibleResources", 893 "web_view/shim", 894 NO_TEST_SERVER); 895} 896 897IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestInvalidChromeExtensionURL) { 898 TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER); 899} 900 901IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestEventName) { 902 TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER); 903} 904 905// WebViewTest.Shim_TestOnEventProperty is flaky, so disable it. 906// http://crbug.com/359832. 907IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestOnEventProperty) { 908 TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER); 909} 910 911IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadProgressEvent) { 912 TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER); 913} 914 915IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestDestroyOnEventListener) { 916 TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER); 917} 918 919IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCannotMutateEventName) { 920 TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER); 921} 922 923IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPartitionRaisesException) { 924 TestHelper("testPartitionRaisesException", "web_view/shim", NO_TEST_SERVER); 925} 926 927IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScriptFail) { 928#if defined(OS_WIN) 929 // Flaky on XP bot http://crbug.com/266185 930 if (base::win::GetVersion() <= base::win::VERSION_XP) 931 return; 932#endif 933 934 TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER); 935} 936 937IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScript) { 938 TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER); 939} 940 941IN_PROC_BROWSER_TEST_F( 942 WebViewTest, 943 Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged) { 944 TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged", 945 "web_view/shim", 946 NO_TEST_SERVER); 947} 948 949IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestTerminateAfterExit) { 950 TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER); 951} 952 953IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAssignSrcAfterCrash) { 954 TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER); 955} 956 957IN_PROC_BROWSER_TEST_F(WebViewTest, 958 Shim_TestNavOnConsecutiveSrcAttributeChanges) { 959 TestHelper("testNavOnConsecutiveSrcAttributeChanges", 960 "web_view/shim", 961 NO_TEST_SERVER); 962} 963 964IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavOnSrcAttributeChange) { 965 TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER); 966} 967 968IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigateAfterResize) { 969 TestHelper("testNavigateAfterResize", "web_view/shim", NO_TEST_SERVER); 970} 971 972IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveSrcAttribute) { 973 TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER); 974} 975 976IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReassignSrcAttribute) { 977 TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER); 978} 979 980IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestBrowserPluginNotAllowed) { 981#if defined(OS_WIN) 982 // Flaky on XP bots. http://crbug.com/267300 983 if (base::win::GetVersion() <= base::win::VERSION_XP) 984 return; 985#endif 986 987 TestHelper("testBrowserPluginNotAllowed", "web_view/shim", NO_TEST_SERVER); 988} 989 990IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindow) { 991 TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER); 992} 993 994IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowTwoListeners) { 995 TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER); 996} 997 998IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoPreventDefault) { 999 TestHelper("testNewWindowNoPreventDefault", 1000 "web_view/shim", 1001 NEEDS_TEST_SERVER); 1002} 1003 1004IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoReferrerLink) { 1005 TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER); 1006} 1007 1008IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestContentLoadEvent) { 1009 TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER); 1010} 1011 1012// http://crbug.com/326330 1013IN_PROC_BROWSER_TEST_F(WebViewTest, 1014 Shim_TestDeclarativeWebRequestAPI) { 1015 TestHelper("testDeclarativeWebRequestAPI", 1016 "web_view/shim", 1017 NEEDS_TEST_SERVER); 1018} 1019 1020IN_PROC_BROWSER_TEST_F(WebViewTest, 1021 Shim_TestDeclarativeWebRequestAPISendMessage) { 1022 TestHelper("testDeclarativeWebRequestAPISendMessage", 1023 "web_view/shim", 1024 NEEDS_TEST_SERVER); 1025} 1026 1027IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPI) { 1028 TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER); 1029} 1030 1031IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIGoogleProperty) { 1032 TestHelper("testWebRequestAPIGoogleProperty", 1033 "web_view/shim", 1034 NO_TEST_SERVER); 1035} 1036 1037// This test is disabled due to being flaky. http://crbug.com/309451 1038#if defined(OS_WIN) 1039#define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \ 1040 DISABLED_Shim_TestWebRequestListenerSurvivesReparenting 1041#else 1042#define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \ 1043 Shim_TestWebRequestListenerSurvivesReparenting 1044#endif 1045IN_PROC_BROWSER_TEST_F( 1046 WebViewTest, 1047 MAYBE_Shim_TestWebRequestListenerSurvivesReparenting) { 1048 TestHelper("testWebRequestListenerSurvivesReparenting", 1049 "web_view/shim", 1050 NEEDS_TEST_SERVER); 1051} 1052 1053IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadStartLoadRedirect) { 1054 TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER); 1055} 1056 1057IN_PROC_BROWSER_TEST_F(WebViewTest, 1058 Shim_TestLoadAbortChromeExtensionURLWrongPartition) { 1059 TestHelper("testLoadAbortChromeExtensionURLWrongPartition", 1060 "web_view/shim", 1061 NO_TEST_SERVER); 1062} 1063 1064IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortEmptyResponse) { 1065 TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER); 1066} 1067 1068IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalChromeURL) { 1069 TestHelper("testLoadAbortIllegalChromeURL", 1070 "web_view/shim", 1071 NO_TEST_SERVER); 1072} 1073 1074IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalFileURL) { 1075 TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER); 1076} 1077 1078IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalJavaScriptURL) { 1079 TestHelper("testLoadAbortIllegalJavaScriptURL", 1080 "web_view/shim", 1081 NO_TEST_SERVER); 1082} 1083 1084IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortInvalidNavigation) { 1085 TestHelper("testLoadAbortInvalidNavigation", "web_view/shim", NO_TEST_SERVER); 1086} 1087 1088IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortNonWebSafeScheme) { 1089 TestHelper("testLoadAbortNonWebSafeScheme", "web_view/shim", NO_TEST_SERVER); 1090} 1091 1092IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) { 1093 TestHelper("testReload", "web_view/shim", NEEDS_TEST_SERVER); 1094} 1095 1096IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) { 1097 TestHelper("testGetProcessId", "web_view/shim", NEEDS_TEST_SERVER); 1098} 1099 1100IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestHiddenBeforeNavigation) { 1101 TestHelper("testHiddenBeforeNavigation", "web_view/shim", NO_TEST_SERVER); 1102} 1103 1104IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) { 1105 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 1106 1107 // Launch the app and wait until it's ready to load a test. 1108 ExtensionTestMessageListener launched_listener("Launched", false); 1109 LoadAndLaunchPlatformApp("web_view/shim"); 1110 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 1111 1112 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); 1113 ASSERT_TRUE(embedder_web_contents); 1114 1115 GURL::Replacements replace_host; 1116 std::string host_str("localhost"); // Must stay in scope with replace_host. 1117 replace_host.SetHostStr(host_str); 1118 1119 std::string guest_path( 1120 "/extensions/platform_apps/web_view/shim/empty_guest.html"); 1121 GURL guest_url = embedded_test_server()->GetURL(guest_path); 1122 guest_url = guest_url.ReplaceComponents(replace_host); 1123 1124 ui_test_utils::UrlLoadObserver guest_observer( 1125 guest_url, content::NotificationService::AllSources()); 1126 1127 // Run the test and wait until the guest WebContents is available and has 1128 // finished loading. 1129 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false); 1130 EXPECT_TRUE(content::ExecuteScript( 1131 embedder_web_contents, 1132 "runTest('testRemoveWebviewOnExit')")); 1133 guest_observer.Wait(); 1134 1135 content::Source<content::NavigationController> source = 1136 guest_observer.source(); 1137 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()-> 1138 IsIsolatedGuest()); 1139 1140 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied()); 1141 1142 content::WebContentsDestroyedWatcher destroyed_watcher( 1143 source->GetWebContents()); 1144 1145 // Tell the embedder to kill the guest. 1146 EXPECT_TRUE(content::ExecuteScript( 1147 embedder_web_contents, 1148 "removeWebviewOnExitDoCrash();")); 1149 1150 // Wait until the guest WebContents is destroyed. 1151 destroyed_watcher.Wait(); 1152} 1153 1154// Remove <webview> immediately after navigating it. 1155// This is a regression test for http://crbug.com/276023. 1156IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewAfterNavigation) { 1157 TestHelper("testRemoveWebviewAfterNavigation", 1158 "web_view/shim", 1159 NO_TEST_SERVER); 1160} 1161 1162IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigationToExternalProtocol) { 1163 TestHelper("testNavigationToExternalProtocol", 1164 "web_view/shim", 1165 NO_TEST_SERVER); 1166} 1167 1168IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestResizeWebviewResizesContent) { 1169 TestHelper("testResizeWebviewResizesContent", 1170 "web_view/shim", 1171 NO_TEST_SERVER); 1172} 1173 1174// This test makes sure we do not crash if app is closed while interstitial 1175// page is being shown in guest. 1176// Disabled under LeakSanitizer due to memory leaks. http://crbug.com/321662 1177#if defined(LEAK_SANITIZER) 1178#define MAYBE_InterstitialTeardown DISABLED_InterstitialTeardown 1179#else 1180#define MAYBE_InterstitialTeardown InterstitialTeardown 1181#endif 1182IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_InterstitialTeardown) { 1183#if defined(OS_WIN) 1184 // Flaky on XP bot http://crbug.com/297014 1185 if (base::win::GetVersion() <= base::win::VERSION_XP) 1186 return; 1187#endif 1188 1189 // Start a HTTPS server so we can load an interstitial page inside guest. 1190 net::SpawnedTestServer::SSLOptions ssl_options; 1191 ssl_options.server_certificate = 1192 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; 1193 net::SpawnedTestServer https_server( 1194 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, 1195 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 1196 ASSERT_TRUE(https_server.Start()); 1197 1198 net::HostPortPair host_and_port = https_server.host_port_pair(); 1199 1200 ExtensionTestMessageListener embedder_loaded_listener("EmbedderLoaded", 1201 false); 1202 LoadAndLaunchPlatformApp("web_view/interstitial_teardown"); 1203 ASSERT_TRUE(embedder_loaded_listener.WaitUntilSatisfied()); 1204 1205 GuestContentBrowserClient new_client; 1206 content::ContentBrowserClient* old_client = 1207 SetBrowserClientForTesting(&new_client); 1208 1209 // Now load the guest. 1210 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); 1211 ExtensionTestMessageListener second("GuestAddedToDom", false); 1212 EXPECT_TRUE(content::ExecuteScript( 1213 embedder_web_contents, 1214 base::StringPrintf("loadGuest(%d);\n", host_and_port.port()))); 1215 ASSERT_TRUE(second.WaitUntilSatisfied()); 1216 1217 // Wait for interstitial page to be shown in guest. 1218 content::WebContents* guest_web_contents = new_client.WaitForGuestCreated(); 1219 SetBrowserClientForTesting(old_client); 1220 ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest()); 1221 WaitForInterstitial(guest_web_contents); 1222 1223 // Now close the app while interstitial page being shown in guest. 1224 apps::AppWindow* window = GetFirstAppWindow(); 1225 window->GetBaseWindow()->Close(); 1226} 1227 1228IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { 1229 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute")) 1230 << message_; 1231} 1232 1233// This test verifies that prerendering has been disabled inside <webview>. 1234// This test is here rather than in PrerenderBrowserTest for testing convenience 1235// only. If it breaks then this is a bug in the prerenderer. 1236IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) { 1237 ASSERT_TRUE(StartEmbeddedTestServer()); 1238 content::WebContents* guest_web_contents = 1239 LoadGuest( 1240 "/extensions/platform_apps/web_view/noprerenderer/guest.html", 1241 "web_view/noprerenderer"); 1242 ASSERT_TRUE(guest_web_contents != NULL); 1243 1244 PrerenderLinkManager* prerender_link_manager = 1245 PrerenderLinkManagerFactory::GetForProfile( 1246 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext())); 1247 ASSERT_TRUE(prerender_link_manager != NULL); 1248 EXPECT_TRUE(prerender_link_manager->IsEmpty()); 1249} 1250 1251// Verify that existing <webview>'s are detected when the task manager starts 1252// up. 1253IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerExistingWebView) { 1254 ASSERT_TRUE(StartEmbeddedTestServer()); 1255 1256 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", 1257 "web_view/task_manager"); 1258 1259 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads. 1260 1261 const char* guest_title = "WebViewed test content"; 1262 const char* app_name = "<webview> task manager test"; 1263 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title))); 1264 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); 1265 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name))); 1266 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name))); 1267 1268 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView())); 1269 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); 1270 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); 1271 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground())); 1272} 1273 1274// Verify that the task manager notices the creation of new <webview>'s. 1275IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerNewWebView) { 1276 ASSERT_TRUE(StartEmbeddedTestServer()); 1277 1278 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads. 1279 1280 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", 1281 "web_view/task_manager"); 1282 1283 const char* guest_title = "WebViewed test content"; 1284 const char* app_name = "<webview> task manager test"; 1285 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title))); 1286 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); 1287 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name))); 1288 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name))); 1289 1290 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView())); 1291 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); 1292 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); 1293 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground())); 1294} 1295 1296// This tests cookie isolation for packaged apps with webview tags. It navigates 1297// the main browser window to a page that sets a cookie and loads an app with 1298// multiple webview tags. Each tag sets a cookie and the test checks the proper 1299// storage isolation is enforced. 1300// This test is disabled due to being flaky. http://crbug.com/294196 1301#if defined(OS_WIN) 1302#define MAYBE_CookieIsolation DISABLED_CookieIsolation 1303#else 1304#define MAYBE_CookieIsolation CookieIsolation 1305#endif 1306IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CookieIsolation) { 1307 ASSERT_TRUE(StartEmbeddedTestServer()); 1308 const std::string kExpire = 1309 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; 1310 std::string cookie_script1(kExpire); 1311 cookie_script1.append( 1312 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';"); 1313 std::string cookie_script2(kExpire); 1314 cookie_script2.append( 1315 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';"); 1316 1317 GURL::Replacements replace_host; 1318 std::string host_str("localhost"); // Must stay in scope with replace_host. 1319 replace_host.SetHostStr(host_str); 1320 1321 GURL set_cookie_url = embedded_test_server()->GetURL( 1322 "/extensions/platform_apps/isolation/set_cookie.html"); 1323 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); 1324 1325 // The first two partitions will be used to set cookies and ensure they are 1326 // shared. The named partition is used to ensure that cookies are isolated 1327 // between partitions within the same app. 1328 content::WebContents* cookie_contents1; 1329 content::WebContents* cookie_contents2; 1330 content::WebContents* named_partition_contents1; 1331 content::WebContents* named_partition_contents2; 1332 1333 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, 1334 &cookie_contents2, &named_partition_contents1, 1335 &named_partition_contents2, NULL, NULL, NULL); 1336 1337 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1)); 1338 EXPECT_TRUE(content::ExecuteScript(cookie_contents2, cookie_script2)); 1339 1340 int cookie_size; 1341 std::string cookie_value; 1342 1343 // Test the regular browser context to ensure we have only one cookie. 1344 ui_test_utils::GetCookies(GURL("http://localhost"), 1345 browser()->tab_strip_model()->GetWebContentsAt(0), 1346 &cookie_size, &cookie_value); 1347 EXPECT_EQ("testCookie=1", cookie_value); 1348 1349 // The default behavior is to combine webview tags with no explicit partition 1350 // declaration into the same in-memory partition. Test the webview tags to 1351 // ensure we have properly set the cookies and we have both cookies in both 1352 // tags. 1353 ui_test_utils::GetCookies(GURL("http://localhost"), 1354 cookie_contents1, 1355 &cookie_size, &cookie_value); 1356 EXPECT_EQ("guest1=true; guest2=true", cookie_value); 1357 1358 ui_test_utils::GetCookies(GURL("http://localhost"), 1359 cookie_contents2, 1360 &cookie_size, &cookie_value); 1361 EXPECT_EQ("guest1=true; guest2=true", cookie_value); 1362 1363 // The third tag should not have any cookies as it is in a separate partition. 1364 ui_test_utils::GetCookies(GURL("http://localhost"), 1365 named_partition_contents1, 1366 &cookie_size, &cookie_value); 1367 EXPECT_EQ("", cookie_value); 1368} 1369 1370// This tests that in-memory storage partitions are reset on browser restart, 1371// but persistent ones maintain state for cookies and HTML5 storage. 1372IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) { 1373 ASSERT_TRUE(StartEmbeddedTestServer()); 1374 const std::string kExpire = 1375 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; 1376 std::string cookie_script1(kExpire); 1377 cookie_script1.append( 1378 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';"); 1379 std::string cookie_script2(kExpire); 1380 cookie_script2.append( 1381 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';"); 1382 std::string cookie_script3(kExpire); 1383 cookie_script3.append( 1384 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';"); 1385 1386 // We don't care where the main browser is on this test. 1387 GURL blank_url("about:blank"); 1388 1389 // The first two partitions will be used to set cookies and ensure they are 1390 // shared. The named partition is used to ensure that cookies are isolated 1391 // between partitions within the same app. 1392 content::WebContents* cookie_contents1; 1393 content::WebContents* cookie_contents2; 1394 content::WebContents* named_partition_contents1; 1395 content::WebContents* named_partition_contents2; 1396 content::WebContents* persistent_partition_contents1; 1397 content::WebContents* persistent_partition_contents2; 1398 content::WebContents* persistent_partition_contents3; 1399 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1, 1400 &cookie_contents2, &named_partition_contents1, 1401 &named_partition_contents2, 1402 &persistent_partition_contents1, 1403 &persistent_partition_contents2, 1404 &persistent_partition_contents3); 1405 1406 // Set the inmemory=true cookie for tags with inmemory partitions. 1407 EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1)); 1408 EXPECT_TRUE(content::ExecuteScript(named_partition_contents1, 1409 cookie_script1)); 1410 1411 // For the two different persistent storage partitions, set the 1412 // two different cookies so we can check that they aren't comingled below. 1413 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1, 1414 cookie_script2)); 1415 1416 EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3, 1417 cookie_script3)); 1418 1419 int cookie_size; 1420 std::string cookie_value; 1421 1422 // Check that all in-memory partitions have a cookie set. 1423 ui_test_utils::GetCookies(GURL("http://localhost"), 1424 cookie_contents1, 1425 &cookie_size, &cookie_value); 1426 EXPECT_EQ("inmemory=true", cookie_value); 1427 ui_test_utils::GetCookies(GURL("http://localhost"), 1428 cookie_contents2, 1429 &cookie_size, &cookie_value); 1430 EXPECT_EQ("inmemory=true", cookie_value); 1431 ui_test_utils::GetCookies(GURL("http://localhost"), 1432 named_partition_contents1, 1433 &cookie_size, &cookie_value); 1434 EXPECT_EQ("inmemory=true", cookie_value); 1435 ui_test_utils::GetCookies(GURL("http://localhost"), 1436 named_partition_contents2, 1437 &cookie_size, &cookie_value); 1438 EXPECT_EQ("inmemory=true", cookie_value); 1439 1440 // Check that all persistent partitions kept their state. 1441 ui_test_utils::GetCookies(GURL("http://localhost"), 1442 persistent_partition_contents1, 1443 &cookie_size, &cookie_value); 1444 EXPECT_EQ("persist1=true", cookie_value); 1445 ui_test_utils::GetCookies(GURL("http://localhost"), 1446 persistent_partition_contents2, 1447 &cookie_size, &cookie_value); 1448 EXPECT_EQ("persist1=true", cookie_value); 1449 ui_test_utils::GetCookies(GURL("http://localhost"), 1450 persistent_partition_contents3, 1451 &cookie_size, &cookie_value); 1452 EXPECT_EQ("persist2=true", cookie_value); 1453} 1454 1455// This is the post-reset portion of the StoragePersistence test. See 1456// PRE_StoragePersistence for main comment. 1457IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_StoragePersistence) { 1458 ASSERT_TRUE(StartEmbeddedTestServer()); 1459 1460 // We don't care where the main browser is on this test. 1461 GURL blank_url("about:blank"); 1462 1463 // The first two partitions will be used to set cookies and ensure they are 1464 // shared. The named partition is used to ensure that cookies are isolated 1465 // between partitions within the same app. 1466 content::WebContents* cookie_contents1; 1467 content::WebContents* cookie_contents2; 1468 content::WebContents* named_partition_contents1; 1469 content::WebContents* named_partition_contents2; 1470 content::WebContents* persistent_partition_contents1; 1471 content::WebContents* persistent_partition_contents2; 1472 content::WebContents* persistent_partition_contents3; 1473 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1, 1474 &cookie_contents2, &named_partition_contents1, 1475 &named_partition_contents2, 1476 &persistent_partition_contents1, 1477 &persistent_partition_contents2, 1478 &persistent_partition_contents3); 1479 1480 int cookie_size; 1481 std::string cookie_value; 1482 1483 // Check that all in-memory partitions lost their state. 1484 ui_test_utils::GetCookies(GURL("http://localhost"), 1485 cookie_contents1, 1486 &cookie_size, &cookie_value); 1487 EXPECT_EQ("", cookie_value); 1488 ui_test_utils::GetCookies(GURL("http://localhost"), 1489 cookie_contents2, 1490 &cookie_size, &cookie_value); 1491 EXPECT_EQ("", cookie_value); 1492 ui_test_utils::GetCookies(GURL("http://localhost"), 1493 named_partition_contents1, 1494 &cookie_size, &cookie_value); 1495 EXPECT_EQ("", cookie_value); 1496 ui_test_utils::GetCookies(GURL("http://localhost"), 1497 named_partition_contents2, 1498 &cookie_size, &cookie_value); 1499 EXPECT_EQ("", cookie_value); 1500 1501 // Check that all persistent partitions kept their state. 1502 ui_test_utils::GetCookies(GURL("http://localhost"), 1503 persistent_partition_contents1, 1504 &cookie_size, &cookie_value); 1505 EXPECT_EQ("persist1=true", cookie_value); 1506 ui_test_utils::GetCookies(GURL("http://localhost"), 1507 persistent_partition_contents2, 1508 &cookie_size, &cookie_value); 1509 EXPECT_EQ("persist1=true", cookie_value); 1510 ui_test_utils::GetCookies(GURL("http://localhost"), 1511 persistent_partition_contents3, 1512 &cookie_size, &cookie_value); 1513 EXPECT_EQ("persist2=true", cookie_value); 1514} 1515 1516#if defined(OS_WIN) 1517// This test is very flaky on Win Aura, Win XP, Win 7. http://crbug.com/248873 1518#define MAYBE_DOMStorageIsolation DISABLED_DOMStorageIsolation 1519#else 1520#define MAYBE_DOMStorageIsolation DOMStorageIsolation 1521#endif 1522 1523// This tests DOM storage isolation for packaged apps with webview tags. It 1524// loads an app with multiple webview tags and each tag sets DOM storage 1525// entries, which the test checks to ensure proper storage isolation is 1526// enforced. 1527IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_DOMStorageIsolation) { 1528 ASSERT_TRUE(StartEmbeddedTestServer()); 1529 GURL regular_url = embedded_test_server()->GetURL("/title1.html"); 1530 1531 std::string output; 1532 std::string get_local_storage("window.domAutomationController.send(" 1533 "window.localStorage.getItem('foo') || 'badval')"); 1534 std::string get_session_storage("window.domAutomationController.send(" 1535 "window.sessionStorage.getItem('bar') || 'badval')"); 1536 1537 content::WebContents* default_tag_contents1; 1538 content::WebContents* default_tag_contents2; 1539 content::WebContents* storage_contents1; 1540 content::WebContents* storage_contents2; 1541 1542 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, 1543 &default_tag_contents2, &storage_contents1, 1544 &storage_contents2, NULL, NULL, NULL); 1545 1546 // Initialize the storage for the first of the two tags that share a storage 1547 // partition. 1548 EXPECT_TRUE(content::ExecuteScript(storage_contents1, 1549 "initDomStorage('page1')")); 1550 1551 // Let's test that the expected values are present in the first tag, as they 1552 // will be overwritten once we call the initDomStorage on the second tag. 1553 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1, 1554 get_local_storage.c_str(), 1555 &output)); 1556 EXPECT_STREQ("local-page1", output.c_str()); 1557 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1, 1558 get_session_storage.c_str(), 1559 &output)); 1560 EXPECT_STREQ("session-page1", output.c_str()); 1561 1562 // Now, init the storage in the second tag in the same storage partition, 1563 // which will overwrite the shared localStorage. 1564 EXPECT_TRUE(content::ExecuteScript(storage_contents2, 1565 "initDomStorage('page2')")); 1566 1567 // The localStorage value now should reflect the one written through the 1568 // second tag. 1569 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1, 1570 get_local_storage.c_str(), 1571 &output)); 1572 EXPECT_STREQ("local-page2", output.c_str()); 1573 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2, 1574 get_local_storage.c_str(), 1575 &output)); 1576 EXPECT_STREQ("local-page2", output.c_str()); 1577 1578 // Session storage is not shared though, as each webview tag has separate 1579 // instance, even if they are in the same storage partition. 1580 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1, 1581 get_session_storage.c_str(), 1582 &output)); 1583 EXPECT_STREQ("session-page1", output.c_str()); 1584 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2, 1585 get_session_storage.c_str(), 1586 &output)); 1587 EXPECT_STREQ("session-page2", output.c_str()); 1588 1589 // Also, let's check that the main browser and another tag that doesn't share 1590 // the same partition don't have those values stored. 1591 EXPECT_TRUE(ExecuteScriptAndExtractString( 1592 browser()->tab_strip_model()->GetWebContentsAt(0), 1593 get_local_storage.c_str(), 1594 &output)); 1595 EXPECT_STREQ("badval", output.c_str()); 1596 EXPECT_TRUE(ExecuteScriptAndExtractString( 1597 browser()->tab_strip_model()->GetWebContentsAt(0), 1598 get_session_storage.c_str(), 1599 &output)); 1600 EXPECT_STREQ("badval", output.c_str()); 1601 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1, 1602 get_local_storage.c_str(), 1603 &output)); 1604 EXPECT_STREQ("badval", output.c_str()); 1605 EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1, 1606 get_session_storage.c_str(), 1607 &output)); 1608 EXPECT_STREQ("badval", output.c_str()); 1609} 1610 1611// See crbug.com/248500 1612#if defined(OS_WIN) 1613#define MAYBE_IndexedDBIsolation DISABLED_IndexedDBIsolation 1614#else 1615#define MAYBE_IndexedDBIsolation IndexedDBIsolation 1616#endif 1617 1618// This tests IndexedDB isolation for packaged apps with webview tags. It loads 1619// an app with multiple webview tags and each tag creates an IndexedDB record, 1620// which the test checks to ensure proper storage isolation is enforced. 1621IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_IndexedDBIsolation) { 1622 ASSERT_TRUE(StartEmbeddedTestServer()); 1623 GURL regular_url = embedded_test_server()->GetURL("/title1.html"); 1624 1625 content::WebContents* default_tag_contents1; 1626 content::WebContents* default_tag_contents2; 1627 content::WebContents* storage_contents1; 1628 content::WebContents* storage_contents2; 1629 1630 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, 1631 &default_tag_contents2, &storage_contents1, 1632 &storage_contents2, NULL, NULL, NULL); 1633 1634 // Initialize the storage for the first of the two tags that share a storage 1635 // partition. 1636 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); 1637 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", 1638 "addItemIDB complete"); 1639 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", 1640 "readItemIDB complete"); 1641 1642 std::string output; 1643 std::string get_value( 1644 "window.domAutomationController.send(getValueIDB() || 'badval')"); 1645 1646 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1, 1647 get_value.c_str(), &output)); 1648 EXPECT_STREQ("page1", output.c_str()); 1649 1650 // Initialize the db in the second tag. 1651 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open"); 1652 1653 // Since we share a partition, reading the value should return the existing 1654 // one. 1655 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", 1656 "readItemIDB complete"); 1657 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2, 1658 get_value.c_str(), &output)); 1659 EXPECT_STREQ("page1", output.c_str()); 1660 1661 // Now write through the second tag and read it back. 1662 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')", 1663 "addItemIDB complete"); 1664 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", 1665 "readItemIDB complete"); 1666 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2, 1667 get_value.c_str(), &output)); 1668 EXPECT_STREQ("page2", output.c_str()); 1669 1670 // Reset the document title, otherwise the next call will not see a change and 1671 // will hang waiting for it. 1672 EXPECT_TRUE(content::ExecuteScript(storage_contents1, 1673 "document.title = 'foo'")); 1674 1675 // Read through the first tag to ensure we have the second value. 1676 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", 1677 "readItemIDB complete"); 1678 EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1, 1679 get_value.c_str(), &output)); 1680 EXPECT_STREQ("page2", output.c_str()); 1681 1682 // Now, let's confirm there is no database in the main browser and another 1683 // tag that doesn't share the same partition. Due to the IndexedDB API design, 1684 // open will succeed, but the version will be 1, since it creates the database 1685 // if it is not found. The two tags use database version 3, so we avoid 1686 // ambiguity. 1687 const char* script = 1688 "indexedDB.open('isolation').onsuccess = function(e) {" 1689 " if (e.target.result.version == 1)" 1690 " document.title = 'db not found';" 1691 " else " 1692 " document.title = 'error';" 1693 "}"; 1694 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0), 1695 script, "db not found"); 1696 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); 1697} 1698 1699// This test ensures that closing app window on 'loadcommit' does not crash. 1700// The test launches an app with guest and closes the window on loadcommit. It 1701// then launches the app window again. The process is repeated 3 times. 1702// http://crbug.com/291278 1703#if defined(OS_WIN) 1704#define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit 1705#else 1706#define MAYBE_CloseOnLoadcommit CloseOnLoadcommit 1707#endif 1708IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CloseOnLoadcommit) { 1709 ExtensionTestMessageListener done_test_listener( 1710 "done-close-on-loadcommit", false); 1711 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit"); 1712 ASSERT_TRUE(done_test_listener.WaitUntilSatisfied()); 1713} 1714 1715IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny_TestDeny) { 1716 MediaAccessAPIDenyTestHelper("testDeny"); 1717} 1718 1719IN_PROC_BROWSER_TEST_F(WebViewTest, 1720 MediaAccessAPIDeny_TestDenyThenAllowThrows) { 1721 MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows"); 1722 1723} 1724 1725IN_PROC_BROWSER_TEST_F(WebViewTest, 1726 MediaAccessAPIDeny_TestDenyWithPreventDefault) { 1727 MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault"); 1728} 1729 1730IN_PROC_BROWSER_TEST_F(WebViewTest, 1731 MediaAccessAPIDeny_TestNoListenersImplyDeny) { 1732 MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny"); 1733} 1734 1735IN_PROC_BROWSER_TEST_F(WebViewTest, 1736 MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny) { 1737 MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny"); 1738} 1739 1740void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string& test_name) { 1741 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 1742 ExtensionTestMessageListener launched_listener("Launched", false); 1743 LoadAndLaunchPlatformApp("web_view/media_access/allow"); 1744 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 1745 1746 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents(); 1747 ASSERT_TRUE(embedder_web_contents); 1748 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate()); 1749 embedder_web_contents->SetDelegate(mock.get()); 1750 1751 ExtensionTestMessageListener done_listener("TEST_PASSED", false); 1752 done_listener.set_failure_message("TEST_FAILED"); 1753 EXPECT_TRUE( 1754 content::ExecuteScript( 1755 embedder_web_contents, 1756 base::StringPrintf("startAllowTest('%s')", 1757 test_name.c_str()))); 1758 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 1759 1760 mock->WaitForSetMediaPermission(); 1761} 1762 1763IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) { 1764 LoadAppWithGuest("web_view/context_menus/basic"); 1765 1766 content::WebContents* guest_web_contents = GetGuestWebContents(); 1767 content::WebContents* embedder = GetEmbedderWebContents(); 1768 ASSERT_TRUE(embedder); 1769 1770 // 1. Basic property test. 1771 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED"); 1772 1773 // 2. Create a menu item and wait for created callback to be called. 1774 ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED"); 1775 1776 // 3. Click the created item, wait for the click handlers to fire from JS. 1777 ExtensionTestMessageListener click_listener("ITEM_CLICKED", false); 1778 GURL page_url("http://www.google.com"); 1779 // Create and build our test context menu. 1780 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create( 1781 guest_web_contents, page_url, GURL(), GURL())); 1782 1783 // Look for the extension item in the menu, and execute it. 1784 int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; 1785 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); 1786 menu->ExecuteCommand(command_id, 0); 1787 1788 // Wait for embedder's script to tell us its onclick fired, it does 1789 // chrome.test.sendMessage('ITEM_CLICKED') 1790 ASSERT_TRUE(click_listener.WaitUntilSatisfied()); 1791 1792 // 4. Update the item's title and verify. 1793 ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED"); 1794 MenuItem::List items = GetItems(); 1795 ASSERT_EQ(1u, items.size()); 1796 MenuItem* item = items.at(0); 1797 EXPECT_EQ("new_title", item->title()); 1798 1799 // 5. Remove the item. 1800 ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED"); 1801 MenuItem::List items_after_removal = GetItems(); 1802 ASSERT_EQ(0u, items_after_removal.size()); 1803 1804 // 6. Add some more items. 1805 ExecuteScriptWaitForTitle( 1806 embedder, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED"); 1807 MenuItem::List items_after_insertion = GetItems(); 1808 ASSERT_EQ(3u, items_after_insertion.size()); 1809 1810 // 7. Test removeAll(). 1811 ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED"); 1812 MenuItem::List items_after_all_removal = GetItems(); 1813 ASSERT_EQ(0u, items_after_all_removal.size()); 1814} 1815 1816IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) { 1817 MediaAccessAPIAllowTestHelper("testAllow"); 1818} 1819 1820IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) { 1821 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny"); 1822} 1823 1824IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) { 1825 MediaAccessAPIAllowTestHelper("testAllowTwice"); 1826} 1827 1828IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAsync) { 1829 MediaAccessAPIAllowTestHelper("testAllowAsync"); 1830} 1831 1832// Checks that window.screenX/screenY/screenLeft/screenTop works correctly for 1833// guests. 1834IN_PROC_BROWSER_TEST_F(WebViewTest, ScreenCoordinates) { 1835 ASSERT_TRUE(RunPlatformAppTestWithArg( 1836 "platform_apps/web_view/common", "screen_coordinates")) 1837 << message_; 1838} 1839 1840#if defined(OS_CHROMEOS) 1841IN_PROC_BROWSER_TEST_F(WebViewTest, ChromeVoxInjection) { 1842 EXPECT_FALSE( 1843 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); 1844 1845 ASSERT_TRUE(StartEmbeddedTestServer()); 1846 content::WebContents* guest_web_contents = LoadGuest( 1847 "/extensions/platform_apps/web_view/chromevox_injection/guest.html", 1848 "web_view/chromevox_injection"); 1849 ASSERT_TRUE(guest_web_contents); 1850 1851 chromeos::SpeechMonitor monitor; 1852 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback( 1853 true, ash::A11Y_NOTIFICATION_NONE); 1854 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage()); 1855 1856 EXPECT_EQ("chrome vox test title", monitor.GetNextUtterance()); 1857} 1858#endif 1859 1860// Flaky on Windows. http://crbug.com/303966 1861#if defined(OS_WIN) 1862#define MAYBE_TearDownTest DISABLED_TearDownTest 1863#else 1864#define MAYBE_TearDownTest TearDownTest 1865#endif 1866IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) { 1867 ExtensionTestMessageListener first_loaded_listener("guest-loaded", false); 1868 const extensions::Extension* extension = 1869 LoadAndLaunchPlatformApp("web_view/teardown"); 1870 ASSERT_TRUE(first_loaded_listener.WaitUntilSatisfied()); 1871 apps::AppWindow* window = NULL; 1872 if (!GetAppWindowCount()) 1873 window = CreateAppWindow(extension); 1874 else 1875 window = GetFirstAppWindow(); 1876 CloseAppWindow(window); 1877 1878 // Load the app again. 1879 ExtensionTestMessageListener second_loaded_listener("guest-loaded", false); 1880 LoadAndLaunchPlatformApp("web_view/teardown"); 1881 ASSERT_TRUE(second_loaded_listener.WaitUntilSatisfied()); 1882} 1883 1884// In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the 1885// platform app) does not have geolocation permission for this test. 1886// No matter what the API does, geolocation permission would be denied. 1887// Note that the test name prefix must be "GeolocationAPI". 1888IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) { 1889 TestHelper("testDenyDenies", 1890 "web_view/geolocation/embedder_has_no_permission", 1891 NEEDS_TEST_SERVER); 1892} 1893 1894IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessDeny) { 1895 TestHelper("testDenyDenies", 1896 "web_view/geolocation/embedder_has_no_permission", 1897 NEEDS_TEST_SERVER); 1898} 1899 1900// In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the 1901// platform app) has geolocation permission 1902// 1903// Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out 1904// geolocation in this case). 1905// 1906// Also note that these are run separately because OverrideGeolocation() doesn't 1907// mock out geolocation for multiple navigator.geolocation calls properly and 1908// the tests become flaky. 1909// GeolocationAPI* test 1 of 3. 1910IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessAllow) { 1911 TestHelper("testAllow", 1912 "web_view/geolocation/embedder_has_permission", 1913 NEEDS_TEST_SERVER); 1914} 1915 1916// GeolocationAPI* test 2 of 3. 1917IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessDeny) { 1918 TestHelper("testDeny", 1919 "web_view/geolocation/embedder_has_permission", 1920 NEEDS_TEST_SERVER); 1921} 1922 1923// GeolocationAPI* test 3 of 3. 1924IN_PROC_BROWSER_TEST_F(WebViewTest, 1925 GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow) { 1926 TestHelper("testMultipleBridgeIdAllow", 1927 "web_view/geolocation/embedder_has_permission", 1928 NEEDS_TEST_SERVER); 1929} 1930 1931// Tests that 1932// BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest 1933// is handled correctly (and does not crash). 1934IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPICancelGeolocation) { 1935 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 1936 ASSERT_TRUE(RunPlatformAppTest( 1937 "platform_apps/web_view/geolocation/cancel_request")) << message_; 1938} 1939 1940IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_GeolocationRequestGone) { 1941 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 1942 ASSERT_TRUE(RunPlatformAppTest( 1943 "platform_apps/web_view/geolocation/geolocation_request_gone")) 1944 << message_; 1945} 1946 1947IN_PROC_BROWSER_TEST_F(WebViewTest, ClearData) { 1948#if defined(OS_WIN) 1949 // Flaky on XP bot http://crbug.com/282674 1950 if (base::win::GetVersion() <= base::win::VERSION_XP) 1951 return; 1952#endif 1953 1954 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 1955 ASSERT_TRUE(RunPlatformAppTestWithArg( 1956 "platform_apps/web_view/common", "cleardata")) 1957 << message_; 1958} 1959 1960// This test is disabled on Win due to being flaky. http://crbug.com/294592 1961#if defined(OS_WIN) 1962#define MAYBE_ConsoleMessage DISABLED_ConsoleMessage 1963#else 1964#define MAYBE_ConsoleMessage ConsoleMessage 1965#endif 1966IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) { 1967 ASSERT_TRUE(RunPlatformAppTestWithArg( 1968 "platform_apps/web_view/common", "console_messages")) 1969 << message_; 1970} 1971 1972IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) { 1973 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 1974 content::WebContents* guest_web_contents = 1975 LoadGuest("/extensions/platform_apps/web_view/download/guest.html", 1976 "web_view/download"); 1977 ASSERT_TRUE(guest_web_contents); 1978 1979 // Replace WebContentsDelegate with mock version so we can intercept download 1980 // requests. 1981 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate(); 1982 scoped_ptr<MockDownloadWebContentsDelegate> 1983 mock_delegate(new MockDownloadWebContentsDelegate(delegate)); 1984 guest_web_contents->SetDelegate(mock_delegate.get()); 1985 1986 // Start test. 1987 // 1. Guest requests a download that its embedder denies. 1988 EXPECT_TRUE(content::ExecuteScript(guest_web_contents, 1989 "startDownload('download-link-1')")); 1990 mock_delegate->WaitForCanDownload(false); // Expect to not allow. 1991 mock_delegate->Reset(); 1992 1993 // 2. Guest requests a download that its embedder allows. 1994 EXPECT_TRUE(content::ExecuteScript(guest_web_contents, 1995 "startDownload('download-link-2')")); 1996 mock_delegate->WaitForCanDownload(true); // Expect to allow. 1997 mock_delegate->Reset(); 1998 1999 // 3. Guest requests a download that its embedder ignores, this implies deny. 2000 EXPECT_TRUE(content::ExecuteScript(guest_web_contents, 2001 "startDownload('download-link-3')")); 2002 mock_delegate->WaitForCanDownload(false); // Expect to not allow. 2003} 2004 2005// This test makes sure loading <webview> does not crash when there is an 2006// extension which has content script whitelisted/forced. 2007IN_PROC_BROWSER_TEST_F(WebViewTest, WhitelistedContentScript) { 2008 // Whitelist the extension for running content script we are going to load. 2009 extensions::ExtensionsClient::ScriptingWhitelist whitelist; 2010 const std::string extension_id = "imeongpbjoodlnmlakaldhlcmijmhpbb"; 2011 whitelist.push_back(extension_id); 2012 extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist); 2013 2014 // Load the extension. 2015 const extensions::Extension* content_script_whitelisted_extension = 2016 LoadExtension(test_data_dir_.AppendASCII( 2017 "platform_apps/web_view/extension_api/content_script")); 2018 ASSERT_TRUE(content_script_whitelisted_extension); 2019 ASSERT_EQ(extension_id, content_script_whitelisted_extension->id()); 2020 2021 // Now load an app with <webview>. 2022 ExtensionTestMessageListener done_listener("TEST_PASSED", false); 2023 LoadAndLaunchPlatformApp("web_view/content_script_whitelisted"); 2024 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 2025} 2026 2027IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentReady) { 2028 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready")) 2029 << message_; 2030} 2031 2032IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentInteractive) { 2033 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive")) 2034 << message_; 2035} 2036 2037IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionAllow) { 2038 ASSERT_TRUE( 2039 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api", 2040 "allowTest")) 2041 << message_; 2042} 2043 2044IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionDeny) { 2045 ASSERT_TRUE( 2046 RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api", 2047 "denyTest")) 2048 << message_; 2049} 2050 2051IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_NoPermission) { 2052 ASSERT_TRUE( 2053 RunPlatformAppTestWithArg("platform_apps/web_view/common", 2054 "speech_recognition_api_no_permission")) 2055 << message_; 2056} 2057 2058// Tests overriding user agent. 2059IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent) { 2060 ASSERT_TRUE(RunPlatformAppTestWithArg( 2061 "platform_apps/web_view/common", "useragent")) << message_; 2062} 2063 2064IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent_NewWindow) { 2065 ASSERT_TRUE(RunPlatformAppTestWithArg( 2066 "platform_apps/web_view/common", 2067 "useragent_newwindow")) << message_; 2068} 2069 2070IN_PROC_BROWSER_TEST_F(WebViewTest, NoPermission) { 2071 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission")) 2072 << message_; 2073} 2074 2075IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestAlertDialog) { 2076 TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER); 2077} 2078 2079IN_PROC_BROWSER_TEST_F(WebViewTest, TestConfirmDialog) { 2080 TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER); 2081} 2082 2083IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogCancel) { 2084 TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER); 2085} 2086 2087IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultCancel) { 2088 TestHelper("testConfirmDialogDefaultCancel", 2089 "web_view/dialog", 2090 NO_TEST_SERVER); 2091} 2092 2093IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultGCCancel) { 2094 TestHelper("testConfirmDialogDefaultGCCancel", 2095 "web_view/dialog", 2096 NO_TEST_SERVER); 2097} 2098 2099IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestPromptDialog) { 2100 TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER); 2101} 2102 2103IN_PROC_BROWSER_TEST_F(WebViewTest, NoContentSettingsAPI) { 2104 // Load the extension. 2105 const extensions::Extension* content_settings_extension = 2106 LoadExtension( 2107 test_data_dir_.AppendASCII( 2108 "platform_apps/web_view/extension_api/content_settings")); 2109 ASSERT_TRUE(content_settings_extension); 2110 TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER); 2111} 2112 2113#if defined(ENABLE_PLUGINS) 2114class WebViewPluginTest : public WebViewTest { 2115 protected: 2116 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 2117 WebViewTest::SetUpCommandLine(command_line); 2118 2119 // Append the switch to register the pepper plugin. 2120 // library name = <out dir>/<test_name>.<library_extension> 2121 // MIME type = application/x-ppapi-<test_name> 2122 base::FilePath plugin_dir; 2123 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 2124 2125 base::FilePath plugin_lib = plugin_dir.Append(library_name); 2126 EXPECT_TRUE(base::PathExists(plugin_lib)); 2127 base::FilePath::StringType pepper_plugin = plugin_lib.value(); 2128 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); 2129 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 2130 pepper_plugin); 2131 } 2132}; 2133 2134IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginEvent) { 2135 TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER); 2136} 2137#endif // defined(ENABLE_PLUGINS) 2138 2139class WebViewCaptureTest : public WebViewTest { 2140 public: 2141 WebViewCaptureTest() {} 2142 virtual ~WebViewCaptureTest() {} 2143 virtual void SetUp() OVERRIDE { 2144 EnablePixelOutput(); 2145 WebViewTest::SetUp(); 2146 } 2147}; 2148 2149IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestZoomAPI) { 2150 TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER); 2151} 2152 2153IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) { 2154 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER); 2155} 2156 2157IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { 2158 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); 2159} 2160 2161// <webview> screenshot capture fails with ubercomp. 2162// See http://crbug.com/327035. 2163IN_PROC_BROWSER_TEST_F(WebViewCaptureTest, 2164 DISABLED_Shim_ScreenshotCapture) { 2165 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); 2166} 2167