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