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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc

Issue 1378123003: Adding SSL ETS Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ets
Patch Set: Rebase. Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 // Verify that it's the correct tab. 234 // Verify that it's the correct tab.
235 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); 235 EXPECT_EQ(GURL("about:blank"), tab->GetURL());
236 } 236 }
237 237
238 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. 238 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer.
239 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { 239 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) {
240 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( 240 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
241 content::NotificationService::AllSources()); 241 content::NotificationService::AllSources());
242 242
243 ASSERT_TRUE(test_server()->Start()); 243 ASSERT_TRUE(embedded_test_server()->Start());
244 GURL echoheader(test_server()->GetURL("echoheader?Referer")); 244 GURL echoheader(embedded_test_server()->GetURL("/echoheader?Referer"));
245 245
246 // Go to a |page| with a link to echoheader URL. 246 // Go to a |page| with a link to echoheader URL.
247 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); 247 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>");
248 ui_test_utils::NavigateToURL(browser(), page); 248 ui_test_utils::NavigateToURL(browser(), page);
249 249
250 // Set up referrer URL with fragment. 250 // Set up referrer URL with fragment.
251 const GURL kReferrerWithFragment("http://foo.com/test#fragment"); 251 const GURL kReferrerWithFragment("http://foo.com/test#fragment");
252 const std::string kCorrectReferrer("http://foo.com/test"); 252 const std::string kCorrectReferrer("http://foo.com/test");
253 253
254 // Set up menu with link URL. 254 // Set up menu with link URL.
(...skipping 29 matching lines...) Expand all
284 "window.domAutomationController.send(window.document.referrer);", 284 "window.domAutomationController.send(window.document.referrer);",
285 &page_referrer)); 285 &page_referrer));
286 ASSERT_EQ(kCorrectReferrer, page_referrer); 286 ASSERT_EQ(kCorrectReferrer, page_referrer);
287 } 287 }
288 288
289 // Verify that "Open Link in Incognito Window " doesn't send referrer URL. 289 // Verify that "Open Link in Incognito Window " doesn't send referrer URL.
290 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenIncognitoNoneReferrer) { 290 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenIncognitoNoneReferrer) {
291 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( 291 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
292 content::NotificationService::AllSources()); 292 content::NotificationService::AllSources());
293 293
294 ASSERT_TRUE(test_server()->Start()); 294 ASSERT_TRUE(embedded_test_server()->Start());
295 GURL echoheader(test_server()->GetURL("echoheader?Referer")); 295 GURL echoheader(embedded_test_server()->GetURL("/echoheader?Referer"));
296 296
297 // Go to a |page| with a link to echoheader URL. 297 // Go to a |page| with a link to echoheader URL.
298 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); 298 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>");
299 ui_test_utils::NavigateToURL(browser(), page); 299 ui_test_utils::NavigateToURL(browser(), page);
300 300
301 // Set up referrer URL with fragment. 301 // Set up referrer URL with fragment.
302 const GURL kReferrerWithFragment("http://foo.com/test#fragment"); 302 const GURL kReferrerWithFragment("http://foo.com/test#fragment");
303 const std::string kNoneReferrer("None"); 303 const std::string kNoneReferrer("None");
304 const std::string kEmptyReferrer(""); 304 const std::string kEmptyReferrer("");
305 305
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 DISALLOW_COPY_AND_ASSIGN(ThumbnailResponseWatcher); 595 DISALLOW_COPY_AND_ASSIGN(ThumbnailResponseWatcher);
596 }; 596 };
597 597
598 // Maintains image search test state. In particular, note that |menu_observer_| 598 // Maintains image search test state. In particular, note that |menu_observer_|
599 // must live until the right-click completes asynchronously. 599 // must live until the right-click completes asynchronously.
600 class SearchByImageBrowserTest : public InProcessBrowserTest { 600 class SearchByImageBrowserTest : public InProcessBrowserTest {
601 protected: 601 protected:
602 void SetupAndLoadImagePage(const std::string& image_path) { 602 void SetupAndLoadImagePage(const std::string& image_path) {
603 // The test server must start first, so that we know the port that the test 603 // The test server must start first, so that we know the port that the test
604 // server is using. 604 // server is using.
605 ASSERT_TRUE(test_server()->Start()); 605 ASSERT_TRUE(embedded_test_server()->Start());
606 SetupImageSearchEngine(); 606 SetupImageSearchEngine();
607 607
608 // Go to a page with an image in it. The test server doesn't serve the image 608 // Go to a page with an image in it. The test server doesn't serve the image
609 // with the right MIME type, so use a data URL to make a page containing it. 609 // with the right MIME type, so use a data URL to make a page containing it.
610 GURL image_url(test_server()->GetURL(image_path)); 610 GURL image_url(embedded_test_server()->GetURL(image_path));
611 GURL page("data:text/html,<img src='" + image_url.spec() + "'>"); 611 GURL page("data:text/html,<img src='" + image_url.spec() + "'>");
612 ui_test_utils::NavigateToURL(browser(), page); 612 ui_test_utils::NavigateToURL(browser(), page);
613 } 613 }
614 614
615 void AttemptImageSearch() { 615 void AttemptImageSearch() {
616 // Right-click where the image should be. 616 // Right-click where the image should be.
617 // |menu_observer_| will cause the search-by-image menu item to be clicked. 617 // |menu_observer_| will cause the search-by-image menu item to be clicked.
618 menu_observer_.reset(new ContextMenuNotificationObserver( 618 menu_observer_.reset(new ContextMenuNotificationObserver(
619 IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE)); 619 IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE));
620 content::WebContents* tab = 620 content::WebContents* tab =
621 browser()->tab_strip_model()->GetActiveWebContents(); 621 browser()->tab_strip_model()->GetActiveWebContents();
622 content::SimulateMouseClickAt(tab, 0, blink::WebMouseEvent::ButtonRight, 622 content::SimulateMouseClickAt(tab, 0, blink::WebMouseEvent::ButtonRight,
623 gfx::Point(15, 15)); 623 gfx::Point(15, 15));
624 } 624 }
625 625
626 GURL GetImageSearchURL() { 626 GURL GetImageSearchURL() {
627 static const char kImageSearchURL[] = "imagesearch"; 627 static const char kImageSearchURL[] = "/imagesearch";
628 return test_server()->GetURL(kImageSearchURL); 628 return embedded_test_server()->GetURL(kImageSearchURL);
629 } 629 }
630 630
631 private: 631 private:
632 void SetupImageSearchEngine() { 632 void SetupImageSearchEngine() {
633 static const char kShortName[] = "test"; 633 static const char kShortName[] = "test";
634 static const char kSearchURL[] = "search?q={searchTerms}"; 634 static const char kSearchURL[] = "/search?q={searchTerms}";
635 static const char kImageSearchPostParams[] = 635 static const char kImageSearchPostParams[] =
636 "thumb={google:imageThumbnail}"; 636 "thumb={google:imageThumbnail}";
637 637
638 TemplateURLService* model = 638 TemplateURLService* model =
639 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 639 TemplateURLServiceFactory::GetForProfile(browser()->profile());
640 ASSERT_TRUE(model); 640 ASSERT_TRUE(model);
641 search_test_utils::WaitForTemplateURLServiceToLoad(model); 641 search_test_utils::WaitForTemplateURLServiceToLoad(model);
642 ASSERT_TRUE(model->loaded()); 642 ASSERT_TRUE(model->loaded());
643 643
644 TemplateURLData data; 644 TemplateURLData data;
645 data.SetShortName(base::ASCIIToUTF16(kShortName)); 645 data.SetShortName(base::ASCIIToUTF16(kShortName));
646 data.SetKeyword(data.short_name()); 646 data.SetKeyword(data.short_name());
647 data.SetURL(test_server()->GetURL(kSearchURL).spec()); 647 data.SetURL(embedded_test_server()->GetURL(kSearchURL).spec());
648 data.image_url = GetImageSearchURL().spec(); 648 data.image_url = GetImageSearchURL().spec();
649 data.image_url_post_params = kImageSearchPostParams; 649 data.image_url_post_params = kImageSearchPostParams;
650 650
651 // The model takes ownership of |template_url|. 651 // The model takes ownership of |template_url|.
652 TemplateURL* template_url = new TemplateURL(data); 652 TemplateURL* template_url = new TemplateURL(data);
653 ASSERT_TRUE(model->Add(template_url)); 653 ASSERT_TRUE(model->Add(template_url));
654 model->SetUserSelectedDefaultSearchProvider(template_url); 654 model->SetUserSelectedDefaultSearchProvider(template_url);
655 } 655 }
656 656
657 void TearDownInProcessBrowserTestFixture() override { 657 void TearDownInProcessBrowserTestFixture() override {
658 menu_observer_.reset(); 658 menu_observer_.reset();
659 } 659 }
660 660
661 scoped_ptr<ContextMenuNotificationObserver> menu_observer_; 661 scoped_ptr<ContextMenuNotificationObserver> menu_observer_;
662 }; 662 };
663 663
664 IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithValidImage) { 664 IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithValidImage) {
665 static const char kValidImage[] = "files/image_search/valid.png"; 665 static const char kValidImage[] = "/image_search/valid.png";
666 SetupAndLoadImagePage(kValidImage); 666 SetupAndLoadImagePage(kValidImage);
667 667
668 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( 668 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
669 content::NotificationService::AllSources()); 669 content::NotificationService::AllSources());
670 AttemptImageSearch(); 670 AttemptImageSearch();
671 671
672 // The browser should open a new tab for an image search. 672 // The browser should open a new tab for an image search.
673 tab_observer.Wait(); 673 tab_observer.Wait();
674 content::WebContents* new_tab = tab_observer.GetTab(); 674 content::WebContents* new_tab = tab_observer.GetTab();
675 content::WaitForLoadStop(new_tab); 675 content::WaitForLoadStop(new_tab);
676 EXPECT_EQ(GetImageSearchURL(), new_tab->GetURL()); 676 EXPECT_EQ(GetImageSearchURL(), new_tab->GetURL());
677 } 677 }
678 678
679 IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithCorruptImage) { 679 IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithCorruptImage) {
680 static const char kCorruptImage[] = "files/image_search/corrupt.png"; 680 static const char kCorruptImage[] = "/image_search/corrupt.png";
681 SetupAndLoadImagePage(kCorruptImage); 681 SetupAndLoadImagePage(kCorruptImage);
682 682
683 content::WebContents* tab = 683 content::WebContents* tab =
684 browser()->tab_strip_model()->GetActiveWebContents(); 684 browser()->tab_strip_model()->GetActiveWebContents();
685 ThumbnailResponseWatcher watcher(tab->GetRenderProcessHost()); 685 ThumbnailResponseWatcher watcher(tab->GetRenderProcessHost());
686 AttemptImageSearch(); 686 AttemptImageSearch();
687 687
688 // The browser should receive a response from the renderer, because the 688 // The browser should receive a response from the renderer, because the
689 // renderer should not crash. 689 // renderer should not crash.
690 EXPECT_EQ(ThumbnailResponseWatcher::THUMBNAIL_RECEIVED, watcher.Wait()); 690 EXPECT_EQ(ThumbnailResponseWatcher::THUMBNAIL_RECEIVED, watcher.Wait());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 // This prevents any risk of flake if any test doesn't wait for a request 753 // This prevents any risk of flake if any test doesn't wait for a request
754 // it sent. Mutable so it can be accessed from a const function. 754 // it sent. Mutable so it can be accessed from a const function.
755 mutable base::WeakPtrFactory<LoadImageRequestInterceptor> weak_factory_; 755 mutable base::WeakPtrFactory<LoadImageRequestInterceptor> weak_factory_;
756 756
757 DISALLOW_COPY_AND_ASSIGN(LoadImageRequestInterceptor); 757 DISALLOW_COPY_AND_ASSIGN(LoadImageRequestInterceptor);
758 }; 758 };
759 759
760 class LoadImageBrowserTest : public InProcessBrowserTest { 760 class LoadImageBrowserTest : public InProcessBrowserTest {
761 protected: 761 protected:
762 void SetupAndLoadImagePage(const std::string& image_path) { 762 void SetupAndLoadImagePage(const std::string& image_path) {
763 ASSERT_TRUE(embedded_test_server()->Start());
763 // Go to a page with an image in it. The test server doesn't serve the image 764 // Go to a page with an image in it. The test server doesn't serve the image
764 // with the right MIME type, so use a data URL to make a page containing it. 765 // with the right MIME type, so use a data URL to make a page containing it.
765 GURL image_url(test_server()->GetURL(image_path)); 766 GURL image_url(embedded_test_server()->GetURL(image_path));
766 GURL page("data:text/html,<img src='" + image_url.spec() + "'>"); 767 GURL page("data:text/html,<img src='" + image_url.spec() + "'>");
767 ui_test_utils::NavigateToURL(browser(), page); 768 ui_test_utils::NavigateToURL(browser(), page);
768 } 769 }
769 770
770 void AddLoadImageInterceptor(const std::string& image_path) { 771 void AddLoadImageInterceptor(const std::string& image_path) {
771 interceptor_ = new LoadImageRequestInterceptor(); 772 interceptor_ = new LoadImageRequestInterceptor();
772 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_); 773 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_);
773 content::BrowserThread::PostTask( 774 content::BrowserThread::PostTask(
774 content::BrowserThread::IO, FROM_HERE, 775 content::BrowserThread::IO, FROM_HERE,
775 base::Bind(&LoadImageBrowserTest::AddInterceptorForURL, 776 base::Bind(&LoadImageBrowserTest::AddInterceptorForURL,
776 base::Unretained(this), 777 base::Unretained(this),
777 GURL(test_server()->GetURL(image_path).spec()), 778 GURL(embedded_test_server()->GetURL(image_path).spec()),
778 base::Passed(&owned_interceptor))); 779 base::Passed(&owned_interceptor)));
779 } 780 }
780 781
781 void AttemptLoadImage() { 782 void AttemptLoadImage() {
782 // Right-click where the image should be. 783 // Right-click where the image should be.
783 // |menu_observer_| will cause the "Load image" menu item to be clicked. 784 // |menu_observer_| will cause the "Load image" menu item to be clicked.
784 menu_observer_.reset(new ContextMenuNotificationObserver( 785 menu_observer_.reset(new ContextMenuNotificationObserver(
785 IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE)); 786 IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE));
786 content::WebContents* tab = 787 content::WebContents* tab =
787 browser()->tab_strip_model()->GetActiveWebContents(); 788 browser()->tab_strip_model()->GetActiveWebContents();
788 content::SimulateMouseClickAt(tab, 0, blink::WebMouseEvent::ButtonRight, 789 content::SimulateMouseClickAt(tab, 0, blink::WebMouseEvent::ButtonRight,
789 gfx::Point(15, 15)); 790 gfx::Point(15, 15));
790 } 791 }
791 792
792 void AddInterceptorForURL( 793 void AddInterceptorForURL(
793 const GURL& url, scoped_ptr<net::URLRequestInterceptor> handler) { 794 const GURL& url, scoped_ptr<net::URLRequestInterceptor> handler) {
794 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 795 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
795 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 796 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
796 url, handler.Pass()); 797 url, handler.Pass());
797 } 798 }
798 799
799 LoadImageRequestInterceptor* interceptor_; 800 LoadImageRequestInterceptor* interceptor_;
800 801
801 private: 802 private:
802 scoped_ptr<ContextMenuNotificationObserver> menu_observer_; 803 scoped_ptr<ContextMenuNotificationObserver> menu_observer_;
803 }; 804 };
804 805
805 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { 806 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) {
806 static const char kValidImage[] = "files/load_image/image.png"; 807 static const char kValidImage[] = "/load_image/image.png";
807 SetupAndLoadImagePage(kValidImage); 808 SetupAndLoadImagePage(kValidImage);
808 AddLoadImageInterceptor(kValidImage); 809 AddLoadImageInterceptor(kValidImage);
809 AttemptLoadImage(); 810 AttemptLoadImage();
810 interceptor_->WaitForRequests(1); 811 interceptor_->WaitForRequests(1);
811 EXPECT_EQ(1, interceptor_->num_requests()); 812 EXPECT_EQ(1, interceptor_->num_requests());
812 } 813 }
813 814
814 } // namespace 815 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698