| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cros/cros_library.h" | 5 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 6 #include "chrome/browser/chromeos/offline/offline_load_page.h" | 6 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
| 7 #include "chrome/browser/renderer_host/offline_resource_handler.h" | 7 #include "chrome/browser/renderer_host/offline_resource_handler.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/tab_contents/navigation_entry.h" | 10 #include "content/browser/tab_contents/navigation_entry.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 void OnBlockingPageComplete(bool proceed) { | 68 void OnBlockingPageComplete(bool proceed) { |
| 69 if (proceed) | 69 if (proceed) |
| 70 user_response_ = OK; | 70 user_response_ = OK; |
| 71 else | 71 else |
| 72 user_response_ = CANCEL; | 72 user_response_ = CANCEL; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void Navigate(const char* url, int page_id) { | 75 void Navigate(const char* url, int page_id) { |
| 76 ViewHostMsg_FrameNavigate_Params params; | 76 ViewHostMsg_FrameNavigate_Params params; |
| 77 InitNavigateParams(¶ms, page_id, GURL(url), PageTransition::TYPED); | 77 InitNavigateParams( |
| 78 ¶ms, page_id, GURL(url), content::PAGE_TRANSITION_TYPED); |
| 78 contents()->TestDidNavigate(contents()->render_view_host(), params); | 79 contents()->TestDidNavigate(contents()->render_view_host(), params); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void ShowInterstitial(const char* url) { | 82 void ShowInterstitial(const char* url) { |
| 82 (new TestOfflineLoadPage(contents(), GURL(url), this))->Show(); | 83 (new TestOfflineLoadPage(contents(), GURL(url), this))->Show(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Returns the OfflineLoadPage currently showing or NULL if none is | 86 // Returns the OfflineLoadPage currently showing or NULL if none is |
| 86 // showing. | 87 // showing. |
| 87 InterstitialPage* GetOfflineLoadPage() { | 88 InterstitialPage* GetOfflineLoadPage() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 | 104 |
| 104 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { | 105 void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { |
| 105 test_page_->OnBlockingPageComplete(proceed); | 106 test_page_->OnBlockingPageComplete(proceed); |
| 106 } | 107 } |
| 107 | 108 |
| 108 | 109 |
| 109 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { | 110 TEST_F(OfflineLoadPageTest, OfflinePageProceed) { |
| 110 // Start a load. | 111 // Start a load. |
| 111 Navigate(kURL1, 1); | 112 Navigate(kURL1, 1); |
| 112 // Load next page. | 113 // Load next page. |
| 113 controller().LoadURL(GURL(kURL2), GURL(), PageTransition::TYPED, | 114 controller().LoadURL(GURL(kURL2), GURL(), content::PAGE_TRANSITION_TYPED, |
| 114 std::string()); | 115 std::string()); |
| 115 | 116 |
| 116 // Simulate the load causing an offline browsing interstitial page | 117 // Simulate the load causing an offline browsing interstitial page |
| 117 // to be shown. | 118 // to be shown. |
| 118 ShowInterstitial(kURL2); | 119 ShowInterstitial(kURL2); |
| 119 InterstitialPage* interstitial = GetOfflineLoadPage(); | 120 InterstitialPage* interstitial = GetOfflineLoadPage(); |
| 120 ASSERT_TRUE(interstitial); | 121 ASSERT_TRUE(interstitial); |
| 121 MessageLoop::current()->RunAllPending(); | 122 MessageLoop::current()->RunAllPending(); |
| 122 | 123 |
| 123 // Simulate the user clicking "proceed". | 124 // Simulate the user clicking "proceed". |
| 124 interstitial->Proceed(); | 125 interstitial->Proceed(); |
| 125 MessageLoop::current()->RunAllPending(); | 126 MessageLoop::current()->RunAllPending(); |
| 126 | 127 |
| 127 EXPECT_EQ(OK, user_response()); | 128 EXPECT_EQ(OK, user_response()); |
| 128 | 129 |
| 129 // The URL remains to be URL2. | 130 // The URL remains to be URL2. |
| 130 EXPECT_EQ(kURL2, contents()->GetURL().spec()); | 131 EXPECT_EQ(kURL2, contents()->GetURL().spec()); |
| 131 | 132 |
| 132 // Commit navigation and the interstitial page is gone. | 133 // Commit navigation and the interstitial page is gone. |
| 133 Navigate(kURL2, 2); | 134 Navigate(kURL2, 2); |
| 134 EXPECT_FALSE(GetOfflineLoadPage()); | 135 EXPECT_FALSE(GetOfflineLoadPage()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 // Tests showing an offline page and not proceeding. | 138 // Tests showing an offline page and not proceeding. |
| 138 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) { | 139 TEST_F(OfflineLoadPageTest, OfflinePageDontProceed) { |
| 139 // Start a load. | 140 // Start a load. |
| 140 Navigate(kURL1, 1); | 141 Navigate(kURL1, 1); |
| 141 controller().LoadURL(GURL(kURL2), GURL(), PageTransition::TYPED, | 142 controller().LoadURL(GURL(kURL2), GURL(), content::PAGE_TRANSITION_TYPED, |
| 142 std::string()); | 143 std::string()); |
| 143 | 144 |
| 144 // Simulate the load causing an offline interstitial page to be shown. | 145 // Simulate the load causing an offline interstitial page to be shown. |
| 145 ShowInterstitial(kURL2); | 146 ShowInterstitial(kURL2); |
| 146 InterstitialPage* interstitial = GetOfflineLoadPage(); | 147 InterstitialPage* interstitial = GetOfflineLoadPage(); |
| 147 ASSERT_TRUE(interstitial); | 148 ASSERT_TRUE(interstitial); |
| 148 MessageLoop::current()->RunAllPending(); | 149 MessageLoop::current()->RunAllPending(); |
| 149 | 150 |
| 150 // Simulate the user clicking "don't proceed". | 151 // Simulate the user clicking "don't proceed". |
| 151 interstitial->DontProceed(); | 152 interstitial->DontProceed(); |
| 152 | 153 |
| 153 // The interstitial should be gone. | 154 // The interstitial should be gone. |
| 154 EXPECT_EQ(CANCEL, user_response()); | 155 EXPECT_EQ(CANCEL, user_response()); |
| 155 EXPECT_FALSE(GetOfflineLoadPage()); | 156 EXPECT_FALSE(GetOfflineLoadPage()); |
| 156 // We did not proceed, the pending entry should be gone. | 157 // We did not proceed, the pending entry should be gone. |
| 157 EXPECT_FALSE(controller().pending_entry()); | 158 EXPECT_FALSE(controller().pending_entry()); |
| 158 // the URL is set back to kURL1. | 159 // the URL is set back to kURL1. |
| 159 EXPECT_EQ(kURL1, contents()->GetURL().spec()); | 160 EXPECT_EQ(kURL1, contents()->GetURL().spec()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 } // namespace chromeos | 163 } // namespace chromeos |
| OLD | NEW |