| OLD | NEW |
| 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 "chrome/browser/chromeos/offline/offline_load_page.h" | 5 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
| 6 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 6 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 7 #include "content/public/browser/interstitial_page.h" | 7 #include "content/public/browser/interstitial_page.h" |
| 8 #include "content/public/browser/navigation_controller.h" | 8 #include "content/public/browser/navigation_controller.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/web_contents_tester.h" | 10 #include "content/public/test/web_contents_tester.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 user_response_ = PENDING; | 54 user_response_ = PENDING; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void OnBlockingPageComplete(bool proceed) { | 57 void OnBlockingPageComplete(bool proceed) { |
| 58 if (proceed) | 58 if (proceed) |
| 59 user_response_ = OK; | 59 user_response_ = OK; |
| 60 else | 60 else |
| 61 user_response_ = CANCEL; | 61 user_response_ = CANCEL; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void Navigate(const char* url, | 64 void Navigate(const char* url, int page_id) { |
| 65 int page_id, | 65 WebContentsTester::For(web_contents())->TestDidNavigate( |
| 66 int nav_entry_id, | 66 web_contents()->GetMainFrame(), page_id, GURL(url), |
| 67 bool did_create_new_entry) { | 67 ui::PAGE_TRANSITION_TYPED); |
| 68 WebContentsTester::For(web_contents()) | |
| 69 ->TestDidNavigate(web_contents()->GetMainFrame(), page_id, nav_entry_id, | |
| 70 did_create_new_entry, GURL(url), | |
| 71 ui::PAGE_TRANSITION_TYPED); | |
| 72 } | 68 } |
| 73 | 69 |
| 74 void ShowInterstitial(const char* url) { | 70 void ShowInterstitial(const char* url) { |
| 75 (new TestOfflineLoadPage(web_contents(), GURL(url), this))->Show(); | 71 (new TestOfflineLoadPage(web_contents(), GURL(url), this))->Show(); |
| 76 } | 72 } |
| 77 | 73 |
| 78 // Returns the OfflineLoadPage currently showing or NULL if none is | 74 // Returns the OfflineLoadPage currently showing or NULL if none is |
| 79 // showing. | 75 // showing. |
| 80 InterstitialPage* GetOfflineLoadPage() { | 76 InterstitialPage* GetOfflineLoadPage() { |
| 81 return InterstitialPage::GetInterstitialPage(web_contents()); | 77 return InterstitialPage::GetInterstitialPage(web_contents()); |
| 82 } | 78 } |
| 83 | 79 |
| 84 UserResponse user_response() const { return user_response_; } | 80 UserResponse user_response() const { return user_response_; } |
| 85 | 81 |
| 86 private: | 82 private: |
| 87 friend class TestOfflineLoadPage; | 83 friend class TestOfflineLoadPage; |
| 88 | 84 |
| 89 UserResponse user_response_; | 85 UserResponse user_response_; |
| 90 }; | 86 }; |
| 91 | 87 |
| 92 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { | 88 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { |
| 93 test_page_->OnBlockingPageComplete(proceed); | 89 test_page_->OnBlockingPageComplete(proceed); |
| 94 } | 90 } |
| 95 | 91 |
| 96 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { | 92 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { |
| 97 // Start a load. | 93 // Start a load. |
| 98 Navigate(kURL1, 1, 0, true); | 94 Navigate(kURL1, 1); |
| 99 // Load next page. | 95 // Load next page. |
| 100 controller().LoadURL(GURL(kURL2), content::Referrer(), | 96 controller().LoadURL(GURL(kURL2), content::Referrer(), |
| 101 ui::PAGE_TRANSITION_TYPED, std::string()); | 97 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 102 | 98 |
| 103 // Simulate the load causing an offline browsing interstitial page | 99 // Simulate the load causing an offline browsing interstitial page |
| 104 // to be shown. | 100 // to be shown. |
| 105 ShowInterstitial(kURL2); | 101 ShowInterstitial(kURL2); |
| 106 InterstitialPage* interstitial = GetOfflineLoadPage(); | 102 InterstitialPage* interstitial = GetOfflineLoadPage(); |
| 107 ASSERT_TRUE(interstitial); | 103 ASSERT_TRUE(interstitial); |
| 108 base::MessageLoop::current()->RunUntilIdle(); | 104 base::MessageLoop::current()->RunUntilIdle(); |
| 109 | 105 |
| 110 // Simulate the user clicking "proceed". | 106 // Simulate the user clicking "proceed". |
| 111 interstitial->Proceed(); | 107 interstitial->Proceed(); |
| 112 base::MessageLoop::current()->RunUntilIdle(); | 108 base::MessageLoop::current()->RunUntilIdle(); |
| 113 | 109 |
| 114 EXPECT_EQ(OK, user_response()); | 110 EXPECT_EQ(OK, user_response()); |
| 115 | 111 |
| 116 // The URL remains to be URL2. | 112 // The URL remains to be URL2. |
| 117 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec()); | 113 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec()); |
| 118 | 114 |
| 119 // Commit navigation and the interstitial page is gone. | 115 // Commit navigation and the interstitial page is gone. |
| 120 Navigate(kURL2, 2, 0, true); | 116 Navigate(kURL2, 2); |
| 121 EXPECT_FALSE(GetOfflineLoadPage()); | 117 EXPECT_FALSE(GetOfflineLoadPage()); |
| 122 } | 118 } |
| 123 | 119 |
| 124 // Tests showing an offline page and not proceeding. | 120 // Tests showing an offline page and not proceeding. |
| 125 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) { | 121 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) { |
| 126 // Start a load. | 122 // Start a load. |
| 127 Navigate(kURL1, 1, 0, true); | 123 Navigate(kURL1, 1); |
| 128 controller().LoadURL(GURL(kURL2), content::Referrer(), | 124 controller().LoadURL(GURL(kURL2), content::Referrer(), |
| 129 ui::PAGE_TRANSITION_TYPED, std::string()); | 125 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 130 | 126 |
| 131 // Simulate the load causing an offline interstitial page to be shown. | 127 // Simulate the load causing an offline interstitial page to be shown. |
| 132 ShowInterstitial(kURL2); | 128 ShowInterstitial(kURL2); |
| 133 InterstitialPage* interstitial = GetOfflineLoadPage(); | 129 InterstitialPage* interstitial = GetOfflineLoadPage(); |
| 134 ASSERT_TRUE(interstitial); | 130 ASSERT_TRUE(interstitial); |
| 135 base::MessageLoop::current()->RunUntilIdle(); | 131 base::MessageLoop::current()->RunUntilIdle(); |
| 136 | 132 |
| 137 // Simulate the user clicking "don't proceed". | 133 // Simulate the user clicking "don't proceed". |
| 138 interstitial->DontProceed(); | 134 interstitial->DontProceed(); |
| 139 | 135 |
| 140 // The interstitial should be gone. | 136 // The interstitial should be gone. |
| 141 EXPECT_EQ(CANCEL, user_response()); | 137 EXPECT_EQ(CANCEL, user_response()); |
| 142 EXPECT_FALSE(GetOfflineLoadPage()); | 138 EXPECT_FALSE(GetOfflineLoadPage()); |
| 143 // We did not proceed, the pending entry should be gone. | 139 // We did not proceed, the pending entry should be gone. |
| 144 EXPECT_FALSE(controller().GetPendingEntry()); | 140 EXPECT_FALSE(controller().GetPendingEntry()); |
| 145 // the URL is set back to kURL1. | 141 // the URL is set back to kURL1. |
| 146 EXPECT_EQ(kURL1, web_contents()->GetLastCommittedURL().spec()); | 142 EXPECT_EQ(kURL1, web_contents()->GetLastCommittedURL().spec()); |
| 147 } | 143 } |
| 148 | 144 |
| 149 } // namespace chromeos | 145 } // namespace chromeos |
| OLD | NEW |