| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "chrome/browser/interstitial_page.h" | 6 #include "chrome/browser/interstitial_page.h" |
| 7 #include "chrome/browser/navigation_controller.h" | 7 #include "chrome/browser/navigation_controller.h" |
| 8 #include "chrome/browser/navigation_entry.h" | 8 #include "chrome/browser/navigation_entry.h" |
| 9 #include "chrome/browser/render_view_host.h" | 9 #include "chrome/browser/render_view_host.h" |
| 10 #include "chrome/browser/render_widget_host_view.h" | 10 #include "chrome/browser/render_widget_host_view.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 class TestInterstitialPage : public InterstitialPage { | 253 class TestInterstitialPage : public InterstitialPage { |
| 254 public: | 254 public: |
| 255 enum InterstitialState { | 255 enum InterstitialState { |
| 256 UNDECIDED = 0, // No decision taken yet. | 256 UNDECIDED = 0, // No decision taken yet. |
| 257 OKED, // Proceed was called. | 257 OKED, // Proceed was called. |
| 258 CANCELED // DontProceed was called. | 258 CANCELED // DontProceed was called. |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 class Delegate { |
| 262 public: |
| 263 virtual void TestInterstitialPageDeleted( |
| 264 TestInterstitialPage* interstitial) = 0; |
| 265 }; |
| 266 |
| 261 // IMPORTANT NOTE: if you pass stack allocated values for |state| and | 267 // IMPORTANT NOTE: if you pass stack allocated values for |state| and |
| 262 // |deleted| (like all interstitial related tests do at this point), make sure | 268 // |deleted| (like all interstitial related tests do at this point), make sure |
| 263 // to create an instance of the TestInterstitialPageStateGuard class on the | 269 // to create an instance of the TestInterstitialPageStateGuard class on the |
| 264 // stack in your test. This will ensure that the TestInterstitialPage states | 270 // stack in your test. This will ensure that the TestInterstitialPage states |
| 265 // are cleared when the test finishes. | 271 // are cleared when the test finishes. |
| 266 // Not doing so will cause stack trashing if your test does not hide the | 272 // Not doing so will cause stack trashing if your test does not hide the |
| 267 // interstitial, as in such a case it will be destroyed in the test TearDown | 273 // interstitial, as in such a case it will be destroyed in the test TearDown |
| 268 // method and will dereference the |deleted| local variable which by then is | 274 // method and will dereference the |deleted| local variable which by then is |
| 269 // out of scope. | 275 // out of scope. |
| 270 TestInterstitialPage(WebContents* tab, | 276 TestInterstitialPage(WebContents* tab, |
| 271 bool new_navigation, | 277 bool new_navigation, |
| 272 const GURL& url, | 278 const GURL& url, |
| 273 InterstitialState* state, | 279 InterstitialState* state, |
| 274 bool* deleted) | 280 bool* deleted) |
| 275 : InterstitialPage(tab, new_navigation, url), | 281 : InterstitialPage(tab, new_navigation, url), |
| 276 state_(state), | 282 state_(state), |
| 277 deleted_(deleted), | 283 deleted_(deleted), |
| 278 command_received_count_(0) { | 284 command_received_count_(0), |
| 285 delegate_(NULL) { |
| 279 *state_ = UNDECIDED; | 286 *state_ = UNDECIDED; |
| 280 *deleted_ = false; | 287 *deleted_ = false; |
| 281 } | 288 } |
| 282 | 289 |
| 283 virtual ~TestInterstitialPage() { | 290 virtual ~TestInterstitialPage() { |
| 284 if (deleted_) | 291 if (deleted_) |
| 285 *deleted_ = true; | 292 *deleted_ = true; |
| 293 if (delegate_) |
| 294 delegate_->TestInterstitialPageDeleted(this); |
| 286 } | 295 } |
| 287 | 296 |
| 288 virtual void DontProceed() { | 297 virtual void DontProceed() { |
| 289 if (state_) | 298 if (state_) |
| 290 *state_ = CANCELED; | 299 *state_ = CANCELED; |
| 291 InterstitialPage::DontProceed(); | 300 InterstitialPage::DontProceed(); |
| 292 } | 301 } |
| 293 virtual void Proceed() { | 302 virtual void Proceed() { |
| 294 if (state_) | 303 if (state_) |
| 295 *state_ = OKED; | 304 *state_ = OKED; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 315 } | 324 } |
| 316 | 325 |
| 317 bool is_showing() const { | 326 bool is_showing() const { |
| 318 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> | 327 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> |
| 319 is_showing(); | 328 is_showing(); |
| 320 } | 329 } |
| 321 | 330 |
| 322 void ClearStates() { | 331 void ClearStates() { |
| 323 state_ = NULL; | 332 state_ = NULL; |
| 324 deleted_ = NULL; | 333 deleted_ = NULL; |
| 334 delegate_ = NULL; |
| 335 } |
| 336 |
| 337 void set_delegate(Delegate* delegate) { |
| 338 delegate_ = delegate; |
| 325 } | 339 } |
| 326 | 340 |
| 327 protected: | 341 protected: |
| 328 virtual RenderViewHost* CreateRenderViewHost() { | 342 virtual RenderViewHost* CreateRenderViewHost() { |
| 329 return new TestRenderViewHost( | 343 return new TestRenderViewHost( |
| 330 SiteInstance::CreateSiteInstance(tab()->profile()), | 344 SiteInstance::CreateSiteInstance(tab()->profile()), |
| 331 this, MSG_ROUTING_NONE, NULL); | 345 this, MSG_ROUTING_NONE, NULL); |
| 332 } | 346 } |
| 333 | 347 |
| 334 virtual void CommandReceived(const std::string& command) { | 348 virtual void CommandReceived(const std::string& command) { |
| 335 command_received_count_++; | 349 command_received_count_++; |
| 336 } | 350 } |
| 337 | 351 |
| 338 private: | 352 private: |
| 339 InterstitialState* state_; | 353 InterstitialState* state_; |
| 340 bool* deleted_; | 354 bool* deleted_; |
| 341 int command_received_count_; | 355 int command_received_count_; |
| 356 Delegate* delegate_; |
| 342 }; | 357 }; |
| 343 | 358 |
| 344 class TestInterstitialPageStateGuard { | 359 class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { |
| 345 public: | 360 public: |
| 346 explicit TestInterstitialPageStateGuard( | 361 explicit TestInterstitialPageStateGuard( |
| 347 TestInterstitialPage* interstitial_page) | 362 TestInterstitialPage* interstitial_page) |
| 348 : interstitial_page_(interstitial_page) { | 363 : interstitial_page_(interstitial_page) { |
| 349 DCHECK(interstitial_page_); | 364 DCHECK(interstitial_page_); |
| 365 interstitial_page_->set_delegate(this); |
| 350 } | 366 } |
| 351 ~TestInterstitialPageStateGuard() { | 367 ~TestInterstitialPageStateGuard() { |
| 352 interstitial_page_->ClearStates(); | 368 if (interstitial_page_) |
| 369 interstitial_page_->ClearStates(); |
| 370 } |
| 371 |
| 372 virtual void TestInterstitialPageDeleted(TestInterstitialPage* interstitial) { |
| 373 DCHECK(interstitial_page_ == interstitial); |
| 374 interstitial_page_ = NULL; |
| 353 } | 375 } |
| 354 | 376 |
| 355 private: | 377 private: |
| 356 TestInterstitialPage* interstitial_page_; | 378 TestInterstitialPage* interstitial_page_; |
| 357 }; | 379 }; |
| 358 | 380 |
| 359 class WebContentsTest : public testing::Test { | 381 class WebContentsTest : public testing::Test { |
| 360 public: | 382 public: |
| 361 WebContentsTest() : contents(NULL) {} | 383 WebContentsTest() : contents(NULL) {} |
| 362 | 384 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 782 |
| 761 // These should still be the default values. | 783 // These should still be the default values. |
| 762 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family); | 784 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family); |
| 763 EXPECT_EQ(true, webkit_prefs.javascript_enabled); | 785 EXPECT_EQ(true, webkit_prefs.javascript_enabled); |
| 764 } | 786 } |
| 765 | 787 |
| 766 //////////////////////////////////////////////////////////////////////////////// | 788 //////////////////////////////////////////////////////////////////////////////// |
| 767 // Interstitial Tests | 789 // Interstitial Tests |
| 768 //////////////////////////////////////////////////////////////////////////////// | 790 //////////////////////////////////////////////////////////////////////////////// |
| 769 | 791 |
| 770 // All the tests have been temporarily disabled while investigating a heap | |
| 771 // corruption problem showing up on the build bot. | |
| 772 // TODO(jcampan): bug #5789 Fix and reenable these tests. | |
| 773 | |
| 774 // Test navigating to a page (with the navigation initiated from the browser, | 792 // Test navigating to a page (with the navigation initiated from the browser, |
| 775 // as when a URL is typed in the location bar) that shows an interstitial and | 793 // as when a URL is typed in the location bar) that shows an interstitial and |
| 776 // creates a new navigation entry, then hiding it without proceeding. | 794 // creates a new navigation entry, then hiding it without proceeding. |
| 777 TEST_F(WebContentsTest, | 795 TEST_F(WebContentsTest, |
| 778 DISABLED_ShowInterstitialFromBrowserWithNewNavigationDontProceed) { | 796 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { |
| 779 // Navigate to a page. | 797 // Navigate to a page. |
| 780 GURL url1("http://www.google.com"); | 798 GURL url1("http://www.google.com"); |
| 781 Navigate(1, url1); | 799 Navigate(1, url1); |
| 782 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 800 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 783 | 801 |
| 784 // Initiate a browser navigation that will trigger the interstitial | 802 // Initiate a browser navigation that will trigger the interstitial |
| 785 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), | 803 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), |
| 786 PageTransition::TYPED); | 804 PageTransition::TYPED); |
| 787 | 805 |
| 788 // Show an interstitial. | 806 // Show an interstitial. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 816 entry = contents->controller()->GetActiveEntry(); | 834 entry = contents->controller()->GetActiveEntry(); |
| 817 ASSERT_TRUE(entry != NULL); | 835 ASSERT_TRUE(entry != NULL); |
| 818 EXPECT_TRUE(entry->url() == url1); | 836 EXPECT_TRUE(entry->url() == url1); |
| 819 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 837 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 820 } | 838 } |
| 821 | 839 |
| 822 // Test navigating to a page (with the navigation initiated from the renderer, | 840 // Test navigating to a page (with the navigation initiated from the renderer, |
| 823 // as when clicking on a link in the page) that shows an interstitial and | 841 // as when clicking on a link in the page) that shows an interstitial and |
| 824 // creates a new navigation entry, then hiding it without proceeding. | 842 // creates a new navigation entry, then hiding it without proceeding. |
| 825 TEST_F(WebContentsTest, | 843 TEST_F(WebContentsTest, |
| 826 DISABLED_ShowInterstitiaFromRendererlWithNewNavigationDontProceed) { | 844 ShowInterstitiaFromRendererlWithNewNavigationDontProceed) { |
| 827 // Navigate to a page. | 845 // Navigate to a page. |
| 828 GURL url1("http://www.google.com"); | 846 GURL url1("http://www.google.com"); |
| 829 Navigate(1, url1); | 847 Navigate(1, url1); |
| 830 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 848 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 831 | 849 |
| 832 // Show an interstitial (no pending entry, the interstitial would have been | 850 // Show an interstitial (no pending entry, the interstitial would have been |
| 833 // triggered by clicking on a link). | 851 // triggered by clicking on a link). |
| 834 TestInterstitialPage::InterstitialState state = | 852 TestInterstitialPage::InterstitialState state = |
| 835 TestInterstitialPage::UNDECIDED; | 853 TestInterstitialPage::UNDECIDED; |
| 836 bool deleted = false; | 854 bool deleted = false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 860 EXPECT_TRUE(contents->interstitial_page() == NULL); | 878 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 861 entry = contents->controller()->GetActiveEntry(); | 879 entry = contents->controller()->GetActiveEntry(); |
| 862 ASSERT_TRUE(entry != NULL); | 880 ASSERT_TRUE(entry != NULL); |
| 863 EXPECT_TRUE(entry->url() == url1); | 881 EXPECT_TRUE(entry->url() == url1); |
| 864 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 882 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 865 } | 883 } |
| 866 | 884 |
| 867 // Test navigating to a page that shows an interstitial without creating a new | 885 // Test navigating to a page that shows an interstitial without creating a new |
| 868 // navigation entry (this happens when the interstitial is triggered by a | 886 // navigation entry (this happens when the interstitial is triggered by a |
| 869 // sub-resource in the page), then hiding it without proceeding. | 887 // sub-resource in the page), then hiding it without proceeding. |
| 870 TEST_F(WebContentsTest, | 888 TEST_F(WebContentsTest, ShowInterstitialNoNewNavigationDontProceed) { |
| 871 DISABLED_ShowInterstitialNoNewNavigationDontProceed) { | |
| 872 // Navigate to a page. | 889 // Navigate to a page. |
| 873 GURL url1("http://www.google.com"); | 890 GURL url1("http://www.google.com"); |
| 874 Navigate(1, url1); | 891 Navigate(1, url1); |
| 875 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 892 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 876 | 893 |
| 877 // Show an interstitial. | 894 // Show an interstitial. |
| 878 TestInterstitialPage::InterstitialState state = | 895 TestInterstitialPage::InterstitialState state = |
| 879 TestInterstitialPage::UNDECIDED; | 896 TestInterstitialPage::UNDECIDED; |
| 880 bool deleted = false; | 897 bool deleted = false; |
| 881 GURL url2("http://interstitial"); | 898 GURL url2("http://interstitial"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 906 entry = contents->controller()->GetActiveEntry(); | 923 entry = contents->controller()->GetActiveEntry(); |
| 907 ASSERT_TRUE(entry != NULL); | 924 ASSERT_TRUE(entry != NULL); |
| 908 EXPECT_TRUE(entry->url() == url1); | 925 EXPECT_TRUE(entry->url() == url1); |
| 909 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 926 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 910 } | 927 } |
| 911 | 928 |
| 912 // Test navigating to a page (with the navigation initiated from the browser, | 929 // Test navigating to a page (with the navigation initiated from the browser, |
| 913 // as when a URL is typed in the location bar) that shows an interstitial and | 930 // as when a URL is typed in the location bar) that shows an interstitial and |
| 914 // creates a new navigation entry, then proceeding. | 931 // creates a new navigation entry, then proceeding. |
| 915 TEST_F(WebContentsTest, | 932 TEST_F(WebContentsTest, |
| 916 DISABLED_ShowInterstitialFromBrowserNewNavigationProceed) { | 933 ShowInterstitialFromBrowserNewNavigationProceed) { |
| 917 // Navigate to a page. | 934 // Navigate to a page. |
| 918 GURL url1("http://www.google.com"); | 935 GURL url1("http://www.google.com"); |
| 919 Navigate(1, url1); | 936 Navigate(1, url1); |
| 920 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 937 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 921 | 938 |
| 922 // Initiate a browser navigation that will trigger the interstitial | 939 // Initiate a browser navigation that will trigger the interstitial |
| 923 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), | 940 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), |
| 924 PageTransition::TYPED); | 941 PageTransition::TYPED); |
| 925 | 942 |
| 926 // Show an interstitial. | 943 // Show an interstitial. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 ASSERT_TRUE(entry != NULL); | 982 ASSERT_TRUE(entry != NULL); |
| 966 EXPECT_TRUE(entry->url() == url3); | 983 EXPECT_TRUE(entry->url() == url3); |
| 967 | 984 |
| 968 EXPECT_EQ(2, contents->controller()->GetEntryCount()); | 985 EXPECT_EQ(2, contents->controller()->GetEntryCount()); |
| 969 } | 986 } |
| 970 | 987 |
| 971 // Test navigating to a page (with the navigation initiated from the renderer, | 988 // Test navigating to a page (with the navigation initiated from the renderer, |
| 972 // as when clicking on a link in the page) that shows an interstitial and | 989 // as when clicking on a link in the page) that shows an interstitial and |
| 973 // creates a new navigation entry, then proceeding. | 990 // creates a new navigation entry, then proceeding. |
| 974 TEST_F(WebContentsTest, | 991 TEST_F(WebContentsTest, |
| 975 DISABLED_ShowInterstitialFromRendererNewNavigationProceed) { | 992 ShowInterstitialFromRendererNewNavigationProceed) { |
| 976 // Navigate to a page. | 993 // Navigate to a page. |
| 977 GURL url1("http://www.google.com"); | 994 GURL url1("http://www.google.com"); |
| 978 Navigate(1, url1); | 995 Navigate(1, url1); |
| 979 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 996 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 980 | 997 |
| 981 // Show an interstitial. | 998 // Show an interstitial. |
| 982 TestInterstitialPage::InterstitialState state = | 999 TestInterstitialPage::InterstitialState state = |
| 983 TestInterstitialPage::UNDECIDED; | 1000 TestInterstitialPage::UNDECIDED; |
| 984 bool deleted = false; | 1001 bool deleted = false; |
| 985 GURL url2("http://interstitial"); | 1002 GURL url2("http://interstitial"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 entry = contents->controller()->GetActiveEntry(); | 1036 entry = contents->controller()->GetActiveEntry(); |
| 1020 ASSERT_TRUE(entry != NULL); | 1037 ASSERT_TRUE(entry != NULL); |
| 1021 EXPECT_TRUE(entry->url() == url3); | 1038 EXPECT_TRUE(entry->url() == url3); |
| 1022 | 1039 |
| 1023 EXPECT_EQ(2, contents->controller()->GetEntryCount()); | 1040 EXPECT_EQ(2, contents->controller()->GetEntryCount()); |
| 1024 } | 1041 } |
| 1025 | 1042 |
| 1026 // Test navigating to a page that shows an interstitial without creating a new | 1043 // Test navigating to a page that shows an interstitial without creating a new |
| 1027 // navigation entry (this happens when the interstitial is triggered by a | 1044 // navigation entry (this happens when the interstitial is triggered by a |
| 1028 // sub-resource in the page), then proceeding. | 1045 // sub-resource in the page), then proceeding. |
| 1029 TEST_F(WebContentsTest, DISABLED_ShowInterstitialNoNewNavigationProceed) { | 1046 TEST_F(WebContentsTest, ShowInterstitialNoNewNavigationProceed) { |
| 1030 // Navigate to a page so we have a navigation entry in the controller. | 1047 // Navigate to a page so we have a navigation entry in the controller. |
| 1031 GURL url1("http://www.google.com"); | 1048 GURL url1("http://www.google.com"); |
| 1032 Navigate(1, url1); | 1049 Navigate(1, url1); |
| 1033 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1050 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 1034 | 1051 |
| 1035 // Show an interstitial. | 1052 // Show an interstitial. |
| 1036 TestInterstitialPage::InterstitialState state = | 1053 TestInterstitialPage::InterstitialState state = |
| 1037 TestInterstitialPage::UNDECIDED; | 1054 TestInterstitialPage::UNDECIDED; |
| 1038 bool deleted = false; | 1055 bool deleted = false; |
| 1039 GURL url2("http://interstitial"); | 1056 GURL url2("http://interstitial"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1064 EXPECT_FALSE(contents->showing_interstitial_page()); | 1081 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 1065 EXPECT_TRUE(contents->interstitial_page() == NULL); | 1082 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 1066 entry = contents->controller()->GetActiveEntry(); | 1083 entry = contents->controller()->GetActiveEntry(); |
| 1067 ASSERT_TRUE(entry != NULL); | 1084 ASSERT_TRUE(entry != NULL); |
| 1068 EXPECT_TRUE(entry->url() == url1); | 1085 EXPECT_TRUE(entry->url() == url1); |
| 1069 | 1086 |
| 1070 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1087 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 1071 } | 1088 } |
| 1072 | 1089 |
| 1073 // Test navigating to a page that shows an interstitial, then navigating away. | 1090 // Test navigating to a page that shows an interstitial, then navigating away. |
| 1074 TEST_F(WebContentsTest, DISABLED_ShowInterstitialThenNavigate) { | 1091 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) { |
| 1075 // Show interstitial. | 1092 // Show interstitial. |
| 1076 TestInterstitialPage::InterstitialState state = | 1093 TestInterstitialPage::InterstitialState state = |
| 1077 TestInterstitialPage::UNDECIDED; | 1094 TestInterstitialPage::UNDECIDED; |
| 1078 bool deleted = false; | 1095 bool deleted = false; |
| 1079 GURL url("http://interstitial"); | 1096 GURL url("http://interstitial"); |
| 1080 TestInterstitialPage* interstitial = | 1097 TestInterstitialPage* interstitial = |
| 1081 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1098 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1082 TestInterstitialPageStateGuard state_guard(interstitial); | 1099 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1083 interstitial->Show(); | 1100 interstitial->Show(); |
| 1084 interstitial->TestDidNavigate(1, url); | 1101 interstitial->TestDidNavigate(1, url); |
| 1085 | 1102 |
| 1086 // While interstitial showing, navigate to a new URL. | 1103 // While interstitial showing, navigate to a new URL. |
| 1087 const GURL url2("http://www.yahoo.com"); | 1104 const GURL url2("http://www.yahoo.com"); |
| 1088 Navigate(1, url2); | 1105 Navigate(1, url2); |
| 1089 | 1106 |
| 1090 EXPECT_TRUE(deleted); | 1107 EXPECT_TRUE(deleted); |
| 1091 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1108 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1092 } | 1109 } |
| 1093 | 1110 |
| 1094 // Test navigating to a page that shows an interstitial, then close the tab. | 1111 // Test navigating to a page that shows an interstitial, then close the tab. |
| 1095 TEST_F(WebContentsTest, DISABLED_ShowInterstitialThenCloseTab) { | 1112 TEST_F(WebContentsTest, ShowInterstitialThenCloseTab) { |
| 1096 // Show interstitial. | 1113 // Show interstitial. |
| 1097 TestInterstitialPage::InterstitialState state = | 1114 TestInterstitialPage::InterstitialState state = |
| 1098 TestInterstitialPage::UNDECIDED; | 1115 TestInterstitialPage::UNDECIDED; |
| 1099 bool deleted = false; | 1116 bool deleted = false; |
| 1100 GURL url("http://interstitial"); | 1117 GURL url("http://interstitial"); |
| 1101 TestInterstitialPage* interstitial = | 1118 TestInterstitialPage* interstitial = |
| 1102 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1119 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1103 TestInterstitialPageStateGuard state_guard(interstitial); | 1120 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1104 interstitial->Show(); | 1121 interstitial->Show(); |
| 1105 interstitial->TestDidNavigate(1, url); | 1122 interstitial->TestDidNavigate(1, url); |
| 1106 | 1123 |
| 1107 // Now close the tab. | 1124 // Now close the tab. |
| 1108 contents->CloseContents(); | 1125 contents->CloseContents(); |
| 1109 contents = NULL; // So we don't detroy it again on TearDown. | 1126 contents = NULL; // So we don't detroy it again on TearDown. |
| 1110 EXPECT_TRUE(deleted); | 1127 EXPECT_TRUE(deleted); |
| 1111 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1128 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1112 } | 1129 } |
| 1113 | 1130 |
| 1114 // Test that after Proceed is called and an interstitial is still shown, no more | 1131 // Test that after Proceed is called and an interstitial is still shown, no more |
| 1115 // commands get executed. | 1132 // commands get executed. |
| 1116 TEST_F(WebContentsTest, DISABLED_ShowInterstitialProceedMultipleCommands) { | 1133 TEST_F(WebContentsTest, ShowInterstitialProceedMultipleCommands) { |
| 1117 // Navigate to a page so we have a navigation entry in the controller. | 1134 // Navigate to a page so we have a navigation entry in the controller. |
| 1118 GURL url1("http://www.google.com"); | 1135 GURL url1("http://www.google.com"); |
| 1119 Navigate(1, url1); | 1136 Navigate(1, url1); |
| 1120 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1137 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 1121 | 1138 |
| 1122 // Show an interstitial. | 1139 // Show an interstitial. |
| 1123 TestInterstitialPage::InterstitialState state = | 1140 TestInterstitialPage::InterstitialState state = |
| 1124 TestInterstitialPage::UNDECIDED; | 1141 TestInterstitialPage::UNDECIDED; |
| 1125 bool deleted = false; | 1142 bool deleted = false; |
| 1126 GURL url2("http://interstitial"); | 1143 GURL url2("http://interstitial"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1140 ASSERT_FALSE(deleted); | 1157 ASSERT_FALSE(deleted); |
| 1141 | 1158 |
| 1142 // While the navigation to the new page is pending, send other commands, they | 1159 // While the navigation to the new page is pending, send other commands, they |
| 1143 // should be ignored. | 1160 // should be ignored. |
| 1144 interstitial->TestDomOperationResponse("hello"); | 1161 interstitial->TestDomOperationResponse("hello"); |
| 1145 interstitial->TestDomOperationResponse("hi"); | 1162 interstitial->TestDomOperationResponse("hi"); |
| 1146 EXPECT_EQ(1, interstitial->command_received_count()); | 1163 EXPECT_EQ(1, interstitial->command_received_count()); |
| 1147 } | 1164 } |
| 1148 | 1165 |
| 1149 // Test showing an interstitial while another interstitial is already showing. | 1166 // Test showing an interstitial while another interstitial is already showing. |
| 1150 TEST_F(WebContentsTest, DISABLED_ShowInterstitialOnInterstitial) { | 1167 TEST_F(WebContentsTest, ShowInterstitialOnInterstitial) { |
| 1151 // Navigate to a page so we have a navigation entry in the controller. | 1168 // Navigate to a page so we have a navigation entry in the controller. |
| 1152 GURL start_url("http://www.google.com"); | 1169 GURL start_url("http://www.google.com"); |
| 1153 Navigate(1, start_url); | 1170 Navigate(1, start_url); |
| 1154 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1171 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 1155 | 1172 |
| 1156 // Show an interstitial. | 1173 // Show an interstitial. |
| 1157 TestInterstitialPage::InterstitialState state1 = | 1174 TestInterstitialPage::InterstitialState state1 = |
| 1158 TestInterstitialPage::UNDECIDED; | 1175 TestInterstitialPage::UNDECIDED; |
| 1159 bool deleted1 = false; | 1176 bool deleted1 = false; |
| 1160 GURL url1("http://interstitial1"); | 1177 GURL url1("http://interstitial1"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1190 EXPECT_FALSE(contents->showing_interstitial_page()); | 1207 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 1191 EXPECT_TRUE(contents->interstitial_page() == NULL); | 1208 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 1192 NavigationEntry* entry = contents->controller()->GetActiveEntry(); | 1209 NavigationEntry* entry = contents->controller()->GetActiveEntry(); |
| 1193 ASSERT_TRUE(entry != NULL); | 1210 ASSERT_TRUE(entry != NULL); |
| 1194 EXPECT_TRUE(entry->url() == landing_url); | 1211 EXPECT_TRUE(entry->url() == landing_url); |
| 1195 EXPECT_EQ(2, contents->controller()->GetEntryCount()); | 1212 EXPECT_EQ(2, contents->controller()->GetEntryCount()); |
| 1196 } | 1213 } |
| 1197 | 1214 |
| 1198 // Test that navigating away from an interstitial while it's loading cause it | 1215 // Test that navigating away from an interstitial while it's loading cause it |
| 1199 // not to show. | 1216 // not to show. |
| 1200 TEST_F(WebContentsTest, DISABLED_NavigateBeforeInterstitialShows) { | 1217 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) { |
| 1201 // Show an interstitial. | 1218 // Show an interstitial. |
| 1202 TestInterstitialPage::InterstitialState state = | 1219 TestInterstitialPage::InterstitialState state = |
| 1203 TestInterstitialPage::UNDECIDED; | 1220 TestInterstitialPage::UNDECIDED; |
| 1204 bool deleted = false; | 1221 bool deleted = false; |
| 1205 GURL interstitial_url("http://interstitial"); | 1222 GURL interstitial_url("http://interstitial"); |
| 1206 TestInterstitialPage* interstitial = | 1223 TestInterstitialPage* interstitial = |
| 1207 new TestInterstitialPage(contents, true, interstitial_url, | 1224 new TestInterstitialPage(contents, true, interstitial_url, |
| 1208 &state, &deleted); | 1225 &state, &deleted); |
| 1209 TestInterstitialPageStateGuard state_guard(interstitial); | 1226 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1210 interstitial->Show(); | 1227 interstitial->Show(); |
| 1211 | 1228 |
| 1212 // Let's simulate a navigation initiated from the browser before the | 1229 // Let's simulate a navigation initiated from the browser before the |
| 1213 // interstitial finishes loading. | 1230 // interstitial finishes loading. |
| 1214 const GURL url("http://www.google.com"); | 1231 const GURL url("http://www.google.com"); |
| 1215 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); | 1232 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); |
| 1216 ASSERT_FALSE(deleted); | 1233 ASSERT_FALSE(deleted); |
| 1217 EXPECT_FALSE(interstitial->is_showing()); | 1234 EXPECT_FALSE(interstitial->is_showing()); |
| 1218 | 1235 |
| 1219 // Now let's make the interstitial navigation commit. | 1236 // Now let's make the interstitial navigation commit. |
| 1220 interstitial->TestDidNavigate(1, interstitial_url); | 1237 interstitial->TestDidNavigate(1, interstitial_url); |
| 1221 | 1238 |
| 1222 // After it loaded the interstitial should be gone. | 1239 // After it loaded the interstitial should be gone. |
| 1223 EXPECT_TRUE(deleted); | 1240 EXPECT_TRUE(deleted); |
| 1224 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1241 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1225 } | 1242 } |
| 1226 | 1243 |
| 1227 // Test showing an interstitial and have its renderer crash. | 1244 // Test showing an interstitial and have its renderer crash. |
| 1228 TEST_F(WebContentsTest, DISABLED_InterstitialCrasher) { | 1245 TEST_F(WebContentsTest, InterstitialCrasher) { |
| 1229 // Show an interstitial. | 1246 // Show an interstitial. |
| 1230 TestInterstitialPage::InterstitialState state = | 1247 TestInterstitialPage::InterstitialState state = |
| 1231 TestInterstitialPage::UNDECIDED; | 1248 TestInterstitialPage::UNDECIDED; |
| 1232 bool deleted = false; | 1249 bool deleted = false; |
| 1233 GURL url("http://interstitial"); | 1250 GURL url("http://interstitial"); |
| 1234 TestInterstitialPage* interstitial = | 1251 TestInterstitialPage* interstitial = |
| 1235 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1252 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1236 TestInterstitialPageStateGuard state_guard(interstitial); | 1253 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1237 interstitial->Show(); | 1254 interstitial->Show(); |
| 1238 // Simulate a renderer crash before the interstitial is shown. | 1255 // Simulate a renderer crash before the interstitial is shown. |
| 1239 interstitial->TestRendererGone(); | 1256 interstitial->TestRendererGone(); |
| 1240 // The interstitial should have been dismissed. | 1257 // The interstitial should have been dismissed. |
| 1241 EXPECT_TRUE(deleted); | 1258 EXPECT_TRUE(deleted); |
| 1242 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1259 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1243 | 1260 |
| 1244 // Now try again but this time crash the intersitial after it was shown. | 1261 // Now try again but this time crash the intersitial after it was shown. |
| 1245 interstitial = | 1262 interstitial = |
| 1246 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1263 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1247 interstitial->Show(); | 1264 interstitial->Show(); |
| 1248 interstitial->TestDidNavigate(1, url); | 1265 interstitial->TestDidNavigate(1, url); |
| 1249 // Simulate a renderer crash. | 1266 // Simulate a renderer crash. |
| 1250 interstitial->TestRendererGone(); | 1267 interstitial->TestRendererGone(); |
| 1251 // The interstitial should have been dismissed. | 1268 // The interstitial should have been dismissed. |
| 1252 EXPECT_TRUE(deleted); | 1269 EXPECT_TRUE(deleted); |
| 1253 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1270 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1254 } | 1271 } |
| OLD | NEW |