Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/extensions/web_view_browsertest.cc

Issue 14189014: Minor cleanup in web_view_browsertest and remove repetitive code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/download/embedder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/stringprintf.h" 5 #include "base/stringprintf.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/automation/automation_util.h" 7 #include "chrome/browser/automation/automation_util.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h" 8 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 9 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
10 #include "chrome/browser/prerender/prerender_link_manager.h" 10 #include "chrome/browser/prerender/prerender_link_manager.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 test_name.c_str()))); 369 test_name.c_str())));
370 done_listener.WaitUntilSatisfied(); 370 done_listener.WaitUntilSatisfied();
371 bool has_test_passed; 371 bool has_test_passed;
372 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 372 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
373 embedder_web_contents, 373 embedder_web_contents,
374 "window.domAutomationController.send(hasTestPassed());", 374 "window.domAutomationController.send(hasTestPassed());",
375 &has_test_passed)); 375 &has_test_passed));
376 ASSERT_TRUE(has_test_passed); 376 ASSERT_TRUE(has_test_passed);
377 } 377 }
378 378
379 content::WebContents* LoadGuest(const std::string& guest_path,
380 const std::string& app_path) {
381 GURL::Replacements replace_host;
382 std::string host_str("localhost"); // Must stay in scope with replace_host.
383 replace_host.SetHostStr(host_str);
384
385 GURL guest_url = test_server()->GetURL(guest_path);
386 guest_url = guest_url.ReplaceComponents(replace_host);
387
388 ui_test_utils::UrlLoadObserver guest_observer(
389 guest_url, content::NotificationService::AllSources());
390
391 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
392 LoadAndLaunchPlatformApp(app_path.c_str());
393 guest_observer.Wait();
394
395 content::Source<content::NavigationController> source =
396 guest_observer.source();
397 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
398
399 bool satisfied = guest_loaded_listener.WaitUntilSatisfied();
400 if (!satisfied)
401 return NULL;
402
403 content::WebContents* guest_web_contents = source->GetWebContents();
404 return guest_web_contents;
405 }
406
407 private:
379 scoped_ptr<content::FakeSpeechRecognitionManager> 408 scoped_ptr<content::FakeSpeechRecognitionManager>
380 fake_speech_recognition_manager_; 409 fake_speech_recognition_manager_;
381 }; 410 };
382 411
383 // http://crbug.com/176122: This test is flaky on Windows. 412 // http://crbug.com/176122: This test is flaky on Windows.
384 #if defined(OS_WIN) 413 #if defined(OS_WIN)
385 #define MAYBE_Shim DISABLED_Shim 414 #define MAYBE_Shim DISABLED_Shim
386 #else 415 #else
387 #define MAYBE_Shim Shim 416 #define MAYBE_Shim Shim
388 #endif 417 #endif
389 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim) { 418 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim) {
390 ASSERT_TRUE(StartTestServer()); 419 ASSERT_TRUE(StartTestServer());
391 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/shim")) << message_; 420 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/shim")) << message_;
392 } 421 }
393 422
394 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { 423 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) {
395 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute")) 424 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
396 << message_; 425 << message_;
397 } 426 }
398 427
399 // This test verifies that prerendering has been disabled inside <webview>. 428 // This test verifies that prerendering has been disabled inside <webview>.
400 // This test is here rather than in PrerenderBrowserTest for testing convenience 429 // This test is here rather than in PrerenderBrowserTest for testing convenience
401 // only. If it breaks then this is a bug in the prerenderer. 430 // only. If it breaks then this is a bug in the prerenderer.
402 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) { 431 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) {
403 ASSERT_TRUE(StartTestServer()); 432 ASSERT_TRUE(StartTestServer());
404 std::string host_str("localhost"); // Must stay in scope with replace_host. 433 content::WebContents* guest_web_contents =
405 GURL::Replacements replace_host; 434 LoadGuest(
406 replace_host.SetHostStr(host_str); 435 "files/extensions/platform_apps/web_view/noprerenderer/guest.html",
407 436 "web_view/noprerenderer");
408 GURL guest_url = test_server()->GetURL(
409 "files/extensions/platform_apps/web_view/noprerenderer/guest.html");
410 guest_url = guest_url.ReplaceComponents(replace_host);
411
412 ui_test_utils::UrlLoadObserver guest_observer(
413 guest_url, content::NotificationService::AllSources());
414
415 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
416 LoadAndLaunchPlatformApp("web_view/noprerenderer");
417 guest_observer.Wait();
418
419 content::Source<content::NavigationController> source =
420 guest_observer.source();
421 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
422
423 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
424 content::WebContents* guest_web_contents = source->GetWebContents();
425 ASSERT_TRUE(guest_web_contents != NULL); 437 ASSERT_TRUE(guest_web_contents != NULL);
426 438
427 PrerenderLinkManager* prerender_link_manager = 439 PrerenderLinkManager* prerender_link_manager =
428 PrerenderLinkManagerFactory::GetForProfile( 440 PrerenderLinkManagerFactory::GetForProfile(
429 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext())); 441 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext()));
430 ASSERT_TRUE(prerender_link_manager != NULL); 442 ASSERT_TRUE(prerender_link_manager != NULL);
431 EXPECT_TRUE(prerender_link_manager->IsEmpty()); 443 EXPECT_TRUE(prerender_link_manager->IsEmpty());
432 } 444 }
433 445
434 // This tests cookie isolation for packaged apps with webview tags. It navigates 446 // This tests cookie isolation for packaged apps with webview tags. It navigates
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 embedder_web_contents, 876 embedder_web_contents,
865 "window.domAutomationController.send(getTestStatus())", &result)); 877 "window.domAutomationController.send(getTestStatus())", &result));
866 ASSERT_EQ(std::string("PASSED"), result); 878 ASSERT_EQ(std::string("PASSED"), result);
867 879
868 mock->WaitForSetMediaPermission(); 880 mock->WaitForSetMediaPermission();
869 } 881 }
870 } 882 }
871 883
872 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { 884 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) {
873 ASSERT_TRUE(StartTestServer()); 885 ASSERT_TRUE(StartTestServer());
874 std::string host_str("localhost"); // Must stay in scope with replace_host. 886 content::WebContents* guest_web_contents = LoadGuest(
875 GURL::Replacements replace_host; 887 "files/extensions/platform_apps/web_view/speech/guest.html",
876 replace_host.SetHostStr(host_str); 888 "web_view/speech");
889 ASSERT_TRUE(guest_web_contents);
877 890
878 GURL guest_url = test_server()->GetURL(
879 "files/extensions/platform_apps/web_view/speech/guest.html");
880 guest_url = guest_url.ReplaceComponents(replace_host);
881
882 ui_test_utils::UrlLoadObserver guest_observer(
883 guest_url, content::NotificationService::AllSources());
884
885 ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
886 LoadAndLaunchPlatformApp("web_view/speech");
887 guest_observer.Wait();
888
889 content::Source<content::NavigationController> source =
890 guest_observer.source();
891 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
892
893 ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
894 content::WebContents* guest_web_contents = source->GetWebContents();
895 // Click on the guest (center of the WebContents), the guest is rendered in a 891 // Click on the guest (center of the WebContents), the guest is rendered in a
896 // way that this will trigger clicking on speech recognition input mic. 892 // way that this will trigger clicking on speech recognition input mic.
897 SimulateMouseClick(guest_web_contents, 0, WebKit::WebMouseEvent::ButtonLeft); 893 SimulateMouseClick(guest_web_contents, 0, WebKit::WebMouseEvent::ButtonLeft);
898 894
899 string16 expected_title(ASCIIToUTF16("PASSED")); 895 string16 expected_title(ASCIIToUTF16("PASSED"));
900 string16 error_title(ASCIIToUTF16("FAILED")); 896 string16 error_title(ASCIIToUTF16("FAILED"));
901 content::TitleWatcher title_watcher(guest_web_contents, expected_title); 897 content::TitleWatcher title_watcher(guest_web_contents, expected_title);
902 title_watcher.AlsoWaitForTitle(error_title); 898 title_watcher.AlsoWaitForTitle(error_title);
903 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 899 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
904 } 900 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 #define MAYBE_NewWindow NewWindow 969 #define MAYBE_NewWindow NewWindow
974 #endif 970 #endif
975 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_NewWindow) { 971 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_NewWindow) {
976 ASSERT_TRUE(StartTestServer()); // For serving guest pages. 972 ASSERT_TRUE(StartTestServer()); // For serving guest pages.
977 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/newwindow")) 973 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/newwindow"))
978 << message_; 974 << message_;
979 } 975 }
980 976
981 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) { 977 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) {
982 ASSERT_TRUE(StartTestServer()); // For serving guest pages. 978 ASSERT_TRUE(StartTestServer()); // For serving guest pages.
983 LoadAndLaunchPlatformApp("web_view/download"); 979 content::WebContents* guest_web_contents =
984 980 LoadGuest("files/extensions/platform_apps/web_view/download/guest.html",
985 GURL::Replacements replace_host; 981 "web_view/download");
986 std::string host_str("localhost"); // Must stay in scope with replace_host. 982 ASSERT_TRUE(guest_web_contents);
987 replace_host.SetHostStr(host_str);
988
989 // Grab the guest's WebContents.
990 GURL guest_url = test_server()->GetURL(
991 "files/extensions/platform_apps/web_view/download/guest.html");
992 guest_url = guest_url.ReplaceComponents(replace_host);
993 ui_test_utils::UrlLoadObserver observer(
994 guest_url, content::NotificationService::AllSources());
995 observer.Wait();
996 content::Source<content::NavigationController> source = observer.source();
997 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
998 content::WebContents* guest_web_contents = source->GetWebContents();
999 983
1000 // Replace WebContentsDelegate with mock version so we can intercept download 984 // Replace WebContentsDelegate with mock version so we can intercept download
1001 // requests. 985 // requests.
1002 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate(); 986 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate();
1003 MockDownloadWebContentsDelegate* mock_delegate = 987 MockDownloadWebContentsDelegate* mock_delegate =
1004 new MockDownloadWebContentsDelegate(delegate); 988 new MockDownloadWebContentsDelegate(delegate);
1005 guest_web_contents->SetDelegate(mock_delegate); 989 guest_web_contents->SetDelegate(mock_delegate);
1006 990
1007 // Start test. 991 // Start test.
1008 // 1. Guest requests a download that its embedder denies. 992 // 1. Guest requests a download that its embedder denies.
1009 EXPECT_TRUE(content::ExecuteScript(guest_web_contents, 993 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
1010 "startDownload('download-link-1')")); 994 "startDownload('download-link-1')"));
1011 mock_delegate->WaitForCanDownload(false); // Expect to not allow. 995 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
1012 mock_delegate->Reset(); 996 mock_delegate->Reset();
1013 997
1014 // 2. Guest requests a download that its embedder allows. 998 // 2. Guest requests a download that its embedder allows.
1015 EXPECT_TRUE(content::ExecuteScript(guest_web_contents, 999 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
1016 "startDownload('download-link-2')")); 1000 "startDownload('download-link-2')"));
1017 mock_delegate->WaitForCanDownload(true); // Expect to allow. 1001 mock_delegate->WaitForCanDownload(true); // Expect to allow.
1018 mock_delegate->Reset(); 1002 mock_delegate->Reset();
1019 1003
1020 // 3. Guest requests a download that its embedder ignores, this implies deny. 1004 // 3. Guest requests a download that its embedder ignores, this implies deny.
1021 EXPECT_TRUE(content::ExecuteScript(guest_web_contents, 1005 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
1022 "startDownload('download-link-3')")); 1006 "startDownload('download-link-3')"));
1023 mock_delegate->WaitForCanDownload(false); // Expect to not allow. 1007 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
1024 } 1008 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/download/embedder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698