| 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 // IMPORTANT NOTE: if you pass stack allocated values for |state| and |
| 262 // |deleted| (like all interstitial related tests do at this point), make sure |
| 263 // to create an instance of the TestInterstitialPageStateGuard class on the |
| 264 // stack in your test. This will ensure that the TestInterstitialPage states |
| 265 // are cleared when the test finishes. |
| 266 // 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 |
| 268 // method and will dereference the |deleted| local variable which by then is |
| 269 // out of scope. |
| 261 TestInterstitialPage(WebContents* tab, | 270 TestInterstitialPage(WebContents* tab, |
| 262 bool new_navigation, | 271 bool new_navigation, |
| 263 const GURL& url, | 272 const GURL& url, |
| 264 InterstitialState* state, | 273 InterstitialState* state, |
| 265 bool* deleted) | 274 bool* deleted) |
| 266 : InterstitialPage(tab, new_navigation, url), | 275 : InterstitialPage(tab, new_navigation, url), |
| 267 state_(state), | 276 state_(state), |
| 268 deleted_(deleted), | 277 deleted_(deleted), |
| 269 command_received_count_(0) { | 278 command_received_count_(0) { |
| 270 *state_ = UNDECIDED; | 279 *state_ = UNDECIDED; |
| 271 *deleted_ = false; | 280 *deleted_ = false; |
| 272 } | 281 } |
| 273 | 282 |
| 274 virtual ~TestInterstitialPage() { | 283 virtual ~TestInterstitialPage() { |
| 275 *deleted_ = true; | 284 if (deleted_) |
| 285 *deleted_ = true; |
| 276 } | 286 } |
| 277 | 287 |
| 278 virtual void DontProceed() { | 288 virtual void DontProceed() { |
| 279 *state_ = CANCELED; | 289 if (state_) |
| 290 *state_ = CANCELED; |
| 280 InterstitialPage::DontProceed(); | 291 InterstitialPage::DontProceed(); |
| 281 } | 292 } |
| 282 virtual void Proceed() { | 293 virtual void Proceed() { |
| 283 *state_ = OKED; | 294 if (state_) |
| 295 *state_ = OKED; |
| 284 InterstitialPage::Proceed(); | 296 InterstitialPage::Proceed(); |
| 285 } | 297 } |
| 286 | 298 |
| 287 int command_received_count() const { | 299 int command_received_count() const { |
| 288 return command_received_count_; | 300 return command_received_count_; |
| 289 } | 301 } |
| 290 | 302 |
| 291 void TestDomOperationResponse(const std::string& json_string) { | 303 void TestDomOperationResponse(const std::string& json_string) { |
| 292 DomOperationResponse(json_string, 1); | 304 DomOperationResponse(json_string, 1); |
| 293 } | 305 } |
| 294 | 306 |
| 295 void TestDidNavigate(int page_id, const GURL& url) { | 307 void TestDidNavigate(int page_id, const GURL& url) { |
| 296 ViewHostMsg_FrameNavigate_Params params; | 308 ViewHostMsg_FrameNavigate_Params params; |
| 297 InitNavigateParams(¶ms, page_id, url); | 309 InitNavigateParams(¶ms, page_id, url); |
| 298 DidNavigate(render_view_host(), params); | 310 DidNavigate(render_view_host(), params); |
| 299 } | 311 } |
| 300 | 312 |
| 301 void TestRendererGone() { | 313 void TestRendererGone() { |
| 302 RendererGone(render_view_host()); | 314 RendererGone(render_view_host()); |
| 303 } | 315 } |
| 304 | 316 |
| 305 bool is_showing() const { | 317 bool is_showing() const { |
| 306 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> | 318 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> |
| 307 is_showing(); | 319 is_showing(); |
| 308 } | 320 } |
| 309 | 321 |
| 322 void ClearStates() { |
| 323 state_ = NULL; |
| 324 deleted_ = NULL; |
| 325 } |
| 326 |
| 310 protected: | 327 protected: |
| 311 virtual RenderViewHost* CreateRenderViewHost() { | 328 virtual RenderViewHost* CreateRenderViewHost() { |
| 312 return new TestRenderViewHost( | 329 return new TestRenderViewHost( |
| 313 SiteInstance::CreateSiteInstance(tab()->profile()), | 330 SiteInstance::CreateSiteInstance(tab()->profile()), |
| 314 this, MSG_ROUTING_NONE, NULL); | 331 this, MSG_ROUTING_NONE, NULL); |
| 315 } | 332 } |
| 316 | 333 |
| 317 virtual void CommandReceived(const std::string& command) { | 334 virtual void CommandReceived(const std::string& command) { |
| 318 command_received_count_++; | 335 command_received_count_++; |
| 319 } | 336 } |
| 320 | 337 |
| 321 private: | 338 private: |
| 322 InterstitialState* state_; | 339 InterstitialState* state_; |
| 323 bool* deleted_; | 340 bool* deleted_; |
| 324 int command_received_count_; | 341 int command_received_count_; |
| 325 }; | 342 }; |
| 326 | 343 |
| 344 class TestInterstitialPageStateGuard { |
| 345 public: |
| 346 TestInterstitialPageStateGuard(TestInterstitialPage* interstitial_page) |
| 347 : interstitial_page_(interstitial_page) { |
| 348 DCHECK(interstitial_page_); |
| 349 } |
| 350 ~TestInterstitialPageStateGuard() { |
| 351 interstitial_page_->ClearStates(); |
| 352 } |
| 353 |
| 354 private: |
| 355 TestInterstitialPage* interstitial_page_; |
| 356 }; |
| 357 |
| 327 class WebContentsTest : public testing::Test { | 358 class WebContentsTest : public testing::Test { |
| 328 public: | 359 public: |
| 329 WebContentsTest() : contents(NULL) {} | 360 WebContentsTest() : contents(NULL) {} |
| 330 | 361 |
| 331 // testing::Test methods: | 362 // testing::Test methods: |
| 332 | 363 |
| 333 virtual void SetUp() { | 364 virtual void SetUp() { |
| 334 profile.reset(new WebContentsTestingProfile()); | 365 profile.reset(new WebContentsTestingProfile()); |
| 335 | 366 |
| 336 // This will be deleted when the WebContents goes away | 367 // This will be deleted when the WebContents goes away |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), | 780 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), |
| 750 PageTransition::TYPED); | 781 PageTransition::TYPED); |
| 751 | 782 |
| 752 // Show an interstitial. | 783 // Show an interstitial. |
| 753 TestInterstitialPage::InterstitialState state = | 784 TestInterstitialPage::InterstitialState state = |
| 754 TestInterstitialPage::UNDECIDED; | 785 TestInterstitialPage::UNDECIDED; |
| 755 bool deleted = false; | 786 bool deleted = false; |
| 756 GURL url2("http://interstitial"); | 787 GURL url2("http://interstitial"); |
| 757 TestInterstitialPage* interstitial = | 788 TestInterstitialPage* interstitial = |
| 758 new TestInterstitialPage(contents, true, url2, &state, &deleted); | 789 new TestInterstitialPage(contents, true, url2, &state, &deleted); |
| 790 TestInterstitialPageStateGuard state_guard(interstitial); |
| 759 interstitial->Show(); | 791 interstitial->Show(); |
| 760 // The interstitial should not show until its navigation has committed. | 792 // The interstitial should not show until its navigation has committed. |
| 761 EXPECT_FALSE(interstitial->is_showing()); | 793 EXPECT_FALSE(interstitial->is_showing()); |
| 762 EXPECT_FALSE(contents->showing_interstitial_page()); | 794 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 763 EXPECT_TRUE(contents->interstitial_page() == NULL); | 795 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 764 // Let's commit the interstitial navigation. | 796 // Let's commit the interstitial navigation. |
| 765 interstitial->TestDidNavigate(1, url2); | 797 interstitial->TestDidNavigate(1, url2); |
| 766 EXPECT_TRUE(interstitial->is_showing()); | 798 EXPECT_TRUE(interstitial->is_showing()); |
| 767 EXPECT_TRUE(contents->showing_interstitial_page()); | 799 EXPECT_TRUE(contents->showing_interstitial_page()); |
| 768 EXPECT_TRUE(contents->interstitial_page() == interstitial); | 800 EXPECT_TRUE(contents->interstitial_page() == interstitial); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 793 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 825 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 794 | 826 |
| 795 // Show an interstitial (no pending entry, the interstitial would have been | 827 // Show an interstitial (no pending entry, the interstitial would have been |
| 796 // triggered by clicking on a link). | 828 // triggered by clicking on a link). |
| 797 TestInterstitialPage::InterstitialState state = | 829 TestInterstitialPage::InterstitialState state = |
| 798 TestInterstitialPage::UNDECIDED; | 830 TestInterstitialPage::UNDECIDED; |
| 799 bool deleted = false; | 831 bool deleted = false; |
| 800 GURL url2("http://interstitial"); | 832 GURL url2("http://interstitial"); |
| 801 TestInterstitialPage* interstitial = | 833 TestInterstitialPage* interstitial = |
| 802 new TestInterstitialPage(contents, true, url2, &state, &deleted); | 834 new TestInterstitialPage(contents, true, url2, &state, &deleted); |
| 835 TestInterstitialPageStateGuard state_guard(interstitial); |
| 803 interstitial->Show(); | 836 interstitial->Show(); |
| 804 // The interstitial should not show until its navigation has committed. | 837 // The interstitial should not show until its navigation has committed. |
| 805 EXPECT_FALSE(interstitial->is_showing()); | 838 EXPECT_FALSE(interstitial->is_showing()); |
| 806 EXPECT_FALSE(contents->showing_interstitial_page()); | 839 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 807 EXPECT_TRUE(contents->interstitial_page() == NULL); | 840 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 808 // Let's commit the interstitial navigation. | 841 // Let's commit the interstitial navigation. |
| 809 interstitial->TestDidNavigate(1, url2); | 842 interstitial->TestDidNavigate(1, url2); |
| 810 EXPECT_TRUE(interstitial->is_showing()); | 843 EXPECT_TRUE(interstitial->is_showing()); |
| 811 EXPECT_TRUE(contents->showing_interstitial_page()); | 844 EXPECT_TRUE(contents->showing_interstitial_page()); |
| 812 EXPECT_TRUE(contents->interstitial_page() == interstitial); | 845 EXPECT_TRUE(contents->interstitial_page() == interstitial); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 835 Navigate(1, url1); | 868 Navigate(1, url1); |
| 836 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 869 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 837 | 870 |
| 838 // Show an interstitial. | 871 // Show an interstitial. |
| 839 TestInterstitialPage::InterstitialState state = | 872 TestInterstitialPage::InterstitialState state = |
| 840 TestInterstitialPage::UNDECIDED; | 873 TestInterstitialPage::UNDECIDED; |
| 841 bool deleted = false; | 874 bool deleted = false; |
| 842 GURL url2("http://interstitial"); | 875 GURL url2("http://interstitial"); |
| 843 TestInterstitialPage* interstitial = | 876 TestInterstitialPage* interstitial = |
| 844 new TestInterstitialPage(contents, false, url2, &state, &deleted); | 877 new TestInterstitialPage(contents, false, url2, &state, &deleted); |
| 878 TestInterstitialPageStateGuard state_guard(interstitial); |
| 845 interstitial->Show(); | 879 interstitial->Show(); |
| 846 // The interstitial should not show until its navigation has committed. | 880 // The interstitial should not show until its navigation has committed. |
| 847 EXPECT_FALSE(interstitial->is_showing()); | 881 EXPECT_FALSE(interstitial->is_showing()); |
| 848 EXPECT_FALSE(contents->showing_interstitial_page()); | 882 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 849 EXPECT_TRUE(contents->interstitial_page() == NULL); | 883 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 850 // Let's commit the interstitial navigation. | 884 // Let's commit the interstitial navigation. |
| 851 interstitial->TestDidNavigate(1, url2); | 885 interstitial->TestDidNavigate(1, url2); |
| 852 EXPECT_TRUE(interstitial->is_showing()); | 886 EXPECT_TRUE(interstitial->is_showing()); |
| 853 EXPECT_TRUE(contents->showing_interstitial_page()); | 887 EXPECT_TRUE(contents->showing_interstitial_page()); |
| 854 EXPECT_TRUE(contents->interstitial_page() == interstitial); | 888 EXPECT_TRUE(contents->interstitial_page() == interstitial); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 882 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), | 916 contents->controller()->LoadURL(GURL("http://www.evil.com"), GURL(), |
| 883 PageTransition::TYPED); | 917 PageTransition::TYPED); |
| 884 | 918 |
| 885 // Show an interstitial. | 919 // Show an interstitial. |
| 886 TestInterstitialPage::InterstitialState state = | 920 TestInterstitialPage::InterstitialState state = |
| 887 TestInterstitialPage::UNDECIDED; | 921 TestInterstitialPage::UNDECIDED; |
| 888 bool deleted = false; | 922 bool deleted = false; |
| 889 GURL url2("http://interstitial"); | 923 GURL url2("http://interstitial"); |
| 890 TestInterstitialPage* interstitial = | 924 TestInterstitialPage* interstitial = |
| 891 new TestInterstitialPage(contents, true, url2, &state, &deleted); | 925 new TestInterstitialPage(contents, true, url2, &state, &deleted); |
| 926 TestInterstitialPageStateGuard state_guard(interstitial); |
| 892 interstitial->Show(); | 927 interstitial->Show(); |
| 893 // The interstitial should not show until its navigation has committed. | 928 // The interstitial should not show until its navigation has committed. |
| 894 EXPECT_FALSE(interstitial->is_showing()); | 929 EXPECT_FALSE(interstitial->is_showing()); |
| 895 EXPECT_FALSE(contents->showing_interstitial_page()); | 930 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 896 EXPECT_TRUE(contents->interstitial_page() == NULL); | 931 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 897 // Let's commit the interstitial navigation. | 932 // Let's commit the interstitial navigation. |
| 898 interstitial->TestDidNavigate(1, url2); | 933 interstitial->TestDidNavigate(1, url2); |
| 899 EXPECT_TRUE(interstitial->is_showing()); | 934 EXPECT_TRUE(interstitial->is_showing()); |
| 900 EXPECT_TRUE(contents->showing_interstitial_page()); | 935 EXPECT_TRUE(contents->showing_interstitial_page()); |
| 901 EXPECT_TRUE(contents->interstitial_page() == interstitial); | 936 EXPECT_TRUE(contents->interstitial_page() == interstitial); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 Navigate(1, url1); | 970 Navigate(1, url1); |
| 936 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 971 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 937 | 972 |
| 938 // Show an interstitial. | 973 // Show an interstitial. |
| 939 TestInterstitialPage::InterstitialState state = | 974 TestInterstitialPage::InterstitialState state = |
| 940 TestInterstitialPage::UNDECIDED; | 975 TestInterstitialPage::UNDECIDED; |
| 941 bool deleted = false; | 976 bool deleted = false; |
| 942 GURL url2("http://interstitial"); | 977 GURL url2("http://interstitial"); |
| 943 TestInterstitialPage* interstitial = | 978 TestInterstitialPage* interstitial = |
| 944 new TestInterstitialPage(contents, true, url2, &state, &deleted); | 979 new TestInterstitialPage(contents, true, url2, &state, &deleted); |
| 980 TestInterstitialPageStateGuard state_guard(interstitial); |
| 945 interstitial->Show(); | 981 interstitial->Show(); |
| 946 // The interstitial should not show until its navigation has committed. | 982 // The interstitial should not show until its navigation has committed. |
| 947 EXPECT_FALSE(interstitial->is_showing()); | 983 EXPECT_FALSE(interstitial->is_showing()); |
| 948 EXPECT_FALSE(contents->showing_interstitial_page()); | 984 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 949 EXPECT_TRUE(contents->interstitial_page() == NULL); | 985 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 950 // Let's commit the interstitial navigation. | 986 // Let's commit the interstitial navigation. |
| 951 interstitial->TestDidNavigate(1, url2); | 987 interstitial->TestDidNavigate(1, url2); |
| 952 EXPECT_TRUE(interstitial->is_showing()); | 988 EXPECT_TRUE(interstitial->is_showing()); |
| 953 EXPECT_TRUE(contents->showing_interstitial_page()); | 989 EXPECT_TRUE(contents->showing_interstitial_page()); |
| 954 EXPECT_TRUE(contents->interstitial_page() == interstitial); | 990 EXPECT_TRUE(contents->interstitial_page() == interstitial); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 Navigate(1, url1); | 1024 Navigate(1, url1); |
| 989 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1025 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 990 | 1026 |
| 991 // Show an interstitial. | 1027 // Show an interstitial. |
| 992 TestInterstitialPage::InterstitialState state = | 1028 TestInterstitialPage::InterstitialState state = |
| 993 TestInterstitialPage::UNDECIDED; | 1029 TestInterstitialPage::UNDECIDED; |
| 994 bool deleted = false; | 1030 bool deleted = false; |
| 995 GURL url2("http://interstitial"); | 1031 GURL url2("http://interstitial"); |
| 996 TestInterstitialPage* interstitial = | 1032 TestInterstitialPage* interstitial = |
| 997 new TestInterstitialPage(contents, false, url2, &state, &deleted); | 1033 new TestInterstitialPage(contents, false, url2, &state, &deleted); |
| 1034 TestInterstitialPageStateGuard state_guard(interstitial); |
| 998 interstitial->Show(); | 1035 interstitial->Show(); |
| 999 // The interstitial should not show until its navigation has committed. | 1036 // The interstitial should not show until its navigation has committed. |
| 1000 EXPECT_FALSE(interstitial->is_showing()); | 1037 EXPECT_FALSE(interstitial->is_showing()); |
| 1001 EXPECT_FALSE(contents->showing_interstitial_page()); | 1038 EXPECT_FALSE(contents->showing_interstitial_page()); |
| 1002 EXPECT_TRUE(contents->interstitial_page() == NULL); | 1039 EXPECT_TRUE(contents->interstitial_page() == NULL); |
| 1003 // Let's commit the interstitial navigation. | 1040 // Let's commit the interstitial navigation. |
| 1004 interstitial->TestDidNavigate(1, url2); | 1041 interstitial->TestDidNavigate(1, url2); |
| 1005 EXPECT_TRUE(interstitial->is_showing()); | 1042 EXPECT_TRUE(interstitial->is_showing()); |
| 1006 EXPECT_TRUE(contents->showing_interstitial_page()); | 1043 EXPECT_TRUE(contents->showing_interstitial_page()); |
| 1007 EXPECT_TRUE(contents->interstitial_page() == interstitial); | 1044 EXPECT_TRUE(contents->interstitial_page() == interstitial); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1027 | 1064 |
| 1028 // Test navigating to a page that shows an interstitial, then navigating away. | 1065 // Test navigating to a page that shows an interstitial, then navigating away. |
| 1029 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) { | 1066 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) { |
| 1030 // Show interstitial. | 1067 // Show interstitial. |
| 1031 TestInterstitialPage::InterstitialState state = | 1068 TestInterstitialPage::InterstitialState state = |
| 1032 TestInterstitialPage::UNDECIDED; | 1069 TestInterstitialPage::UNDECIDED; |
| 1033 bool deleted = false; | 1070 bool deleted = false; |
| 1034 GURL url("http://interstitial"); | 1071 GURL url("http://interstitial"); |
| 1035 TestInterstitialPage* interstitial = | 1072 TestInterstitialPage* interstitial = |
| 1036 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1073 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1074 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1037 interstitial->Show(); | 1075 interstitial->Show(); |
| 1038 interstitial->TestDidNavigate(1, url); | 1076 interstitial->TestDidNavigate(1, url); |
| 1039 | 1077 |
| 1040 // While interstitial showing, navigate to a new URL. | 1078 // While interstitial showing, navigate to a new URL. |
| 1041 const GURL url2("http://www.yahoo.com"); | 1079 const GURL url2("http://www.yahoo.com"); |
| 1042 Navigate(1, url2); | 1080 Navigate(1, url2); |
| 1043 | 1081 |
| 1044 EXPECT_TRUE(deleted); | 1082 EXPECT_TRUE(deleted); |
| 1045 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1083 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1046 } | 1084 } |
| 1047 | 1085 |
| 1048 // Test navigating to a page that shows an interstitial, then close the tab. | 1086 // Test navigating to a page that shows an interstitial, then close the tab. |
| 1049 TEST_F(WebContentsTest, ShowInterstitialThenCloseTab) { | 1087 TEST_F(WebContentsTest, ShowInterstitialThenCloseTab) { |
| 1050 // Show interstitial. | 1088 // Show interstitial. |
| 1051 TestInterstitialPage::InterstitialState state = | 1089 TestInterstitialPage::InterstitialState state = |
| 1052 TestInterstitialPage::UNDECIDED; | 1090 TestInterstitialPage::UNDECIDED; |
| 1053 bool deleted = false; | 1091 bool deleted = false; |
| 1054 GURL url("http://interstitial"); | 1092 GURL url("http://interstitial"); |
| 1055 TestInterstitialPage* interstitial = | 1093 TestInterstitialPage* interstitial = |
| 1056 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1094 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1095 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1057 interstitial->Show(); | 1096 interstitial->Show(); |
| 1058 interstitial->TestDidNavigate(1, url); | 1097 interstitial->TestDidNavigate(1, url); |
| 1059 | 1098 |
| 1060 // Now close the tab. | 1099 // Now close the tab. |
| 1061 contents->CloseContents(); | 1100 contents->CloseContents(); |
| 1062 contents = NULL; // So we don't detroy it again on TearDown. | 1101 contents = NULL; // So we don't detroy it again on TearDown. |
| 1063 EXPECT_TRUE(deleted); | 1102 EXPECT_TRUE(deleted); |
| 1064 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1103 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1065 } | 1104 } |
| 1066 | 1105 |
| 1067 // Test that after Proceed is called and an interstitial is still shown, no more | 1106 // Test that after Proceed is called and an interstitial is still shown, no more |
| 1068 // commands get executed. | 1107 // commands get executed. |
| 1069 // TODO(jcampan): bug #5700 Disabled because crashes on "XP Test" build bot. | 1108 TEST_F(WebContentsTest, ShowInterstitialProceedMultipleCommands) { |
| 1070 TEST_F(WebContentsTest, DISABLED_ShowInterstitialProceedMultipleCommands) { | |
| 1071 // Navigate to a page so we have a navigation entry in the controller. | 1109 // Navigate to a page so we have a navigation entry in the controller. |
| 1072 GURL url1("http://www.google.com"); | 1110 GURL url1("http://www.google.com"); |
| 1073 Navigate(1, url1); | 1111 Navigate(1, url1); |
| 1074 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1112 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 1075 | 1113 |
| 1076 // Show an interstitial. | 1114 // Show an interstitial. |
| 1077 TestInterstitialPage::InterstitialState state = | 1115 TestInterstitialPage::InterstitialState state = |
| 1078 TestInterstitialPage::UNDECIDED; | 1116 TestInterstitialPage::UNDECIDED; |
| 1079 bool deleted = false; | 1117 bool deleted = false; |
| 1080 GURL url2("http://interstitial"); | 1118 GURL url2("http://interstitial"); |
| 1081 TestInterstitialPage* interstitial = | 1119 TestInterstitialPage* interstitial = |
| 1082 new TestInterstitialPage(contents, true, url2, &state, &deleted); | 1120 new TestInterstitialPage(contents, true, url2, &state, &deleted); |
| 1121 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1083 interstitial->Show(); | 1122 interstitial->Show(); |
| 1084 interstitial->TestDidNavigate(1, url2); | 1123 interstitial->TestDidNavigate(1, url2); |
| 1085 | 1124 |
| 1086 // Run a command. | 1125 // Run a command. |
| 1087 EXPECT_EQ(0, interstitial->command_received_count()); | 1126 EXPECT_EQ(0, interstitial->command_received_count()); |
| 1088 interstitial->TestDomOperationResponse("toto"); | 1127 interstitial->TestDomOperationResponse("toto"); |
| 1089 EXPECT_EQ(1, interstitial->command_received_count()); | 1128 EXPECT_EQ(1, interstitial->command_received_count()); |
| 1090 | 1129 |
| 1091 // Then proceed. | 1130 // Then proceed. |
| 1092 interstitial->Proceed(); | 1131 interstitial->Proceed(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1106 Navigate(1, start_url); | 1145 Navigate(1, start_url); |
| 1107 EXPECT_EQ(1, contents->controller()->GetEntryCount()); | 1146 EXPECT_EQ(1, contents->controller()->GetEntryCount()); |
| 1108 | 1147 |
| 1109 // Show an interstitial. | 1148 // Show an interstitial. |
| 1110 TestInterstitialPage::InterstitialState state1 = | 1149 TestInterstitialPage::InterstitialState state1 = |
| 1111 TestInterstitialPage::UNDECIDED; | 1150 TestInterstitialPage::UNDECIDED; |
| 1112 bool deleted1 = false; | 1151 bool deleted1 = false; |
| 1113 GURL url1("http://interstitial1"); | 1152 GURL url1("http://interstitial1"); |
| 1114 TestInterstitialPage* interstitial1 = | 1153 TestInterstitialPage* interstitial1 = |
| 1115 new TestInterstitialPage(contents, true, url1, &state1, &deleted1); | 1154 new TestInterstitialPage(contents, true, url1, &state1, &deleted1); |
| 1155 TestInterstitialPageStateGuard state_guard1(interstitial1); |
| 1116 interstitial1->Show(); | 1156 interstitial1->Show(); |
| 1117 interstitial1->TestDidNavigate(1, url1); | 1157 interstitial1->TestDidNavigate(1, url1); |
| 1118 | 1158 |
| 1119 // Now show another interstitial. | 1159 // Now show another interstitial. |
| 1120 TestInterstitialPage::InterstitialState state2 = | 1160 TestInterstitialPage::InterstitialState state2 = |
| 1121 TestInterstitialPage::UNDECIDED; | 1161 TestInterstitialPage::UNDECIDED; |
| 1122 bool deleted2 = false; | 1162 bool deleted2 = false; |
| 1123 GURL url2("http://interstitial2"); | 1163 GURL url2("http://interstitial2"); |
| 1124 TestInterstitialPage* interstitial2 = | 1164 TestInterstitialPage* interstitial2 = |
| 1125 new TestInterstitialPage(contents, true, url2, &state2, &deleted2); | 1165 new TestInterstitialPage(contents, true, url2, &state2, &deleted2); |
| 1166 TestInterstitialPageStateGuard state_guard2(interstitial2); |
| 1126 interstitial2->Show(); | 1167 interstitial2->Show(); |
| 1127 interstitial2->TestDidNavigate(1, url2); | 1168 interstitial2->TestDidNavigate(1, url2); |
| 1128 | 1169 |
| 1129 // Showing interstitial2 should have caused interstitial1 to go away. | 1170 // Showing interstitial2 should have caused interstitial1 to go away. |
| 1130 EXPECT_TRUE(deleted1); | 1171 EXPECT_TRUE(deleted1); |
| 1131 EXPECT_EQ(TestInterstitialPage::CANCELED, state1); | 1172 EXPECT_EQ(TestInterstitialPage::CANCELED, state1); |
| 1132 | 1173 |
| 1133 // Let's make sure interstitial2 is working as intended. | 1174 // Let's make sure interstitial2 is working as intended. |
| 1134 ASSERT_FALSE(deleted2); | 1175 ASSERT_FALSE(deleted2); |
| 1135 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); | 1176 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1150 // not to show. | 1191 // not to show. |
| 1151 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) { | 1192 TEST_F(WebContentsTest, NavigateBeforeInterstitialShows) { |
| 1152 // Show an interstitial. | 1193 // Show an interstitial. |
| 1153 TestInterstitialPage::InterstitialState state = | 1194 TestInterstitialPage::InterstitialState state = |
| 1154 TestInterstitialPage::UNDECIDED; | 1195 TestInterstitialPage::UNDECIDED; |
| 1155 bool deleted = false; | 1196 bool deleted = false; |
| 1156 GURL interstitial_url("http://interstitial"); | 1197 GURL interstitial_url("http://interstitial"); |
| 1157 TestInterstitialPage* interstitial = | 1198 TestInterstitialPage* interstitial = |
| 1158 new TestInterstitialPage(contents, true, interstitial_url, | 1199 new TestInterstitialPage(contents, true, interstitial_url, |
| 1159 &state, &deleted); | 1200 &state, &deleted); |
| 1201 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1160 interstitial->Show(); | 1202 interstitial->Show(); |
| 1161 | 1203 |
| 1162 // Let's simulate a navigation initiated from the browser before the | 1204 // Let's simulate a navigation initiated from the browser before the |
| 1163 // interstitial finishes loading. | 1205 // interstitial finishes loading. |
| 1164 const GURL url("http://www.google.com"); | 1206 const GURL url("http://www.google.com"); |
| 1165 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); | 1207 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); |
| 1166 ASSERT_FALSE(deleted); | 1208 ASSERT_FALSE(deleted); |
| 1167 EXPECT_FALSE(interstitial->is_showing()); | 1209 EXPECT_FALSE(interstitial->is_showing()); |
| 1168 | 1210 |
| 1169 // Now let's make the interstitial navigation commit. | 1211 // Now let's make the interstitial navigation commit. |
| 1170 interstitial->TestDidNavigate(1, interstitial_url); | 1212 interstitial->TestDidNavigate(1, interstitial_url); |
| 1171 | 1213 |
| 1172 // After it loaded the interstitial should be gone. | 1214 // After it loaded the interstitial should be gone. |
| 1173 EXPECT_TRUE(deleted); | 1215 EXPECT_TRUE(deleted); |
| 1174 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1216 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1175 } | 1217 } |
| 1176 | 1218 |
| 1177 // Test showing an interstitial and have its renderer crash. | 1219 // Test showing an interstitial and have its renderer crash. |
| 1178 TEST_F(WebContentsTest, InterstitialCrasher) { | 1220 TEST_F(WebContentsTest, InterstitialCrasher) { |
| 1179 // Show an interstitial. | 1221 // Show an interstitial. |
| 1180 TestInterstitialPage::InterstitialState state = | 1222 TestInterstitialPage::InterstitialState state = |
| 1181 TestInterstitialPage::UNDECIDED; | 1223 TestInterstitialPage::UNDECIDED; |
| 1182 bool deleted = false; | 1224 bool deleted = false; |
| 1183 GURL url("http://interstitial"); | 1225 GURL url("http://interstitial"); |
| 1184 TestInterstitialPage* interstitial = | 1226 TestInterstitialPage* interstitial = |
| 1185 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1227 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1228 TestInterstitialPageStateGuard state_guard(interstitial); |
| 1186 interstitial->Show(); | 1229 interstitial->Show(); |
| 1187 // Simulate a renderer crash before the interstitial is shown. | 1230 // Simulate a renderer crash before the interstitial is shown. |
| 1188 interstitial->TestRendererGone(); | 1231 interstitial->TestRendererGone(); |
| 1189 // The interstitial should have been dismissed. | 1232 // The interstitial should have been dismissed. |
| 1190 EXPECT_TRUE(deleted); | 1233 EXPECT_TRUE(deleted); |
| 1191 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1234 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1192 | 1235 |
| 1193 // Now try again but this time crash the intersitial after it was shown. | 1236 // Now try again but this time crash the intersitial after it was shown. |
| 1194 interstitial = | 1237 interstitial = |
| 1195 new TestInterstitialPage(contents, true, url, &state, &deleted); | 1238 new TestInterstitialPage(contents, true, url, &state, &deleted); |
| 1196 interstitial->Show(); | 1239 interstitial->Show(); |
| 1197 interstitial->TestDidNavigate(1, url); | 1240 interstitial->TestDidNavigate(1, url); |
| 1198 // Simulate a renderer crash. | 1241 // Simulate a renderer crash. |
| 1199 interstitial->TestRendererGone(); | 1242 interstitial->TestRendererGone(); |
| 1200 // The interstitial should have been dismissed. | 1243 // The interstitial should have been dismissed. |
| 1201 EXPECT_TRUE(deleted); | 1244 EXPECT_TRUE(deleted); |
| 1202 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1245 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
| 1203 } | 1246 } |
| OLD | NEW |